/* AI Word Games — bright, mobile-first */
:root {
    --bg: #f4f1ff;
    --bg2: #e8f7ff;
    --card: #ffffff;
    --ink: #2d2a4a;
    --muted: #7a7799;
    --primary: #6c5ce7;
    --primary-dark: #5141d1;
    --good: #20bf6b;
    --bad: #eb3b5a;
    --key: #ffffff;
    --key-ink: #2d2a4a;
    --key-shadow: #c9c4ea;
    --slot: #ece9ff;
    --shadow: 0 6px 18px rgba(80, 60, 180, .12);
    --lv: #6c5ce7;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
html { background: var(--bg2); }
body {
    font-family: 'Fredoka', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
    color: var(--ink);
    background: linear-gradient(160deg, var(--bg) 0%, var(--bg2) 100%) fixed;
    min-height: 100vh;
    -webkit-tap-highlight-color: transparent;
}
a { color: var(--primary); }

.btn {
    display: inline-block; border: 0; border-radius: 14px; padding: .7rem 1.2rem;
    font: inherit; font-weight: 600; font-size: 1rem; cursor: pointer; text-decoration: none;
    box-shadow: 0 4px 0 rgba(0,0,0,.12); transition: transform .08s;
}
.btn:active { transform: translateY(2px); box-shadow: 0 2px 0 rgba(0,0,0,.12); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-light { background: #fff; color: var(--ink); }

.level-chip {
    display: inline-block; background: var(--lv); color: #fff; font-weight: 700;
    border-radius: 999px; padding: .1rem .7rem; font-size: .95em;
}

/* ── Home ─────────────────────────────────────────── */
.home-wrap { max-width: 960px; margin: 0 auto; padding: 24px 16px 40px; }
.home-header { text-align: center; margin-bottom: 24px; }
.home-logo { font-size: 3.2rem; line-height: 1; }
.home-header h1 { margin: .3rem 0 .2rem; font-size: 2.2rem; color: var(--primary-dark); }
.home-sub { margin: 0; color: var(--muted); font-size: 1.15rem; }
.home-back { text-align: center; margin-top: 24px; font-size: 1.05rem; }

.level-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 14px; }
.level-card {
    background: var(--card); border-radius: 20px; padding: 18px 10px; text-align: center; text-decoration: none;
    color: var(--ink); box-shadow: var(--shadow); border-bottom: 6px solid var(--lv);
    display: flex; flex-direction: column; gap: 4px; transition: transform .12s;
}
.level-card:hover, .game-card:hover { transform: translateY(-3px); }
.level-code { font-size: 2rem; font-weight: 700; color: var(--lv); }
.level-name { color: var(--muted); font-size: .95rem; }

.game-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 16px; }
.game-card {
    background: var(--card); border-radius: 24px; padding: 26px 18px; text-align: center; text-decoration: none;
    color: var(--ink); box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 6px; transition: transform .12s;
}
.game-icon { font-size: 3.4rem; }
.game-name { font-size: 1.4rem; font-weight: 700; color: var(--primary-dark); }
.game-desc { color: var(--muted); }

/* ── Play shell ───────────────────────────────────── */
.play-wrap { max-width: 720px; margin: 0 auto; padding: 10px 16px 16px; min-height: 100vh; display: flex; flex-direction: column; }
.play-bar { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.bar-btn {
    width: 44px; height: 44px; border-radius: 14px; border: 0; background: #fff; box-shadow: var(--shadow);
    font-size: 1.3rem; display: grid; place-items: center; text-decoration: none; color: var(--ink); cursor: pointer;
}
.bar-title { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 1.1rem; min-width: 0; }
.bar-game { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.hud { display: flex; justify-content: space-between; gap: 8px; margin: 12px 0; }
.hud-item { background: #fff; border-radius: 14px; padding: 6px 12px; box-shadow: var(--shadow); font-size: 1.05rem; }
.hud-item:empty { display: none; }
#hud-score { display: inline-block; }
#hud-score.bump { animation: bump .35s; }
@keyframes bump { 50% { transform: scale(1.5); color: var(--good); } }

.stage { flex: 1; display: flex; flex-direction: column; }
.loading { margin: auto; text-align: center; color: var(--muted); font-size: 1.1rem; }
.spinner {
    width: 54px; height: 54px; margin: 0 auto 12px; border-radius: 50%;
    border: 6px solid #ddd8ff; border-top-color: var(--primary); animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.hint-box {
    background: #fff; border-radius: 18px; padding: 12px 16px; box-shadow: var(--shadow);
    display: flex; align-items: center; gap: 12px; font-size: 1.15rem; margin-bottom: 18px;
}
.hint-emoji { font-size: 2rem; flex-shrink: 0; }

.slots { display: flex; justify-content: center; flex-wrap: wrap; gap: 6px; margin: 8px 0 18px; }
.slot {
    width: clamp(30px, 9vw, 48px); height: clamp(40px, 11vw, 56px); border-radius: 12px; border: 0;
    background: var(--slot); font: inherit; font-size: clamp(1.2rem, 5vw, 1.8rem); font-weight: 700; color: var(--ink);
    display: grid; place-items: center; border-bottom: 4px solid #d3cdfa; padding: 0;
}
.slot.filled { background: #fff; border-bottom-color: var(--primary); }
.slot.reveal { color: var(--bad); }
.slots.win .slot { background: var(--good); color: #fff; border-bottom-color: #148f4f; animation: hop .4s; }
.slots.shake { animation: shake .4s; }
@keyframes shake { 20%, 60% { transform: translateX(-8px); } 40%, 80% { transform: translateX(8px); } }
@keyframes hop { 50% { transform: translateY(-8px); } }

.tiles { display: flex; justify-content: center; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.tile {
    width: clamp(36px, 10vw, 52px); height: clamp(36px, 10vw, 52px); border-radius: 12px; border: 0;
    background: var(--lv); color: #fff; font: inherit; font-size: clamp(1.2rem, 5vw, 1.7rem); font-weight: 700;
    box-shadow: 0 4px 0 rgba(0,0,0,.18); cursor: pointer; padding: 0;
}
.tile.used { opacity: .2; box-shadow: none; }
.row-actions { display: flex; justify-content: center; gap: 10px; flex-wrap: wrap; }

/* keyboard */
.keyboard { margin-top: 14px; user-select: none; }
.kb-row { display: flex; justify-content: center; gap: 5px; margin-bottom: 6px; }
.kb-key {
    flex: 1 1 0; max-width: 52px; min-width: 0; height: 52px; border: 0; border-radius: 10px;
    background: var(--key); color: var(--key-ink); font: inherit; font-size: 1.25rem; font-weight: 600;
    box-shadow: 0 3px 0 var(--key-shadow); cursor: pointer; padding: 0; touch-action: manipulation;
}
.kb-key.kb-wide { flex: 1.5 1 0; max-width: 78px; background: #e3defd; }
.kb-key:active, .kb-key.pressed { transform: translateY(2px); box-shadow: 0 1px 0 var(--key-shadow); }
.kb-key:disabled { opacity: .35; cursor: default; }
.kb-key.correct { background: var(--good); color: #fff; opacity: 1; box-shadow: 0 3px 0 #148f4f; }
.kb-key.wrong { background: var(--bad); color: #fff; opacity: .75; box-shadow: 0 3px 0 #a3233b; }

/* hangman */
.hm-svg { display: block; width: min(220px, 60vw); margin: 0 auto; }
.hm-frame { stroke: #8e88b8; stroke-width: 5; stroke-linecap: round; }
.hm-part { stroke: var(--ink); stroke-width: 5; stroke-linecap: round; fill: none; animation: pop-in .25s; }
@keyframes pop-in { from { opacity: 0; } }
.hm-tries { text-align: center; color: var(--muted); margin: 4px 0 12px; }

/* balloons */
.bl-card { flex: 1; display: flex; flex-direction: column; }
.bl-instr { text-align: center; font-size: 1.2rem; margin: 0 0 8px; }
.bl-sky {
    position: relative; flex: 1; min-height: 360px; max-height: 640px; border-radius: 24px;
    background: linear-gradient(180deg, #8fd3fe 0%, #d8f1ff 75%, #b8f2c8 100%); box-shadow: var(--shadow);
    display: flex; justify-content: space-evenly; align-items: center; gap: 8px; padding: 24px 10px 70px;
}
.balloon {
    position: relative; flex: 0 1 140px; width: 26%; max-width: 140px; aspect-ratio: 5 / 6;
    border: 0; padding: 0; cursor: pointer; background: transparent; touch-action: manipulation; font: inherit;
    transform-origin: 50% 120%; animation: sway 3s ease-in-out var(--delay) infinite;
    transition: transform .15s;
}
.balloon::before {
    content: ''; position: absolute; inset: 0; border-radius: 50% 50% 48% 48% / 55% 55% 45% 45%;
    background: radial-gradient(circle at 32% 28%, rgba(255,255,255,.65) 0 10%, transparent 11%), var(--c);
    box-shadow: inset -8px -10px 0 rgba(0,0,0,.12); transition: box-shadow .15s;
}
.balloon-word {
    position: relative; z-index: 1; display: grid; place-items: center; height: 100%; padding: 0 6px;
    color: #fff; font-weight: 700; font-size: clamp(.95rem, 4vw, 1.35rem); text-shadow: 0 2px 2px rgba(0,0,0,.3);
    word-break: break-word;
}
.balloon-string { position: absolute; left: 50%; top: 100%; width: 2px; height: 50px; background: rgba(0,0,0,.25); }
@keyframes sway { 0%, 100% { transform: rotate(-3deg); } 50% { transform: rotate(3deg); } }
.balloon.selected { animation: none; transform: scale(1.05); }
.balloon.selected::before { box-shadow: inset -8px -10px 0 rgba(0,0,0,.12), 0 0 0 5px #fff, 0 0 0 9px var(--primary); }
.balloon.popped { animation: none; visibility: hidden; }
.balloon.popped::after { content: '💥'; visibility: visible; position: absolute; inset: 0; display: grid; place-items: center; font-size: 3rem; animation: burst .6s forwards; }
@keyframes burst { from { transform: scale(.6); } 60% { transform: scale(1.4); opacity: 1; } to { transform: scale(1.6); opacity: 0; } }
.balloon.wobble { animation: wobble .5s; }
@keyframes wobble { 25% { transform: rotate(-12deg); } 75% { transform: rotate(12deg); } }
.bl-meaning { min-height: 2.2em; text-align: center; font-size: 1.15rem; margin-top: 10px; }
.bl-meaning span { color: var(--muted); }

/* toast + result */
.toast {
    position: fixed; left: 50%; top: 18px; transform: translate(-50%, calc(-100% - 40px)); background: var(--ink); color: #fff;
    padding: 10px 18px; border-radius: 14px; font-size: 1.1rem; font-weight: 600; transition: transform .25s; z-index: 50;
    max-width: calc(100% - 32px); text-align: center;
}
.toast.show { transform: translate(-50%, 0); }
.toast.good { background: var(--good); }
.toast.bad { background: var(--bad); }

.result-overlay { position: fixed; inset: 0; background: rgba(30, 20, 70, .55); display: grid; place-items: center; padding: 16px; z-index: 40; }
.result-overlay[hidden] { display: none; }
.result-card { background: #fff; border-radius: 28px; padding: 28px 22px; text-align: center; width: min(420px, 100%); animation: hop .4s; }
.result-emoji { font-size: 4rem; }
.result-card h2 { margin: .3rem 0; color: var(--primary-dark); font-size: 1.8rem; }
.result-score { font-size: 1.4rem; margin: .3rem 0; }
.result-detail { color: var(--muted); }
.result-actions { display: flex; flex-direction: column; gap: 10px; margin-top: 16px; }

.notice-card { max-width: 460px; margin: 0 auto; background: var(--card); border-radius: 24px; padding: 28px 20px; text-align: center; box-shadow: var(--shadow); }
.notice-card h2 { margin: .4rem 0; color: var(--primary-dark); font-size: 1.35rem; }
.notice-card p { margin: 0; color: var(--muted); }
.notice-emoji { font-size: 3rem; }

/* ── Login ────────────────────────────────────────── */
.login-wrap { max-width: 460px; }
.login-card { background: var(--card); border-radius: 24px; padding: 22px 18px; box-shadow: var(--shadow); }
.login-error { background: #ffe3e8; color: #a3233b; border-radius: 14px; padding: 10px 14px; margin-bottom: 14px; }
.login-toggle { display: flex; background: var(--slot); border-radius: 14px; padding: 4px; margin-bottom: 18px; }
.login-toggle button { flex: 1; border: 0; background: transparent; font: inherit; font-weight: 600; padding: .55rem; border-radius: 11px; color: var(--muted); cursor: pointer; }
.login-toggle button.active { background: #fff; color: var(--primary-dark); box-shadow: 0 2px 6px rgba(80, 60, 180, .15); }
.login-label { display: block; font-weight: 600; margin-bottom: 6px; }
.login-input { width: 100%; font: inherit; font-size: 1.2rem; padding: .7rem .9rem; border: 2px solid var(--key-shadow); border-radius: 14px; outline: none; }
.login-input:focus { border-color: var(--primary); }
.login-submit { width: 100%; margin-top: 14px; font-size: 1.15rem; }
.qr-reader { width: 100%; max-width: 400px; margin: 0 auto; border-radius: 14px; overflow: hidden; }
.login-hint { text-align: center; color: var(--muted); margin: 12px 0 0; }

@media (max-width: 480px) {
    .kb-key { height: 46px; font-size: 1.1rem; }
    .kb-row { gap: 4px; }
    .bl-sky { min-height: 300px; }
    .home-header h1 { font-size: 1.8rem; }
    .level-grid { grid-template-columns: repeat(3, 1fr); gap: 10px; }
    .level-code { font-size: 1.6rem; }
}

/* word builder */
.meaning-box > span:last-child { display: flex; flex-direction: column; }
.meaning-label { color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; }
.tiles-bank { max-width: 420px; margin-left: auto; margin-right: auto; }
.slot.given { background: #fff4d6; border-bottom-color: #f6b93b; color: #b7791f; }
