/* Turnul — 3D block stacking (js/turnul.js, three.js).
   Theme-aware like the other game pages: tokens on :root, redefined under body.dark-theme.
   The sky behind the tower is a CSS gradient whose hue the script moves as the tower grows (--tu-h). */
:root {
    --tu-accent: #0f766e;
    --tu-accent-2: #0d9488;
    --tu-accent-soft: #ddf5f1;
    --tu-on-accent: #ffffff;
    --tu-page-bg: #f3f7f6;
    --tu-card-bg: #ffffff;
    --tu-card-border: #d7e5e2;
    --tu-muted: #52625f;
    --tu-shadow: 0 10px 30px rgba(10, 60, 55, .12);
    --tu-overlay: rgba(8, 25, 24, .45);
    --tu-gold: #d97706;
    --tu-sky-l1: 78%;
    --tu-sky-l2: 60%;
    --tu-sky-s: 55%;
}

body.dark-theme {
    --tu-accent: #2dd4bf;
    --tu-accent-2: #5eead4;
    --tu-accent-soft: #10302c;
    --tu-on-accent: #04201c;
    --tu-page-bg: #0a1211;
    --tu-card-bg: #13201e;
    --tu-card-border: #26403c;
    --tu-muted: #9fb8b3;
    --tu-shadow: 0 10px 30px rgba(0, 0, 0, .5);
    --tu-overlay: rgba(0, 0, 0, .55);
    --tu-gold: #fbbf24;
    --tu-sky-l1: 26%;
    --tu-sky-l2: 9%;
    --tu-sky-s: 38%;
}

/* 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. */
.tu-body, body.tu-body#page-top {
    font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
    background: var(--tu-page-bg);
    color: var(--text-color);
    min-height: 100vh;
    overflow-x: clip;
}
body.tu-max { overflow: hidden; }
.tu-main { padding-top: 92px; padding-bottom: 40px; }
.tu-game .container, .tu-hero .container { max-width: 760px; }

