:root {
  color-scheme: light;
  --bg: #f7f4ee;
  --surface: #fffdf8;
  --surface-strong: #ffffff;
  --text: #17201c;
  --muted: #66736d;
  --line: #d9ded4;
  --green: #27745d;
  --green-strong: #145641;
  --amber: #b96f23;
  --coral: #c75146;
  --teal-soft: #d9eee7;
  --amber-soft: #f7e4c8;
  --shadow: 0 20px 55px rgba(32, 44, 38, 0.12);
  --radius: 8px;
}

body.dark {
  color-scheme: dark;
  --bg: #141815;
  --surface: #1f2722;
  --surface-strong: #26312b;
  --text: #f4f1ea;
  --muted: #aeb9b2;
  --line: #3b4841;
  --green: #78c6a9;
  --green-strong: #9bdfc7;
  --amber: #f0b66d;
  --coral: #f08880;
  --teal-soft: #203d35;
  --amber-soft: #47331e;
  --shadow: 0 20px 55px rgba(0, 0, 0, 0.3);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  background: linear-gradient(180deg, var(--bg), var(--surface));
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  width: min(1180px, 100%);
  margin: 0 auto;
  padding: 18px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.topbar h1,
.case-header h2,
.status-card h2,
.dialog-header h2 {
  margin: 0;
  letter-spacing: 0;
}

.topbar h1 {
  font-size: clamp(2rem, 6vw, 3.75rem);
  line-height: 0.95;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--green);
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.topbar-actions,
.result-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.icon-button,
.nav-button,
.primary-button,
.secondary-button {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  min-height: 44px;
  transition:
    transform 160ms ease,
    border-color 160ms ease,
    background 160ms ease;
}

.icon-button {
  width: 42px;
  background: var(--surface-strong);
  color: var(--text);
  font-weight: 800;
  font-size: 1.05rem;
}

.nav-button {
  padding: 0 14px;
  background: var(--surface-strong);
  color: var(--text);
  font-size: 0.98rem;
  font-weight: 850;
}

.nav-button.active {
  background: var(--green);
  border-color: var(--green);
  color: #fff;
}

.icon-button:hover,
.nav-button:hover,
.primary-button:hover,
.secondary-button:hover {
  transform: translateY(-1px);
}

.game-layout,
.archive-layout {
  display: grid;
  grid-template-columns: minmax(0, 780px);
  gap: 18px;
  align-items: start;
  justify-content: center;
}

.archive-layout {
  grid-template-columns: 1fr;
}

.game-panel,
.status-card,
.help-dialog,
.result-dialog {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 253, 248, 0.88);
  box-shadow: var(--shadow);
}

body.dark .game-panel,
body.dark .status-card,
body.dark .help-dialog,
body.dark .result-dialog {
  background: rgba(31, 39, 34, 0.92);
}

.game-panel {
  padding: clamp(18px, 3vw, 32px);
}

.case-header {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: start;
  margin-bottom: 18px;
}

.case-header h2 {
  font-size: clamp(1.45rem, 4vw, 2.35rem);
  line-height: 1.06;
}

.species-chip,
.guess-pill {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  border-radius: 999px;
  padding: 5px 10px;
  white-space: nowrap;
  font-size: 0.82rem;
  font-weight: 800;
}

.species-chip {
  background: var(--teal-soft);
  color: var(--green-strong);
}

.stats-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}

.stats-row div {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-strong);
  padding: 10px 12px;
}

.stats-row span {
  display: block;
  font-size: 1.18rem;
  font-weight: 850;
}

.stats-row small {
  color: var(--muted);
}

.clue-stack {
  display: grid;
  gap: 10px;
  margin-bottom: 22px;
}

.clue {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 10px;
  border: 1px solid var(--line);
  border-left: 5px solid var(--green);
  border-radius: var(--radius);
  background: var(--surface-strong);
  padding: 14px;
}

.clue.with-guess {
  grid-template-columns: minmax(0, 1fr) minmax(190px, 250px);
  align-items: start;
}

