:root {
  --paper: #f8f5ec;
  --paper-shadow: #ece6d7;
  --ink: #1f1d1a;
  --muted-ink: #5f594c;
  --accent: #8c2f17;
  --line: #cabfa7;
  --card: #fcfaf4;
  --body-top: #f3ecdb;
  --body-bottom: #e6ddc8;
  --body-burst: #fff8e3;
  --header-top: rgba(255, 255, 255, 0.72);
  --header-bottom: rgba(255, 255, 255, 0.28);
  --button-text: #fdfaf2;
  --button-hover: #0f0e0b;
  --input-border: #b7ab90;
  --input-bg: #fffef8;
  --grain-opacity: 0.15;
  --shadow: 0 6px 20px rgba(64, 40, 8, 0.08);
  --theme-chip-bg: rgba(255, 252, 244, 0.75);
  --theme-chip-border: #a89b7f;
  --badge-line: #aa9874;
  --badge-bg: #f4eddc;
  --result-line: #d5c8af;
  --result-bg: #fffcf4;
  --empty-line: #b8ab91;
  --empty-bg: #fffdf7;
}

body[data-theme="playful"] {
  --paper: #fffdf6;
  --paper-shadow: #ffe2bf;
  --ink: #17324f;
  --muted-ink: #4d6885;
  --accent: #ff7a59;
  --line: #ffd59c;
  --card: #fffefb;
  --body-top: #fff9c9;
  --body-bottom: #cff6ee;
  --body-burst: #ffe2ef;
  --header-top: rgba(255, 255, 255, 0.86);
  --header-bottom: rgba(255, 232, 188, 0.72);
  --button-text: #ffffff;
  --button-hover: #ef6948;
  --input-border: #ffbe73;
  --input-bg: #ffffff;
  --grain-opacity: 0.08;
  --shadow: 0 10px 28px rgba(255, 122, 89, 0.16);
  --theme-chip-bg: rgba(255, 255, 255, 0.9);
  --theme-chip-border: #ffb44d;
  --badge-line: #ffb44d;
  --badge-bg: #fff1b8;
  --result-line: #ffd7a1;
  --result-bg: #fffdfc;
  --empty-line: #ffbf8d;
  --empty-bg: #fff7e8;
}

body[data-theme="editorial"] {
  --paper: #f4f6f7;
  --paper-shadow: #d0dbe3;
  --ink: #1a2332;
  --muted-ink: #4a5a6e;
  --accent: #2a7a6f;
  --line: #c0cad2;
  --card: #f9fafb;
  --body-top: #e8edf2;
  --body-bottom: #d8e2ea;
  --body-burst: #e0f0ed;
  --header-top: rgba(255, 255, 255, 0.78);
  --header-bottom: rgba(216, 230, 238, 0.5);
  --button-text: #ffffff;
  --button-hover: #1f5e56;
  --input-border: #9aadb8;
  --input-bg: #ffffff;
  --grain-opacity: 0.10;
  --shadow: 0 6px 20px rgba(26, 35, 50, 0.09);
  --theme-chip-bg: rgba(255, 255, 255, 0.82);
  --theme-chip-border: #9aadb8;
  --badge-line: #7fb3ad;
  --badge-bg: #e4f3f1;
  --result-line: #b2c4ce;
  --result-bg: #f7fafb;
  --empty-line: #9fb8c4;
  --empty-bg: #f4f8fa;
}

