/* Tumblox — skinned to the Skorven portal design system.
   Background matches the wrapper's .board gradient so the iframe is seamless.
   Accent: Tumblox cyan (--c on the portal), brand orange reserved for danger. */
:root {
    --bg-deep: #101218;
    --accent: #54A9FF;
    --accent-ink: #06222E;
    --orange: #FF6A3D;
    --green: #2BD67B;
    --amber: #FFB23D;
    --purple: #7C5CFF;
    --text-primary: #F4F5F7;
    --text-secondary: #9097A3;
    --text-tertiary: #7E8595;
    --panel-grad: linear-gradient(180deg, #181B23, #131519);
    --line: rgba(255, 255, 255, 0.08);
    --line-strong: rgba(255, 255, 255, 0.14);
    --font-body: 'Inter', system-ui, sans-serif;
    --font-disp: 'Bricolage Grotesque', 'Space Grotesk', sans-serif;
    --font-mono: 'Space Mono', monospace;
}

* { margin: 0; padding: 0; box-sizing: border-box; user-select: none; -webkit-user-select: none; }

body, html {
    width: 100%; height: 100%; overflow: hidden;
    font-family: var(--font-body);
    color: var(--text-primary);
    background:
        radial-gradient(80% 90% at 50% 18%, rgba(84, 169, 255, 0.14), rgba(0, 0, 0, 0) 70%),
        linear-gradient(180deg, #15171F, #101218);
    touch-action: none;
    -webkit-font-smoothing: antialiased;
}

#game-container { position: relative; width: 100vw; height: 100vh; }
canvas { display: block; touch-action: none; }

#ui-layer {
    position: absolute; top: 0; left: 0; width: 100%; height: 100%;
    pointer-events: none;
}

/* ---------- HUD ---------- */
#hud {
    position: absolute; top: 14px; left: 14px; right: 14px;
    display: flex; justify-content: space-between; align-items: center; gap: 8px;
    pointer-events: auto; z-index: 10;
    transition: opacity 0.25s;
}
#hud.hidden { opacity: 0; pointer-events: none; }
#hud-left, #hud-right { display: flex; gap: 7px; align-items: center; flex-wrap: wrap; }

.hud-pill {
    display: inline-flex; align-items: center; gap: 8px;
    font-family: var(--font-mono); font-size: 12px; color: var(--text-primary);
    padding: 7px 12px; border-radius: 11px;
    background: rgba(19, 21, 27, 0.82); border: 1px solid var(--line);
    backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05), 0 4px 14px rgba(0, 0, 0, 0.35);
    white-space: nowrap;
}
.hud-pill .pk {
    font-size: 10px; letter-spacing: 0.14em; text-transform: uppercase;
    color: var(--text-tertiary);
}

.glass-btn {
    pointer-events: auto; cursor: pointer;
    font-family: var(--font-body); font-weight: 600; font-size: 12.5px;
    color: #C7CCD5;
    padding: 8px 12px; border-radius: 11px;
    background: rgba(19, 21, 27, 0.82); border: 1px solid var(--line);
    backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
    transition: background 0.18s, color 0.18s, border-color 0.18s;
}
.glass-btn:hover { background: rgba(255, 255, 255, 0.08); color: #EDEFF2; border-color: var(--line-strong); }
.glass-btn:active { transform: scale(0.96); }

/* ---------- compass D-pad ---------- */
#dpad {
    position: absolute; right: 16px; bottom: 16px; z-index: 9;
    display: grid; grid-template-columns: repeat(2, 46px); gap: 7px;
    pointer-events: auto;
}
#dpad.hidden { display: none; }
.dp {
    position: relative; width: 46px; height: 46px; border-radius: 13px;
    display: grid; place-items: center; cursor: pointer;
    background: rgba(19, 21, 27, 0.78); border: 1px solid var(--line);
    backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
    touch-action: manipulation;
    transition: background 0.15s, border-color 0.15s, transform 0.1s;
}
.dp svg {
    width: 21px; height: 21px; fill: none;
    stroke: #A8E4FF; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
    transform: rotate(var(--rot));
}
.dp span {
    position: absolute; right: 5px; bottom: 3px;
    font-family: var(--font-mono); font-size: 9px; color: var(--text-tertiary);
}
.dp:hover { background: rgba(84, 169, 255, 0.14); border-color: rgba(84, 169, 255, 0.4); }
.dp:active { transform: scale(0.92); }
@media (pointer: coarse) {
    #dpad { grid-template-columns: repeat(2, 56px); gap: 8px; }
    .dp { width: 56px; height: 56px; border-radius: 15px; }
    .dp svg { width: 24px; height: 24px; }
}

