:root {
    --void: #0B1020;
    --hull: #1C2740;
    --panel: #2E3F5C;
    --foam: #E8F0FF;
    --ink: #0E1424;
    --blue: #4DA3FF;
    --green: #3DDB7A;
    --purple: #B07CFF;
    --gold: #FFC857;
    --danger: #FF7A45;
    --lightning: #C9B6FF;
    --cloak: #2A1840;
    color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    height: 100%;
    background: var(--void);
    color: var(--foam);
    font-family: "Avenir Next", "Segoe UI", sans-serif;
    overflow: hidden;
    /* manipulation disables double-tap zoom and still allows a menu to pan */
    touch-action: manipulation;
}

#frame {
    position: fixed;
    inset: 0;
    touch-action: manipulation;
}

#gameCanvas {
    width: 100%;
    height: 100%;
    display: block;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
    background: var(--void);
    touch-action: manipulation;
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
}

.screen {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    overflow: auto;
    background: rgba(11, 16, 32, 0.28);
    touch-action: manipulation;
}

.screen.hidden { display: none; }

.panel {
    width: min(560px, 100%);
    background: rgba(28, 39, 64, 0.94);
    border: 2px solid var(--panel);
    border-radius: 18px;
    padding: 22px 22px 18px;
}

.panel.loud {
    border-color: var(--gold);
    box-shadow: 0 0 0 4px rgba(255, 200, 87, 0.38);
    animation: card-pop 0.18s ease-out;
}

.panel.loud h2 {
    color: var(--gold);
    font-size: 32px;
}

.panel.trophy {
    width: min(640px, 96%);
    background: var(--foam);
    color: var(--ink);
    border: 4px solid var(--gold);
    border-radius: 26px;
    padding: 26px 26px 20px;
    box-shadow: 0 8px 0 var(--ink), 0 0 0 6px rgba(255, 200, 87, 0.4);
}

.panel.trophy h2 {
    color: var(--ink);
    font-size: 40px;
}

.panel.trophy .kicker,
.panel.trophy .win-line,
.panel.trophy .win-time {
    color: #6b4e12;
}

.panel.trophy .lede,
.panel.trophy .win-tease,
.panel.trophy #card-who,
.panel.trophy #card-notes,
.panel.trophy #card-notes li {
    color: var(--ink);
}

.panel.trophy #card-notes {
    list-style: none;
    padding-left: 0;
    margin-top: 8px;
    font-size: 15px;
    letter-spacing: 0.03em;
}

.panel.trophy .actions button:first-child {
    min-height: 48px;
    padding: 12px 18px;
    font-size: 18px;
}

#screen-card.is-trophy {
    background: rgba(11, 16, 32, 0.5);
}

#screen-card.is-fail {
    background: rgba(11, 16, 32, 0.58);
}

.panel.fail {
    background: var(--foam);
    color: var(--ink);
    border-color: var(--panel);
    box-shadow: none;
}

.panel.fail h2,
.panel.fail .lede,
.panel.fail .kicker {
    color: var(--ink);
}

.panel.fail h2 {
    font-size: 28px;
}

.panel.power-drop {
    box-shadow: 0 0 0 6px rgba(255, 200, 87, 0.62), 0 0 36px rgba(77, 163, 255, 0.35);
    animation: card-pop 0.22s ease-out, power-glow 0.7s ease-out;
}

@keyframes power-glow {
    from { box-shadow: 0 0 0 0 rgba(255, 200, 87, 0.9); }
    to { box-shadow: 0 0 0 10px rgba(255, 200, 87, 0); }
}

.celebrate {
    position: relative;
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 14px;
    min-height: 64px;
}

.celebrate.hidden { display: none; }

.celebrate canvas {
    image-rendering: pixelated;
    image-rendering: crisp-edges;
    background: transparent;
}

#card-who {
    margin: 0;
    font-size: 18px;
}

#card-saber {
    margin: 4px 0 0;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    font-size: 13px;
}

#card-grogu.hop {
    animation: grogu-hop 0.45s ease-in-out infinite;
}

#card-grogu.hidden { display: none; }

@keyframes grogu-hop {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
}

#card-sparks {
    display: none;
}

.panel.trophy {
    position: relative;
    overflow: hidden;
}

.panel.trophy #card-sparks.is-on {
    display: block;
    position: absolute;
    inset: 0;
    pointer-events: none;
    overflow: hidden;
    z-index: 2;
}

.panel.trophy #card-sparks i {
    position: absolute;
    left: 50%;
    top: 42%;
    width: 12px;
    height: 12px;
    margin: -6px 0 0 -6px;
    background: var(--gold);
    box-shadow: 0 0 0 2px rgba(255, 200, 87, 0.55);
    opacity: 0;
    animation: spark-burst 0.72s ease-out forwards;
}

.panel.trophy #card-sparks i:nth-child(3n) {
    width: 8px;
    height: 8px;
    margin: -4px 0 0 -4px;
    background: #fff6d4;
    box-shadow: none;
}

@keyframes spark-burst {
    0% { opacity: 1; transform: translate(0, 0) scale(1); }
    55% { opacity: 1; }
    100% { opacity: 0; transform: translate(var(--dx), var(--dy)) scale(0.3); }
}

