:root {
    --bg: #2f9c95;
    --ink: #16324f;
    --muted: #5f7590;
    --accent: #2f6fe0;
    --accent-2: #ffd21f;
    --gold: #ffc21f;
    --card: #ffffff;
    --line: rgba(43, 35, 80, 0.16);
    --emoji: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
    height: 100%;
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: ui-rounded, "SF Pro Rounded", "Nunito", system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
    overflow: hidden;
    overscroll-behavior: none;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

#stage {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    display: block;
    touch-action: none;
    cursor: pointer;
}

/* ---------- HUD ---------- */
.hud {
    position: fixed;
    top: 0; left: 0; right: 0;
    z-index: 5;
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 8px;
    padding: calc(10px + env(safe-area-inset-top)) calc(12px + env(safe-area-inset-right)) 0 calc(12px + env(safe-area-inset-left));
    pointer-events: none;
}
.hud-left { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.hud-right { display: flex; justify-content: flex-end; gap: 8px; }

.pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 12px;
    font-size: 16px;
    font-weight: 900;
    color: var(--ink);
    background: rgba(255, 255, 255, 0.86);
    border-radius: 999px;
    box-shadow: 0 3px 0 rgba(43, 35, 80, 0.14);
    font-variant-numeric: tabular-nums;
}
.pill.big { font-size: 22px; padding: 4px 14px 4px 10px; }
.pill .star { font-family: var(--emoji); font-size: 20px; line-height: 1; }
.pill.big.bump { animation: bump 0.45s ease-out; }
@keyframes bump {
    30% { transform: scale(1.35) rotate(-6deg); }
    60% { transform: scale(0.95); }
}

.tool {
    pointer-events: auto;
    position: relative;
    width: 42px; height: 42px;
    display: grid; place-items: center;
    padding: 0;
    color: var(--ink);
    background: rgba(255, 255, 255, 0.86);
    border: 0;
    border-radius: 50%;
    box-shadow: 0 3px 0 rgba(43, 35, 80, 0.14);
    cursor: pointer;
    touch-action: none;
}
.tool svg { width: 22px; height: 22px; fill: currentColor; overflow: visible; }
.tool .cross { display: none; }
.tool.muted .wave { display: none; }
.tool.muted .cross { display: inline; }
.tool:active { transform: scale(0.94); }

/* ---------- transient messages ---------- */
.banner {
    position: fixed;
    top: calc(84px + env(safe-area-inset-top));
    left: 0; right: 0;
    z-index: 4;
    text-align: center;
    font-family: ui-rounded, "SF Pro Rounded", "Nunito", system-ui, sans-serif, var(--emoji);
    font-size: clamp(30px, 9vw, 56px);
    font-weight: 900;
    color: #fff;
    text-shadow: 0 3px 0 rgba(10, 10, 40, 0.5), 0 0 24px rgba(180, 140, 255, 0.95);
    opacity: 0;
    pointer-events: none;
}
.banner.show { animation: banner 1.9s ease-out; }
@keyframes banner {
    0% { opacity: 0; transform: scale(0.5) rotate(-6deg); }
    14% { opacity: 1; transform: scale(1.18) rotate(3deg); }
    26% { transform: scale(1) rotate(0); }
    78% { opacity: 1; transform: scale(1); }
    100% { opacity: 0; transform: scale(1.08); }
}

/* ---------- screens ---------- */
.screen {
    position: fixed;
    inset: 0;
    z-index: 10;
    display: flex;
    padding: 16px;
    background: rgba(3, 4, 18, 0.55);
    -webkit-backdrop-filter: blur(3px);
    backdrop-filter: blur(3px);
    overflow-y: auto;
}
.card {
    width: min(420px, 100%);
    margin: auto;
    padding: 22px 22px 18px;
    text-align: center;
    background: var(--card);
    border-radius: 28px;
    box-shadow: 0 10px 0 rgba(43, 35, 80, 0.16), 0 24px 60px rgba(43, 35, 80, 0.3);
}

