:root {
  --ink: #181512;
  --muted: #665f55;
  --paper: #fbfff8;
  --line: #2b241d;
  --court: #277b52;
  --court-dark: #1f6040;
  --clay: #cf5831;
  --gold: #efbf55;
  --mint: #d9f2d8;
  --surface: #f4fbf2;
  --panel: #fffdf7;
  --x: #0f6c80;
  --o: #ae394a;
  --shadow: rgba(24, 21, 18, 0.18);
  --deep: #151f1a;
  font-family: "Aptos", "Inter", "Segoe UI", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    linear-gradient(135deg, rgba(251, 255, 248, 0.96) 0%, rgba(240, 248, 238, 0.9) 46%, rgba(255, 244, 220, 0.86) 100%),
    repeating-linear-gradient(0deg, #277b52 0 18px, #2e875b 18px 36px);
  text-rendering: optimizeLegibility;
}

[dir="rtl"] body {
  direction: rtl;
}

[dir="rtl"] input,
[dir="rtl"] select,
[dir="rtl"] .suggestion-option {
  text-align: right;
}

[dir="rtl"] .brand-lockup {
  flex-direction: row-reverse;
}

button,
input,
select {
  font: inherit;
}

button {
  border: 2px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(180deg, #f8cf6e, var(--gold));
  color: var(--ink);
  cursor: pointer;
  font-weight: 900;
  box-shadow: 0 3px 0 var(--line), 0 8px 18px rgba(24, 21, 18, 0.1);
  transition: transform 140ms ease, box-shadow 140ms ease, filter 140ms ease;
}

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

button:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 var(--line);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
  filter: grayscale(0.15);
}

.app-shell {
  width: min(1220px, calc(100% - 24px));
  margin: 0 auto;
  padding: 22px 0 28px;
}

.setup-screen {
  display: grid;
  gap: 20px;
  padding: 24px;
  border: 4px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.74), rgba(251, 255, 248, 0.96)),
    linear-gradient(90deg, rgba(15, 108, 128, 0.12), rgba(239, 191, 85, 0.16));
  box-shadow: 0 10px 0 var(--shadow), 0 26px 48px rgba(24, 21, 18, 0.16);
}

.setup-heading h1 {
  margin: 0;
  font-size: clamp(2.45rem, 5vw, 4.6rem);
  line-height: 0.92;
  text-transform: uppercase;
}

.setup-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 12px;
}

.setup-field {
  min-width: 0;
}

.start-button {
  width: min(280px, 100%);
  padding: 14px 18px;
  font-size: 1.05rem;
}

.online-setup {
  display: grid;
  gap: 14px;
  padding: 16px;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 247, 0.76);
}

.online-setup h2,
.online-setup p {
  margin: 0;
}

.online-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.join-row {
  display: flex;
  gap: 8px;
  min-width: min(100%, 320px);
}

.join-row input {
  flex: 1;
  min-width: 0;
  text-transform: uppercase;
}

.online-status {
  min-height: 1.25rem;
  color: var(--muted);
  font-weight: 800;
}

.room-banner {
  display: grid;
  gap: 2px;
  padding: 9px 12px;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 3px 0 var(--line);
  font-weight: 900;
}

.room-banner span {
  font-size: 0.72rem;
  color: var(--muted);
  text-transform: uppercase;
}

.game-screen[hidden],
.setup-screen[hidden] {
  display: none;
}

.scoreboard {
  display: grid;
  grid-template-columns: 1fr minmax(190px, auto) minmax(150px, auto) minmax(230px, auto);
  gap: 14px;
  align-items: center;
  padding: 16px;
  border: 3px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.9), rgba(251, 255, 248, 0.98)),
    linear-gradient(90deg, rgba(207, 88, 49, 0.1), rgba(15, 108, 128, 0.1));
  box-shadow: 0 9px 0 var(--shadow), 0 22px 42px rgba(24, 21, 18, 0.14);
}

.brand-lockup {
  display: flex;
  gap: 12px;
  align-items: center;
  min-width: 0;
}

.ball-mark {
  width: 70px;
  height: 70px;
  flex: 0 0 auto;
  filter: drop-shadow(0 4px 0 rgba(24, 21, 18, 0.18));
}

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

h1,
h2,
p {
  overflow-wrap: anywhere;
}

h1 {
  margin: 0;
  font-size: clamp(2rem, 3vw, 2.75rem);
  line-height: 0.95;
  font-weight: 950;
  letter-spacing: 0;
}

