:root {
  --bg: #0b1020; --bg2: #18214a; --ink: #eef1ff; --muted: #9aa6d1;
  --card: rgba(255, 255, 255, .06); --line: rgba(255, 255, 255, .13);
  --red: #ff4d6a; --red2: #c81e45; --yel: #ffd43b; --yel2: #e69b00;
  --board: #2a4de0; --green: #3ddc97; --warn: #ff7a59; --accent: #7c9cff;
  --pad: 12px;
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
body {
  min-height: 100svh; color: var(--ink);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: radial-gradient(1200px 700px at 50% -10%, var(--bg2), var(--bg) 70%) fixed, var(--bg);
}
button { font: inherit; color: inherit; cursor: pointer; }
h1, h2, p { margin: 0; }

.app { max-width: 1060px; margin: 0 auto; padding: 12px 12px calc(20px + env(safe-area-inset-bottom)); }
.top { display: flex; align-items: center; justify-content: space-between; padding: 4px 2px 12px; }
.brand { display: flex; align-items: center; gap: 10px; }
.brand h1 { font-size: 1.25rem; letter-spacing: .2px; white-space: nowrap; }
.brand small { color: var(--accent); font-weight: 600; font-size: .8em; }
@media (max-width: 440px) { .brand small { display: none; } }
.logo { display: grid; grid-template: 1fr 1fr / 1fr 1fr; gap: 3px; padding: 5px; width: 34px; height: 34px; background: var(--board); border-radius: 9px; }
.logo i { border-radius: 50%; background: var(--yel); }
.logo i:nth-child(1), .logo i:nth-child(4) { background: var(--red); }
nav { display: flex; gap: 8px; }
.chip { background: var(--card); border: 1px solid var(--line); border-radius: 999px; padding: 6px 14px; white-space: nowrap; }
.chip:hover { background: rgba(255, 255, 255, .12); }

/* Telefon: sırayla skor, tahta, koç, ayarlar (stage "contents" olunca çocukları doğrudan sıralanır) */
.layout { display: flex; flex-direction: column; align-items: center; gap: 14px; }
.stage { display: contents; }
.scorebar { order: 0; } .board-wrap { order: 1; } .coach { order: 2; } .controls { order: 3; }
@media (min-width: 960px) {
  .layout { display: grid; grid-template-columns: auto minmax(320px, 1fr); align-items: start; gap: 28px; }
  .stage { display: flex; flex-direction: column; align-items: center; gap: 14px; max-width: 100%; }
  .coach { position: sticky; top: 16px; }
}

.card { background: var(--card); border: 1px solid var(--line); border-radius: 18px; backdrop-filter: blur(6px); }

/* ---------- skor / sıra ---------- */
.scorebar { display: flex; align-items: center; justify-content: space-between; gap: 10px; width: calc(7 * var(--cell, 60px) + 2 * var(--pad)); max-width: 100%; }
.pl { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.pl em { font-style: normal; background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 0 9px; min-width: 28px; text-align: center; }
.dot { width: 16px; height: 16px; border-radius: 50%; }
.dot.red { background: radial-gradient(circle at 35% 30%, #ff9aa9, var(--red) 55%, var(--red2)); }
.dot.yellow { background: radial-gradient(circle at 35% 30%, #fff2a8, var(--yel) 55%, var(--yel2)); }
.turn-pill { background: var(--card); border: 1px solid var(--line); border-radius: 999px; padding: 4px 14px; font-size: .9rem; font-weight: 600; white-space: nowrap; }
body[data-turn="1"] .turn-pill { border-color: color-mix(in srgb, var(--red) 60%, transparent); }
body[data-turn="2"] .turn-pill { border-color: color-mix(in srgb, var(--yel) 60%, transparent); }
.turn-pill.think::after { content: "…"; display: inline-block; animation: dots 1s steps(4) infinite; width: 1.2em; text-align: left; overflow: hidden; vertical-align: bottom; }
@keyframes dots { from { width: 0; } to { width: 1.2em; } }

/* ---------- tahta ---------- */
.board-wrap { position: relative; padding-top: var(--cell, 60px); }
.board {
  --cell: clamp(34px, min(calc((100vw - 48px) / 7), calc((100svh - 330px) / 7)), 76px);
  position: relative; background: var(--board); border-radius: 20px; padding: var(--pad);
  width: calc(7 * var(--cell) + 2 * var(--pad)); height: calc(6 * var(--cell) + 2 * var(--pad));
  box-shadow: inset 0 3px 0 rgba(255, 255, 255, .25), inset 0 -7px 0 rgba(0, 0, 0, .28), 0 24px 50px rgba(0, 0, 0, .5);
}
.board-wrap, .scorebar { --cell: clamp(34px, min(calc((100vw - 48px) / 7), calc((100svh - 330px) / 7)), 76px); }
.discs, .front, .rim, .marks { position: absolute; inset: var(--pad); }
.discs { overflow: hidden; z-index: 1; background: #080d24; }
.front {
  z-index: 2; background: var(--board);
  -webkit-mask: radial-gradient(circle closest-side, transparent 0 83.5%, #000 85%) 0 0 / var(--cell) var(--cell);
  mask: radial-gradient(circle closest-side, transparent 0 83.5%, #000 85%) 0 0 / var(--cell) var(--cell);
}
.rim {
  z-index: 3; pointer-events: none;
  background: radial-gradient(circle closest-side, transparent 0 78%, rgba(0, 0, 0, .38) 83.5%, transparent 85%, transparent 86.5%, rgba(255, 255, 255, .2) 89%, transparent 94%) 0 0 / var(--cell) var(--cell);
}
.marks { z-index: 4; pointer-events: none; }
.mark { position: absolute; width: var(--cell); height: var(--cell); }
.mark::before, .mark::after { content: ""; position: absolute; border-radius: 50%; border: 3px dashed transparent; opacity: .95; }
.mark.me::before { inset: 20%; border-color: var(--green); animation: spin 8s linear infinite; }
.mark.opp::after { inset: 11%; border-color: var(--warn); animation: spin 8s linear infinite reverse; }
@keyframes spin { to { transform: rotate(360deg); } }

.disc { position: absolute; width: var(--cell); height: var(--cell); }
.disc::before {
  content: ""; position: absolute; inset: 5%; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, var(--hi), var(--c1) 55%, var(--c2));
  box-shadow: inset 0 0 0 calc(var(--cell) * .09) rgba(0, 0, 0, .12), inset 0 -4px 8px rgba(0, 0, 0, .25);
}
.disc.p1 { --hi: #ff9aa9; --c1: var(--red); --c2: var(--red2); }
.disc.p2 { --hi: #fff2a8; --c1: var(--yel); --c2: var(--yel2); }
.disc.fall { animation: fall var(--dur, 400ms) cubic-bezier(.45, .05, .9, .6) both; }
@keyframes fall {
  from { transform: translateY(calc(var(--fall) * var(--cell) * -1)); }
  80% { transform: translateY(0); }
  90% { transform: translateY(-4%); }
  to { transform: translateY(0); }
}
.disc.win::after { content: ""; position: absolute; inset: 17%; border-radius: 50%; border: 4px solid #fff; animation: pulse .9s ease-in-out infinite alternate; }
@keyframes pulse { from { transform: scale(.85); opacity: .6; } to { transform: scale(1.08); opacity: 1; } }

/* sütun düğmeleri + üst slot (hayalet taş / öneri rozetleri) */
.cols { position: absolute; z-index: 5; left: var(--pad); top: calc(-1 * var(--cell)); width: calc(7 * var(--cell)); height: calc(7 * var(--cell) + var(--pad)); display: grid; grid-template-columns: repeat(7, var(--cell)); }
.col { position: relative; border: 0; background: none; padding: 0; display: flex; flex-direction: column; outline: none; }
.col::before { content: ""; position: absolute; left: 0; right: 0; top: var(--cell); bottom: 0; background: rgba(255, 255, 255, .09); opacity: 0; transition: opacity .12s; border-radius: 10px; }
.col:focus-visible::before { opacity: 1; }
@media (hover: hover) { .col:hover::before { opacity: 1; } .col:hover .ghost { opacity: .6; } }
.col.shake { animation: shake .3s; }
@keyframes shake { 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }
.slot { position: relative; height: var(--cell); width: 100%; }
.ghost { position: absolute; inset: 12%; border-radius: 50%; opacity: 0; transition: opacity .12s; background: var(--red); }
body[data-turn="2"] .ghost { background: var(--yel); }
.badge { position: absolute; left: 50%; top: 50%; width: 52%; aspect-ratio: 1; margin: -26% 0 0 -26%; border-radius: 50%; display: none; place-items: center; font-weight: 800; font-size: calc(var(--cell) * .3); color: #04210f; }
.col[data-badge="best"] .badge { display: grid; background: var(--green); animation: bob 1s ease-in-out infinite alternate; box-shadow: 0 0 0 4px rgba(61, 220, 151, .3); }
.col[data-badge="bad"] .badge { display: grid; background: var(--warn); color: #3a0b00; }
.col[data-badge="best"] .badge::before { content: "★"; }
.col[data-badge="bad"] .badge::before { content: "!"; }
@keyframes bob { to { transform: translateY(18%); } }
body[data-lock="1"] .ghost { display: none; }

/* ---------- sonuç bandı ---------- */
.banner { position: absolute; inset: var(--cell) 0 0; z-index: 10; display: grid; place-items: center; background: rgba(8, 12, 30, .55); border-radius: 20px; backdrop-filter: blur(2px); animation: fade .3s; }
.banner[hidden] { display: none; }
@keyframes fade { from { opacity: 0; } }
.banner-card { text-align: center; padding: 18px 24px; background: rgba(20, 28, 64, .92); border: 1px solid var(--line); border-radius: 18px; max-width: 92%; }
.banner-emoji { font-size: 2.4rem; }
.banner-card h2 { font-size: 1.5rem; margin: 2px 0 4px; }
.banner-card p { color: var(--muted); margin-bottom: 12px; font-size: .95rem; }

/* ---------- kontroller ---------- */
.controls { width: 100%; max-width: 560px; display: flex; flex-direction: column; gap: 10px; align-items: center; }
.row { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; align-items: center; }
.btn { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 9px 16px; font-weight: 600; transition: transform .08s, background .15s; }
.btn:hover { background: rgba(255, 255, 255, .13); }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .4; cursor: default; }
.btn.primary { background: linear-gradient(180deg, #6f8fff, #4b6df0); border-color: transparent; color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.good { background: linear-gradient(180deg, #43e6a1, #22b878); color: #04210f; border-color: transparent; }
.settings { gap: 14px 20px; }
.field { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: .88rem; }
.seg { display: inline-flex; background: rgba(0, 0, 0, .25); border: 1px solid var(--line); border-radius: 10px; padding: 2px; }
.seg button { border: 0; background: none; padding: 4px 12px; border-radius: 8px; color: var(--muted); font-size: .88rem; }
.seg button[aria-pressed="true"] { background: var(--accent); color: #0a1235; font-weight: 700; }
.switch { display: inline-flex; align-items: center; gap: 8px; font-size: .88rem; color: var(--muted); cursor: pointer; user-select: none; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.track { width: 38px; height: 22px; border-radius: 999px; background: rgba(255, 255, 255, .18); position: relative; transition: background .2s; }
.track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .2s; }
.switch input:checked + .track { background: var(--green); }
.switch input:checked + .track::after { transform: translateX(16px); }
.switch input:focus-visible + .track { outline: 2px solid var(--accent); outline-offset: 2px; }
body[data-mode="lesson"] .settings, body[data-mode="lesson"] #btn-undo, body[data-mode="lesson"] #btn-new { display: none; }

/* ---------- koç paneli ---------- */
.coach { width: 100%; max-width: 560px; padding: 16px; display: flex; flex-direction: column; gap: 12px; }
@media (min-width: 960px) { .coach { max-width: none; } }
.coach-head { display: flex; align-items: center; gap: 12px; }
.avatar { width: 44px; height: 44px; display: grid; place-items: center; font-size: 1.5rem; background: linear-gradient(135deg, #6f8fff, #b57bff); border-radius: 14px; }
.coach-head h2 { font-size: 1.1rem; }
.coach-head p { color: var(--muted); font-size: .85rem; }
.bubble { border-radius: 12px; padding: 9px 12px; font-size: .93rem; border: 1px solid var(--line); animation: pop .25s; }
.bubble[hidden] { display: none; }
@keyframes pop { from { transform: translateY(4px); opacity: 0; } }
.bubble.feedback.good { background: rgba(61, 220, 151, .12); border-color: rgba(61, 220, 151, .45); }
.bubble.feedback.ok { background: rgba(124, 156, 255, .12); border-color: rgba(124, 156, 255, .45); }
.bubble.feedback.bad { background: rgba(255, 122, 89, .13); border-color: rgba(255, 122, 89, .5); }
.bubble.cpu { background: rgba(255, 212, 59, .09); border-color: rgba(255, 212, 59, .35); }
.advice h3 { font-size: 1.1rem; margin-bottom: 4px; }
.advice .body { color: #d5dcff; font-size: .95rem; }
.advice .body + .body { margin-top: 6px; }
.advice .warn { color: #ffb29f; }
.advice .actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.steps { list-style: none; margin: 14px 0 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.steps li { display: grid; grid-template-columns: 26px 1fr; gap: 10px; align-items: start; padding: 7px 10px; border-radius: 10px; border: 1px solid transparent; font-size: .88rem; }
.steps .n { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: .8rem; background: rgba(255, 255, 255, .12); }
.steps .q { font-weight: 600; }
.steps .a { color: var(--muted); }
.steps li.after { opacity: .45; }
.steps li.decided { background: rgba(61, 220, 151, .12); border-color: rgba(61, 220, 151, .5); }
.steps li.decided .n { background: var(--green); color: #04210f; }
.steps li.decided .a { color: #c9f7e2; }
.steps li.warn .n { background: var(--warn); color: #3a0b00; }
.steps li.warn .a { color: #ffc8b8; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; color: var(--muted); font-size: .8rem; padding-top: 10px; border-top: 1px solid var(--line); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.lg { width: 18px; height: 18px; border-radius: 50%; display: inline-grid; place-items: center; font-style: normal; font-weight: 800; font-size: .7rem; }
.lg.best { background: var(--green); color: #04210f; }
.lg.bad { background: var(--warn); color: #3a0b00; }
.lg.ring { border: 3px dashed; }
.lg.ring.me { border-color: var(--green); }
.lg.ring.opp { border-color: var(--warn); }
.stats { color: var(--muted); font-size: .82rem; display: flex; gap: 14px; flex-wrap: wrap; }
.stats b { color: var(--ink); }
.dots { display: inline-flex; gap: 5px; margin-left: 6px; vertical-align: middle; }
.dots i { width: 9px; height: 9px; border-radius: 50%; background: rgba(255, 255, 255, .2); }
.dots i.on { background: var(--green); }
.dots i.cur { background: var(--accent); }
body[data-mode="lesson"] #legend, body[data-mode="lesson"] #btn-hint { display: none; }
body[data-mode="lesson"] #legend.show { display: flex; }
.loading { color: var(--muted); }

.foot { text-align: center; color: var(--muted); font-size: .8rem; margin-top: 18px; }

/* ---------- modal ---------- */
.modal { position: fixed; inset: 0; z-index: 50; background: rgba(5, 8, 20, .7); display: grid; place-items: center; padding: 16px; backdrop-filter: blur(3px); animation: fade .2s; }
.modal[hidden] { display: none; }
.sheet { width: min(480px, 100%); max-height: 90svh; overflow: auto; background: #151d3f; border: 1px solid var(--line); border-radius: 20px; padding: 20px; box-shadow: 0 30px 80px rgba(0, 0, 0, .6); }
.sheet h2 { font-size: 1.3rem; margin-bottom: 8px; }
.sheet p { color: #d5dcff; margin-bottom: 10px; }
.sheet .actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; margin-top: 14px; }
.sheet .demo { display: flex; gap: 6px; margin: 10px 0 14px; }
.sheet .demo i { width: 34px; height: 34px; border-radius: 50%; background: var(--red); box-shadow: inset 0 -3px 6px rgba(0, 0, 0, .25); }
.sheet .demo i.y { background: var(--yel); }
.sheet .pager { color: var(--muted); font-size: .8rem; margin-right: auto; align-self: center; }
.lesson-list { display: grid; gap: 8px; margin-top: 10px; }
.lesson-item { display: grid; grid-template-columns: 30px 1fr auto; gap: 10px; align-items: center; text-align: left; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }
.lesson-item:hover { background: rgba(255, 255, 255, .12); }
.lesson-item .n { width: 30px; height: 30px; border-radius: 50%; background: rgba(255, 255, 255, .13); display: grid; place-items: center; font-weight: 700; }
.lesson-item.done .n { background: var(--green); color: #04210f; }
.lesson-item small { display: block; color: var(--muted); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}
