:root {
  --bg: #f3f6f4;
  --card: #ffffff;
  --text: #17231e;
  --muted: #65766d;
  --line: #d9e2dd;
  --brand: #173b2f;
  --brand-2: #245c48;
  --player: #1f6feb;
  --machine: #cf3f3f;
  --free: #eef2ef;
  --selected: #f2c94c;
  --win: #f7d75f;
  --shadow: 0 10px 30px rgba(19, 55, 43, .08);
}

* { box-sizing: border-box; }
html { color-scheme: light; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button, select { font: inherit; }
button { cursor: pointer; }

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 1rem clamp(1rem, 3vw, 2rem);
  background: var(--brand);
  color: white;
}
.topbar h1 { margin: 0; font-size: clamp(1.8rem, 4vw, 2.7rem); line-height: 1; }
.subtitle { margin: .35rem 0 0; color: #d6e6df; font-size: .95rem; }
.top-actions { display: flex; flex-wrap: wrap; gap: .5rem; justify-content: flex-end; }

.btn, select {
  border: 1px solid transparent;
  border-radius: .7rem;
  padding: .65rem .85rem;
}
.btn.primary { background: #f4d35e; color: #18231f; font-weight: 800; }
.btn.secondary { background: rgba(255,255,255,.1); color: white; border-color: rgba(255,255,255,.25); }
.btn:hover { filter: brightness(.98); }

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(300px, .75fr);
  gap: 1rem;
  padding: 1rem;
  max-width: 1500px;
  margin: 0 auto;
}
.side-panel { display: grid; gap: 1rem; align-content: start; }
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 1rem;
  box-shadow: var(--shadow);
  padding: 1rem;
}

.status-grid, .stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: .6rem;
}
.status-grid > div, .stats-grid > div {
  padding: .7rem;
  border-radius: .8rem;
  background: #f7faf8;
  border: 1px solid var(--line);
}
.status-grid span, .stats-grid span { display: block; color: var(--muted); font-size: .78rem; margin-bottom: .2rem; }
.status-grid strong, .stats-grid strong { font-size: 1rem; }
.status-grid select { width: 100%; background: white; padding: .35rem .45rem; border-color: var(--line); }