/* ---------- first-level guide banner ---------- */
#guide-banner {
    position: absolute; top: 66px; left: 50%; transform: translateX(-50%);
    max-width: min(92vw, 560px); text-align: center;
    font-size: 13px; font-weight: 500; color: #C8EFFF; line-height: 1.45;
    padding: 9px 18px; border-radius: 999px;
    background: rgba(14, 28, 36, 0.88); border: 1px solid rgba(84, 169, 255, 0.35);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
    pointer-events: none; z-index: 9;
}
#guide-banner.hidden { display: none; }
@media (max-width: 480px) {
    #guide-banner { top: 108px; font-size: 12px; padding: 8px 14px; }
}

/* ---------- touch hint ---------- */
#touch-hint {
    position: absolute; bottom: 160px; left: 50%; transform: translateX(-50%);
    font-family: var(--font-mono); font-size: 11px; letter-spacing: 0.08em;
    color: var(--text-secondary);
    padding: 8px 14px; border-radius: 999px;
    background: rgba(19, 21, 27, 0.8); border: 1px solid var(--line);
    animation: hintFloat 2.2s ease-in-out infinite;
    pointer-events: none; z-index: 9;
}
#touch-hint.hidden { display: none; }
@keyframes hintFloat {
    0%, 100% { transform: translateX(-50%) translateY(0); opacity: 0.85; }
    50% { transform: translateX(-50%) translateY(-5px); opacity: 1; }
}

/* ---------- screens ---------- */
.screen {
    position: absolute; top: 0; left: 0; width: 100%; height: 100%;
    display: flex; justify-content: center; align-items: center;
    background: rgba(10, 12, 16, 0.6);
    backdrop-filter: blur(9px); -webkit-backdrop-filter: blur(9px);
    pointer-events: auto; z-index: 20;
    transition: opacity 0.3s ease;
}
.screen.hidden { opacity: 0; pointer-events: none !important; }
.screen.hidden * { pointer-events: none !important; }

.glass-panel {
    background: var(--panel-grad);
    border: 1px solid var(--line);
    padding: 2.2rem 2.4rem; border-radius: 18px; text-align: center;
    min-width: 320px; max-width: min(92vw, 460px);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05), 0 24px 60px rgba(0, 0, 0, 0.55);
    animation: panelIn 0.35s cubic-bezier(0.21, 0.9, 0.35, 1.1);
}
.wide-panel { max-width: min(92vw, 560px); }