.clue p {
  margin: 0;
  line-height: 1.45;
}

.clue.locked {
  border-left-color: var(--line);
  color: var(--muted);
}

.clue-number {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.inline-guess {
  display: grid;
  grid-template-columns: 32px minmax(0, 1fr);
  gap: 9px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--amber-soft);
  color: var(--text);
  padding: 9px;
  font-size: 0.9rem;
  font-weight: 750;
}

.inline-guess.correct {
  background: var(--teal-soft);
  border-color: var(--green);
}

.inline-guess.passed {
  background: var(--surface);
  color: var(--muted);
}

.inline-guess span:last-child {
  overflow-wrap: anywhere;
}

.guess-mark {
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--coral);
  color: #fff;
  font-size: 0.78rem;
  font-weight: 900;
}

.inline-guess.correct .guess-mark {
  background: var(--green);
}

.inline-guess.passed .guess-mark {
  background: var(--muted);
}

.guess-form {
  display: grid;
  gap: 10px;
}

.guess-actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
}

.guess-form label,
.editor-form label {
  font-weight: 800;
}

.editor-login,
.editor-form {
  display: grid;
  gap: 18px;
}

.editor-form fieldset {
  display: grid;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
}

.editor-form legend {
  padding: 0 6px;
  color: var(--green);
  font-weight: 900;
}

.editor-sheet-note {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}

.editor-sheet-note a {
  color: var(--green);
  font-weight: 850;
}

.editor-login label,
.editor-form label {
  display: grid;
  gap: 6px;
}

.editor-login input,
.editor-form input,
.editor-form textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-strong);
  color: var(--text);
  padding: 12px;
  outline: none;
}

.editor-form textarea {
  min-height: 84px;
  resize: vertical;
}

.combo-wrap {
  position: relative;
}

#guess-input {
  width: 100%;
  min-height: 52px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-strong);
  color: var(--text);
  padding: 0 14px;
  outline: none;
}

#guess-input:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 4px rgba(39, 116, 93, 0.16);
}

.suggestions {
  position: absolute;
  inset: calc(100% + 6px) 0 auto;
  z-index: 10;
  max-height: 270px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-strong);
  box-shadow: var(--shadow);
  display: none;
}

.suggestions.open {
  display: block;
}

.suggestion {
  width: 100%;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  background: transparent;
  color: var(--text);
  text-align: left;
  padding: 12px 14px;
}

.suggestion:hover,
.suggestion.active {
  background: var(--teal-soft);
}

.suggestion strong,
.suggestion span {
  display: block;
}

.suggestion span {
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.84rem;
}

.form-note {
  min-height: 21px;
  margin: 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.form-note.error {
  color: var(--coral);
  font-weight: 750;
}

.primary-button,
.secondary-button {
  padding: 0 16px;
  font-weight: 850;
}

.primary-button {
  width: 100%;
  background: var(--green);
  color: #fff;
  border-color: var(--green);
}

a.primary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}

.primary-button:disabled {
  cursor: not-allowed;
  opacity: 0.6;
  transform: none;
}

.secondary-button {
  background: var(--surface-strong);
  color: var(--text);
}

.educational-note {
  width: min(780px, 100%);
  margin: 12px auto 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-strong);
  padding: 10px 12px;
  font-size: 0.86rem;
}

.educational-note p:last-child {
  margin-bottom: 0;
}

.footer-links {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--line);
}

.footer-links button,
.footer-links a {
  border: 0;
  background: transparent;
  color: var(--green);
  padding: 0;
  font: inherit;
  font-weight: 850;
  text-decoration: none;
}

.footer-links button:hover,
.footer-links a:hover {
  text-decoration: underline;
}

.footer-links .admin-link {
  margin-left: auto;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 700;
}

.status-card {
  padding: 18px;
}

.result-below {
  width: min(780px, 100%);
  margin-left: auto;
  margin-right: auto;
  margin-top: 18px;
}

.status-card h2 {
  font-size: 1.25rem;
}

.quiet,
.empty-state,
#result-text {
  color: var(--muted);
  line-height: 1.55;
}

