/*
 * Island UI. The world itself is drawn on a canvas (js/art.js); this file styles the frame around
 * it: the top bar, prompts, touch controls, dialogs, and the plain codex people see without JavaScript.
 * Day is a sunny cream-and-candy palette; night (the theme toggle) is deep indigo.
 */
:root {
    --ink: #1d1b3a;
    --panel: #fff6e0;
    --panel-2: #ffe9bf;
    --text: #1d1b3a;
    --muted: #5a5483;
    --border: #1d1b3a;
    --link: #2f55d4;
    --label: #c2255f;
    --pink: #ff4d8d;
    --cyan: #27d3cc;
    --lemon: #ffd23f;
    --lime: #5ec24c;
    --violet: #8e63ff;
    --coral: #ff5d6c;
    --bar: #1d1b3a;
    --bar-text: #fff6e0;
    --font-pixel: "Silkscreen", "Courier New", monospace;
    --font-body: "DM Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
    --hud-h: 60px;
}

html[data-theme="dark"] {
    --panel: #292561;
    --panel-2: #342f7d;
    --text: #fff6e0;
    --muted: #c4beee;
    --border: #0b0a26;
    --link: #8fb0ff;
    --label: #ff8ab8;
    --bar: #0f0d33;
}

*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; padding: 0; }

html {
    background: #bfe8ff;
    color-scheme: light;
}

html[data-theme="dark"] {
    background: #10153f;
    color-scheme: dark;
}

body {
    min-width: 320px;
    color: var(--text);
    font-family: var(--font-body);
    font-size: 16px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

[hidden] { display: none !important; }

button, a, input { font: inherit; }
button { border: 0; color: inherit; background: none; cursor: pointer; }
a { color: inherit; }
code { font-family: var(--font-body); font-weight: 500; background: color-mix(in srgb, var(--pink) 18%, transparent); padding: 0 0.25em; }

:focus-visible { outline: 3px solid var(--pink); outline-offset: 3px; }

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

/* ---- which layer shows ---- */

html.js body {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100svh;
    overflow: hidden;
}

html.js .codex { display: none; }
html:not(.js) .hud,
html:not(.js) .stage,
html:not(.js) .dlg { display: none; }

/* ---- top bar ---- */

.hud {
    position: relative;
    z-index: 5;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.4rem 0.9rem;
    padding: 0.5rem clamp(0.6rem, 2vw, 1.25rem);
    padding-top: calc(0.5rem + env(safe-area-inset-top, 0px));
    color: var(--bar-text);
    background: var(--bar);
    box-shadow: 0 4px 0 var(--pink);
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 0.6rem;
    min-height: 44px;
    margin-right: auto;
    font-family: var(--font-pixel);
    font-size: 0.8rem;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    text-decoration: none;
}

.brand img { display: block; image-rendering: pixelated; }

.hud-stats { display: flex; gap: 0.5rem; }

.chip {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.28rem 0.6rem;
    border: 3px solid var(--border);
    color: var(--bar-text);
    background: #2b2860;
    font-family: var(--font-pixel);
    font-size: 0.66rem;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    white-space: nowrap;
}

.chip b { color: var(--lemon); font-weight: 700; }
.chip.is-done { background: var(--lime); color: var(--ink); }
.chip.is-done b { color: var(--ink); }

.hud-actions { display: flex; flex-wrap: wrap; gap: 0.45rem; }

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.45rem;
    min-width: 44px;
    min-height: 44px;
    padding: 0 0.95rem;
    border: 3px solid var(--border);
    box-shadow: 3px 3px 0 var(--border);
    color: var(--ink);
    background: var(--panel-2);
    font-family: var(--font-pixel);
    font-size: 0.7rem;
    letter-spacing: 0.04em;
    text-decoration: none;
    text-transform: uppercase;
    transition: transform 90ms ease, box-shadow 90ms ease, background 120ms ease;
}

.btn:hover { transform: translate(-1px, -1px); box-shadow: 4px 4px 0 var(--border); }
.btn:active { transform: translate(3px, 3px); box-shadow: 0 0 0 var(--border); }
.btn-lemon { background: var(--lemon); }
.btn-cyan { background: var(--cyan); }
.btn-pink { background: var(--pink); }
.btn-ghost { background: #fff6e0; }
.btn-big { min-height: 52px; padding: 0 1.4rem; font-size: 0.8rem; }

.btn-theme svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    fill: none;
    stroke: currentColor;
    stroke-linecap: square;
    stroke-width: 1.8;
}