@keyframes panelIn {
    from { opacity: 0; transform: translateY(20px) scale(0.96); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.eyebrow {
    font-family: var(--font-mono); font-size: 11px;
    letter-spacing: 0.22em; text-transform: uppercase;
    color: var(--accent); margin-bottom: 10px;
}
.eyebrow.success-eyebrow { color: var(--green); }
.eyebrow.danger-eyebrow { color: var(--orange); }

.glass-panel h1 {
    font-family: var(--font-disp);
    font-size: 2.6rem; font-weight: 800; letter-spacing: -0.02em; line-height: 1.02;
    color: var(--text-primary);
    margin-bottom: 0.4rem;
}
.glass-panel h1.h-sm { font-size: 1.9rem; }

.subtitle { color: var(--text-secondary); margin-bottom: 1.3rem; font-size: 14px; }

/* ---------- instructions ---------- */
.instructions {
    background: rgba(0, 0, 0, 0.28);
    border: 1px solid rgba(255, 255, 255, 0.06);
    padding: 14px 16px; border-radius: 13px;
    margin-bottom: 1.4rem; text-align: left; font-size: 13px;
}
.irow {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    color: #A6ADBA; margin-bottom: 9px;
}
.keys { display: flex; gap: 6px; }
.key {
    min-width: 26px; height: 26px; padding: 0 8px;
    display: inline-grid; place-items: center;
    border-radius: 8px;
    background: linear-gradient(180deg, #22252E, #191B22);
    border: 1px solid rgba(255, 255, 255, 0.12);
    box-shadow: 0 2px 0 rgba(0, 0, 0, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.08);
    font-family: var(--font-mono); font-size: 11.5px; color: #D6DAE2;
    white-space: nowrap;
}
.legend {
    display: flex; flex-direction: column; gap: 6px;
    border-top: 1px solid rgba(255, 255, 255, 0.07);
    margin-top: 11px; padding-top: 11px;
}
.lg { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--text-secondary); }
.sw { width: 10px; height: 10px; border-radius: 3px; display: inline-block; flex: none; }
.sw.amber { background: var(--amber); box-shadow: 0 0 8px rgba(255, 178, 61, 0.5); }
.sw.purple { background: var(--purple); box-shadow: 0 0 8px rgba(124, 92, 255, 0.5); }
.sw.cyan { background: var(--accent); box-shadow: 0 0 8px rgba(84, 169, 255, 0.5); }

/* ---------- buttons ---------- */
.primary-btn {
    display: inline-block; pointer-events: auto; cursor: pointer;
    background: var(--accent); color: var(--accent-ink);
    border: none; padding: 0.72rem 2.1rem;
    font-family: var(--font-body); font-size: 15px; font-weight: 700;
    border-radius: 12px;
    box-shadow: 0 6px 22px rgba(84, 169, 255, 0.32), inset 0 1px 0 rgba(255, 255, 255, 0.35);
    transition: transform 0.16s, box-shadow 0.16s, filter 0.16s;
    margin: 0.3rem;
}
.primary-btn:hover { transform: translateY(-2px); filter: brightness(1.08); box-shadow: 0 9px 28px rgba(84, 169, 255, 0.42), inset 0 1px 0 rgba(255, 255, 255, 0.35); }
.primary-btn:active { transform: translateY(0); }

.secondary-btn {
    display: inline-block; pointer-events: auto; cursor: pointer;
    background: rgba(255, 255, 255, 0.04); color: #C7CCD5;
    border: 1px solid var(--line); padding: 0.66rem 1.4rem;
    font-family: var(--font-body); font-size: 13.5px; font-weight: 600;
    border-radius: 12px; transition: all 0.16s; margin: 0.3rem;
}
.secondary-btn:hover { color: var(--text-primary); background: rgba(255, 255, 255, 0.08); border-color: var(--line-strong); }

/* ---------- level select ---------- */
#level-grid {
    display: grid; grid-template-columns: repeat(5, 1fr);
    gap: 9px; margin: 1.4rem 0; max-height: 52vh; overflow-y: auto;
    padding: 4px;
    scrollbar-width: thin; scrollbar-color: #242838 transparent;
}
#level-grid::-webkit-scrollbar { width: 5px; }
#level-grid::-webkit-scrollbar-thumb { background: #242838; border-radius: 5px; }

.level-cell {
    aspect-ratio: 1; display: flex; flex-direction: column;
    justify-content: center; align-items: center; gap: 2px;
    border-radius: 11px; cursor: pointer;
    background: rgba(255, 255, 255, 0.04); border: 1px solid var(--line);
    transition: all 0.16s; position: relative;
}
.level-cell .ln { font-family: var(--font-mono); font-weight: 700; font-size: 15px; color: #D6DAE2; }
.level-cell:hover { background: rgba(255, 255, 255, 0.09); transform: translateY(-2px); border-color: var(--line-strong); }
.level-cell.locked { opacity: 0.32; cursor: default; }
.level-cell.locked:hover { transform: none; background: rgba(255, 255, 255, 0.04); border-color: var(--line); }
.level-cell.locked .lock { font-size: 9px; }
.level-cell.completed {
    border-color: rgba(84, 169, 255, 0.45);
    box-shadow: inset 0 0 18px rgba(84, 169, 255, 0.08);
}
.level-cell .stars { font-size: 9px; letter-spacing: 1px; color: var(--amber); }

/* ---------- win ---------- */
.win-stars { font-size: 2.1rem; margin: 0.5rem 0 0.6rem; letter-spacing: 8px; color: var(--amber); text-shadow: 0 0 24px rgba(255, 178, 61, 0.45); }
.win-nums { color: var(--text-secondary); font-size: 13.5px; margin-bottom: 0.4rem; }
.win-nums b { color: var(--text-primary); font-weight: 700; }
#win-rating { color: var(--green); font-family: var(--font-mono); font-size: 12px; letter-spacing: 0.06em; margin-bottom: 0.9rem; }

/* ---------- responsive ---------- */
@media (max-width: 480px) {
    .glass-panel { padding: 1.5rem 1.2rem; min-width: 280px; }
    .glass-panel h1 { font-size: 2rem; }
    #level-grid { grid-template-columns: repeat(4, 1fr); }
    .hud-pill { font-size: 11px; padding: 6px 9px; gap: 6px; }
    .hud-pill .pk { font-size: 9px; }
    #hud-left .hud-pill:first-child span:not(.pk) { max-width: 72px; overflow: hidden; text-overflow: ellipsis; }
    .btn-label { display: none; }
    .glass-btn { padding: 8px 10px; }
}

/* ---------- Tumbloop extras ---------- */
.hud-pill.hud-crack {
    color: var(--amber, #FFB23D);
    border-color: rgba(255, 178, 61, 0.45);
    font-size: 10px;
    letter-spacing: 0.16em;
}
.hud-pill.hud-crack.hidden { display: none; }
