:root {
  --bg: #0e1020;
  --panel: #161a30;
  --line: #2a3058;
  --text: #e8ebff;
  --muted: #8e96c0;
  --you: #ffb000;
  --bot: #4dd6ff;
  --good: #5be38a;
  --bad: #ff5c6c;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  min-height: 100dvh;
  background:
    radial-gradient(900px 500px at 12% -10%, rgba(255, 176, 0, .10), transparent),
    radial-gradient(900px 500px at 92% -10%, rgba(77, 214, 255, .12), transparent),
    var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; }

.app {
  max-width: 1180px;
  margin: 0 auto;
  padding: 16px max(16px, env(safe-area-inset-right)) 28px max(16px, env(safe-area-inset-left));
}

/* ---------- Üst bar ---------- */
.top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 20px;
  justify-content: space-between;
}
.logo { margin: 0; font-size: 1.6rem; font-weight: 900; letter-spacing: -.02em; }
.logo span { color: var(--you); }
.modes { display: flex; gap: 6px; flex-wrap: wrap; }
.modes button {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 14px;
  cursor: pointer;
  color: var(--muted);
  font-weight: 600;
}
.modes button[aria-checked="true"] { background: var(--you); border-color: var(--you); color: #1a1020; }
.modes button:disabled { opacity: .45; cursor: not-allowed; }
.modes button[aria-checked="true"]:disabled { opacity: .9; }
.modes button:not(:disabled):not([aria-checked="true"]):hover { color: var(--text); border-color: var(--muted); }
.actions { display: flex; gap: 8px; }
.btn {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 18px;
  font-weight: 700;
  cursor: pointer;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--you); border-color: var(--you); color: #1a1020; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger.armed { background: var(--bad); border-color: var(--bad); color: #1a0508; }
.btn[hidden] { display: none; }
button:focus-visible { outline: 2px solid var(--bot); outline-offset: 2px; }

/* ---------- Süre / fark çubuğu ---------- */
.hud {
  margin: 18px 0 14px;
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-areas: "time bar" "time text";
  align-items: center;
  gap: 4px 18px;
}
.hud-time { grid-area: time; text-align: center; min-width: 130px; }
.clock { font-size: 2.6rem; font-weight: 900; font-variant-numeric: tabular-nums; line-height: 1; }
.clock.low { color: var(--bad); }
.clock-label { color: var(--muted); font-size: .8rem; margin-top: 4px; }
.lead { grid-area: bar; display: flex; height: 12px; border-radius: 999px; overflow: hidden; background: var(--panel); border: 1px solid var(--line); }
.lead-you { background: var(--you); width: 50%; transition: width .25s ease; }
.lead-bot { background: var(--bot); flex: 1; }
.lead-text { grid-area: text; color: var(--muted); font-size: .9rem; }
.lead-text b { color: var(--text); }

/* ---------- Arena ---------- */
.arena {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: start;
  gap: 16px;
}
.vs { align-self: center; color: var(--muted); font-weight: 900; letter-spacing: .1em; }
.side { min-width: 0; background: var(--panel); border: 1px solid var(--line); border-radius: 20px; padding: 14px; }
.side.you { box-shadow: 0 0 0 1px rgba(255, 176, 0, .15); }
.side.bot { box-shadow: 0 0 0 1px rgba(77, 214, 255, .15); }
.side.winner { box-shadow: 0 0 0 2px var(--good), 0 0 30px rgba(91, 227, 138, .25); }
.pane-head { display: flex; justify-content: space-between; align-items: flex-end; margin-bottom: 8px; }
.who { font-weight: 900; letter-spacing: .12em; }
.you .who { color: var(--you); }
.bot .who { color: var(--bot); }
.score { text-align: right; }
.score small { display: block; color: var(--muted); font-size: .7rem; letter-spacing: .12em; }
.score b { font-size: 2rem; font-variant-numeric: tabular-nums; line-height: 1; }
.stats { display: flex; justify-content: space-between; gap: 8px; color: var(--muted); font-size: .85rem; margin-bottom: 10px; }
.stats b { color: var(--text); font-variant-numeric: tabular-nums; margin-left: 4px; }

/* ---------- Tahta ---------- */
.board {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  background: #0a0c1b;
  border: 2px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
  container-type: inline-size;
  touch-action: none;
  user-select: none;
}
.grid { position: absolute; inset: 0; display: grid; grid-template: repeat(4, 1fr) / repeat(4, 1fr); }
.grid i { margin: 1.6cqw; background: #151933; border-radius: 1.8cqw; }
.tiles { position: absolute; inset: 0; }
.tile {
  position: absolute; left: 0; top: 0; width: 25%; height: 25%;
  transform: translate(calc(var(--c) * 100%), calc(var(--r) * 100%));
  transition: transform .11s ease-out;
  z-index: 2;
}
.tile.gone { z-index: 1; }
.board.ff .tile { transition: none; }
.tile > b {
  position: absolute; inset: 1.6cqw;
  border-radius: 1.8cqw;
  display: grid; place-items: center;
  font-weight: 800;
  font-size: 9.5cqw;
  background: var(--tbg);
  color: var(--tfg);
  font-variant-numeric: tabular-nums;
}
.tile > b[data-len="3"] { font-size: 8cqw; }
.tile > b[data-len="4"] { font-size: 6.6cqw; }
.tile > b[data-len="5"] { font-size: 5.4cqw; }
.tile > b.glow { box-shadow: 0 0 3cqw var(--tbg); }

.board.over .tiles { filter: grayscale(.8) brightness(.6); }
.badge {
  position: absolute; inset: 0; z-index: 5;
  display: grid; place-items: center; text-align: center;
  background: rgba(10, 12, 27, .72);
  font-weight: 900;
  font-size: 7cqw;
  padding: 4cqw;
  letter-spacing: .02em;
  white-space: pre-line;
  backdrop-filter: blur(2px);
}
.badge.count { font-size: 30cqw; background: rgba(10, 12, 27, .55); }
.badge.small { font-size: 5cqw; color: var(--muted); }
.badge.fin { background: rgba(10, 12, 27, .55); color: var(--bad); }
.badge[hidden] { display: none; }

/* ---------- Alt bilgi ---------- */
.foot { margin-top: 22px; color: var(--muted); font-size: .85rem; line-height: 1.55; }
.foot p { margin: 4px 0; }
.foot b { color: var(--text); }
.record { color: var(--text); }

/* ---------- Sonuç penceresi ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 50;
  display: grid; place-items: center;
  background: rgba(6, 7, 18, .78);
  padding: 16px;
}
.overlay[hidden] { display: none; }
.card {
  width: min(460px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 24px;
  text-align: center;
}
.card h2 { margin: 0 0 6px; font-size: 2rem; }
.card h2.win { color: var(--good); }
.card h2.lose { color: var(--bad); }
.res-reason { margin: 0 0 14px; color: var(--muted); }
.res-table { width: 100%; border-collapse: collapse; margin-bottom: 12px; font-variant-numeric: tabular-nums; }
.res-table th, .res-table td { padding: 8px 6px; border-bottom: 1px solid var(--line); }
.res-table th { color: var(--muted); font-weight: 600; font-size: .85rem; }
.res-table td:first-child { text-align: left; color: var(--muted); }
.res-table td.best { color: var(--good); font-weight: 800; }
.res-record { color: var(--muted); min-height: 1.2em; margin: 4px 0 16px; }
.card-actions { display: flex; gap: 10px; justify-content: center; }

/* ---------- Telefon ---------- */
@media (max-width: 760px) {
  .arena { grid-template-columns: 1fr; }
  .vs { display: none; }
  .logo { font-size: 1.3rem; }
  .hud { grid-template-columns: 1fr; grid-template-areas: "time" "bar" "text"; text-align: center; }
  .clock { font-size: 2.2rem; }
  .side.bot .board { max-width: 300px; margin-inline: auto; }
  .actions { width: 100%; }
  .actions .btn { flex: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .tile { transition: none; }
}