html[data-theme="dark"] .btn-theme .icon-moon,
html:not([data-theme="dark"]) .btn-theme .icon-sun { display: none; }

/* ---- the stage ---- */

.stage {
    position: relative;
    flex: 1;
    min-height: 0;
    background: #3a86e8;
    overflow: hidden;
}

#world {
    position: absolute;
    inset: 0;
    display: block;
    width: 100%;
    height: 100%;
    touch-action: none;
    -webkit-tap-highlight-color: transparent;
    -webkit-user-select: none;
    user-select: none;
    image-rendering: pixelated;
    outline: none;
}

#world:focus-visible { outline: 3px solid var(--pink); outline-offset: -3px; }

.minimap {
    position: absolute;
    top: 0.7rem;
    right: 0.7rem;
    z-index: 2;
    width: 144px;
    height: 108px;
    border: 3px solid var(--border);
    box-shadow: 3px 3px 0 var(--border);
    background: #3a86e8;
    image-rendering: pixelated;
    pointer-events: none;
}

.hud-bottom {
    position: absolute;
    right: 0;
    bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
    left: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.6rem;
    padding: 0 0.75rem;
    pointer-events: none;
}

.prompt,
.bubble {
    pointer-events: auto;
    border: 3px solid var(--border);
    box-shadow: 4px 4px 0 var(--border);
    color: var(--text);
    background: var(--panel);
}

