:root {
  color-scheme: light;
  --paper: #faf7ed;
  --ink: #172243;
  --muted: #535d72;
  --edge: #d9d4c8;
  --blue: #234ad9;
  --blue-edge: #132d9f;
  --coral: #ff9f8c;
  --coral-edge: #a94130;
  --lime: #d9ec86;
  --white: #fffdf6;
  --tile-size: 66px;
  --tile-gap: 12px;
  font-family:"Helvetica Neue",Arial,sans-serif;
  font-size: 16px;
  color: var(--ink);
  background: var(--paper);
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
body { min-width: 0; margin: 0; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; }
button:disabled { cursor: default; }
a { color: var(--blue-edge); }
:focus-visible { outline: 3px solid var(--blue-edge); outline-offset: 5px; }
h1, h2, h3, p { margin: 0; }

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 72px;
  max-width: 1170px;
  margin: auto;
  padding: 13px 34px;
  border-bottom: 1px solid var(--edge);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 11px;
  border: 0;
  padding: 0;
  background: transparent;
  font-weight: 850;
  letter-spacing: -.035em;
  text-decoration: none;
  color: var(--ink);
}

.brand-mark {
  display: grid;
  place-items: center;
  flex: 0 0 37px;
  width: 37px;
  height: 35px;
  border: 1.5px solid var(--blue-edge);
  border-radius: 7px;
  background: var(--blue);
  color: white;
  box-shadow: 0 3px var(--blue-edge);
  transform: rotate(-8deg);
  font-weight: 850;
}

.app-shell { max-width: 1100px; margin: auto; padding: 0 34px 42px; }
.app-shell:focus { outline: none; }
.screen { margin: auto; animation: screen-in .22s ease both; }
@keyframes screen-in {
  from { opacity: 0; transform: translateY(5px); }
  to { opacity: 1; transform: translateY(0); }
}

.home-screen { max-width: 850px; padding: clamp(48px, 9vh, 98px) 0 22px; text-align: center; }
.hero-eyebrow, .game-label, .tutorial-meta, .hint-heading {
  color: var(--blue-edge);
  font-size: .76rem;
  font-weight: 850;
  letter-spacing: .12em;
  text-transform: uppercase;
}

.hero-title {
  margin: 9px 0 12px;
  font-size: clamp(3rem, 9.4vw, 7.25rem);
  font-weight: 900;
  letter-spacing: -.065em;
  line-height: .94;
  text-wrap: balance;
}

.hero-subtitle { font-size: clamp(1.05rem, 2.4vw, 1.45rem); font-weight: 600; text-wrap: balance; }
.decorative-tiles { display: flex; justify-content: center; align-items: center; gap: 10px; margin: 28px 0 33px; }
.decorative-tiles .tile:first-child { transform: translateY(5px) rotate(-13deg); }
.decorative-tiles .tile:nth-child(2) { transform: translateY(-3px) rotate(6deg); }
.decorative-tiles .tile:last-child { transform: translateY(7px) rotate(14deg); }
.decorative-tiles .tile:not(.player-0):not(.player-1) { background: var(--lime); }
.choice-heading { margin-bottom: 14px; font-size: 1.12rem; font-weight: 800; }
.mode-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; max-width: 610px; margin: 0 auto 18px; }

.mode-card {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) 18px;
  grid-template-rows: auto auto;
  align-content: center;
  align-items: center;
  column-gap: 12px;
  min-width: 0;
  min-height: 86px;
  padding: 13px 15px;
  text-align: left;
  background: var(--white);
  border: 2px solid var(--ink);
  border-radius: 12px;
  box-shadow: 0 4px var(--ink);
  transition: transform .15s ease, box-shadow .15s ease, background .15s ease;
}

.mode-card:first-child { border-color: var(--blue-edge); background: var(--blue); color: white; box-shadow: 0 4px var(--blue-edge); }
.mode-icon {
  grid-area: 1 / 1 / 3 / 2;
  display: grid;
  place-items: center;
  flex: 0 0 42px;
  width: 42px;
  height: 42px;
  border: 1px solid currentColor;
  border-radius: 8px;
  font-size: 1.3rem;
}
.mode-icon svg { width: 23px; height: 23px; }
.mode-title { grid-area: 1 / 2; display: block; font-size: clamp(1rem, 2.2vw, 1.19rem); font-weight: 850; letter-spacing: -.035em; }
.mode-description { display: block; margin-top: 3px; font-size: .84rem; line-height: 1.35; }
.mode-card .mode-description { grid-area: 2 / 2; }
.mode-arrow { grid-area: 1 / 3 / 3 / 4; display: grid; place-items: center; }
.mode-arrow svg { width: 18px; height: 18px; }
.footer-note { margin-top: 20px; font-size: .83rem; color: var(--muted); }

