:root {
  color-scheme: light;
  --brand: #b7833a;
  --brand-strong: #8e6326;
  --brand-soft: #f0e4ce;
  --brand-contrast: #ffffff;
  --muted: #6f6a5c;
  --rule: #c6bfad;
  --line-strong: #d8cfbe;
  --paper-card: #fbf8f1;
  --paper-3: #ddd7c8;
  --paper-2: #eae5da;
  --paper: #f2eee5;
  --surface-sunken: #f3efe7;
  --ink-3: #2a2b25;
  --ink-2: #1a1b17;
  --ink: #1a1712;
  --tile-amber: #e08a2b;
  --tile-teal: #2f8f83;
  --tile-indigo: #4b4fa6;
  --tile-coral: #d95c4a;
  --tile-olive: #7a8b3c;
  --tile-plum: #7e4a72;
  --shadow-sm: 0 1px 2px rgba(26, 23, 18, 0.05), 0 1px 1px rgba(26, 23, 18, 0.04);
  --shadow-md: 0 4px 16px rgba(26, 23, 18, 0.07), 0 2px 4px rgba(26, 23, 18, 0.04);
  --shadow-lg: 0 12px 40px rgba(26, 23, 18, 0.1), 0 4px 10px rgba(26, 23, 18, 0.05);
}

:root.dark {
  color-scheme: dark;
  --brand: #d5a45a;
  --brand-strong: #f0c577;
  --brand-soft: #392f20;
  --brand-contrast: #1a1712;
  --muted: #beb7a7;
  --rule: #514a3f;
  --line-strong: #665d4e;
  --paper-card: #211f1a;
  --paper-3: #38342b;
  --paper-2: #2d2a24;
  --paper: #181713;
  --surface-sunken: #12110f;
  --ink-3: #eee8dc;
  --ink-2: #f8f2e7;
  --ink: #fbf8f1;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.2);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.28);
  --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.38);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

button,
select {
  font: inherit;
}

button {
  border: 0;
  background: var(--brand);
  color: var(--brand-contrast);
  min-height: 42px;
  border-radius: 8px;
  padding: 0 16px;
  font-weight: 800;
  cursor: pointer;
}

button:hover {
  background: var(--brand-strong);
}

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

.app-shell {
  width: min(1180px, calc(100% - 32px));
  min-height: 100vh;
  margin: 0 auto;
  padding: 32px 0;
  display: grid;
  grid-template-columns: minmax(320px, 1fr) 320px;
  gap: 22px;
  align-items: start;
}

.brand-bar {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand-mark,
.hub-link,
.mini-footer a {
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  display: inline-flex;
  align-items: center;
  gap: 12px;
}

.brand-mark strong,
.brand-mark small {
  display: block;
}

.brand-mark strong {
  font-size: 1rem;
}

.brand-mark small {
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 700;
}

.mark-grid {
  display: grid;
  width: 38px;
  height: 38px;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
}

.mark-grid span {
  border-radius: 4px;
}

.mark-grid span:nth-child(1) { background: var(--tile-amber); }
.mark-grid span:nth-child(2) { background: var(--tile-teal); }
.mark-grid span:nth-child(3) { background: var(--tile-indigo); }
.mark-grid span:nth-child(4) { background: var(--tile-coral); }

.hub-link {
  border: 1px solid var(--rule);
  border-radius: 8px;
  background: var(--paper-card);
  padding: 10px 14px;
  color: var(--muted);
  font-weight: 900;
  box-shadow: var(--shadow-sm);
}

.game-panel,
.side-panel {
  background: var(--paper-card);
  border: 1px solid var(--rule);
  border-radius: 8px;
  box-shadow: var(--shadow-lg);
}

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

.side-panel {
  padding: 22px;
  position: sticky;
  top: 22px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: start;
}

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

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

h1 {
  margin-bottom: 0;
  font-size: clamp(2rem, 6vw, 4.4rem);
  line-height: 0.95;
  letter-spacing: 0;
}

h2 {
  font-size: 1.05rem;
  letter-spacing: 0;
}

.icon-button {
  width: 42px;
  padding: 0;
  background: var(--paper);
  color: var(--ink);
  border: 1px solid var(--rule);
}

.status-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin: 24px 0 18px;
}

.stat {
  border: 1px solid var(--rule);
  background: var(--surface-sunken);
  border-radius: 8px;
  padding: 12px;
}

.stat span {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.stat strong {
  display: block;
  margin-top: 5px;
  font-size: 1.3rem;
}

.board-frame {
  width: min(72vh, 100%);
  max-width: 680px;
  margin: 0 auto;
}

.board {
  --size: 4;
  display: grid;
  grid-template-columns: repeat(var(--size), 1fr);
  gap: clamp(6px, 1.2vw, 10px);
  aspect-ratio: 1;
  padding: clamp(8px, 1.6vw, 14px);
  background: var(--ink-2);
  border: 1px solid var(--ink-3);
  border-radius: 8px;
  touch-action: none;
  user-select: none;
}

.tile {
  display: grid;
  place-items: center;
  min-width: 0;
  border-radius: 7px;
  color: #1a1712;
  font-size: clamp(1.05rem, 6vw, 2.65rem);
  font-weight: 950;
  box-shadow: inset 0 -5px 0 rgba(0, 0, 0, 0.16), 0 8px 20px rgba(0, 0, 0, 0.16);
  transition: transform 120ms ease, filter 120ms ease;
}

.tile:hover {
  filter: brightness(1.04);
  transform: translateY(-1px);
}

.tile.empty {
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.04), transparent), rgba(255, 255, 255, 0.07);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.1);
}

