/* 4 în linie — Connect Four for two players on one phone, or against the phone
   (js/patru-in-linie.js). Theme-aware like the other pages: tokens on :root,
   redefined under body.dark-theme. */
:root {
    --c4-accent: #1d4ed8;
    --c4-accent-soft: #dbeafe;
    --c4-page-bg: #f3f6fd;
    --c4-card-bg: #ffffff;
    --c4-card-border: #e2e8f0;
    --c4-muted: #64748b;
    --c4-shadow: 0 10px 30px rgba(15, 40, 120, .10);
    --c4-frame: #1d4ed8;
    --c4-frame-edge: #1e3a8a;
    --c4-hole: #e8eefb;
    --c4-red: #e11d2e;
    --c4-red-hi: #ff6b6b;
    --c4-red-lo: #9f1020;
    --c4-red-soft: #fee2e2;
    --c4-red-ink: #b4121f;
    --c4-yel: #facc15;
    --c4-yel-hi: #fff2a0;
    --c4-yel-lo: #c48a00;
    --c4-yel-soft: #fef9c3;
    --c4-yel-ink: #8a5a00;
}

body.dark-theme {
    --c4-accent: #60a5fa;
    --c4-accent-soft: #1e2a4a;
    --c4-page-bg: #0f172a;
    --c4-card-bg: #1e293b;
    --c4-card-border: #334155;
    --c4-muted: #94a3b8;
    --c4-shadow: 0 10px 30px rgba(0, 0, 0, .4);
    --c4-frame: #1e40af;
    --c4-frame-edge: #172554;
    --c4-hole: #0b1222;
    --c4-red-soft: rgba(225, 29, 46, .18);
    --c4-red-ink: #fca5a5;
    --c4-yel-soft: rgba(250, 204, 21, .16);
    --c4-yel-ink: #fde68a;
}

/* clip, not hidden: the site-wide `body { overflow-x: hidden }` makes <body> a scroll
   container that never scrolls, which silently kills any position: sticky inside. */
.c4-body, body.c4-body#page-top {
    font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
    background: var(--c4-page-bg);
    color: var(--text-color);
    min-height: 100vh;
    overflow-x: clip;
}
.c4-main { padding-top: 100px; padding-bottom: 32px; }
.c4-wrap { max-width: 620px; padding-left: 16px; padding-right: 16px; }

/* ---- heading ---- */
.c4-head { text-align: center; margin-bottom: 12px; }
.c4-head h1 { display: inline-flex; align-items: center; gap: 10px; font-weight: 800; font-size: clamp(1.6rem, 6vw, 2.3rem); margin: 0 0 4px; }
.c4-title-discs { display: inline-flex; }
.c4-title-discs .c4-dot { width: .8em; height: .8em; }
.c4-title-discs .c4-dot + .c4-dot { margin-left: -.25em; }
.c4-lead { color: var(--c4-muted); margin: 0; font-size: .98rem; line-height: 1.45; }

.c4-dot { display: inline-block; flex: none; width: 14px; height: 14px; border-radius: 50%; box-shadow: inset 0 -2px 0 rgba(0, 0, 0, .18); }
.c4-dot.is-r { background: radial-gradient(circle at 35% 30%, var(--c4-red-hi), var(--c4-red) 55%, var(--c4-red-lo)); }
.c4-dot.is-g { background: radial-gradient(circle at 35% 30%, var(--c4-yel-hi), var(--c4-yel) 55%, var(--c4-yel-lo)); }