.start-row {
  display: grid;
  grid-template-columns: auto auto minmax(200px, 1fr);
  gap: .6rem;
  align-items: center;
  margin: .9rem 0;
}
.start-row select { background: white; border-color: var(--line); padding: .48rem .55rem; }
.message {
  min-height: 2.5rem;
  display: flex;
  align-items: center;
  padding: .55rem .75rem;
  border-radius: .7rem;
  background: #eef5f1;
  color: var(--brand);
  font-weight: 650;
}
.message.error { background: #fff0f0; color: #8d2222; }
.message.success { background: #fff7d7; color: #634f00; }

.board-shell { overflow-x: auto; padding-bottom: .25rem; }
.column-labels {
  display: grid;
  grid-template-columns: 2rem repeat(10, minmax(46px, 1fr));
  gap: .25rem;
  min-width: 540px;
  padding: 0 .15rem .25rem;
  color: var(--muted);
  font-weight: 800;
  text-align: center;
}
.board-with-rows {
  display: grid;
  grid-template-columns: 2rem minmax(500px, 1fr);
  gap: .25rem;
  min-width: 540px;
}
.row-labels {
  display: grid;
  grid-template-rows: repeat(10, minmax(46px, 1fr));
  gap: .25rem;
  color: var(--muted);
  font-weight: 800;
}
.row-labels span { display: grid; place-items: center; }
.board {
  display: grid;
  grid-template-columns: repeat(10, minmax(46px, 1fr));
  gap: .25rem;
  aspect-ratio: 1 / 1;
}
.cell {
  min-width: 0;
  border: 1px solid #c9d5cf;
  background: #fbfdfc;
  border-radius: .55rem;
  display: grid;
  place-items: center;
  position: relative;
  font-weight: 900;
  font-size: clamp(.9rem, 2vw, 1.18rem);
  color: var(--text);
  transition: transform .12s ease, border-color .12s ease, background .12s ease;
}
.cell.empty:hover { transform: translateY(-1px); border-color: var(--brand-2); background: #f0f7f3; }
.cell.player { background: #edf4ff; border-color: #99baf0; color: #174a9d; }
.cell.machine { background: #fff0f0; border-color: #efaaaa; color: #922727; }
.cell.winner { background: #fff0a9; border-color: #c49c00; box-shadow: inset 0 0 0 2px #d0a900; }
.owner-badge {
  position: absolute;
  right: .18rem;
  bottom: .12rem;
  font-size: .55rem;
  font-weight: 900;
  opacity: .65;
}

.section-heading { display: flex; justify-content: space-between; align-items: baseline; gap: .75rem; }
.section-heading h2, .stats-card h2, .log-card h2 { margin: 0 0 .7rem; font-size: 1.05rem; }
.selected-number { font-size: .82rem; color: var(--muted); font-weight: 700; }
.legend { display: flex; gap: .8rem; flex-wrap: wrap; margin-bottom: .7rem; color: var(--muted); font-size: .8rem; }
.legend span { display: inline-flex; align-items: center; gap: .32rem; }
.dot { width: .72rem; height: .72rem; border-radius: 50%; display: inline-block; border: 1px solid #b9c7c0; }
.dot.free { background: var(--free); }
.dot.player { background: #9dc1ff; }
.dot.machine { background: #f4a3a3; }

.number-panel {
  display: grid;
  grid-template-columns: repeat(10, minmax(0, 1fr));
  gap: .28rem;
}
.number-btn {
  aspect-ratio: 1 / 1;
  border: 1px solid #cbd6d0;
  border-radius: .45rem;
  background: var(--free);
  padding: 0;
  font-size: clamp(.65rem, 1.6vw, .86rem);
  font-weight: 800;
  color: #31423a;
}
.number-btn.available:hover { border-color: var(--brand); background: #e3eee8; }
.number-btn.selected { background: var(--selected); border-color: #aa8800; color: #3f3300; box-shadow: 0 0 0 2px rgba(242,201,76,.3); }
.number-btn.used-player { background: #dfeaff; border-color: #86acec; color: #174a9d; cursor: default; }
.number-btn.used-machine { background: #ffe0e0; border-color: #e89b9b; color: #922727; cursor: default; }
.number-btn:disabled { opacity: .8; }

.stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.move-log { margin: 0; padding-left: 1.6rem; max-height: 240px; overflow: auto; color: #415048; }
.move-log li { margin-bottom: .35rem; }
.move-log li.player-log strong { color: var(--player); }
.move-log li.machine-log strong { color: var(--machine); }

#helpDialog, #resultDialog {
  border: 0;
  border-radius: 1rem;
  padding: 0;
  max-width: min(620px, calc(100vw - 2rem));
  box-shadow: 0 24px 80px rgba(0,0,0,.24);
}
#helpDialog::backdrop, #resultDialog::backdrop { background: rgba(8, 20, 15, .55); }
.dialog-content { padding: 1.2rem; }
.dialog-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; }
.dialog-head h2 { margin: 0; }
.icon-btn { border: 0; background: transparent; font-size: 1.8rem; line-height: 1; }
.dialog-content li { margin-bottom: .55rem; }
.result-content { text-align: center; min-width: min(420px, calc(100vw - 2rem)); }
.result-content h2 { margin-top: 0; font-size: 1.8rem; }
.result-sequence { font-weight: 900; font-size: 1.25rem; margin: 1rem 0 1.2rem; letter-spacing: .06em; }

@media (max-width: 980px) {
  .layout { grid-template-columns: 1fr; }
  .side-panel { grid-template-columns: 1fr 1fr; }
  .number-card { grid-column: 1 / -1; }
}

@media (max-width: 680px) {
  .topbar { align-items: flex-start; flex-direction: column; }
  .top-actions { width: 100%; justify-content: stretch; }
  .top-actions .btn { flex: 1; }
  .layout { padding: .55rem; }
  .card { padding: .7rem; border-radius: .8rem; }
  .status-grid { grid-template-columns: repeat(2, 1fr); }
  .start-row { grid-template-columns: auto 1fr; }
  .message { grid-column: 1 / -1; }
  .side-panel { grid-template-columns: 1fr; }
  .number-panel { gap: .2rem; }
  .number-btn { border-radius: .32rem; }
}
