:root {
  color-scheme: light;
  --ink: #182022;
  --muted: #657174;
  --paper: #f7f4ed;
  --panel: #fffdf8;
  --line: #d8d0c2;
  --accent: #0c7a75;
  --accent-strong: #075d59;
  --warn: #a85d17;
  --bad: #aa3131;
  --good: #287349;
  --neutral: #5f6769;
  --chip: #fbf8f0;
  --chip-hover: #f3efe5;
  --field: #ffffff;
  --share: #2f6150;
  --shadow: 0 18px 40px rgba(44, 39, 32, 0.14);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --ink: #edf5f4;
  --muted: #a4b7b5;
  --paper: #0c1112;
  --panel: #111a1b;
  --line: #243233;
  --accent: #21b3ab;
  --accent-strong: #1a9992;
  --warn: #d48a3b;
  --bad: #ff6b6b;
  --good: #40c77d;
  --neutral: #647476;
  --chip: #161f20;
  --chip-hover: #1e292a;
  --field: #0b1213;
  --share: #2aa37f;
  --shadow: 0 18px 40px rgba(0, 0, 0, 0.45);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    linear-gradient(135deg, rgba(12, 122, 117, 0.12), transparent 34%),
    linear-gradient(225deg, rgba(168, 93, 23, 0.13), transparent 30%),
    var(--paper);
}

body.modal-open {
  overflow: hidden;
}

button,
input,
textarea {
  font: inherit;
}

button {
  border: 0;
  border-radius: 7px;
  background: var(--accent);
  color: white;
  min-height: 42px;
  padding: 0 16px;
  font-weight: 750;
  cursor: pointer;
}

button:hover:not(:disabled),
button:focus-visible:not(:disabled) {
  background: var(--accent-strong);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

button.secondary,
.meta-button {
  background: var(--neutral);
}

.meta-pill-button {
  border: 1px solid var(--line);
  border-radius: 999px;
  min-height: 0;
  padding: 6px 10px;
  background: var(--chip);
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 800;
}

.meta-pill-button:hover:not(:disabled),
.meta-pill-button:focus-visible:not(:disabled) {
  background: var(--chip-hover);
}

.full-button {
  width: 100%;
  margin-top: 12px;
}

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

.game-panel {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(280px, 0.9fr);
  gap: 18px;
  align-items: start;
}

.top-bar,
.meta-row,
.ranking-section,
.stats-section,
.archive-section,
.guess-form,
.feedback-panel,
.hint-section,
.history-section {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.top-bar {
  grid-column: 1 / -1;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 18px;
  padding: 22px;
}

.mode-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
}

.mode-nav button {
  min-height: 36px;
  padding: 0 11px;
  background: var(--neutral);
  font-size: 0.88rem;
}

.mode-nav button.active {
  background: var(--accent);
}

.site-nav,
.content-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.site-nav a,
.content-nav a,
.content-page a {
  color: var(--accent-strong);
  font-weight: 800;
  text-decoration: none;
}

.site-nav a:hover,
.site-nav a:focus-visible,
.content-nav a:hover,
.content-nav a:focus-visible,
.content-page a:hover,
.content-page a:focus-visible {
  text-decoration: underline;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent-strong);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(2.2rem, 10vw, 4.5rem);
  line-height: 0.9;
}

h2 {
  margin-bottom: 12px;
  font-size: 1.02rem;
}

.score-card {
  min-width: 112px;
  border-left: 1px solid var(--line);
  padding-left: 18px;
  text-align: right;
}

.score-label {
  display: block;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

#score {
  display: block;
  font-size: 2.3rem;
}

.meta-row {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 10px;
  box-shadow: none;
}

.meta-row span,
.meta-button {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 0.86rem;
  font-weight: 700;
}

.meta-row span {
  color: var(--muted);
  background: var(--chip);
}

.meta-spacer {
  margin-left: auto;
}

.meta-button {
  min-height: 0;
  color: #fff;
}

.ranking-section {
  grid-row: span 4;
  padding: 18px;
}

.ranking-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.ranking-controls {
  display: flex;
  align-items: center;
  gap: 10px;
}