.turn-panel,
.match-panel,
.score-pair {
  border: 2px solid var(--line);
  border-radius: 8px;
  padding: 12px 13px;
  background: linear-gradient(180deg, #fff7e6, #ffeec5);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.7);
}

.turn-text {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 900;
}

.timer-text,
.match-text {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.95rem;
  font-weight: 850;
}

.score-pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.score-pair div {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
}

.score-name {
  min-width: 0;
  font-size: 0.9rem;
  font-weight: 900;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.score-pair strong {
  font-size: 1.45rem;
}

.token {
  display: inline-grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border: 2px solid var(--line);
  border-radius: 8px;
  color: white;
  font-weight: 950;
}

.token-x {
  background: var(--x);
}

.token-o {
  background: var(--o);
}

.game-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 18px;
  align-items: start;
  margin-top: 18px;
}

.board-zone {
  display: grid;
  grid-template-columns: minmax(88px, 128px) repeat(3, minmax(0, 1fr));
  grid-template-rows: minmax(78px, auto) repeat(3, minmax(120px, 1fr));
  gap: 9px;
  padding: 14px;
  border: 4px solid var(--line);
  border-radius: 8px;
  background:
    radial-gradient(circle at center, transparent 0 17%, rgba(251, 255, 248, 0.22) 18% 20%, transparent 21%),
    linear-gradient(90deg, transparent 0 49%, rgba(251, 255, 248, 0.22) 50% 51%, transparent 52%),
    var(--court);
  box-shadow: 0 11px 0 rgba(24, 21, 18, 0.24), 0 28px 48px rgba(24, 21, 18, 0.18);
}

.axis-corner,
.header-cell,
.cell {
  border: 2px solid var(--line);
  border-radius: 8px;
}

.axis-corner {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  min-height: 78px;
  padding: 10px;
  background: linear-gradient(180deg, #263128, var(--deep));
  color: var(--paper);
  font-size: 0.82rem;
  font-weight: 900;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.column-headers,
.row-headers,
.grid {
  display: contents;
}

.header-cell {
  display: grid;
  place-items: center;
  gap: 7px;
  min-height: 78px;
  padding: 9px;
  background: linear-gradient(180deg, #ffffff, #eff9ed);
  text-align: center;
  font-weight: 950;
  line-height: 1.08;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.8);
}

.axis-logo {
  width: 50px;
  height: 50px;
  object-fit: contain;
  border-radius: 8px;
  filter: drop-shadow(0 3px 0 rgba(24, 21, 18, 0.12));
}

.header-cell span {
  max-width: 100%;
  font-size: 0.94rem;
}

.row-header {
  min-height: 120px;
}

.cell {
  position: relative;
  display: grid;
  grid-template-rows: 1fr auto;
  align-items: center;
  justify-items: center;
  min-height: 126px;
  padding: 12px 10px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.96), rgba(241, 250, 239, 0.95));
  text-align: center;
  transition: transform 150ms ease, background 150ms ease, box-shadow 150ms ease;
}

.cell:hover,
.cell.selected {
  background: var(--mint);
  transform: translateY(-2px);
  box-shadow: 0 5px 0 rgba(24, 21, 18, 0.14);
}

.cell.claimed {
  cursor: default;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.96), rgba(241, 250, 239, 0.95));
  transform: none;
  box-shadow: none;
}