body[data-theme="mocha"] {
  --paper: #faf4ec;
  --paper-shadow: #e8d5be;
  --ink: #2c1a0e;
  --muted-ink: #7a5c44;
  --accent: #8b5e3c;
  --line: #d4b896;
  --card: #fdf8f2;
  --body-top: #ede0cf;
  --body-bottom: #d9c5ae;
  --body-burst: #f5e8d4;
  --header-top: rgba(253, 248, 242, 0.84);
  --header-bottom: rgba(237, 224, 207, 0.55);
  --button-text: #fdf8f2;
  --button-hover: #5c3a22;
  --input-border: #c4a07a;
  --input-bg: #fffefb;
  --grain-opacity: 0.14;
  --shadow: 0 6px 20px rgba(44, 26, 14, 0.10);
  --theme-chip-bg: rgba(253, 248, 242, 0.82);
  --theme-chip-border: #c4a07a;
  --badge-line: #c69060;
  --badge-bg: #f5e8d4;
  --result-line: #d4b896;
  --result-bg: #fdfaf5;
  --empty-line: #c4a07a;
  --empty-bg: #fdf8f2;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 20% 0%, var(--body-burst) 0%, transparent 35%),
    linear-gradient(180deg, var(--body-top) 0%, var(--body-bottom) 100%);
  font-family: Verdana, Geneva, Tahoma, sans-serif;
  min-height: 100vh;
  position: relative;
  transition: background 220ms ease, color 220ms ease;
}

a {
  color: inherit;
}

.paper-grain {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image: radial-gradient(rgba(0, 0, 0, 0.05) 0.5px, transparent 0.5px);
  background-size: 3px 3px;
  opacity: var(--grain-opacity);
}

.site-shell {
  width: min(1100px, calc(100vw - 32px));
  margin: 20px auto 32px;
}

.masthead {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 1rem;
  padding: 1rem;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  background: linear-gradient(180deg, var(--header-top), var(--header-bottom));
}

.header-controls {
  display: flex;
  align-items: center;
  justify-self: end;
  gap: 0.6rem;
}

.brand-block {
  min-width: 0;
}

.brand-block a {
  display: inline-flex;
  align-items: center;
  text-decoration: none;
}

.brand-mark {
  display: inline-flex;
  align-items: center;
  gap: 0.7rem;
}

.brand-icon {
  width: 64px;
  height: 64px;
  flex: 0 0 auto;
  object-fit: contain;
}

.edition {
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  font-size: 0.74rem;
  color: var(--muted-ink);
}

.masthead h1 {
  font-family: "Libre Baskerville", "Times New Roman", serif;
  font-size: clamp(2rem, 4vw, 3rem);
  margin: 0.2rem 0 0;
}

.tagline {
  margin: 0;
  color: var(--muted-ink);
  font-size: 0.98rem;
  grid-column: 1 / -1;
  padding-top: 0.65rem;
  border-top: 1px solid rgba(202, 191, 167, 0.8);
}

.menu-toggle {
  display: none;
  flex-direction: column;
  gap: 4px;
  padding: 0.5rem;
  border-color: var(--theme-chip-border);
  background: var(--theme-chip-bg);
}

.theme-toggle {
  border-color: var(--theme-chip-border);
  background: var(--theme-chip-bg);
  color: var(--ink);
  font-weight: 600;
  white-space: nowrap;
}

.theme-toggle:hover {
  border-color: var(--accent);
}

.menu-toggle span {
  display: block;
  width: 22px;
  height: 2px;
  background: var(--ink);
}

.masthead[data-has-menu="false"] .menu-toggle,
.masthead[data-has-menu="false"] .site-nav {
  display: none;
}

.site-nav {
  justify-self: end;
}

.menu-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  align-items: center;
  gap: 1rem;
}

.menu-list a {
  text-decoration: none;
  font-weight: 600;
  white-space: nowrap;
}

.content-grid {
  margin-top: 1rem;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 1rem;
}

.main-column {
  min-width: 0;
  display: grid;
  grid-template-rows: auto;
  row-gap: 1rem;
}

.sidebar-column {
  width: 320px;
  display: grid;
  gap: 1rem;
}

.panel {
  background: var(--card);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  padding: 1.2rem;
  animation: riseIn 450ms ease both;
  transition: background 220ms ease, border-color 220ms ease, box-shadow 220ms ease;
}

.search-panel {
  position: relative;
  z-index: 1;
  animation-delay: 120ms;
}

