:root {
    --ink: #3a2d52;
    --soft: #7d6aa3;
    --paper: #fffdf7;
    --pink: #ff8fab;
    --lilac: #b8a1ff;
    --mint: #7bd389;
    --sun: #feca57;
    --sky: #74b9ff;
    --shadow: 0 6px 0 rgba(90, 60, 140, .14), 0 14px 30px rgba(90, 60, 140, .12);
    --sat: env(safe-area-inset-top, 0px);
    --sab: env(safe-area-inset-bottom, 0px);
    font-family: 'Fredoka', system-ui, sans-serif;
    color: var(--ink);
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
    min-height: 100dvh;
    background:
        radial-gradient(circle at 15% 10%, #ffd6ec 0, transparent 40%),
        radial-gradient(circle at 90% 85%, #d6e4ff 0, transparent 45%),
        radial-gradient(rgba(150, 120, 200, .18) 1.6px, transparent 1.7px) 0 0 / 22px 22px,
        linear-gradient(160deg, #fde7f3, #eef0ff);
    background-attachment: fixed;
    -webkit-tap-highlight-color: transparent;
    overflow-x: hidden;
}
[hidden] { display: none !important; }

.screen { min-height: 100dvh; display: flex; flex-direction: column; align-items: center; padding: calc(18px + var(--sat)) 14px calc(18px + var(--sab)); }
.screen > .card { margin: auto 0; }
.card {
    width: min(460px, 100%); background: #fff; border-radius: 28px; padding: 22px 20px; box-shadow: var(--shadow);
    border: 3px solid #f1e6ff; display: flex; flex-direction: column; gap: 12px; animation: pop .4s cubic-bezier(.3, 1.6, .5, 1);
}
.card.wide { width: min(560px, 100%); }
h2 { margin: 0; font-size: 24px; }
.hint { margin: 0; color: var(--soft); font-size: 14px; }
.center { text-align: center; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; }

/* title */
.hero { text-align: center; align-items: center; }
.hero-doodles { display: flex; gap: 10px; font-size: 30px; }
.hero-doodles span { display: inline-block; animation: bob 2.4s ease-in-out infinite; }
.hero-doodles span:nth-child(2n) { animation-delay: .4s; }
.hero-doodles span:nth-child(3n) { animation-delay: .8s; }
.logo { margin: 4px 0 0; font-family: 'Gochi Hand', 'Fredoka', cursive; font-size: clamp(46px, 13vw, 66px); line-height: 1; letter-spacing: 1px; }
.logo span:first-child { color: #ff6f9f; text-shadow: 3px 3px 0 #ffd3e2; }
.logo span:last-child { color: #7b61ff; text-shadow: 3px 3px 0 #ddd3ff; }
.tag { margin: 0; color: var(--soft); font-size: 16px; line-height: 1.4; }
.howto { width: 100%; text-align: left; background: #faf6ff; border-radius: 16px; padding: 10px 14px; }
.howto summary { cursor: pointer; font-weight: 600; }
.howto ol { margin: 8px 0 2px; padding-left: 20px; line-height: 1.5; font-size: 15px; }

/* buttons & fields */
.btn {
    font: inherit; font-weight: 600; font-size: 17px; padding: 12px 18px; border-radius: 18px; border: 3px solid var(--ink);
    background: #fff; color: var(--ink); cursor: pointer; box-shadow: 0 4px 0 var(--ink); transition: transform .08s, box-shadow .08s;
}
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: linear-gradient(180deg, #ff9fbf, #ff7aa8); color: #fff; text-shadow: 0 1px 0 rgba(0,0,0,.15); }
.btn.mint { background: linear-gradient(180deg, #9ae6ad, #6fcf86); }
.btn.big { font-size: 20px; padding: 14px 20px; width: 100%; }
.btn.small { font-size: 14px; padding: 7px 12px; border-radius: 14px; box-shadow: 0 3px 0 var(--ink); }
.btn.ghost { box-shadow: none; }
.btn.link { border: 0; box-shadow: none; background: none; color: var(--soft); text-decoration: underline; padding: 6px; }
.field { display: flex; flex-direction: column; gap: 4px; font-weight: 600; }
input, select {
    font: inherit; font-size: 17px; padding: 11px 14px; border-radius: 16px; border: 3px solid #e4d8fb; background: var(--paper); color: var(--ink); outline: none;
}
input:focus, select:focus { border-color: var(--lilac); }
.code-row { display: flex; gap: 8px; }
.code-row input { flex: 1; min-width: 0; text-transform: uppercase; letter-spacing: 4px; text-align: center; }
.divider { display: flex; align-items: center; gap: 10px; color: var(--soft); font-size: 13px; }
.divider::before, .divider::after { content: ''; flex: 1; height: 2px; background: #eee3ff; border-radius: 2px; }
.error { margin: 0; color: #d63f6b; font-weight: 600; text-align: center; }

/* lobby ring */
.ring { position: relative; width: min(300px, 78vw); aspect-ratio: 1; margin: 6px auto 0; }
.ring::before { content: ''; position: absolute; inset: 16%; border: 3px dashed #e4d8fb; border-radius: 50%; }
.ring .arrow { position: absolute; left: 50%; top: 50%; width: 0; height: 0; font-size: 18px; color: var(--lilac); }
.seat {
    position: absolute; width: 74px; transform: translate(-50%, -50%); display: flex; flex-direction: column; align-items: center; gap: 2px;
    font-size: 13px; font-weight: 600; animation: pop .35s cubic-bezier(.3, 1.6, .5, 1);
}
.seat .av {
    width: 48px; height: 48px; border-radius: 50%; display: grid; place-items: center; font-size: 24px; background: var(--pc, #ffd6ec);
    border: 3px solid #fff; box-shadow: 0 3px 0 rgba(90,60,140,.2);
}
.seat.me .av { outline: 3px solid var(--ink); }
.seat.off { opacity: .4; }
.seat small { max-width: 74px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ring .mid { position: absolute; inset: 0; display: grid; place-items: center; font-size: 34px; pointer-events: none; }
.settings { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 10px; }
.settings label { display: flex; flex-direction: column; gap: 3px; font-size: 13px; font-weight: 600; color: var(--soft); }
.settings select { font-size: 15px; padding: 8px 10px; }
.settings select:disabled { opacity: .85; background: #f6f2ff; }

/* game */
.game { padding-top: calc(8px + var(--sat)); gap: 8px; }
.gbar { width: min(720px, 100%); display: flex; align-items: center; gap: 10px; background: #fff; border-radius: 20px; padding: 8px 12px; box-shadow: var(--shadow); }
.gstep { font-weight: 700; font-size: 15px; white-space: nowrap; }
.gdots { flex: 1; display: flex; gap: 4px; flex-wrap: wrap; justify-content: center; }
.gdots i { width: 14px; height: 14px; border-radius: 50%; background: #eee6ff; border: 2px solid #fff; box-shadow: 0 1px 0 rgba(0,0,0,.08); transition: background .2s, transform .2s; }
.gdots i.on { background: var(--pc); transform: scale(1.15); }
.gtimer { position: relative; width: 44px; height: 44px; flex: none; }
.gtimer svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.gtimer .tt { fill: none; stroke: #f0e8ff; stroke-width: 4; }
.gtimer .tv { fill: none; stroke: var(--mint); stroke-width: 4; stroke-linecap: round; stroke-dasharray: 97.4; transition: stroke-dashoffset .9s linear, stroke .3s; }
.gtimer.low .tv { stroke: #ff6b6b; }
.gtimer b { position: absolute; inset: 0; display: grid; place-items: center; font-size: 14px; }
.gtimer.low b { color: #e04f6c; animation: tick 1s infinite; }
.gbody { width: min(720px, 100%); flex: 1; display: flex; flex-direction: column; gap: 10px; min-height: 0; }
.prompt {
    background: #fff; border-radius: 22px; padding: 10px 16px; box-shadow: var(--shadow); text-align: center; animation: pop .35s cubic-bezier(.3, 1.6, .5, 1);
}
.prompt small { display: block; color: var(--soft); font-size: 13px; font-weight: 600; }
.prompt b { font-size: clamp(22px, 6vw, 32px); color: #6b4fd8; }
.task-actions { display: flex; gap: 10px; }
.task-actions .btn { flex: 1; }
.waiting { margin: auto; text-align: center; display: flex; flex-direction: column; gap: 10px; align-items: center; padding: 20px; }
.waiting .blob { font-size: 64px; animation: bob 1.6s ease-in-out infinite; }
.waiting p { margin: 0; color: var(--soft); font-size: 17px; }
.guess-art { background: #fff; border-radius: 22px; padding: 10px; box-shadow: var(--shadow); display: grid; place-items: center; }
.guess-art canvas { border-radius: 14px; max-width: 100%; height: auto !important; }
.textbox { display: flex; gap: 8px; }
.textbox input { flex: 1; min-width: 0; font-size: 20px; }

/* drawing pad */
.pad { flex: 1; display: flex; flex-direction: column; gap: 8px; min-height: 0; }
.pad-sheet { flex: 0 1 auto; width: 100%; aspect-ratio: 4 / 3; max-height: calc(100dvh - 340px - var(--sat) - var(--sab)); min-height: 170px; display: grid; place-items: center; }
.gbody.drawing .pad { flex: 0 1 auto; }
.pad-canvas { border-radius: 18px; background: var(--paper); box-shadow: 0 0 0 4px #fff, 0 0 0 7px #eadfff, var(--shadow); touch-action: none; cursor: crosshair; }
.pad.locked .pad-canvas { filter: saturate(.7) brightness(.97); cursor: default; }
.pad.full .pad-canvas { animation: shake .4s; }
.pad-tools { background: #fff; border-radius: 20px; padding: 8px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 8px; }
.pad-swatches { display: grid; grid-template-columns: repeat(13, 1fr); gap: 5px; }
.swatch { aspect-ratio: 1; border-radius: 50%; border: 3px solid #fff; background: var(--c); box-shadow: 0 0 0 2px #e9e0fb; cursor: pointer; padding: 0; transition: transform .12s; }
.swatch.on { transform: scale(1.18); box-shadow: 0 0 0 3px var(--ink); }
.swatch.custom { position: relative; overflow: hidden; background: conic-gradient(#ff6b6b, #feca57, #7bd389, #48dbfb, #a29bfe, #ff8fd1, #ff6b6b); }
.swatch.custom.on { background: var(--c); }
.swatch.custom input { position: absolute; inset: -8px; opacity: 0; cursor: pointer; width: 200%; height: 200%; padding: 0; border: 0; }
.pad-row { display: flex; gap: 6px; justify-content: center; }
.tool { font: inherit; font-size: 20px; min-width: 46px; height: 42px; border-radius: 14px; border: 3px solid #eee6ff; background: #fbf8ff; cursor: pointer; display: grid; place-items: center; }
.tool.on { border-color: var(--ink); background: #fff1f7; }
.tool:disabled { opacity: .4; }
.tool.size i { display: block; width: var(--d); height: var(--d); border-radius: 50%; background: var(--c, var(--ink)); }

/* drawing step, portrait: prompt → pad → Done */
.gbody.drawing .side { display: contents; }
.gbody.drawing .prompt { order: 0; }
.gbody.drawing .pad { order: 1; }
.gbody.drawing .side > .btn { order: 2; }

/* landscape phones: tools beside the sheet */
@media (orientation: landscape) and (max-height: 560px) {
    .gbody.drawing { flex-direction: row; }
    .gbody.drawing .side { width: 200px; display: flex; flex-direction: column; gap: 8px; justify-content: center; order: 0; }
    .gbody.drawing .pad { flex-direction: row; flex: 1; }
    .gbody.drawing .pad-sheet { aspect-ratio: auto; max-height: none; height: 100%; flex: 1; }
    .gbody.drawing .pad-tools { width: 210px; }
    .pad-swatches { grid-template-columns: repeat(7, 1fr); }
    .pad-row { flex-wrap: wrap; }
    .gbody.guessing { flex-direction: row; align-items: stretch; }
    .gbody.guessing .guess-art { flex: 1.3; }
    .gbody.guessing .side { flex: 1; display: flex; flex-direction: column; gap: 10px; justify-content: center; }
}

/* reveal & album */
.reveal { gap: 10px; }
.rhead { width: min(720px, 100%); display: flex; flex-direction: column; gap: 8px; align-items: center; }
.rhead h2 { font-family: 'Gochi Hand', 'Fredoka', cursive; font-size: clamp(30px, 8vw, 42px); color: #6b4fd8; text-align: center; }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; }
.tabs button { font: inherit; font-weight: 600; font-size: 14px; padding: 6px 12px; border-radius: 999px; border: 3px solid var(--pc); background: #fff; cursor: pointer; }
.tabs button.on { background: var(--pc); }
.rlist { width: min(560px, 100%); display: flex; flex-direction: column; gap: 14px; padding-bottom: 110px; }
.entry { background: #fff; border-radius: 24px; padding: 12px 14px 14px; box-shadow: var(--shadow); border: 4px solid var(--pc, #e4d8fb); display: flex; flex-direction: column; gap: 8px; }
.entry.fresh { animation: drop .55s cubic-bezier(.3, 1.6, .5, 1); }
.entry-who { font-weight: 600; color: var(--soft); font-size: 14px; }
.entry-text { font-size: clamp(24px, 6.5vw, 32px); font-weight: 700; text-align: center; color: var(--ink); padding: 4px 0 6px; }
.entry-art { display: grid; place-items: center; }
.entry-art canvas { width: 100% !important; height: auto !important; border-radius: 14px; }
.rbar {
    position: fixed; left: 0; right: 0; bottom: 0; padding: 12px 14px calc(12px + var(--sab)); display: flex; gap: 8px; justify-content: center; flex-wrap: wrap;
    background: linear-gradient(180deg, rgba(253,231,243,0), rgba(253,231,243,.95) 30%);
}
.rbar .btn { min-width: 0; }
.rbar .note { width: 100%; text-align: center; color: var(--soft); font-size: 14px; margin: 0; }
.linkbox { display: flex; gap: 6px; width: min(560px, 100%); }
.linkbox input { flex: 1; min-width: 0; font-size: 14px; }

/* misc */
.banner { position: fixed; top: calc(10px + var(--sat)); left: 50%; transform: translateX(-50%); background: #fff3c4; border: 3px solid var(--ink); padding: 6px 14px; border-radius: 14px; font-weight: 600; z-index: 30; }
.toasts { position: fixed; left: 50%; bottom: calc(18px + var(--sab)); transform: translateX(-50%); display: flex; flex-direction: column; gap: 6px; align-items: center; z-index: 40; pointer-events: none; }
.toast { background: var(--ink); color: #fff; padding: 9px 16px; border-radius: 16px; font-weight: 600; animation: pop .3s cubic-bezier(.3, 1.6, .5, 1); box-shadow: var(--shadow); }
.toast.good { background: #2f9e5b; }
.toast.bad { background: #d63f6b; }
.confetti { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 50; }

@keyframes pop { from { transform: scale(.85); opacity: 0; } }
@keyframes drop { from { transform: translateY(-24px) rotate(-3deg) scale(.9); opacity: 0; } }
@keyframes bob { 50% { transform: translateY(-8px) rotate(-6deg); } }
@keyframes tick { 50% { transform: scale(1.15); } }
@keyframes shake { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