/* ---- hero ---- */
.tu-hero { text-align: center; padding: 4px 0 10px; }
.tu-hero h1 { font-weight: 800; font-size: clamp(1.6rem, 5vw, 2.2rem); margin: 0 0 6px; display: inline-flex; align-items: center; gap: 12px; }
.tu-hero-icon { width: 46px; height: 46px; border-radius: 14px; display: inline-grid; place-items: center; font-size: 22px; color: #fff; background: linear-gradient(135deg, #0d9488, #f59e0b); box-shadow: var(--tu-shadow); }
.tu-lead { max-width: 620px; margin: 0 auto; color: var(--tu-muted); font-size: .98rem; line-height: 1.5; }

/* ---- the stage ---- */
.tu-stage {
    --tu-h: 175;
    --tu-hgt: clamp(480px, calc(100vh - 110px), 820px);
    position: relative;
    width: 100%;
    max-width: 640px;
    height: var(--tu-hgt);
    margin: 0 auto;
    border-radius: 22px;
    overflow: hidden;
    background: linear-gradient(180deg, hsl(var(--tu-h) var(--tu-sky-s) var(--tu-sky-l1)), hsl(calc(var(--tu-h) + 40) var(--tu-sky-s) var(--tu-sky-l2)));
    box-shadow: var(--tu-shadow);
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    cursor: pointer;
    outline: none;
    transition: background 1.2s linear;
}
@supports (height: 100svh) { .tu-stage { --tu-hgt: clamp(480px, calc(100svh - 110px), 820px); } }
.tu-stage:focus-visible { box-shadow: 0 0 0 3px var(--tu-accent), var(--tu-shadow); }
@media (max-width: 575.98px) {
    .tu-stage { width: calc(100% + 24px); margin: 0 -12px; border-radius: 0; }
}
.tu-stage:fullscreen { max-width: none; width: 100%; height: 100%; border-radius: 0; margin: 0; }
.tu-stage:-webkit-full-screen { max-width: none; width: 100%; height: 100%; border-radius: 0; margin: 0; }
.tu-stage.is-max { position: fixed; inset: 0; z-index: 1052; max-width: none; width: 100vw; height: 100vh; margin: 0; border-radius: 0; }
@supports (height: 100dvh) { .tu-stage.is-max { height: 100dvh; } }
.tu-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

.tu-hud { position: absolute; left: 0; right: 0; top: 0; display: flex; align-items: flex-start; gap: 8px; padding: 10px; z-index: 2; pointer-events: none; }
.tu-hud-left { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; padding: 4px 6px; color: #fff; text-shadow: 0 1px 3px rgba(0, 0, 0, .45); }
.tu-who { font-weight: 800; font-size: .95rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tu-best { font-size: .82rem; font-weight: 600; opacity: .92; }
.tu-tools { display: flex; gap: 6px; pointer-events: auto; }
.tu-round { width: 42px; height: 42px; border-radius: 50%; border: 1px solid rgba(255, 255, 255, .35); display: grid; place-items: center; background: rgba(0, 0, 0, .22); color: #fff; font-size: 16px; cursor: pointer; touch-action: manipulation; padding: 0; backdrop-filter: blur(4px); }
.tu-round:hover { background: rgba(0, 0, 0, .4); }
.tu-round:focus-visible, .tu-btn:focus-visible, .tu-chip:focus-visible, .tu-mode:focus-visible, .tu-chipbtn:focus-visible { outline: 3px solid #fde68a; outline-offset: 2px; }
.tu-round span[hidden], .tu-round[hidden] { display: none; }

.tu-score { position: absolute; left: 0; right: 0; top: 56px; margin: 0; text-align: center; font-weight: 900; font-size: clamp(3rem, 14vw, 4.6rem); line-height: 1; color: #fff; text-shadow: 0 3px 12px rgba(0, 0, 0, .3); pointer-events: none; z-index: 1; font-variant-numeric: tabular-nums; }
.tu-combo { position: absolute; left: 50%; top: calc(56px + clamp(3rem, 14vw, 4.6rem) + 6px); transform: translateX(-50%) scale(.9); margin: 0; padding: 4px 12px; border-radius: 999px; background: rgba(255, 255, 255, .9); color: #0f766e; font-weight: 800; font-size: .95rem; white-space: nowrap; opacity: 0; transition: opacity .2s, transform .2s; pointer-events: none; z-index: 1; }
.tu-stage[data-phase="setup"] .tu-score, .tu-stage[data-phase="setup"] .tu-hud-left { opacity: 0; }
.tu-combo.is-on { opacity: 1; transform: translateX(-50%) scale(1); }
.tu-hint { position: absolute; left: 50%; bottom: 22px; transform: translateX(-50%); margin: 0; padding: 8px 16px; border-radius: 999px; background: rgba(0, 0, 0, .35); color: #fff; font-weight: 700; white-space: nowrap; pointer-events: none; z-index: 1; animation: tu-pulse 1.4s ease-in-out infinite; }
.tu-hint[hidden] { display: none; }
@keyframes tu-pulse { 0%, 100% { opacity: .65; } 50% { opacity: 1; } }
.tu-loading { position: absolute; inset: 0; display: grid; place-items: center; margin: 0; color: #fff; font-weight: 700; text-shadow: 0 1px 3px rgba(0, 0, 0, .4); z-index: 3; padding: 20px; text-align: center; }
.tu-loading[hidden] { display: none; }
.tu-ai { position: absolute; left: 50%; bottom: 16px; transform: translateX(-50%); display: flex; align-items: center; gap: 8px; padding: 6px 6px 6px 14px; border-radius: 999px; background: rgba(0, 0, 0, .45); color: #fff; z-index: 2; white-space: nowrap; cursor: default; }
.tu-ai[hidden] { display: none; }
.tu-ai-txt { font-weight: 700; font-size: .9rem; }
.tu-chipbtn { min-height: 40px; min-width: 44px; padding: 4px 12px; border-radius: 999px; border: 1px solid rgba(255, 255, 255, .4); background: rgba(255, 255, 255, .12); color: #fff; font-weight: 800; cursor: pointer; touch-action: manipulation; }
.tu-chipbtn[aria-pressed="true"] { background: #fff; color: #0f766e; }

/* ---- overlays (inside the stage, so they work in full screen) ---- */
.tu-overlay { position: absolute; inset: 0; z-index: 5; display: grid; place-items: center; padding: 12px; background: var(--tu-overlay); animation: tu-fade .2s ease-out; cursor: default; }
.tu-overlay[hidden] { display: none; }
.tu-overlay-low { align-items: end; background: linear-gradient(180deg, transparent 30%, var(--tu-overlay)); }
@keyframes tu-fade { from { opacity: 0; } to { opacity: 1; } }
.tu-card { width: 100%; max-width: 400px; max-height: 100%; overflow: auto; padding: 18px 16px 16px; border-radius: 22px; background: var(--tu-card-bg); color: var(--text-color); text-align: center; box-shadow: 0 20px 50px rgba(0, 0, 0, .3); display: flex; flex-direction: column; gap: 9px; }
.tu-card h2 { font-weight: 800; font-size: 1.35rem; margin: 0; font-style: normal; font-family: inherit; }
.tu-sub { margin: 0; color: var(--tu-muted); line-height: 1.45; }
.tu-sub b { color: var(--text-color); }
.tu-dialog-icon { font-size: 32px; color: var(--tu-accent); line-height: 1; }
.tu-modes { display: grid; gap: 6px; }
.tu-mode { min-height: 52px; display: flex; align-items: center; gap: 12px; padding: 8px 14px; border-radius: 14px; border: 1px solid var(--tu-card-border); background: var(--tu-page-bg); color: inherit; font-weight: 700; text-align: left; cursor: pointer; touch-action: manipulation; }
.tu-mode svg, .tu-mode i { width: 20px; color: var(--tu-accent); flex: none; }
.tu-mode span { display: flex; flex-direction: column; line-height: 1.2; }
.tu-mode small { font-weight: 600; color: var(--tu-muted); font-size: .78rem; }
.tu-mode[aria-checked="true"] { border-color: var(--tu-accent); background: var(--tu-accent-soft); box-shadow: inset 0 0 0 1px var(--tu-accent); }
.tu-opt { display: flex; flex-direction: column; gap: 6px; text-align: left; }
.tu-opt[hidden] { display: none; }
.tu-label { font-weight: 700; font-size: .9rem; color: var(--tu-muted); }
.tu-note { color: var(--tu-muted); font-size: .82rem; line-height: 1.4; }
.tu-chips { display: flex; gap: 6px; }
.tu-chip { flex: 1; min-height: 44px; border-radius: 12px; border: 1px solid var(--tu-card-border); background: var(--tu-page-bg); color: inherit; font-weight: 800; font-size: 1rem; cursor: pointer; touch-action: manipulation; }
.tu-chip[aria-checked="true"] { background: var(--tu-accent); border-color: var(--tu-accent); color: var(--tu-on-accent); }
.tu-names { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.tu-names input { min-width: 0; width: 100%; min-height: 42px; padding: 6px 10px; border-radius: 10px; border: 1px solid var(--tu-card-border); background: var(--tu-card-bg); color: inherit; font-size: 1rem; }
.tu-names input:focus { outline: 2px solid var(--tu-accent); outline-offset: 1px; }
.tu-btn { min-height: 48px; padding: 8px 16px; border-radius: 14px; border: 1px solid var(--tu-card-border); background: var(--tu-card-bg); color: inherit; font-weight: 700; font-size: 1rem; display: inline-flex; align-items: center; justify-content: center; gap: 8px; cursor: pointer; touch-action: manipulation; width: 100%; }
.tu-btn:hover { border-color: var(--tu-accent); }
.tu-btn[hidden] { display: none; }
.tu-btn-primary { background: var(--tu-accent); border-color: var(--tu-accent); color: var(--tu-on-accent); }
.tu-btn-primary:hover { background: var(--tu-accent-2); border-color: var(--tu-accent-2); }
.tu-btn-ghost { background: transparent; border-color: transparent; color: var(--tu-muted); }
.tu-final { margin: 0; padding: 0; list-style: none; display: grid; gap: 4px; }
.tu-final[hidden] { display: none; }
.tu-final li { display: flex; align-items: center; gap: 8px; padding: 6px 10px; border-radius: 10px; background: var(--tu-page-bg); font-weight: 700; }
.tu-final li.is-win { background: var(--tu-accent-soft); }
.tu-final .tu-pos { width: 22px; color: var(--tu-muted); }
.tu-final .tu-nm { flex: 1; text-align: left; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tu-final .tu-h { font-variant-numeric: tabular-nums; }

.tu-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; margin: 0; }

/* ---- below the stage ---- */
.tu-record { text-align: center; color: var(--tu-muted); margin: 12px 0 0; font-size: .92rem; min-height: 1.4em; }
.tu-record b { color: var(--text-color); }
.tu-reset-wrap { text-align: center; margin: 2px 0 0; }
.tu-reset-wrap[hidden] { display: none; }
.tu-link { border: 0; background: none; color: var(--tu-muted); text-decoration: underline; font-size: .85rem; cursor: pointer; padding: 6px; }
.tu-help { max-width: 640px; margin: 16px auto 0; padding: 12px 16px; border-radius: 16px; background: var(--tu-card-bg); border: 1px solid var(--tu-card-border); }
.tu-help summary { font-weight: 800; cursor: pointer; min-height: 32px; display: flex; align-items: center; gap: 8px; }
.tu-help summary svg, .tu-help summary i { color: var(--tu-accent); }
.tu-help ul { margin: 10px 0 0; padding-left: 20px; line-height: 1.55; }
.tu-help li { margin-bottom: 6px; }
.tu-help kbd { background: var(--tu-accent-soft); color: inherit; border: 1px solid var(--tu-card-border); border-radius: 6px; padding: 1px 6px; font-size: .85em; }
.tu-credit { color: var(--tu-muted); font-size: .84rem; margin: 8px 0 0; line-height: 1.45; }
.tu-powered { text-align: center; color: var(--tu-muted); font-size: .88rem; margin: 18px 0 0; }
.tu-powered a { color: var(--tu-accent); }

@media (prefers-reduced-motion: reduce) {
    .tu-overlay, .tu-combo, .tu-hint, .tu-stage { animation: none !important; transition: none !important; }
}