/* ---- mode + difficulty ---- */
.c4-modes { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px; border-radius: 14px; background: var(--c4-card-bg); border: 1px solid var(--c4-card-border); box-shadow: var(--c4-shadow); }
.c4-seg { min-width: 0; border: 0; border-radius: 10px; padding: 9px 8px; background: transparent; color: inherit; font-weight: 700; font-size: .88rem; line-height: 1.25; cursor: pointer; touch-action: manipulation; display: flex; align-items: center; justify-content: center; gap: 7px; text-align: center; }
.c4-seg[aria-checked="true"] { background: var(--c4-accent); color: #fff; }
body.dark-theme .c4-seg[aria-checked="true"] { color: #0b1222; }
.c4-seg:focus-visible, .c4-chip:focus-visible, .c4-btn:focus-visible, .c4-link:focus-visible, .c4-col:focus-visible { outline: 3px solid var(--c4-accent); outline-offset: 2px; }
.c4-diff { display: flex; align-items: center; justify-content: center; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.c4-diff[hidden] { display: none; }
.c4-diff-label { color: var(--c4-muted); font-size: .9rem; font-weight: 600; }
.c4-chip { border: 1px solid var(--c4-card-border); border-radius: 999px; padding: 5px 16px; background: var(--c4-card-bg); color: inherit; font-weight: 700; font-size: .9rem; cursor: pointer; touch-action: manipulation; }
.c4-chip[aria-checked="true"] { background: var(--c4-accent-soft); border-color: var(--c4-accent); color: var(--c4-accent); }

/* ---- score ---- */
.c4-score { display: grid; grid-template-columns: 1fr auto 1fr; gap: 8px; margin: 12px 0 10px; }
.c4-score-item { min-width: 0; display: flex; align-items: center; justify-content: center; gap: 7px; padding: 7px 10px; border-radius: 12px; background: var(--c4-card-bg); border: 1px solid var(--c4-card-border); font-size: .9rem; }
.c4-score-item strong { font-size: 1.15rem; font-variant-numeric: tabular-nums; }
.c4-score-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--c4-muted); font-weight: 600; }
.c4-score-item.is-d { padding-left: 12px; padding-right: 12px; }

/* ---- turn indicator ---- */
.c4-turn { display: flex; align-items: center; justify-content: center; gap: 12px; padding: 10px 14px; margin: 0 auto 10px; border-radius: 16px; border: 2px solid transparent; transition: background-color .25s, border-color .25s, color .25s; min-height: 64px; }
.c4-turn-disc { width: 38px; height: 38px; border-radius: 50%; flex: none; box-shadow: inset 0 -3px 0 rgba(0, 0, 0, .2), 0 2px 6px rgba(0, 0, 0, .15); }
.c4-turn-text { display: flex; flex-direction: column; min-width: 0; text-align: left; }
.c4-turn-main { font-weight: 800; font-size: clamp(1.25rem, 5.5vw, 1.6rem); line-height: 1.15; }
.c4-turn-sub { font-size: .88rem; font-weight: 600; opacity: .85; }
.c4-turn-sub:empty { display: none; }
.c4-turn.is-r { background: var(--c4-red-soft); border-color: var(--c4-red); color: var(--c4-red-ink); }
.c4-turn.is-r .c4-turn-disc { background: radial-gradient(circle at 35% 30%, var(--c4-red-hi), var(--c4-red) 55%, var(--c4-red-lo)); }
.c4-turn.is-g { background: var(--c4-yel-soft); border-color: var(--c4-yel); color: var(--c4-yel-ink); }
.c4-turn.is-g .c4-turn-disc { background: radial-gradient(circle at 35% 30%, var(--c4-yel-hi), var(--c4-yel) 55%, var(--c4-yel-lo)); }
.c4-turn.is-d { background: var(--c4-accent-soft); border-color: var(--c4-accent); color: var(--c4-accent); }
.c4-turn.is-d .c4-turn-disc { background: conic-gradient(var(--c4-red) 0 50%, var(--c4-yel) 0 100%); }
.c4-turn.is-thinking .c4-turn-disc { animation: c4-think 1s ease-in-out infinite; }
@keyframes c4-think { 50% { transform: scale(.82); } }

/* ---- the board ----
   .c4-stage = ghost row (preview disc) + board. The board has a 3% padding; the SVG frame
   (blue, with round holes) covers the whole board above the discs, so a falling disc slides
   behind the frame and shows only through the holes. */
.c4-stage { position: relative; width: min(100%, 560px); margin: 0 auto; user-select: none; -webkit-user-select: none; -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
.c4-ghost-row { padding: 0 3%; }
.c4-ghost-track { position: relative; aspect-ratio: 7 / 1; }
.c4-ghost { position: absolute; left: 0; top: 0; width: calc(100% / 7); height: 100%; opacity: 0; transition: transform .12s ease-out, opacity .15s; pointer-events: none; }
.c4-ghost::before { content: ""; position: absolute; inset: 9%; border-radius: 50%; box-shadow: inset 0 -3px 0 rgba(0, 0, 0, .18); }
.c4-ghost.is-r::before { background: radial-gradient(circle at 35% 30%, var(--c4-red-hi), var(--c4-red) 55%, var(--c4-red-lo)); }
.c4-ghost.is-g::before { background: radial-gradient(circle at 35% 30%, var(--c4-yel-hi), var(--c4-yel) 55%, var(--c4-yel-lo)); }
.c4-ghost.is-on { opacity: .9; }

.c4-board { position: relative; padding: 3%; isolation: isolate; }
/* the shadow sits on the static frame, not the board, so falling discs don't re-filter it */
.c4-frame { filter: drop-shadow(0 8px 14px rgba(15, 40, 120, .25)); }
body.dark-theme .c4-frame { filter: drop-shadow(0 8px 14px rgba(0, 0, 0, .55)); }
.c4-inner { position: relative; aspect-ratio: 7 / 6; background: var(--c4-hole); border-radius: 4px; }
.c4-discs { position: absolute; inset: 0; z-index: 1; }
.c4-frame { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 2; pointer-events: none; display: block; }
.c4-frame .c4-frame-body { fill: var(--c4-frame); }
.c4-frame .c4-frame-rim { fill: none; stroke: var(--c4-frame-edge); stroke-width: 5; opacity: .55; }
.c4-frame .c4-frame-edge { fill: none; stroke: var(--c4-frame-edge); stroke-width: 6; }
.c4-cols { position: absolute; inset: 0; z-index: 3; display: grid; grid-template-columns: repeat(7, 1fr); }
.c4-col { border: 0; padding: 0; margin: 0; background: transparent; cursor: pointer; border-radius: 10px; transition: background-color .12s; touch-action: manipulation; }
.c4-col.is-hover { background: rgba(255, 255, 255, .12); }
.c4-stage.is-locked .c4-col { cursor: default; }
.c4-stage.is-locked .c4-col.is-hover { background: transparent; }

.c4-disc { position: absolute; width: calc(100% / 7); height: calc(100% / 6); will-change: transform; }
.c4-disc::before { content: ""; position: absolute; inset: 5%; border-radius: 50%; box-shadow: inset 0 -4px 0 rgba(0, 0, 0, .18), inset 0 0 0 4px rgba(0, 0, 0, .08); }
.c4-disc.is-r::before { background: radial-gradient(circle at 35% 30%, var(--c4-red-hi), var(--c4-red) 55%, var(--c4-red-lo)); }
.c4-disc.is-g::before { background: radial-gradient(circle at 35% 30%, var(--c4-yel-hi), var(--c4-yel) 55%, var(--c4-yel-lo)); }
/* the winning four: a bright pulsing ring; the other discs fade a little */
.c4-disc::after { content: ""; position: absolute; inset: 24%; border-radius: 50%; border: 4px solid #fff; opacity: 0; box-shadow: 0 0 10px rgba(255, 255, 255, .9); }
.c4-disc.is-win::after { animation: c4-win 1s ease-in-out infinite; }
@keyframes c4-win { 0%, 100% { opacity: .95; transform: scale(1); } 50% { opacity: .45; transform: scale(.82); } }
.c4-board.is-over .c4-disc:not(.is-win) { opacity: .55; transition: opacity .4s .3s; }
.c4-disc.is-last::after { opacity: .5; border-width: 3px; inset: 38%; box-shadow: none; }
.c4-disc.is-last.is-win::after { inset: 24%; border-width: 4px; }

/* ---- result overlay ---- */
.c4-overlay { position: absolute; inset: 0; z-index: 4; display: grid; place-items: center; padding: 10px; animation: c4-fade .25s ease-out; }
.c4-overlay[hidden] { display: none !important; }
.c4-overlay-card { width: min(92%, 300px); padding: 16px 16px 14px; border-radius: 18px; background: var(--c4-card-bg); color: var(--text-color); border: 1px solid var(--c4-card-border); box-shadow: 0 16px 40px rgba(0, 0, 0, .3); text-align: center; animation: c4-pop .3s cubic-bezier(.2, 1.4, .4, 1); }
.c4-overlay-disc { display: block; width: 46px; height: 46px; margin: 0 auto 8px; border-radius: 50%; box-shadow: inset 0 -3px 0 rgba(0, 0, 0, .2); }
.c4-overlay-disc.is-r { background: radial-gradient(circle at 35% 30%, var(--c4-red-hi), var(--c4-red) 55%, var(--c4-red-lo)); }
.c4-overlay-disc.is-g { background: radial-gradient(circle at 35% 30%, var(--c4-yel-hi), var(--c4-yel) 55%, var(--c4-yel-lo)); }
.c4-overlay-disc.is-d { background: conic-gradient(var(--c4-red) 0 50%, var(--c4-yel) 0 100%); }
.c4-overlay-card h2 { font-size: 1.35rem; font-weight: 800; margin: 0 0 4px; }
.c4-overlay-card p { color: var(--c4-muted); margin: 0 0 12px; font-size: .92rem; }
.c4-overlay-card p:empty { display: none; }
.c4-overlay-actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
@keyframes c4-fade { from { opacity: 0; } }
@keyframes c4-pop { from { opacity: 0; transform: scale(.85); } }

/* ---- buttons ---- */
.c4-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 14px auto 6px; max-width: 560px; }
.c4-btn { min-height: 46px; border-radius: 12px; border: 1px solid var(--c4-card-border); background: var(--c4-card-bg); color: inherit; font-weight: 700; font-size: .95rem; padding: 8px 12px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; cursor: pointer; touch-action: manipulation; line-height: 1.2; }
.c4-btn:hover:not(:disabled) { border-color: var(--c4-accent); }
.c4-btn:disabled { opacity: .45; cursor: default; }
.c4-btn-primary { background: var(--c4-accent); border-color: var(--c4-accent); color: #fff; }
body.dark-theme .c4-btn-primary { color: #0b1222; }
.c4-note { text-align: center; color: var(--c4-muted); font-size: .88rem; margin: 0 0 8px; }
.c4-tools { display: flex; justify-content: center; gap: 6px 18px; flex-wrap: wrap; margin-bottom: 12px; }
.c4-link { border: 0; background: none; color: var(--c4-accent); font-weight: 600; font-size: .9rem; padding: 6px 4px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; }
.c4-link span { display: inline-flex; align-items: center; gap: 6px; }
.c4-link span[hidden] { display: none; }

.c4-help { max-width: 560px; margin: 0 auto; padding: 12px 16px; border-radius: 14px; background: var(--c4-card-bg); border: 1px solid var(--c4-card-border); }
.c4-help summary { font-weight: 700; cursor: pointer; }
.c4-help ul { margin: 10px 0 8px; padding-left: 20px; line-height: 1.55; }
.c4-help p { margin: 0; color: var(--c4-muted); font-size: .9rem; }
.c4-powered { text-align: center; color: var(--c4-muted); font-size: .85rem; margin: 18px 0 0; }
.c4-powered a { color: var(--c4-accent); }

@media (max-width: 420px) {
    .c4-seg { font-size: .8rem; padding: 8px 4px; gap: 5px; }
    .c4-score-item { padding: 6px 6px; font-size: .82rem; gap: 5px; }
    .c4-btn { font-size: .88rem; padding: 8px 8px; }
    .c4-turn { min-height: 58px; padding: 8px 12px; }
    .c4-turn-disc { width: 32px; height: 32px; }
}

@media (prefers-reduced-motion: reduce) {
    .c4-disc.is-win::after, .c4-turn.is-thinking .c4-turn-disc { animation: none; opacity: .9; }
    .c4-overlay, .c4-overlay-card { animation: none; }
}