h1, h2 { margin: 0; font-weight: 900; letter-spacing: 0.01em; }
h1 {
    font-size: clamp(27px, 8.2vw, 38px);
    line-height: 1.05;
    background: linear-gradient(90deg, #1f8078, #2b5a8c 55%, #b5532c);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}
h2 { font-size: 28px; margin-bottom: 10px; }

.tagline { margin: 6px 0 14px; color: var(--muted); font-size: 16px; font-weight: 700; }

.logo { display: block; width: 200px; height: 104px; margin: 0 auto 6px; border-radius: 18px; }

.howto {
    list-style: none;
    margin: 0 0 6px;
    padding: 0;
    text-align: left;
    font-size: 14px;
    line-height: 1.4;
    color: #4a4570;
}
.howto li { display: flex; gap: 10px; align-items: flex-start; padding: 4px 0; }
.howto strong { color: var(--ink); }
.dot { flex: none; width: 14px; height: 14px; margin-top: 3px; border-radius: 50%; }

.keys { margin: 12px 0 0; font-size: 12px; font-weight: 700; letter-spacing: 0.06em; color: var(--muted); }

.btn {
    display: block;
    width: 100%;
    margin-top: 10px;
    padding: 14px 16px;
    font: inherit;
    font-size: 18px;
    font-weight: 900;
    color: var(--ink);
    background: #f1f0f8;
    border: 0;
    border-radius: 18px;
    box-shadow: 0 4px 0 #d8d5ea;
    cursor: pointer;
    transition: transform 0.08s, filter 0.15s;
}
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 #d8d5ea; }
.btn:hover { filter: brightness(1.04); }
.btn:focus-visible, .tool:focus-visible, input:focus-visible { outline: 3px solid #2f9cf0; outline-offset: 2px; }
.btn.primary {
    padding: 16px;
    font-size: 22px;
    color: #fff;
    background: linear-gradient(180deg, #4fd384, #23a35a);
    box-shadow: 0 5px 0 #17703d;
    text-shadow: 0 2px 0 rgba(30, 10, 90, 0.4);
}
.btn.primary:active { box-shadow: 0 2px 0 #17703d; }
.btn.small { width: auto; margin: 0; padding: 0 16px; font-size: 14px; white-space: nowrap; background: #ffe7a3; box-shadow: 0 3px 0 #f0c64a; }
.btn:disabled { opacity: 0.5; cursor: default; }

/* ---------- finish screen ---------- */
.newbest {
    display: inline-block;
    margin-bottom: 6px;
    padding: 4px 12px;
    font-size: 12px;
    font-weight: 900;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: #4a3200;
    background: var(--gold);
    border-radius: 999px;
}
.final {
    font-size: clamp(54px, 17vw, 76px);
    font-weight: 900;
    line-height: 1;
    color: var(--accent);
    font-variant-numeric: tabular-nums;
    text-shadow: 0 4px 0 rgba(47, 111, 224, 0.2);
}
.unit { margin: 2px 0 0; font-size: 14px; font-weight: 800; color: var(--muted); }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 14px 0; }
.stats div { padding: 10px 4px; background: #f6f5fb; border-radius: 16px; }
.stats b { display: block; font-size: 20px; }
.stats span { font-size: 11px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }

.save { display: flex; gap: 8px; }
.save input {
    flex: 1;
    min-width: 0;
    height: 46px;
    padding: 0 14px;
    font: inherit;
    font-size: 16px;
    font-weight: 700;
    color: var(--ink);
    background: #fff;
    border: 2px solid #d8d5ea;
    border-radius: 14px;
    -webkit-user-select: text;
    user-select: text;
}
.save .btn { height: 43px; }

.note { min-height: 18px; margin: 10px 0 6px; font-size: 13px; font-weight: 600; color: var(--muted); }

.board { list-style: none; margin: 0 0 6px; padding: 0; text-align: left; font-size: 14px; font-weight: 700; }
.board li {
    display: grid;
    grid-template-columns: 30px 1fr auto;
    gap: 8px;
    align-items: center;
    padding: 7px 10px;
    border-radius: 12px;
    font-variant-numeric: tabular-nums;
}
.board li:nth-child(odd) { background: #f6f5fb; }
.board li.me { background: #fff0c2; outline: 2px solid var(--gold); }
.board .rank { font-weight: 900; color: var(--muted); }
.board li:nth-child(1) .rank { color: #e08a00; }
.board .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.board .pts { font-weight: 900; }
.board li.empty { display: block; text-align: center; color: var(--muted); background: none; }

@media (max-height: 620px) {
    .card { padding: 14px 18px; }
    .logo { display: none; }
    .howto { font-size: 13px; margin-bottom: 8px; }
    .howto li { padding: 2px 0; }
    .btn { padding: 10px 14px; margin-top: 8px; }
    .btn.primary { padding: 12px; font-size: 20px; }
    .stats { margin: 10px 0; }
}

@media (prefers-reduced-motion: reduce) {
    .pill.big.bump { animation: none; }
}


/* ---------- Pixel Nonogram extras ---------- */
body { background: #2f9c95; }
#stage { pointer-events: none; cursor: default; }
.card { color: var(--ink); }
.howto .dot { width: 20px; height: auto; margin: 0; border-radius: 0; font-family: var(--emoji); font-size: 18px; font-weight: 900; line-height: 1.2; text-align: center; }
.logo { display: grid; grid-template-columns: repeat(6, 20px); gap: 3px; justify-content: center; width: auto; height: auto; margin: 0 auto 10px; }
.logo i { width: 20px; height: 20px; background: #eef0ea; border-radius: 4px; }
.logo i.a { background: #e5484d; }
.logo i.b { background: #f7c631; }
.logo i.c { background: #3b82e0; }
.btn small { display: block; margin-top: 2px; font-size: 12px; font-weight: 700; opacity: 0.85; text-shadow: none; }
.btn.ghost { background: transparent; box-shadow: none; color: var(--muted); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
.card.wide { width: min(620px, 100%); }
.card h3 { margin: 14px 0 6px; font-size: 14px; font-weight: 900; color: var(--muted); text-align: left; font-family: ui-rounded, system-ui, var(--emoji); }
.micon { font-family: var(--emoji); font-size: 50px; line-height: 1.1; margin-bottom: 4px; }
.bigstars { margin: 2px 0 6px; font-family: var(--emoji); font-size: 38px; letter-spacing: 4px; }
.stats.two { grid-template-columns: 1fr 1fr; }
.tool.sound { position: fixed; top: calc(8px + env(safe-area-inset-top)); right: calc(10px + env(safe-area-inset-right)); z-index: 30; width: 38px; height: 38px; }
.tool.sound svg { width: 20px; height: 20px; }
.ledger { margin: 8px 0 0; }
.lrow { display: flex; justify-content: space-between; padding: 5px 10px; font-size: 14px; font-weight: 700; border-radius: 8px; }
.lrow:nth-child(odd) { background: #f3f6fd; }

/* puzzle */
.play { position: fixed; inset: 0; z-index: 4; display: flex; flex-direction: column; align-items: center; gap: 7px; width: min(860px, 100%); margin: 0 auto; padding: calc(8px + env(safe-area-inset-top)) calc(8px + env(safe-area-inset-right)) calc(10px + env(safe-area-inset-bottom)) calc(8px + env(safe-area-inset-left)); }
.top { display: flex; align-items: center; gap: 8px; width: 100%; padding-right: 46px; color: #fff; }
.top .tool { flex: none; width: 38px; height: 38px; }
.top .tool svg { width: 20px; height: 20px; }
.top .title { flex: 1; min-width: 0; line-height: 1.2; }
.top .title b, .top .title span { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-family: ui-rounded, system-ui, var(--emoji); }
.top .title b { font-size: 16px; font-weight: 900; }
.top .title span { font-size: 12px; font-weight: 700; opacity: 0.9; }
.top .pill { flex: none; padding: 3px 10px; font-size: 15px; font-weight: 900; color: #16324f; background: rgba(255, 255, 255, 0.92); white-space: nowrap; font-variant-numeric: tabular-nums; font-family: ui-rounded, system-ui, var(--emoji); }
.top .pill.low { color: #fff; background: #e5484d; }
.grid { flex: 1; min-height: 0; width: 100%; display: block; touch-action: none; cursor: pointer; }
.tools { display: flex; justify-content: center; gap: 7px; width: 100%; }
.tbtn { flex: 1; max-width: 130px; min-width: 0; height: 60px; padding: 2px 4px; font: inherit; font-size: 22px; font-weight: 900; line-height: 1.1; color: #fff; background: rgba(8, 40, 60, 0.4); border: 0; border-radius: 16px; cursor: pointer; font-family: ui-rounded, system-ui, "Segoe UI Symbol", var(--emoji); touch-action: manipulation; }
.tbtn small { display: block; margin-top: 2px; font-size: 11px; font-weight: 800; white-space: nowrap; }
.tbtn.tool.on { color: #16324f; background: #ffd23f; width: auto; height: 60px; border-radius: 16px; }
.tbtn.tool { width: auto; height: 60px; border-radius: 16px; box-shadow: none; display: block; color: #fff; background: rgba(8, 40, 60, 0.4); }
.tbtn:disabled { opacity: 0.4; cursor: default; }
.tbtn:active:not(:disabled) { transform: translateY(2px); }

.msg { position: fixed; bottom: calc(84px + env(safe-area-inset-bottom)); left: 50%; z-index: 8; width: max-content; max-width: min(520px, calc(100% - 24px)); padding: 8px 14px; font-size: 14px; font-weight: 800; color: #16324f; text-align: center; background: #fff3c9; border-radius: 14px; transform: translateX(-50%); opacity: 0; transition: opacity 0.25s; pointer-events: none; font-family: ui-rounded, system-ui, var(--emoji); }
.msg.show { opacity: 1; }
.banner { top: 40%; z-index: 9; font-size: clamp(30px, 8vw, 54px); color: #fff; text-shadow: 0 3px 0 rgba(0, 40, 60, 0.6), 0 0 24px rgba(255, 210, 63, 0.95); }

/* gallery */
.zone { margin: 0 0 12px; text-align: left; }
.pics { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.pic { display: grid; justify-items: center; align-content: center; gap: 2px; aspect-ratio: 1 / 1.12; padding: 5px 3px 4px; font: inherit; color: #2b5a8c; background: #e6f3f1; border: 0; border-radius: 13px; cursor: pointer; overflow: hidden; }
.pic b { font-size: 26px; font-weight: 900; font-family: ui-rounded, system-ui, var(--emoji); }
.pic small { font-family: ui-rounded, system-ui, var(--emoji); font-size: 10px; font-weight: 800; letter-spacing: -0.5px; line-height: 1.2; min-height: 12px; }
.pic.solved { background: #c9e2ea; }
.pic.locked { color: #9aa3c4; background: #eceef4; cursor: default; }
.pic.locked b { font-size: 18px; }
.thumb { width: 78%; height: auto; image-rendering: pixelated; }
.respic { display: grid; place-items: center; margin: 0 auto 8px; width: 190px; height: 190px; background: #c9e2ea; border-radius: 20px; }
.respic .thumb { width: 150px; }
.daypic { display: block; margin: 0 auto 8px; padding: 14px; width: 190px; height: 190px; background: #c9e2ea; border-radius: 20px; image-rendering: pixelated; }

@media (max-height: 520px) {
    .logo { display: none; }
    .play { width: 100%; display: grid; grid-template-columns: 1fr 150px; grid-template-rows: auto 1fr; gap: 4px 8px; }
    .top { grid-column: 2; grid-row: 1; flex-wrap: wrap; padding-right: 0; gap: 4px; padding-top: 44px; }
    .top .title { flex-basis: 100%; order: 3; }
    .top .title span { white-space: normal; }
    .grid { grid-column: 1; grid-row: 1 / 3; height: 100%; }
    .tools { grid-column: 2; grid-row: 2; display: grid; grid-template-columns: 1fr 1fr; align-content: end; gap: 5px; }
    .tbtn, .tbtn.tool, .tbtn.tool.on { height: 46px; font-size: 18px; max-width: none; }
    .tbtn small { font-size: 10px; margin-top: 0; }
    .msg { bottom: 10px; }
}