.results-panel {
  animation-delay: 210ms;
}

.sidebar-card {
  align-content: start;
}

.sidebar-copy,
.sidebar-list {
  color: var(--muted-ink);
}

.sidebar-list {
  margin: 0;
  padding-left: 1.1rem;
}

h2 {
  font-family: "Libre Baskerville", "Times New Roman", serif;
  margin-top: 0;
  margin-bottom: 0.6rem;
  font-size: 1.35rem;
}

.lede {
  color: var(--muted-ink);
  margin-top: 0;
}

label {
  display: block;
  margin-top: 0.75rem;
  margin-bottom: 0.35rem;
  font-weight: 600;
}

.autocomplete {
  position: relative;
}

input {
  width: 100%;
  border: 1px solid var(--input-border);
  background: var(--input-bg);
  border-radius: 4px;
  padding: 0.66rem 0.7rem;
  font-size: 1rem;
  font-family: inherit;
}

input:focus {
  outline: 2px solid rgba(140, 47, 23, 0.32);
  border-color: var(--accent);
}

.hint {
  margin: 0.35rem 0 0;
  color: var(--muted-ink);
  font-size: 0.92rem;
}

.autocomplete-list {
  list-style: none;
  margin: 0.3rem 0 0;
  padding: 0.3rem;
  position: absolute;
  left: 0;
  right: 0;
  z-index: 20;
  border: 1px solid var(--result-line);
  border-radius: 10px;
  background: var(--card);
  box-shadow: 0 10px 30px rgba(32, 22, 16, 0.12);
  display: grid;
  gap: 0.15rem;
}

.autocomplete-list[hidden] {
  display: none !important;
}

.autocomplete-option {
  padding: 0.65rem 0.8rem;
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  color: var(--ink);
  font-weight: 600;
  transition: background 140ms ease, border-color 140ms ease, color 140ms ease, box-shadow 140ms ease;
}

.autocomplete-option:hover {
  background: var(--empty-bg);
  border-color: var(--result-line);
}

.autocomplete-option.is-active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--button-text);
  box-shadow: 0 0 0 2px rgba(140, 47, 23, 0.18);
}

.autocomplete-status {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.inline-filters {
  margin-top: 0.5rem;
}

.actions {
  margin-top: 1rem;
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
}

button {
  font: inherit;
  border: 1px solid transparent;
  border-radius: 4px;
  cursor: pointer;
  padding: 0.6rem 1rem;
}

.btn-primary {
  background: var(--accent);
  color: var(--button-text);
}

.btn-primary:hover {
  background: var(--button-hover);
}

.btn-ghost {
  background: transparent;
  border-color: var(--theme-chip-border);
  color: var(--ink);
}

.results-head {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: baseline;
  flex-wrap: wrap;
}

.mode-label {
  margin: 0;
  color: var(--muted-ink);
  font-size: 0.95rem;
}

.results-list {
  list-style: none;
  margin: 0.8rem 0 0;
  padding: 0;
  display: grid;
  gap: 0.95rem;
}

.result-group {
  list-style: none;
}

.result-group-title {
  margin: 0;
  padding: 0.38rem 0.6rem;
  border-radius: 4px;
  background: var(--accent);
  color: var(--button-text);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 1.15rem;
  font-weight: 700;
  line-height: 1;
  letter-spacing: 0.02em;
  text-transform: lowercase;
}

.result-group-list {
  list-style: none;
  margin: 0.7rem 0 0;
  padding: 0;
  display: grid;
  gap: 0.5rem;
}

.result-item {
  border: 0;
  background: transparent;
  padding: 0;
}

.result-link {
  display: inline-block;
  text-decoration: none;
}

.result-link:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.result-word {
  display: inline-flex;
  align-items: center;
  gap: 2px;
}

.letter-tile {
  min-width: 1.45rem;
  height: 1.62rem;
  border: 1px solid var(--result-line);
  background: var(--result-bg);
  color: var(--ink);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 1.05rem;
  font-weight: 500;
  line-height: 1;
}

.empty-state {
  border: 1px dashed var(--empty-line);
  padding: 1rem;
  margin-top: 0.9rem;
  background: var(--empty-bg);
}

.empty-state h3 {
  margin: 0 0 0.3rem;
}

.empty-state p {
  color: var(--muted-ink);
}

.pagination {
  margin-top: 1rem;
  border-top: 1px solid var(--line);
  padding-top: 0.85rem;
}

.pagination-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.pagination-pages {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  align-items: center;
}

.pagination-control,
.pagination-page,
.pagination-ellipsis {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 2.25rem;
  padding: 0.15rem 0.85rem;
  border: 1px solid transparent;
  border-radius: 999px;
  background: var(--empty-bg);
  color: var(--ink);
  text-decoration: none;
  font-size: 0.92rem;
  font-weight: 600;
  line-height: 1;
  white-space: nowrap;
}

.pagination-control,
.pagination-page {
  border-color: var(--result-line);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.02);
}

