:root {
  color-scheme: light;
  --bg: #f4efe5;
  --paper: rgba(255, 251, 244, 0.88);
  --paper-strong: #fffaf1;
  --ink: #241b12;
  --muted: #756554;
  --accent: #0c7c59;
  --accent-2: #c65d1f;
  --line: rgba(36, 27, 18, 0.12);
  --shadow: 0 24px 60px rgba(75, 46, 16, 0.16);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Trebuchet MS", "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at top, rgba(230, 146, 88, 0.18), transparent 28%),
    radial-gradient(circle at bottom right, rgba(12, 124, 89, 0.15), transparent 24%),
    linear-gradient(145deg, #f8f2e8 0%, #f0e7d9 48%, #eadfcf 100%);
}

.shell {
  width: min(1200px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 24px 0 36px;
}

.hero {
  display: grid;
  grid-template-columns: 1.3fr 0.9fr;
  gap: 18px;
  align-items: stretch;
  margin-bottom: 18px;
}

.hero-copy,
.hero-stats,
.panel {
  background: var(--paper);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.45);
  border-radius: 24px;
  box-shadow: var(--shadow);
}

.hero-copy {
  padding: 24px 28px;
}

.eyebrow {
  margin: 0 0 8px;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--accent);
  font-size: 0.82rem;
  font-weight: 700;
}

h1 {
  margin: 0;
  font-size: clamp(2rem, 4vw, 3.4rem);
  line-height: 1;
}

.intro {
  margin: 14px 0 0;
  max-width: 54ch;
  color: var(--muted);
  line-height: 1.6;
}

.hero-stats {
  padding: 16px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.stat {
  padding: 16px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.58);
  border: 1px solid rgba(36, 27, 18, 0.08);
}

.stat span {
  display: block;
  font-size: 0.84rem;
  color: var(--muted);
  margin-bottom: 8px;
}

.stat strong {
  font-size: 1.2rem;
}

.board {
  display: grid;
  grid-template-columns: minmax(0, 1.7fr) minmax(300px, 0.9fr);
  gap: 18px;
  align-items: start;
}

.site-footer {
  margin: 24px 0 0;
  padding: 8px 4px 0;
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
}

.site-footer p {
  margin: 0;
}

.site-footer a {
  color: var(--accent);
  text-decoration: none;
}

.site-footer a:hover {
  text-decoration: underline;
}

#game-canvas {
  width: 100%;
  height: auto;
  display: block;
  border-radius: 28px;
  box-shadow: var(--shadow);
  background: #f9f4ea;
}

.panel {
  padding: 20px;
}

.guess-form label,
.message-box h2,
.history-box h2,
.challenge-box h2 {
  font-size: 0.95rem;
  margin: 0 0 10px;
}

.mode-box {
  padding: 16px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.56);
  border: 1px solid rgba(36, 27, 18, 0.08);
}