@keyframes card-pop {
    from { transform: scale(0.94); }
    to { transform: scale(1); }
}

.panel.wide { width: min(880px, 100%); }

.kicker {
    margin: 0 0 6px;
    color: var(--gold);
    letter-spacing: 0.18em;
    text-transform: uppercase;
    font-size: 12px;
}

h1, h2 {
    margin: 0;
    font-weight: 650;
    letter-spacing: 0.04em;
}

h1 { font-size: 34px; line-height: 1.05; }

h2 { font-size: 26px; }

.by {
    margin: 8px 0 0;
    color: var(--gold);
    letter-spacing: 0.16em;
    text-transform: uppercase;
    font-size: 13px;
}

.lede {
    color: var(--foam);
    line-height: 1.4;
    margin: 12px 0 0;
}

.actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 16px;
}

button {
    appearance: none;
    background: var(--void);
    color: var(--foam);
    border: 2px solid var(--blue);
    font: inherit;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    padding: 10px 14px;
    min-height: 44px;
    cursor: pointer;
    touch-action: manipulation;
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
}

button:hover, button:focus-visible {
    background: var(--hull);
    outline: 2px solid var(--gold);
    outline-offset: 2px;
}

.actions button:first-child {
    background: var(--gold);
    color: var(--ink);
    border-color: var(--gold);
}

.actions button:first-child:hover,
.actions button:first-child:focus-visible {
    background: #ffe09a;
}

.choices {
    display: flex;
    gap: 10px;
    margin-top: 14px;
}

.choice {
    flex: 1;
    text-transform: none;
    letter-spacing: 0;
    text-align: left;
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 0;
}

.choice canvas {
    width: 64px;
    height: 64px;
    image-rendering: pixelated;
    background: var(--void);
    border: 2px solid var(--panel);
}

.choice strong { font-size: 16px; }

.choice span {
    font-size: 13px;
    line-height: 1.35;
    color: var(--foam);
    text-transform: none;
    letter-spacing: 0;
}

.swatches {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 14px;
}

.swatch {
    display: flex;
    align-items: center;
    gap: 8px;
    text-transform: none;
    letter-spacing: 0.04em;
}

.swatch i {
    width: 18px;
    height: 18px;
    display: block;
    border: 2px solid var(--ink);
}

.keys {
    list-style: none;
    padding: 0;
    margin: 12px 0 0;
}

.keys li { margin: 6px 0; }

kbd {
    display: inline-block;
    min-width: 1.4em;
    padding: 2px 6px;
    margin-right: 4px;
    border: 2px solid var(--panel);
    background: var(--void);
    color: var(--gold);
    font-family: ui-monospace, monospace;
}

.win-time {
    margin: 14px 0 0;
    color: var(--gold);
    font-size: 26px;
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.04em;
}

.win-line.hidden,
.win-time.hidden,
.win-tease.hidden { display: none; }

.win-line {
    margin: 8px 0 0;
    color: var(--gold);
    font-size: 20px;
    letter-spacing: 0.03em;
}

.win-tease {
    margin: 6px 0 0;
    color: var(--foam);
    font-size: 15px;
}

#screen-crawl {
    z-index: 9;
    align-items: flex-end;
    padding-bottom: 14vh;
    cursor: pointer;
    background:
        linear-gradient(to top, rgba(11, 16, 32, 0.15), rgba(11, 16, 32, 0.72) 46%, rgba(11, 16, 32, 0.88));
}

.crawl-stage {
    width: min(680px, 94%);
    text-align: center;
    perspective: 520px;
}

.crawl-kicker {
    margin: 0 0 16px;
    color: var(--gold);
    letter-spacing: 0.22em;
    text-transform: uppercase;
    font-size: 13px;
}

.crawl-tilt {
    transform-origin: center bottom;
    animation: crawl-rise 5.2s linear forwards;
}

.crawl-tilt p {
    margin: 0 0 12px;
    color: var(--gold);
    font-size: clamp(22px, 3.6vw, 34px);
    line-height: 1.25;
    font-weight: 700;
    text-shadow: 0 2px 0 #0e1424, 0 0 18px rgba(255, 200, 87, 0.45);
}

.crawl-skip {
    margin: 22px 0 0;
    color: var(--foam);
    font-size: 15px;
    letter-spacing: 0.04em;
}

@keyframes crawl-rise {
    from { transform: rotateX(26deg) translateY(36px); opacity: 0.15; }
    14% { opacity: 1; }
    to { transform: rotateX(18deg) translateY(-36px); opacity: 1; }
}

body.crawling #touch { display: none; }

.swatch.is-prism i {
    box-shadow: 0 0 0 3px var(--gold);
}

@media (prefers-reduced-motion: reduce) {
    .crawl-tilt { animation: none; transform: none; }
    .panel.trophy #card-sparks i { animation: none; opacity: 0; }
}

#card-notes {
    margin: 10px 0 0;
    padding-left: 18px;
}

#card-notes:empty { display: none; }