.value-label {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
  text-transform: uppercase;
}

.scale-label {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.scale-select {
  min-height: 32px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--neutral);
  color: var(--text);
  font-size: 0.88rem;
  font-weight: 800;
}

.scale-select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.ranking-list {
  list-style: none;
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
}

.rank-row {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 9px;
  background: linear-gradient(90deg, rgba(12, 122, 117, 0.15) var(--bar), transparent var(--bar));
}

.rank-number {
  color: var(--muted);
  font-weight: 800;
}

.rank-name {
  overflow-wrap: anywhere;
  font-weight: 800;
}

.rank-value {
  min-width: 56px;
  color: var(--accent-strong);
  font-variant-numeric: tabular-nums;
  font-weight: 800;
  text-align: right;
}

.guess-form,
.stats-section,
.archive-section,
.feedback-panel,
.hint-section,
.history-section {
  padding: 16px;
}

.section-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
}

.section-head span {
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 800;
}

.archive-section {
  grid-column: 1 / -1;
}

.archive-section[hidden] {
  display: none;
}

.archive-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin: 12px 0 10px;
}

.archive-daily {
  display: flex;
  flex: 1 1 100%;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.archive-date {
  min-width: 170px;
}

.archive-daily-open {
  flex: 0 0 auto;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--chip);
  color: var(--ink);
  font-weight: 900;
}

.archive-daily-open:hover,
.archive-daily-open:focus-visible {
  border-color: var(--accent);
  background: var(--chip-hover);
}

.archive-daily-preview {
  flex: 1 1 220px;
  min-width: 160px;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 800;
}

.archive-calendar {
  flex: 1 1 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--chip);
  padding: 10px;
}

.archive-calendar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}

.archive-cal-label {
  font-weight: 900;
  color: var(--ink);
}

.archive-cal-nav {
  flex: 0 0 auto;
  width: 36px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--neutral);
  color: var(--text);
  font-size: 1.1rem;
  font-weight: 900;
}

.archive-cal-nav:hover,
.archive-cal-nav:focus-visible {
  border-color: var(--accent);
  background: var(--chip-hover);
}

.archive-cal-weekdays {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 6px;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 900;
  text-transform: uppercase;
}

.archive-cal-weekdays span {
  text-align: center;
}

.archive-cal-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 6px;
}

.archive-cal-day {
  display: grid;
  gap: 4px;
  min-height: 54px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px;
  background: var(--neutral);
  color: var(--text);
  text-align: left;
}

.archive-cal-day:hover,
.archive-cal-day:focus-visible {
  border-color: var(--accent);
  background: var(--chip-hover);
}

.archive-cal-day[disabled] {
  cursor: not-allowed;
  opacity: 0.55;
}

.archive-cal-day[disabled]:hover,
.archive-cal-day[disabled]:focus-visible {
  border-color: var(--line);
  background: var(--neutral);
}

.archive-cal-day.is-other-month {
  opacity: 0.55;
}

.archive-cal-day.is-today {
  border-color: var(--accent);
}

.archive-cal-day.is-played {
  border-color: rgba(40, 115, 73, 0.55);
}

.archive-cal-day.is-played.is-revealed {
  border-color: rgba(170, 120, 40, 0.6);
}

.archive-cal-day strong {
  font-size: 0.9rem;
}

.archive-cal-day span {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 850;
}

.archive-search {
  flex: 1 1 220px;
  min-width: 180px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--neutral);
  color: var(--text);
  font-weight: 700;
}

.archive-filter {
  flex: 0 0 auto;
  padding: 10px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--neutral);
  color: var(--text);
  font-weight: 800;
}

.archive-clear {
  flex: 0 0 auto;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--chip);
  color: var(--ink);
  font-weight: 900;
}

.archive-clear:hover,
.archive-clear:focus-visible {
  border-color: var(--accent);
  background: var(--chip-hover);
}

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

.archive-card {
  display: grid;
  gap: 4px;
  min-height: 86px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: var(--chip);
  color: var(--ink);
  text-align: left;
}