.tile.hue-0 { background: var(--tile-amber); }
.tile.hue-1 { background: var(--tile-teal); }
.tile.hue-2 { background: var(--tile-indigo); color: #fbf8f1; }
.tile.hue-3 { background: var(--tile-coral); color: #fbf8f1; }
.tile.hue-4 { background: var(--tile-olive); }
.tile.hue-5 { background: var(--tile-plum); color: #fbf8f1; }

.message {
  min-height: 24px;
  margin: 16px 0;
  color: var(--muted);
  font-weight: 700;
  text-align: center;
}

.message.win {
  color: var(--brand);
}

.controls {
  display: grid;
  grid-template-columns: 1.35fr repeat(5, minmax(82px, 1fr));
  gap: 10px;
  align-items: end;
}

.field span {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 900;
  text-transform: uppercase;
}

select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--rule);
  border-radius: 8px;
  background: var(--surface-sunken);
  color: var(--ink);
  padding: 0 12px;
  font-weight: 800;
}

.leaderboard {
  display: grid;
  gap: 10px;
  min-height: 162px;
  margin: 0;
  padding-left: 24px;
}

.leaderboard li {
  padding: 10px 12px;
  border: 1px solid var(--rule);
  border-radius: 8px;
  background: var(--surface-sunken);
  font-weight: 800;
}

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

.help {
  margin-top: 24px;
  padding-top: 18px;
  border-top: 1px solid var(--rule);
  color: var(--muted);
  line-height: 1.55;
}

.mini-footer {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 22px;
  padding-top: 16px;
  border-top: 1px solid var(--rule);
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 800;
}

.mini-footer a {
  color: var(--brand);
}

@media (max-width: 900px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .side-panel {
    box-shadow: none;
    position: static;
  }
}

@media (max-width: 680px) {
  .app-shell {
    width: min(100% - 20px, 560px);
    padding: 10px 0;
  }

  .brand-bar {
    align-items: flex-start;
  }

  .brand-mark small {
    display: none;
  }

  .status-grid {
    grid-template-columns: 1fr 1fr 1fr;
  }

  .controls {
    grid-template-columns: 1fr 1fr;
  }

  .field {
    grid-column: 1 / -1;
  }

  .tile {
    font-size: clamp(0.9rem, 9vw, 2rem);
  }
}

/* Compact production layout: keep the full game above the fold on desktop. */
@media (min-width: 901px) {
  .app-shell {
    width: min(1120px, calc(100% - 24px));
    min-height: 100vh;
    padding: 14px 0;
    grid-template-columns: minmax(360px, 1fr) 280px;
    gap: 14px;
  }

  .brand-bar {
    min-height: 32px;
  }

  .mark-grid {
    width: 30px;
    height: 30px;
    gap: 3px;
  }

  .brand-mark {
    gap: 9px;
  }

  .brand-mark strong {
    font-size: 0.92rem;
  }

  .brand-mark small {
    font-size: 0.76rem;
  }

  .hub-link {
    padding: 7px 11px;
    font-size: 0.84rem;
  }

  .game-panel {
    padding: 14px;
  }

  .side-panel {
    padding: 14px;
    top: 14px;
  }

  .eyebrow {
    margin-bottom: 2px;
    font-size: 0.7rem;
  }

  h1 {
    font-size: clamp(2rem, 4vw, 3.2rem);
  }

  h2 {
    margin-bottom: 10px;
    font-size: 0.98rem;
  }

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

  .status-grid {
    gap: 8px;
    margin: 12px 0 10px;
  }

  .stat {
    padding: 8px 10px;
  }

  .stat span {
    font-size: 0.68rem;
  }

  .stat strong {
    margin-top: 2px;
    font-size: 1.05rem;
  }

  .board-frame {
    width: min(58vh, 100%, 520px);
    max-width: 520px;
  }

  .board {
    gap: 7px;
    padding: 10px;
  }

  .tile {
    border-radius: 6px;
    font-size: clamp(1.1rem, 4.6vh, 2.15rem);
    box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.16), 0 5px 14px rgba(0, 0, 0, 0.14);
  }

  .message {
    min-height: 20px;
    margin: 9px 0;
    font-size: 0.88rem;
  }

  .controls {
    grid-template-columns: 1.25fr repeat(3, minmax(76px, 1fr));
    gap: 8px;
  }

  .controls button,
  select {
    min-height: 36px;
    padding: 0 10px;
    font-size: 0.88rem;
  }

  .field span {
    margin-bottom: 4px;
    font-size: 0.68rem;
  }

  .leaderboard {
    gap: 7px;
    min-height: 0;
    padding-left: 20px;
  }

  .leaderboard li {
    padding: 7px 9px;
    font-size: 0.9rem;
  }

  .leaderboard span {
    font-size: 0.74rem;
  }

  .help {
    margin-top: 14px;
    padding-top: 12px;
    font-size: 0.88rem;
    line-height: 1.42;
  }

  .help p {
    margin-bottom: 0;
  }

  .mini-footer {
    margin-top: 13px;
    padding-top: 11px;
    font-size: 0.78rem;
  }
}

@media (min-width: 901px) and (max-height: 760px) {
  .brand-mark small,
  .help {
    display: none;
  }

  .app-shell {
    padding: 10px 0;
    gap: 10px;
  }

  .game-panel,
  .side-panel {
    padding: 12px;
  }

  .board-frame {
    width: min(54vh, 100%, 480px);
  }

  h1 {
    font-size: clamp(1.8rem, 3.2vw, 2.65rem);
  }

  .status-grid {
    margin: 8px 0;
  }

  .message {
    margin: 7px 0;
  }
}