.cell.winning {
  background: linear-gradient(180deg, #fff0a8, #ffd764);
}

.cell-token {
  display: grid;
  place-items: center;
  width: 62px;
  height: 62px;
  margin-bottom: 8px;
  border: 3px solid var(--line);
  border-radius: 8px;
  color: white;
  font-size: 2rem;
  font-weight: 950;
}

.claimed-visual {
  position: relative;
  display: inline-grid;
  place-items: center;
  margin-bottom: 8px;
}

.player-photo {
  width: 72px;
  height: 72px;
  border: 3px solid var(--line);
  border-radius: 8px;
  background: white;
  object-fit: cover;
  object-position: 50% 18%;
  box-shadow: 0 4px 10px rgba(24, 21, 18, 0.16);
}

.claim-badge {
  position: absolute;
  right: -8px;
  bottom: -8px;
  display: grid;
  place-items: center;
  width: 29px;
  height: 29px;
  border: 2px solid var(--line);
  border-radius: 8px;
  color: white;
  font-size: 1rem;
  font-weight: 950;
}

.claim-badge.x {
  background: var(--x);
}

.claim-badge.o {
  background: var(--o);
}

.cell-token.x {
  background: var(--x);
}

.cell-token.o {
  background: var(--o);
}

.confetti-layer {
  position: fixed;
  inset: 0;
  z-index: 999;
  overflow: hidden;
  pointer-events: none;
}

.confetti-piece {
  position: absolute;
  top: -18px;
  width: 10px;
  height: 16px;
  border: 1px solid rgba(31, 23, 18, 0.22);
  border-radius: 3px;
  animation-name: confetti-fall;
  animation-timing-function: cubic-bezier(0.14, 0.74, 0.34, 1);
  animation-fill-mode: forwards;
}

@keyframes confetti-fall {
  0% {
    translate: 0 -20px;
    rotate: 0deg;
    opacity: 1;
  }

  100% {
    translate: calc((var(--drift, 0) * 1px)) 110vh;
    rotate: 720deg;
    opacity: 0.92;
  }
}

.cell-player {
  min-height: 2.6em;
  font-size: 0.92rem;
  font-weight: 850;
  line-height: 1.15;
}

.control-rail {
  display: grid;
  gap: 14px;
}

.entry-box,
.rules,
.answer-peek,
.actions {
  border: 3px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(180deg, #ffffff, var(--paper));
  padding: 14px;
  box-shadow: 0 6px 0 rgba(24, 21, 18, 0.12);
}

.selected-cell {
  margin: 0 0 12px;
  font-weight: 950;
  font-size: 1.02rem;
}

label {
  display: block;
  margin-bottom: 7px;
  color: var(--muted);
  font-weight: 900;
}

.input-row {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 88px;
  gap: 8px;
}

input,
select {
  width: 100%;
  min-width: 0;
  border: 2px solid var(--line);
  border-radius: 8px;
  padding: 10px 11px;
  background: white;
  color: var(--ink);
  font-weight: 700;
  outline: none;
  transition: border-color 140ms ease, box-shadow 140ms ease;
}

input:focus,
select:focus {
  border-color: var(--x);
  box-shadow: 0 0 0 3px rgba(15, 108, 128, 0.18);
}

.player-search input {
  grid-column: 1;
}

.player-search button {
  grid-column: 2;
  grid-row: 1;
}

.player-suggestions {
  position: absolute;
  z-index: 20;
  top: calc(100% + 6px);
  left: 0;
  width: calc(100% - 96px);
  max-height: 250px;
  overflow: auto;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: white;
  box-shadow: 0 7px 0 rgba(31, 23, 18, 0.18), 0 18px 32px rgba(24, 21, 18, 0.14);
}

.suggestion-option {
  display: grid;
  gap: 3px;
  width: 100%;
  padding: 9px 10px;
  border: 0;
  border-bottom: 1px solid #ded8ce;
  border-radius: 0;
  background: white;
  box-shadow: none;
  color: var(--ink);
  text-align: left;
  font-weight: 800;
}

.suggestion-name {
  overflow-wrap: anywhere;
  white-space: normal;
  line-height: 1.15;
}

.suggestion-years {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 900;
}

.suggestion-empty {
  padding: 10px;
  color: var(--muted);
  font-weight: 800;
}

.suggestion-option:hover,
.suggestion-option.active {
  background: var(--mint);
}

.suggestion-option:active {
  transform: none;
  box-shadow: none;
}

.feedback {
  min-height: 3.6em;
  margin: 12px 0 0;
  color: var(--muted);
  line-height: 1.2;
}

.feedback.good {
  color: #17603f;
  font-weight: 850;
}

.feedback.bad {
  color: #9d2536;
  font-weight: 850;
}

.actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.rules h2 {
  margin: 0 0 8px;
  font-size: 1.2rem;
}

.rules p {
  margin: 8px 0 0;
  line-height: 1.35;
}

.ghost-button {
  width: 100%;
  background: white;
}

.ghost-button:disabled {
  background: #f0f0ec;
  color: var(--muted);
  box-shadow: 0 2px 0 rgba(43, 36, 29, 0.55);
}

.answer-list {
  margin-top: 12px;
  max-height: 260px;
  overflow: auto;
  border-top: 2px solid var(--line);
  padding-top: 10px;
  font-size: 0.9rem;
  line-height: 1.3;
}

.answer-list h3 {
  margin: 10px 0 4px;
  font-size: 0.95rem;
}

.answer-list p {
  margin: 0;
  color: var(--muted);
}

.site-footer {
  display: grid;
  gap: 8px;
  margin-top: 18px;
  padding: 14px;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: rgba(251, 255, 248, 0.92);
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.35;
}

.site-footer p {
  margin: 0;
}

.site-footer nav {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

a {
  color: var(--x);
  font-weight: 900;
}

.legal-page {
  width: min(760px, calc(100% - 24px));
  margin: 24px auto;
  padding: 22px;
  border: 3px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  box-shadow: 0 8px 0 var(--shadow);
}

.legal-page p {
  line-height: 1.55;
}

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

  .score-pair div {
    grid-template-columns: auto minmax(80px, 1fr) auto;
  }

  .board-zone {
    grid-template-columns: minmax(76px, 96px) repeat(3, minmax(0, 1fr));
    grid-template-rows: minmax(70px, auto) repeat(3, minmax(96px, 1fr));
    gap: 6px;
    padding: 8px;
  }

  .header-cell,
  .axis-corner {
    min-height: 70px;
    padding: 7px;
    font-size: 0.82rem;
  }

  .row-header,
  .cell {
    min-height: 96px;
  }

  .cell-token {
    width: 46px;
    height: 46px;
    font-size: 1.55rem;
  }

  .player-photo {
    width: 50px;
    height: 50px;
  }

  .claim-badge {
    width: 25px;
    height: 25px;
    font-size: 0.88rem;
  }
}

@media (max-width: 560px) {
  .app-shell {
    width: min(100% - 12px, 1180px);
    padding-top: 8px;
  }

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

  .ball-mark {
    width: 48px;
    height: 48px;
  }

  .board-zone {
    grid-template-columns: 72px repeat(3, minmax(0, 1fr));
    gap: 4px;
  }

  .header-cell,
  .axis-corner {
    font-size: 0.7rem;
  }

  .cell {
    padding: 6px 4px;
  }

  .cell-player {
    font-size: 0.75rem;
  }

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

  .player-search button {
    grid-column: 1;
    grid-row: 2;
  }

  .player-suggestions {
    top: 48px;
    width: 100%;
  }
}