.button, .header-action, .text-button {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  padding: 9px 17px;
  min-height: 44px;
  gap: 8px;
  border: 1.5px solid var(--ink);
  border-radius: 8px;
  background: var(--white);
  font-weight: 800;
  line-height: 1.15;
  text-align: center;
  text-decoration: none;
  transition: transform .15s ease, background .15s ease, box-shadow .15s ease;
}

.button.primary { color: white; border-color: var(--blue-edge); background: var(--blue); box-shadow: 0 3px var(--blue-edge); }
.button.secondary { box-shadow: 0 3px var(--ink); }
.button.small, .header-action { padding-inline: 13px; font-size: .9rem; }
span.header-action { min-height: 0; padding: 0; border: 0; background: transparent; color: var(--muted); font-size: .78rem; text-align: right; }
.text-button { padding-inline: 11px; border-color: transparent; background: transparent; text-decoration: underline; text-underline-offset: 4px; }
.button:disabled, .header-action:disabled, .text-button:disabled { opacity: .48; box-shadow: none; }
@media (hover: hover) {
  .mode-card:hover { transform: translateY(-3px); box-shadow: 0 7px var(--ink); }
  .mode-card:first-child:hover { box-shadow: 0 7px var(--blue-edge); }
  .button:not(:disabled):hover, button.header-action:not(:disabled):hover { transform: translateY(-2px); }
  .text-button:not(:disabled):hover { color: var(--blue-edge); background: #eeeadc; }
}
.mode-card:active, .button:not(:disabled):active { transform: translateY(2px); box-shadow: none; }

.settings-screen, .secret-screen { max-width: 595px; padding-top: clamp(33px, 7vh, 78px); }
.settings-card, .waiting-card {
  padding: clamp(20px, 4.7vw, 43px);
  border: 2px solid var(--ink);
  border-radius: 17px;
  background: var(--white);
  box-shadow: 0 6px var(--ink);
}

.section-heading, .secret-heading {
  margin-bottom: 25px;
  font-size: clamp(2.2rem, 7vw, 4.45rem);
  line-height: .98;
  font-weight: 900;
  letter-spacing: -.055em;
  text-wrap: balance;
}

.fieldset { display: block; min-width: 0; padding: 0; margin: 0 0 22px; border: 0; }
.fieldset legend { margin-bottom: 8px; padding: 0; font-weight: 800; }
.segment-group { display: flex; gap: 6px; padding: 5px; border-radius: 10px; background: #efebdf; }
.segment {
  flex: 1 1 0;
  display: inline-flex;
  justify-content: center;
  align-items: center;
  min-height: 44px;
  min-width: 0;
  padding: 5px 8px;
  border: 1px solid transparent;
  border-radius: 7px;
  background: transparent;
  font-weight: 750;
}
.segment:has(:checked), .segment.selected, .segment[aria-pressed="true"] { border-color: var(--blue-edge); background: var(--blue); color: white; }
.segment:has(:focus-visible) { outline: 3px solid var(--blue-edge); outline-offset: 3px; }
.toggle-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; min-height: 47px; font-weight: 800; }
.toggle-input { width: 25px; height: 25px; margin: 0 9px 0 0; accent-color: var(--blue); cursor: pointer; }
.help-note { margin-top: 10px; font-size: .88rem; color: var(--muted); line-height: 1.5; }
.settings-actions, .game-actions, .tutorial-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 11px; }
.settings-actions { margin-top: 20px; }
.waiting-card > svg { display: block; width: 32px; height: 32px; margin-bottom: 14px; color: var(--blue-edge); }
.link-label { font-weight: 800; }
.link-row { display: flex; align-items: center; flex-wrap: wrap; gap: 9px; margin-block: 16px; }
.link-input { flex: 1 1 100%; min-width: 0; width: 100%; min-height: 44px; padding: 8px 10px; border: 1px solid var(--ink); border-radius: 7px; background: var(--paper); }