.prompt {
    display: inline-flex;
    align-items: center;
    gap: 0.7rem;
    min-height: 44px;
    padding: 0.35rem 1rem 0.35rem 0.5rem;
    font-family: var(--font-pixel);
    font-size: 0.74rem;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.prompt[hidden], .bubble[hidden] { display: none; }

.prompt kbd {
    display: inline-grid;
    min-width: 28px;
    height: 28px;
    place-items: center;
    border: 3px solid var(--border);
    background: var(--lemon);
    color: var(--ink);
    font-family: var(--font-pixel);
    font-size: 0.72rem;
}

.bubble {
    position: relative;
    max-width: min(34rem, 100%);
    padding: 0.8rem 1rem;
    font-size: 0.82rem;
    line-height: 1.55;
    animation: pop 180ms ease-out both;
}

.bubble b {
    display: block;
    margin-bottom: 0.2rem;
    color: var(--label);
    font-family: var(--font-pixel);
    font-size: 0.62rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.touch {
    position: absolute;
    right: 0;
    bottom: 0;
    left: 0;
    display: none;
    align-items: flex-end;
    justify-content: space-between;
    padding: 0 0.9rem calc(0.9rem + env(safe-area-inset-bottom, 0px));
    pointer-events: none;
}

.dpad {
    display: grid;
    grid-template-columns: repeat(3, 58px);
    grid-template-areas: ". up ." "left down right";
    gap: 6px;
    pointer-events: auto;
}

.dpad button,
.act {
    display: grid;
    place-items: center;
    border: 3px solid var(--border);
    box-shadow: 3px 3px 0 var(--border);
    color: var(--ink);
    background: rgba(255, 246, 224, 0.9);
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.dpad button { width: 58px; height: 54px; }
.dpad button[data-dir="up"] { grid-area: up; }
.dpad button[data-dir="left"] { grid-area: left; }
.dpad button[data-dir="down"] { grid-area: down; }
.dpad button[data-dir="right"] { grid-area: right; }
.dpad svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-linecap: square; stroke-width: 2.4; }

.act {
    width: 76px;
    height: 76px;
    margin-bottom: 4px;
    font-family: var(--font-pixel);
    font-size: 1.3rem;
    background: var(--pink);
    pointer-events: auto;
}

.act:disabled { opacity: 0.45; }
.dpad button:active, .act:active:not(:disabled) { transform: translate(3px, 3px); box-shadow: 0 0 0 var(--border); }

@media (hover: none), (pointer: coarse) {
    html.js .touch { display: flex; }
    html.js .hud-bottom { bottom: calc(9.4rem + env(safe-area-inset-bottom, 0px)); }
}

/* ---- dialogs ---- */

.dlg {
    width: min(740px, calc(100vw - 1.25rem));
    max-height: calc(100svh - 1.25rem);
    margin: auto;
    padding: 0;
    overflow: auto;
    overscroll-behavior: contain;
    border: 3px solid var(--border);
    box-shadow: 6px 6px 0 var(--border);
    color: var(--text);
    background: var(--panel);
}

.dlg[open] { animation: pop 200ms ease-out both; }
.dlg::backdrop { background: rgba(13, 11, 43, 0.62); }

.dlg-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.9rem 1.1rem;
    border-bottom: 3px solid var(--border);
    color: var(--ink);
    background: var(--hue, var(--pink));
}

.dlg-title {
    font-family: var(--font-pixel);
    font-size: clamp(1rem, 4vw, 1.35rem);
    font-weight: 700;
    line-height: 1.2;
    letter-spacing: 0.01em;
    text-transform: none;
}

.pixel-kicker {
    margin-bottom: 0.35rem;
    color: var(--label);
    font-family: var(--font-pixel);
    font-size: 0.62rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.dlg-head .pixel-kicker { color: var(--ink); opacity: 0.8; margin-bottom: 0.25rem; }
.dlg-body { padding: clamp(1rem, 3vw, 1.5rem); }
.dlg-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 0.7rem; margin-top: 1.4rem; }

.intro-title {
    font-family: var(--font-pixel);
    font-size: clamp(1.9rem, 8vw, 3.2rem);
    font-weight: 700;
    line-height: 1.02;
    letter-spacing: -0.01em;
}

.intro-title span { display: block; color: var(--pink); }
.intro-tagline { max-width: 40ch; margin-top: 1rem; font-size: 0.95rem; line-height: 1.6; color: var(--muted); }

.intro-steps {
    display: grid;
    gap: 0.7rem;
    margin: 1.4rem 0 0;
    padding: 0;
    list-style: none;
    counter-reset: step;
    font-size: 0.8rem;
    line-height: 1.6;
}

.intro-steps li { display: grid; grid-template-columns: 1.8rem 1fr; gap: 0.7rem; align-items: start; counter-increment: step; }
.intro-steps li::before {
    content: counter(step);
    display: grid;
    width: 1.8rem;
    height: 1.8rem;
    place-items: center;
    border: 3px solid var(--border);
    color: var(--ink);
    background: var(--lemon);
    font-family: var(--font-pixel);
    font-size: 0.7rem;
}
.intro-steps li:nth-child(2)::before { background: var(--cyan); }
.intro-steps li:nth-child(3)::before { background: var(--pink); }

.intro-links { display: flex; flex-wrap: wrap; gap: 0 1.25rem; margin-top: 1rem; font-family: var(--font-pixel); font-size: 0.66rem; letter-spacing: 0.06em; text-transform: uppercase; }
.intro-links a { display: inline-flex; align-items: center; min-height: 44px; color: var(--link); text-decoration-thickness: 2px; text-underline-offset: 4px; }

.spot-foot {
    margin-top: 1.4rem;
    padding-top: 0.9rem;
    border-top: 3px dashed color-mix(in srgb, var(--border) 35%, transparent);
    color: var(--muted);
    font-size: 0.74rem;
    line-height: 1.6;
}

.spot-foot b { color: var(--label); font-family: var(--font-pixel); font-weight: 700; font-size: 0.66rem; letter-spacing: 0.04em; }

.detail-title { font-family: var(--font-pixel); font-size: clamp(1.4rem, 6vw, 2.2rem); line-height: 1.1; }
.detail-text { margin-top: 0.9rem; font-size: 0.95rem; line-height: 1.7; max-width: 52ch; }
.detail-extra:not(:empty) { margin-top: 1rem; }

.verdict {
    padding: 0.9rem 1rem;
    border: 3px solid var(--border);
    background: var(--panel-2);
    font-size: 0.8rem;
    line-height: 1.6;
}

.verdict-result { display: block; margin-bottom: 0.3rem; font-family: var(--font-pixel); font-size: 1.5rem; line-height: 1; }
.verdict.is-solved .verdict-result { color: #1f8f4a; }
.verdict.is-lost .verdict-result { color: var(--coral); }
.verdict p + p { margin-top: 0.4rem; }

/* ---- index ---- */

.index-h { margin: 1.2rem 0 0.6rem; font-family: var(--font-pixel); font-size: 0.8rem; letter-spacing: 0.06em; text-transform: uppercase; }
.index-h:first-child { margin-top: 0; }
.index-h span { color: var(--label); }
.index-list { display: grid; gap: 0.5rem; margin: 0; padding: 0; list-style: none; }

.index-item {
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 0.8rem;
    padding: 0.6rem 0.8rem;
    border: 3px solid var(--border);
    background: var(--panel-2);
}

.index-dot { width: 18px; height: 18px; border: 3px solid var(--border); background: var(--hue, var(--pink)); }
.index-item.is-done .index-dot { background: var(--lime); }
.index-name { font-family: var(--font-pixel); font-size: 0.78rem; line-height: 1.3; }
.index-name small { display: block; margin-top: 0.15rem; color: var(--muted); font-family: var(--font-body); font-size: 0.72rem; font-weight: 400; line-height: 1.5; }
.index-btns { display: flex; flex-wrap: wrap; gap: 0.4rem; justify-content: flex-end; }
.index-btns .btn { min-height: 44px; padding: 0 0.7rem; font-size: 0.62rem; }
.index-item.is-secret .index-name { color: var(--muted); }
.index-note { color: var(--muted); font-size: 0.74rem; }

/* ---- content reused from the codex ---- */

.card-body,
.codex { font-size: 0.82rem; line-height: 1.7; }

.card-body > * + * { margin-top: 1.1rem; }

.about-copy { font-size: 1rem; line-height: 1.65; }
.about-copy p + p { margin-top: 0.9rem; }

.availability-line { padding-top: 0.9rem; border-top: 3px dashed color-mix(in srgb, var(--border) 35%, transparent); font-size: 0.8rem; }
.availability-line strong { color: var(--label); font-weight: 500; }

.role-card-head,
.contribution-card-head {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    justify-content: space-between;
    gap: 0.4rem 1.2rem;
    margin-bottom: 0.9rem;
}

.role-card h3,
.contribution-card h3,
.project-card h3,
.education-block h3 {
    font-family: var(--font-pixel);
    font-size: clamp(1.05rem, 4vw, 1.4rem);
    font-weight: 700;
    line-height: 1.25;
}

.role-position,
.role-meta,
.contribution-meta,
.contribution-status span,
.project-beats dt,
.proof-chip,
.education-block h3 {
    font-family: var(--font-pixel);
    font-size: 0.62rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.role-position { margin-top: 0.3rem; color: var(--muted); }
.role-meta, .contribution-meta { color: var(--muted); text-align: right; }
.role-meta span, .contribution-meta span { display: block; color: var(--label); }

.role-highlights,
.project-evidence-list,
.education-block ul { padding-left: 1.1rem; }
.role-highlights li + li,
.education-block li + li { margin-top: 0.6rem; }
.project-evidence-list { margin-top: 0.8rem; color: var(--muted); font-size: 0.76rem; }
.project-evidence-list li + li { margin-top: 0.3rem; }
.role-highlights li::marker, .project-evidence-list li::marker { color: var(--pink); }

.education-block h3 { margin-bottom: 0.7rem; color: var(--label); font-size: 0.7rem; }
.education-block li span { display: block; font-family: var(--font-pixel); font-size: 0.9rem; }

.contribution-card p + p { margin-top: 0.7rem; }
.contribution-status { color: var(--muted); font-size: 0.76rem; }
.contribution-status span { margin-right: 0.5rem; color: var(--label); }

.proof-chips { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: 0.6rem; padding: 0; list-style: none; }
.proof-chip { display: inline-flex; align-items: center; min-height: 1.6rem; padding: 0.2rem 0.55rem; border: 2px solid var(--border); color: var(--ink); background: var(--lemon); }

.project-beats { display: grid; gap: 1.1rem; margin-top: 1rem; }
.project-beats dt { margin-bottom: 0.3rem; color: var(--label); }
.project-beats dd p + ul { margin-top: 0.7rem; }

.card-body a:not(.btn):not(.text-link):not(.contact-cta),
.codex a:not(.btn):not(.text-link):not(.contact-cta) {
    color: var(--link);
    text-decoration: underline;
    text-decoration-thickness: 2px;
    text-underline-offset: 3px;
}

.project-actions { display: flex; flex-wrap: wrap; gap: 0.5rem 0.7rem; margin-top: 1.2rem; }

.text-link,
.contact-cta {
    display: inline-flex;
    align-items: center;
    gap: 0.6rem;
    min-height: 44px;
    padding: 0 0.9rem;
    border: 3px solid var(--border);
    box-shadow: 3px 3px 0 var(--border);
    color: var(--ink);
    background: var(--cyan);
    font-family: var(--font-pixel);
    font-size: 0.66rem;
    letter-spacing: 0.04em;
    text-decoration: none;
    text-transform: uppercase;
    transition: transform 90ms ease, box-shadow 90ms ease;
}

.text-link:hover, .contact-cta:hover { transform: translate(-1px, -1px); box-shadow: 4px 4px 0 var(--border); }
.contact-cta { background: var(--pink); }
.icon-arrow { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-linecap: square; stroke-width: 2; }

.link-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(11rem, 1fr)); gap: 0.6rem; }
.link-list a {
    display: flex;
    align-items: center;
    min-height: 44px;
    padding: 0 0.9rem;
    border: 3px solid var(--border);
    box-shadow: 3px 3px 0 var(--border);
    color: var(--ink);
    background: var(--panel-2);
    font-family: var(--font-pixel);
    font-size: 0.66rem;
    letter-spacing: 0.04em;
    text-decoration: none;
    text-transform: uppercase;
}
.link-list a:hover { background: var(--lemon); }

.contact-title { max-width: 16ch; font-family: var(--font-pixel); font-size: clamp(1.5rem, 6vw, 2.2rem); font-weight: 700; line-height: 1.12; }
.contact-stage .contact-cta { margin-top: 1.2rem; }
.contact-links { display: flex; flex-wrap: wrap; gap: 0 1.2rem; margin-top: 1.1rem; padding-top: 0.6rem; border-top: 3px dashed color-mix(in srgb, var(--border) 35%, transparent); font-size: 0.74rem; }
.contact-links a { display: inline-flex; align-items: center; min-height: 44px; }

/* ---- the plain codex, for no-JavaScript visitors ---- */

html:not(.js) body { background: #bfe8ff; }
.codex { max-width: 760px; margin: 0 auto; padding: 2rem 1rem 3rem; }
.codex > section { margin-bottom: 1.5rem; padding: 1.25rem; border: 3px solid var(--border); box-shadow: 6px 6px 0 var(--border); background: var(--panel); }
.codex-intro h1 { font-family: var(--font-pixel); font-size: clamp(2rem, 9vw, 3.4rem); line-height: 1; }
.codex-intro h1 span { display: block; color: var(--pink); }
.codex-statement { margin-top: 1rem; font-size: 1rem; }
.codex-note { margin-top: 0.6rem; color: var(--muted); }
.codex-h { margin-bottom: 0.9rem; font-family: var(--font-pixel); font-size: 0.8rem; letter-spacing: 0.06em; text-transform: uppercase; color: var(--label); }
.codex-footer { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 0.5rem; font-family: var(--font-pixel); font-size: 0.62rem; letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink); }

/* ---- small screens ---- */

@media (max-width: 900px) {
    .minimap { display: none; }
}

@media (max-width: 720px) {
    .hud { gap: 0.3rem 0.6rem; }
    .brand-name { display: none; }
    .brand { margin-right: 0; }
    .hud-stats { margin-right: auto; }
    .hud-actions { width: 100%; justify-content: space-between; }
    .hud-actions .btn { flex: 1; padding: 0 0.4rem; }
    .btn-theme-text { display: none; }
    .index-item { grid-template-columns: auto 1fr; }
    .index-btns { grid-column: 1 / -1; justify-content: flex-start; }
}

@keyframes pop {
    from { opacity: 0; transform: translateY(8px) scale(0.98); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

@media (prefers-reduced-motion: reduce) {
    .dlg[open], .bubble { animation: none; }
    .btn, .text-link, .contact-cta { transition: none; }
}