.pagination-control:hover,
.pagination-page:hover {
  border-color: var(--accent);
  background: var(--result-bg);
}

.pagination-control:focus-visible,
.pagination-page:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.pagination-page.is-current {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--button-text);
  font-weight: 700;
}

.pagination-ellipsis {
  min-width: 2rem;
  border-style: dashed;
  color: var(--muted-ink);
  background: transparent;
  padding-inline: 0.35rem;
}

.pagination-control {
  flex: 0 0 auto;
}

.pagination-control-primary {
  background: var(--accent);
  color: var(--button-text);
  border-color: var(--accent);
}

.pagination-control-primary:hover {
  background: var(--button-hover);
  border-color: var(--button-hover);
}

.pagination-control-secondary {
  background: var(--result-bg);
}

.pagination-control.is-disabled {
  opacity: 0.48;
  pointer-events: none;
}

.pagination-pages:empty {
  display: none;
}

.footer-note {
  text-align: center;
  border-top: 1px solid var(--line);
  color: var(--muted-ink);
  padding: 0.9rem;
  font-size: 0.9rem;
  margin-top: 1rem;
}

@keyframes riseIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 980px) {
  .masthead {
    grid-template-columns: 1fr auto;
  }

  .header-controls {
    justify-self: end;
  }

  .menu-toggle {
    display: inline-flex;
  }

  .site-nav {
    grid-column: 1 / -1;
    justify-self: stretch;
  }

  .menu-list {
    display: none;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.75rem;
    padding-top: 0.9rem;
    border-top: 1px solid rgba(202, 191, 167, 0.8);
  }

  .site-shell.menu-open .menu-list {
    display: flex;
  }
}

@media (max-width: 900px) {
  .content-grid {
    grid-template-columns: 1fr;
  }

  .sidebar-column {
    width: auto;
  }
}

@media (max-width: 560px) {
  .site-shell {
    width: calc(100vw - 20px);
    margin-top: 20px;
  }

  .masthead {
    padding: 1rem;
  }

  .header-controls {
    gap: 0.4rem;
  }

  .theme-toggle {
    padding-inline: 0.75rem;
  }

  .theme-toggle-label {
    font-size: 0.9rem;
  }

  .panel {
    padding: 1rem;
  }

  .actions {
    flex-direction: column;
  }

  button {
    width: 100%;
  }

  .pagination-bar {
    gap: 0.65rem;
    justify-content: center;
  }

  .pagination-control,
  .pagination-page,
  .pagination-ellipsis {
    min-height: 2.1rem;
  }

  .pagination-pages {
    order: 3;
    width: 100%;
    justify-content: center;
  }

  .pagination-control-secondary {
    order: 1;
  }

  .pagination-control-primary {
    order: 2;
  }

  .pagination-pages,
  .pagination-bar {
    text-align: center;
  }
}