.game-screen { max-width: 920px; padding-top: 22px; }
.level-badge { padding: 4px 9px; border: 1px solid var(--edge); border-radius: 5px; background: var(--white); font-size: .77rem; font-weight: 750; }
.game-topbar { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 13px; }
.player-zone {
  display: grid;
  grid-template-columns: minmax(158px, .65fr) minmax(0, 1.35fr);
  align-items: center;
  gap: 10px 18px;
  padding: 16px 19px 19px;
  border: 1px solid #ead5cb;
  border-radius: 12px;
  background: #fff0e8;
}
.human-zone { border-color: #ccd6fc; background: #edf0ff; }
.zone-heading { display: flex; align-items: center; gap: 11px; min-width: 0; }
.avatar {
  display: grid;
  place-items: center;
  flex: 0 0 36px;
  width: 36px;
  height: 36px;
  border: 1px solid var(--coral-edge);
  border-radius: 8px;
  background: repeating-linear-gradient(135deg, var(--coral) 0 5px, #ffd1c6 5px 8px);
  color: var(--ink);
  font-weight: 850;
}
.avatar svg { width: 22px; height: 22px; }
.human-zone .avatar { border-color: var(--blue-edge); background: var(--blue); color: white; }
.zone-meta { min-width: 0; }
.zone-name { font-size: clamp(1.02rem, 2.5vw, 1.25rem); font-weight: 850; letter-spacing: -.035em; line-height: 1.15; }
.zone-subtitle { margin-top: 4px; color: var(--muted); font-size: .82rem; }
.hand { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; min-height: 60px; }
.hints { grid-column: 1 / -1; }
.hint-heading { margin-bottom: 5px; }
.hint-list { display: flex; align-items: center; flex-wrap: wrap; gap: 5px; margin: 0; padding: 0; list-style: none; }
.hint-pill { display: inline-block; padding: 5px 9px; border: 1px solid #c3cc95; border-radius: 5px; color: var(--ink); background: #f0f4d8; font-size: .86rem; font-weight: 650; }
.human-zone .hint-pill { border-color: #b6c371; background: var(--lime); }

.table-center { padding: 22px 0 19px; text-align: center; }
.turn-label { display: flex; justify-content: center; align-items: center; gap: 8px; margin-bottom: 15px; font-size: 1.14rem; font-weight: 850; letter-spacing: -.025em; }
.turn-dot { width: 10px; height: 10px; border: 1px solid var(--blue-edge); border-radius: 50%; background: var(--blue); }
.turn-dot.player-1 { border-color: var(--coral-edge); background: var(--coral); }
.available-tiles {
  display: grid;
  grid-template-columns: repeat(9, var(--tile-size));
  justify-content: center;
  gap: var(--tile-gap);
  width: 100%;
}
.tile, .number-tile, .magic-cell {
  display: grid;
  place-items: center;
  width: var(--tile-size);
  height: var(--tile-size);
  min-width: 56px;
  min-height: 56px;
  margin: 0;
  padding: 0;
  border: 1.5px solid var(--ink);
  border-radius: 9px;
  background: #fffdfa;
  color: var(--ink);
  box-shadow: 0 4px var(--ink);
  font-size: 1.88rem;
  font-weight: 850;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  user-select: none;
}
.number-tile { transition: transform .15s ease, box-shadow .15s ease, background .15s ease; }
.number-tile:not(:disabled):active, .number-tile.pressed:not(:disabled) { transform: translateY(-5px); box-shadow: 0 9px var(--ink); }
@media (hover: hover) {
  .number-tile:not(:disabled):hover { transform: translateY(-5px); box-shadow: 0 9px var(--ink); background: var(--lime); }
}
.tile.player-0, .magic-cell.player-0, .number-tile.player-0 { color: white; border-color: var(--blue-edge); background: var(--blue); box-shadow: 0 4px var(--blue-edge); }
.tile.player-1, .magic-cell.player-1, .number-tile.player-1 {
  border-color: var(--coral-edge);
  background: repeating-linear-gradient(135deg, var(--coral) 0 7px, #ffc8b9 7px 11px);
  box-shadow: 0 4px var(--coral-edge);
}
.hand .tile { --tile-size: 56px; font-size: 1.58rem; }
.hand .tile { animation: tile-arrive .28s cubic-bezier(.18, .76, .4, 1.24) both; }
@keyframes tile-arrive {
  from { opacity: .2; scale: .84; translate: 0 -9px; }
  to { opacity: 1; scale: 1; translate: 0 0; }
}
.tile-placeholder { color: var(--muted); font-size: .88rem; }
.tile-ghost {
  border: 1px dashed #bdb8a9;
  background: transparent;
  color: #777b84;
  box-shadow: none;
}
.number-tile:disabled { background-color: #f5f1e7; }
.winning, .tile.winning, .magic-cell.winning, .number-tile.target-tile {
  outline: 3px solid #263118;
  outline-offset: 2px;
  box-shadow: 0 4px #263118, 0 0 0 7px var(--lime);
  position: relative;
  z-index: 1;
}
.number-tile:focus-visible { z-index: 2; }
.keyboard-note { margin-top: 13px; font-size: .78rem; color: var(--muted); }
.game-actions { justify-content: flex-end; margin-top: 13px; }
.result-card {
  display: grid;
  justify-items: center;
  gap: 10px;
  margin-top: 18px;
  padding: 18px 14px 20px;
  border: 1.5px solid var(--ink);
  border-radius: 10px;
  background: var(--lime);
  text-align: center;
  font-weight: 750;
}
.result-card h2 { font-size: clamp(1.12rem, 4vw, 1.6rem); }
.result-equation { font-size: clamp(1.4rem, 5vw, 2.25rem); font-weight: 900; letter-spacing: -.06em; }

.secret-screen { text-align: center; }
.magic-square {
  --tile-size: clamp(67px, 17vw, 98px);
  width: max-content;
  position: relative;
  display: grid;
  grid-template-columns: repeat(3, var(--tile-size));
  gap: 11px;
  margin: 25px auto;
}
.magic-cell { font-size: clamp(1.9rem, 6vw, 2.7rem); }
.winning-line { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 2; pointer-events: none; overflow: visible; color: #283419; }
.winning-line line { stroke: currentColor; stroke-width: 4px; stroke-linecap: round; opacity: .75; }
.secret-copy { max-width: 480px; margin: 24px auto; line-height: 1.58; }
.secret-screen .settings-actions, .secret-screen .game-actions { justify-content: center; }

.tutorial-panel {
  position: relative;
  margin: 15px 0;
  padding: 16px 18px 18px;
  border: 1.5px solid var(--ink);
  border-radius: 12px;
  background: #f4f7dd;
  box-shadow: 0 4px var(--ink);
}
.tutorial-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 17px; }
.tutorial-copy { max-width: 680px; margin: 7px 0 12px; font-size: 1.04rem; line-height: 1.47; font-weight: 650; }
.tutorial-instruction { margin: 0 0 12px; color: var(--blue-edge); font-size: .88rem; font-weight: 750; }
.tutorial-actions { justify-content: space-between; gap: 7px 12px; }
.tutorial-actions > div { display: flex; flex-wrap: wrap; gap: 8px; }
.tutorial-progress { display: flex; gap: 5px; }
.tutorial-progress span { width: 8px; height: 8px; border: 1px solid var(--blue-edge); border-radius: 50%; }
.tutorial-progress .active { background: var(--blue); }
.online-status, .error-banner { margin: 10px 0; padding: 11px 13px; border-radius: 7px; background: #eeeedf; font-size: .9rem; line-height: 1.4; }
.error-banner { border: 1px solid var(--coral-edge); background: #ffe6dc; }
.toast {
  position: fixed;
  right: 15px;
  bottom: 15px;
  z-index: 10;
  max-width: calc(100% - 30px);
  padding: 10px 15px;
  border-radius: 7px;
  background: var(--ink);
  color: white;
  box-shadow: 0 3px 9px #17224342;
}
.toast:not(.visible) { visibility: hidden; }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 815px) {
  :root { --tile-size: 60px; --tile-gap: 8px; }
  .site-header { padding-inline: 22px; }
  .app-shell { padding-inline: 22px; }
}

@media (max-width: 655px) {
  .available-tiles {
    grid-template-columns: repeat(10, minmax(0, calc((var(--tile-size) - var(--tile-gap)) / 2)));
  }
  .available-tiles > * { grid-column: span 2; }
  .available-tiles > :nth-child(6) { grid-column: 2 / span 2; }
  .player-zone { grid-template-columns: minmax(0, 1fr); }
  .hand { min-height: 0; }
}

@media (max-width: 430px) {
  :root { --tile-size: 56px; --tile-gap: 5px; }
  .site-header { min-height: 62px; }
  .site-header, .app-shell { padding-inline: 10px; }
  .home-screen { padding-top: 39px; }
  .hero-title { font-size: clamp(2.9rem, 13vw, 3.45rem); }
  .mode-grid { grid-template-columns: minmax(0, 1fr); gap: 11px; max-width: 295px; }
  .mode-card { min-height: 63px; padding-block: 8px; }
  .decorative-tiles { margin-block: 24px 28px; }
  .player-zone { padding: 11px 10px 13px; }
  .hand { gap: 4px; }
  .table-center { padding-block: 15px; }
  .available-tiles { row-gap: 9px; }
  .keyboard-note { line-height: 1.35; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}

@media (max-width: 350px) {
  :root { --tile-gap: 3px; }
  .app-shell { padding-inline: 4px; }
}