.mode-switch {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.mode-btn {
  padding: 12px 14px;
}

.mode-btn.active {
  background: linear-gradient(135deg, #0c7c59, #13936b);
  color: #fff9f0;
}

.mode-note,
.challenge-meta {
  margin: 12px 0 0;
  color: var(--muted);
  line-height: 1.55;
  font-size: 0.9rem;
}

.challenge-meta.subtle {
  margin-top: 6px;
  font-size: 0.84rem;
}

.guess-row {
  display: flex;
  gap: 10px;
}

input,
select,
button {
  font: inherit;
}

input,
select {
  flex: 1;
  min-width: 0;
  border: 1px solid rgba(36, 27, 18, 0.14);
  background: var(--paper-strong);
  border-radius: 14px;
  padding: 14px 16px;
  color: var(--ink);
}

input:focus,
select:focus {
  outline: 2px solid rgba(12, 124, 89, 0.25);
  border-color: rgba(12, 124, 89, 0.4);
}

button {
  border: 0;
  border-radius: 14px;
  padding: 14px 18px;
  cursor: pointer;
  color: #fff9f0;
  background: linear-gradient(135deg, #0c7c59, #13936b);
  transition: transform 120ms ease, filter 120ms ease;
}

button:hover {
  transform: translateY(-1px);
  filter: brightness(1.03);
}

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
  filter: none;
}

button.secondary {
  color: var(--ink);
  background: #ead9c0;
}

button.danger {
  background: linear-gradient(135deg, #b4451f, #d36629);
}

.hint {
  margin: 10px 2px 0;
  color: var(--muted);
  font-size: 0.88rem;
}

.actions {
  margin: 16px 0;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

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

.challenge-head span {
  color: var(--accent);
  font-size: 0.88rem;
  font-weight: 700;
}

.challenge-submit-form {
  margin-top: 14px;
}

.challenge-history-picker {
  margin-top: 14px;
}

.challenge-history-picker label {
  display: block;
  margin-bottom: 8px;
  font-size: 0.9rem;
  font-weight: 700;
}

.challenge-history-controls {
  display: flex;
  gap: 10px;
}

.challenge-history-controls select {
  flex: 1;
  min-width: 0;
}

.challenge-preview {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px dashed rgba(36, 27, 18, 0.12);
}

#challenge-preview-canvas {
  width: 100%;
  height: auto;
  display: block;
  border-radius: 16px;
  background: rgba(255, 250, 241, 0.82);
  border: 1px solid rgba(36, 27, 18, 0.08);
}

.challenge-preview-answer {
  margin: 10px 0 0;
  color: var(--ink);
  font-family: "Courier New", monospace;
  word-break: break-word;
}

.toggle-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 4px 0 0;
  color: var(--ink);
  font-size: 0.95rem;
}

.toggle-row input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
  flex: none;
  padding: 0;
  border: 0;
  background: transparent;
  border-radius: 0;
}

.message-box,
.history-box,
.challenge-box {
  margin-top: 18px;
  padding: 16px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.56);
  border: 1px solid rgba(36, 27, 18, 0.08);
}

.message-box p {
  margin: 0;
  line-height: 1.6;
  color: var(--muted);
}

.answer-box p {
  font-family: "Courier New", monospace;
  color: var(--ink);
  word-break: break-word;
}

.history-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: baseline;
  margin-bottom: 10px;
}

.history-head span {
  color: var(--muted);
  font-size: 0.88rem;
}

.history-list {
  margin: 0;
  padding-left: 20px;
  max-height: 360px;
  overflow: auto;
}

.history-list li {
  padding: 8px 0;
  border-bottom: 1px dashed rgba(36, 27, 18, 0.08);
}

.history-list li:last-child {
  border-bottom: 0;
}

.leaderboard-list {
  margin: 0;
  padding-left: 0;
  list-style: none;
  max-height: 320px;
  overflow: auto;
}

.leaderboard-list li {
  padding: 10px 0;
  border-bottom: 1px dashed rgba(36, 27, 18, 0.08);
}

.leaderboard-list li:last-child {
  border-bottom: 0;
}

.leaderboard-name {
  display: flex;
  align-items: baseline;
  gap: 10px;
  font-weight: 700;
}

.leaderboard-rank {
  color: var(--accent);
  min-width: 2.2em;
}

.leaderboard-stats,
.leaderboard-answer {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.5;
}

.leaderboard-answer {
  font-family: "Courier New", monospace;
  color: var(--ink);
  word-break: break-word;
}

.guess-expr {
  font-family: "Courier New", monospace;
  font-weight: 700;
}

.guess-loss {
  color: var(--muted);
  font-size: 0.88rem;
}

@media (max-width: 980px) {
  .hero,
  .board {
    grid-template-columns: 1fr;
  }

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

@media (max-width: 640px) {
  .shell {
    width: min(100vw - 20px, 1200px);
    padding-top: 14px;
  }

  .hero-copy,
  .hero-stats,
  .panel {
    border-radius: 20px;
  }

  .hero-stats {
    grid-template-columns: 1fr;
  }

  .challenge-history-controls,
  .guess-row {
    flex-direction: column;
  }

  .actions {
    flex-direction: column;
  }
}