.archive-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(68px, 1fr));
  gap: 12px;
}

.results-summary {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 18px;
}

.results-summary div {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-strong);
  padding: 12px;
}

.results-summary strong {
  display: block;
  font-size: 1.35rem;
}

.results-summary span {
  color: var(--muted);
  font-size: 0.9rem;
}

.results-chart {
  display: grid;
  gap: 12px;
}

.result-bar-row {
  display: grid;
  grid-template-columns: 58px minmax(0, 1fr) 48px;
  gap: 12px;
  align-items: center;
}

.result-bar-track {
  min-width: 0;
  height: 28px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-strong);
  overflow: hidden;
}

.result-bar {
  height: 100%;
  border-radius: 0 var(--radius) var(--radius) 0;
  background: var(--green);
}

.result-bar-row.empty .result-bar {
  background: transparent;
}

.result-bar-row small {
  color: var(--muted);
  font-weight: 800;
}

.archive-item {
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-strong);
  padding: 8px;
}

.archive-number {
  display: inline-grid;
  place-items: center;
  width: 100%;
  min-height: 54px;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  color: var(--text);
  cursor: pointer;
  font-weight: 900;
  font-size: 1.05rem;
}

.archive-item.current {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(39, 116, 93, 0.12);
}

.archive-item.solved {
  border-color: var(--green);
  background: var(--teal-soft);
}

.archive-item.revealed {
  border-color: var(--amber);
  background: var(--amber-soft);
}

.archive-item.current .archive-number {
  color: var(--amber);
}

.archive-item.solved .archive-number {
  color: var(--green-strong);
}

.archive-item.revealed .archive-number {
  color: var(--amber);
}

.help-dialog,
.result-dialog {
  width: min(520px, calc(100% - 28px));
  color: var(--text);
  padding: 20px;
}

.help-dialog::backdrop,
.result-dialog::backdrop {
  background: rgba(0, 0, 0, 0.45);
}

.result-dialog h2 {
  margin: 10px 0 8px;
  font-size: clamp(1.8rem, 8vw, 3rem);
}

.result-dialog p:not(.eyebrow) {
  color: var(--muted);
  line-height: 1.55;
}

.dialog-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
}

@media (max-width: 860px) {
  .game-layout {
    grid-template-columns: 1fr;
  }

  .side-panel {
    grid-row: auto;
  }
}

@media (max-width: 560px) {
  .app-shell {
    padding: 14px;
  }

  .topbar {
    align-items: start;
    display: grid;
  }

  .topbar-actions {
    width: 100%;
    gap: 6px;
    flex-wrap: nowrap;
  }

  .nav-button {
    flex: 1 1 0;
    min-width: 0;
    min-height: 44px;
    padding: 0 11px;
    font-size: 0.94rem;
  }

  .icon-button {
    flex: 0 0 40px;
    width: 40px;
    min-height: 40px;
    font-size: 0.95rem;
  }

  .case-header {
    display: grid;
  }

  .stats-row {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 7px;
  }

  .stats-row div {
    padding: 8px 6px;
    text-align: center;
  }

  .stats-row span {
    font-size: 1.05rem;
  }

  .stats-row small {
    font-size: 0.76rem;
  }

  .results-summary {
    grid-template-columns: 1fr;
  }

  .result-bar-row {
    grid-template-columns: 46px minmax(0, 1fr) 42px;
  }

  .clue.with-guess {
    grid-template-columns: 1fr;
  }

  .result-actions {
    display: grid;
  }

  .secondary-button {
    width: 100%;
  }

  .guess-actions {
    grid-template-columns: 1fr;
  }

  .archive-list {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
  }

  .archive-number {
    min-height: 46px;
    font-size: 0.96rem;
  }
}

@media (max-width: 380px) {
  .topbar-actions {
    gap: 4px;
  }

  .nav-button {
    padding: 0 6px;
    font-size: 0.8rem;
  }

  .icon-button {
    flex-basis: 34px;
    width: 34px;
    min-height: 34px;
  }

  .archive-list {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}
