#theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  gap: .45rem;
  padding: .4rem .65rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  font-size: .9rem;
  font-weight: 650;
  white-space: nowrap;
}

#theme-toggle:hover, .theme-close:hover { background: var(--surface-alt); }
.theme-symbol {
  width: 1.15rem;
  height: 1.15rem;
  border: 1px solid var(--accent);
  border-radius: 50%;
  background: conic-gradient(from 35deg, var(--accent) 0 46%, var(--accent-soft) 46% 75%, var(--highlight) 75%);
}

#theme-dialog {
  width: min(49rem, calc(100% - 2rem));
  max-height: min(90dvh, 46rem);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 1rem;
  background: var(--surface);
  box-shadow: 0 24px 80px #0004;
  color: var(--ink);
  overflow: auto;
  overscroll-behavior: contain;
}

#theme-dialog::backdrop { background: rgb(8 17 24 / 62%); }
.theme-heading {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  border-bottom: 1px solid var(--line);
  padding: 1.4rem 1.6rem 1.05rem;
  background: var(--surface);
}
.theme-heading h2 { margin: 0; font: 750 1.5rem/1.3 var(--font-heading); }
.theme-heading p { margin: .4rem 0 0; color: var(--muted); font-size: .9rem; }
.theme-close {
  min-height: 40px;
  padding: .35rem .8rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  white-space: nowrap;
}
.theme-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: .65rem;
  margin: 0;
  padding: 1.25rem 1.6rem 1.6rem;
  min-inline-size: 0;
  border: 0;
}
.theme-option { position: relative; display: block; cursor: pointer; min-width: 0; }
.theme-option input {
  cursor: pointer;
  position: absolute;
  inset: 0;
  z-index: 1;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  scroll-margin: 7rem 0 1rem;
}
.theme-tile {
  display: grid;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: .55rem;
  background: var(--surface);
}
.theme-option:hover .theme-tile { border-color: var(--accent); }
.theme-option input:checked + .theme-tile {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}
.theme-option input:focus-visible + .theme-tile { outline: 3px solid var(--focus); outline-offset: 3px; }
.theme-sample {
  position: relative;
  display: block;
  overflow: hidden;
  aspect-ratio: 2 / 1;
  background: var(--hero-bg);
  color: var(--hero-ink);
}
.theme-sample-lines, .theme-sample-lines::after {
  position: absolute;
  display: block;
  width: 34%;
  height: 7%;
  top: 37%;
  left: 10%;
  border-radius: 1px;
  background: currentColor;
}
.theme-sample-lines::after { content: ""; width: 73%; height: 65%; top: 195%; left: 0; }
.theme-sample-shape {
  position: absolute;
  inset: 13% -9% 12% 56%;
  background: var(--hero-accent);
  border-radius: 3rem 0 0 .4rem;
  transform: rotate(-12deg);
}
.theme-sample-chips { position: absolute; left: 10%; bottom: 10%; display: flex; }
.theme-sample-chips i {
  width: .65rem;
  height: .65rem;
  border: 1px solid var(--hero-bg);
  border-radius: 50%;
  background: var(--surface);
}
.theme-sample-chips i:nth-child(2) { margin-left: -2px; background: var(--accent); }
.theme-sample-chips i:nth-child(3) { margin-left: -2px; background: var(--highlight); }
.theme-caption {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: .2rem;
  padding: .48rem .6rem;
  font-size: .88rem;
  font-weight: 650;
}
.theme-check {
  flex: 0 0 .95rem;
  height: .95rem;
  border: 1px solid var(--muted);
  border-radius: 50%;
}
.theme-option input:checked + .theme-tile .theme-check {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--on-accent);
}
.theme-option input:checked + .theme-tile .theme-check::after {
  content: "";
  display: block;
  width: .36rem;
  height: .2rem;
  margin: .24rem auto 0;
  border: solid currentColor;
  border-width: 0 0 2px 2px;
  transform: rotate(-45deg);
}
@media (max-width: 680px) {
  .theme-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); padding: 1rem; }
  .theme-heading { padding: 1rem; }
}
@media (max-width: 500px) {
  #theme-dialog { width: calc(100% - 1.5rem); max-height: 86dvh; }
  .theme-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .theme-sample { aspect-ratio: 2.9 / 1; }
  .headbar { gap: .3rem; }
  .head-actions { gap: .3rem; }
  #theme-toggle { min-height: 36px; padding: .35rem .45rem; gap: .28rem; }
}
@media (max-width: 400px) {
  .headbar { width: calc(100% - 20px); }
  .headbar .brand { font-size: 15px; gap: 5px; }
  .headbar .mark { width: 27px; height: 28px; padding: 4px; gap: 2px; }
  .headbar .login { padding-inline: .35rem; font-size: 13px; white-space: nowrap; }
  #theme-toggle { font-size: .8rem; }
  #theme-toggle .theme-symbol { display: none; }
}
@media (max-width: 360px) {
  .headbar .mark { display: none; }
  .headbar .brand { font-size: 14px; }
  .headbar .brand small { font-size: 9px; }
}
@media (forced-colors: active) {
  .theme-option input:checked + .theme-tile { outline: 2px solid Highlight; }
  .theme-option input:checked + .theme-tile .theme-check { forced-color-adjust: none; background: Highlight; color: HighlightText; }
}
@media print {
  #theme-toggle, #theme-dialog, #theme-dialog::backdrop { display: none !important; }
}