.archive-card:hover,
.archive-card:focus-visible {
  border-color: var(--accent);
  background: var(--chip-hover);
}

.archive-card strong {
  font-size: 0.94rem;
}

.archive-card span {
  color: var(--muted);
  font-size: 0.8rem;
}

.archive-card.complete {
  border-color: rgba(40, 115, 73, 0.45);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin: 0;
}

.stats-grid div {
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 10px 8px;
  background: var(--chip);
}

.stats-grid dt {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
}

.stats-grid dd {
  margin: 2px 0 0;
  font-size: 1.2rem;
  font-weight: 850;
}

.distribution {
  display: grid;
  gap: 6px;
  margin-top: 12px;
}

.distribution-row {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr) 28px;
  gap: 8px;
  align-items: center;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}

.distribution-track {
  display: block;
  height: 10px;
  border-radius: 999px;
  background: #e8e1d4;
  overflow: hidden;
}

.distribution-fill {
  display: block;
  width: var(--fill);
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
}

.guess-form label {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 800;
}

.input-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

input {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 0 12px;
  background: var(--field);
  color: var(--ink);
}

textarea {
  width: 100%;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 10px 12px;
  background: var(--field);
  color: var(--ink);
}

input:focus,
textarea:focus {
  border-color: var(--accent);
  outline: 2px solid rgba(12, 122, 117, 0.18);
}

.feedback-panel {
  border-left: 5px solid var(--accent);
}

.feedback-panel.correct {
  border-left-color: var(--good);
}

.feedback-panel.close {
  border-left-color: var(--warn);
}

.feedback-panel.miss {
  border-left-color: var(--bad);
}

#feedback-body {
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.45;
}

.hint-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

#reset-button {
  background: var(--neutral);
}

#share-button {
  background: var(--share);
}

.hint-list,
.guess-history {
  display: grid;
  gap: 8px;
  margin: 12px 0 0;
  padding: 0;
  list-style: none;
}

.hint-list li,
.guess-history li {
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 9px 10px;
  background: var(--chip);
  line-height: 1.35;
}

.guess-history li {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.guess-history strong {
  color: var(--accent-strong);
}

.wrong-guess-note {
  margin: 12px 0;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 10px;
  color: var(--muted);
  background: var(--chip);
  line-height: 1.35;
}

.common-wrong-guess-panel {
  margin: 12px 0 0;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 10px;
  background: var(--chip);
}

.common-wrong-guess-panel h3 {
  margin: 0 0 8px;
  font-size: 14px;
  font-weight: 650;
  color: var(--muted);
}

.common-wrong-guess-list {
  margin: 0;
  padding: 0;
  display: grid;
  gap: 10px;
  list-style: none;
}

.common-wrong-guess-term {
  font-weight: 650;
  color: var(--text);
}

.common-wrong-guess-detail {
  margin-top: 3px;
  color: var(--muted);
  line-height: 1.35;
}

.wrong-guess-note:empty {
  display: none;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(24, 32, 34, 0.42);
  z-index: 10;
}

.modal-backdrop[hidden] {
  display: none;
}

.result-card {
  position: relative;
  width: min(560px, 100%);
  max-height: min(720px, calc(100vh - 32px));
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 22px;
  background: var(--panel);
  box-shadow: 0 26px 70px rgba(0, 0, 0, 0.28);
}

.close-button {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 34px;
  min-width: 34px;
  min-height: 34px;
  padding: 0;
  border-radius: 50%;
  background: var(--neutral);
}

.result-answer {
  margin-bottom: 12px;
  font-size: 1.25rem;
  font-weight: 850;
}

.result-score {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}

.result-score span {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 10px;
  color: var(--accent-strong);
  background: var(--chip);
  font-size: 0.86rem;
  font-weight: 800;
}

#result-explanation {
  color: var(--muted);
  line-height: 1.45;
}

.source-list {
  display: grid;
  gap: 8px;
  margin: 14px 0;
}

.source-list div {
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 10px;
  background: var(--chip);
}

.source-list dt {
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 800;
  text-transform: uppercase;
}