#touch {
    display: none;
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 3;
    touch-action: manipulation;
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
}

body.playing.touch #touch,
body.playing.has-coarse #touch { display: block; }

body.playing.touch.hud-lock #touch,
body.playing.has-coarse.hud-lock #touch { display: none; }

#btn-pause-touch {
    pointer-events: auto;
    position: absolute;
    top: max(10px, env(safe-area-inset-top));
    left: max(12px, env(safe-area-inset-left));
    min-width: 76px;
    min-height: 44px;
    border-radius: 22px;
    border-color: var(--foam);
    background: rgba(11, 16, 32, 0.78);
    z-index: 4;
    touch-action: manipulation;
}

#power-chips {
    pointer-events: auto;
    position: absolute;
    right: max(16px, env(safe-area-inset-right));
    bottom: calc(max(16px, env(safe-area-inset-bottom)) + 88px);
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    touch-action: manipulation;
}

#power-chips[data-empty="1"] { display: none; }

.power-chip {
    position: relative;
    min-width: 52px;
    min-height: 44px;
    padding: 4px 8px;
    border-radius: 14px;
    font-size: 11px;
    line-height: 1.1;
    letter-spacing: 0.04em;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    touch-action: manipulation;
    background: var(--cloak);
    border-color: var(--purple);
    color: var(--foam);
}

.power-chip canvas {
    width: 32px;
    height: 32px;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
    pointer-events: none;
}

.power-chip b {
    position: absolute;
    top: 1px;
    left: 4px;
    z-index: 1;
    font-size: 11px;
    line-height: 1;
    padding: 1px 3px;
    border-radius: 4px;
    background: rgba(14, 20, 36, 0.78);
    color: var(--foam);
}

.power-chip.is-locked {
    opacity: 0.62;
    background: var(--panel);
    border-color: var(--panel);
    color: var(--foam);
}

.power-chip.is-on {
    background: var(--gold);
    color: var(--ink);
    border-color: var(--gold);
    opacity: 1;
}

.power-chip.is-on b {
    background: var(--ink);
    color: var(--gold);
}

#btn-power .power-face {
    width: 32px;
    height: 32px;
    display: block;
    margin: 0 auto;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
    pointer-events: none;
}

#stick {
    pointer-events: auto;
    position: absolute;
    left: max(16px, env(safe-area-inset-left));
    bottom: max(16px, env(safe-area-inset-bottom));
    width: 128px;
    height: 128px;
    border-radius: 50%;
    border: 2px solid rgba(232, 240, 255, 0.45);
    background: rgba(11, 16, 32, 0.35);
    touch-action: manipulation;
}

#nub {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 52px;
    height: 52px;
    margin: -26px 0 0 -26px;
    border-radius: 50%;
    background: var(--blue);
}

#touch-actions {
    pointer-events: auto;
    position: absolute;
    right: max(16px, env(safe-area-inset-right));
    bottom: max(16px, env(safe-area-inset-bottom));
    display: flex;
    gap: 10px;
    align-items: flex-end;
    touch-action: manipulation;
}

#touch-actions button {
    width: 76px;
    height: 76px;
    border-radius: 50%;
    padding: 6px;
    font-size: 26px;
    letter-spacing: 0;
    text-transform: none;
    touch-action: manipulation;
}

#btn-attack { border-color: var(--danger); }
#btn-special { border-color: var(--gold); }
#btn-power { border-color: var(--lightning); }
#btn-interact { border-color: var(--gold); }

#btn-special.is-ready {
    background: rgba(255, 200, 87, 0.2);
    color: var(--gold);
}

#btn-power.is-idle,
#btn-interact.is-idle,
#btn-special.is-idle {
    opacity: 0.38;
    border-color: var(--panel);
}

#btn-interact.is-ready {
    opacity: 1;
    border-color: var(--gold);
    background: rgba(255, 200, 87, 0.18);
    color: var(--gold);
}

#btn-interact.is-lesson {
    opacity: 1;
    border-color: var(--blue);
    background: rgba(77, 163, 255, 0.45);
    color: var(--foam);
    font-size: 15px;
    animation: lesson-pulse 0.8s ease-in-out infinite;
}

@keyframes lesson-pulse {
    50% { box-shadow: 0 0 0 8px rgba(255, 200, 87, 0.55); }
}

#rotate-gate {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 8;
    background: var(--void);
    color: var(--foam);
    padding: 32px 20px;
    text-align: left;
    touch-action: manipulation;
}

@media (orientation: portrait) and (max-width: 900px) {
    #rotate-gate { display: block; }
    #frame { display: none; }
}

@media (max-height: 420px) {
    h1 { font-size: 26px; }
    h2 { font-size: 20px; }
    .panel { padding: 12px; }
    .lede { margin-top: 6px; }
    .choice span { display: none; }
    .choice canvas { width: 48px; height: 48px; }
    #stick { width: 108px; height: 108px; }
    #touch-actions button { width: 58px; height: 58px; font-size: 18px; }
    #power-chips { bottom: calc(max(8px, env(safe-area-inset-bottom)) + 74px); }
    .panel.loud h2 { font-size: 24px; }
}