.source-list dd {
  margin: 3px 0 0;
  line-height: 1.35;
}

.related-panel {
  display: grid;
  gap: 10px;
  margin: 14px 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: var(--chip);
}

.related-panel h3 {
  margin: 0;
  font-size: 0.95rem;
}

.related-links {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.related-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 0 12px;
  text-decoration: none;
  text-align: center;
  font-weight: 800;
}

.related-link:focus-visible {
  outline: 3px solid var(--accent-strong);
  outline-offset: 2px;
}

.modal-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.how-copy p {
  color: var(--muted);
  line-height: 1.45;
}

.playtest-panel {
  display: grid;
  gap: 10px;
  margin: 14px 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: var(--chip);
}

.playtest-panel h3 {
  margin: 0;
  font-size: 0.95rem;
}

.playtest-panel label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}

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

.rating-row button {
  min-height: 36px;
  padding: 0 8px;
  background: var(--neutral);
  font-size: 0.84rem;
}

.rating-row button.active {
  background: var(--accent);
}

.playtest-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.playtest-actions button {
  flex: 1;
  min-width: 140px;
}

#playtest-status {
  margin: 0;
  color: var(--accent-strong);
  font-size: 0.84rem;
  font-weight: 800;
}

.content-shell {
  width: min(760px, 100%);
  margin: 0 auto;
  padding: 28px 16px;
}

.content-nav {
  margin-bottom: 14px;
}

.content-page {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 24px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.content-page h1 {
  margin-bottom: 18px;
}

.content-page p,
.content-page li {
  color: var(--muted);
  line-height: 1.55;
}

.content-page ul {
  padding-left: 22px;
}

.data-note {
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 10px;
  background: var(--chip);
}

.stats-page-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 12px;
  margin: 18px 0 24px;
}

.stat-card {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 14px;
  background: var(--chip);
}

.stat-label {
  margin: 0;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 800;
}

.stat-value {
  margin: 6px 0 0;
  font-size: 1.35rem;
  font-weight: 900;
}

.distribution--page {
  margin-bottom: 22px;
}

.stats-table-wrap {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  overflow: auto;
  margin: 12px 0 18px;
}

.stats-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 520px;
}

.stats-table th,
.stats-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
  color: var(--muted);
  font-size: 0.95rem;
}

.stats-table thead th {
  background: var(--neutral);
  color: var(--text);
  font-weight: 900;
  position: sticky;
  top: 0;
  z-index: 1;
}

.stats-empty {
  padding: 14px 12px;
  color: var(--muted);
  font-style: italic;
}

.pill {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 3px 10px;
  font-weight: 900;
  font-size: 0.82rem;
  border: 1px solid var(--line);
  background: var(--chip);
  color: var(--text);
}

.pill--win {
  border-color: color-mix(in srgb, var(--accent) 55%, var(--line));
}

.pill--loss {
  border-color: color-mix(in srgb, var(--danger) 55%, var(--line));
}

.stats-actions {
  display: grid;
  gap: 8px;
}

.stats-subtle {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.stats-export-pre {
  margin: 10px 0 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--neutral);
  overflow: auto;
  color: var(--text);
  font-size: 0.84rem;
  max-height: 280px;
}

.idea-form {
  display: grid;
  gap: 12px;
}

.idea-form label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-weight: 800;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

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

  .game-panel {
    grid-template-columns: 1fr;
  }

  .ranking-section {
    grid-row: auto;
  }

  .top-bar {
    align-items: flex-start;
    flex-direction: column;
    padding: 18px;
  }

  .score-card {
    width: 100%;
    border-left: 0;
    border-top: 1px solid var(--line);
    padding-top: 12px;
    min-width: 88px;
    padding-left: 0;
    text-align: left;
  }

  .mode-nav {
    justify-content: flex-start;
  }

  .site-nav {
    justify-content: flex-start;
  }

  .meta-button {
    margin-left: 0;
  }

  .input-row {
    grid-template-columns: 1fr;
  }

  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .related-links {
    grid-template-columns: 1fr;
  }

  .rating-row {
    grid-template-columns: 1fr;
  }
}
