* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
:root {
    --frame-bottom: 0px; --frame-left: 0px; --frame-right: 0px;
    --accent: #0e6e8c; --accent-dark: #0a5068; --gold: #f59e0b; --tile: #ffffff; --tile-empty: rgba(255, 255, 255, .55);
}
html, body { height: 100%; }
/* Inside the site iframe a fixed footer bar (~40px) covers the bottom; the site hides it when height <= 400px. */
html.in-frame { --frame-bottom: 44px; }
@media (max-height: 400px) { html.in-frame { --frame-bottom: 0px; } }

body { font-family: Arial, Helvetica, sans-serif; background: #1d4f6e; color: #fff; overflow: hidden; user-select: none; -webkit-user-select: none; }
#bg { position: fixed; inset: 0; z-index: 0; transition: opacity .4s; }
#bg svg { width: 100%; height: 100%; display: block; }
#app {
    position: relative; z-index: 1; display: flex; justify-content: center;
    height: calc(100vh - var(--frame-bottom)); height: calc(100dvh - var(--frame-bottom));
    padding: 0 var(--frame-right) 0 var(--frame-left);
}
#stage { position: relative; width: 100%; max-width: 480px; height: 100%; overflow: hidden; }
.screen { display: none; position: absolute; inset: 0; flex-direction: column; }
.screen.active { display: flex; }

/* ---------- Start ---------- */
#start-screen { justify-content: center; align-items: center; padding: 20px; text-align: center; background: linear-gradient(180deg, rgba(8, 40, 60, .25), rgba(8, 40, 60, .55)); }
.logo svg { width: 110px; height: 110px; filter: drop-shadow(0 8px 14px rgba(0, 0, 0, .3)); }
#start-screen h1 { font-size: 40px; letter-spacing: 2px; margin: 6px 0 6px; text-shadow: 0 3px 8px rgba(0, 0, 0, .45); }
#start-screen .desc { font-size: 16px; line-height: 1.45; max-width: 320px; margin-bottom: 18px; text-shadow: 0 1px 4px rgba(0, 0, 0, .5); }
.start-stats { font-size: 13px; margin-top: 10px; opacity: .95; text-shadow: 0 1px 3px rgba(0, 0, 0, .6); min-height: 1.2em; }

.btn { display: block; width: 270px; max-width: 100%; border: none; padding: 14px 20px; margin: 6px auto; font-size: 18px; font-weight: bold; border-radius: 50px; cursor: pointer; font-family: inherit; box-shadow: 0 4px 14px rgba(0, 0, 0, .25); }
.btn:active { transform: translateY(1px); }
.btn-primary { background: #fff; color: var(--accent); }
.btn-secondary { background: rgba(10, 60, 85, .55); color: #fff; border: 2px solid rgba(255, 255, 255, .8); }
.btn-ghost { background: transparent; color: #fff; box-shadow: none; text-decoration: underline; font-size: 15px; padding: 6px; text-shadow: 0 1px 3px rgba(0, 0, 0, .6); }
.btn:disabled { opacity: .55; cursor: default; }
.icon-btn { width: 38px; height: 38px; border-radius: 50%; border: 2px solid rgba(255, 255, 255, .75); background: rgba(10, 50, 70, .45); color: #fff; font-size: 18px; font-weight: bold; cursor: pointer; flex-shrink: 0; display: flex; align-items: center; justify-content: center; font-family: inherit; }
.icon-spacer { width: 38px; flex-shrink: 0; }

/* ---------- Top bar ---------- */
.topbar { height: 52px; flex-shrink: 0; display: flex; align-items: center; gap: 8px; padding: 0 10px; background: linear-gradient(rgba(6, 34, 52, .7), rgba(6, 34, 52, .35)); }
.topbar .title { flex: 1; min-width: 0; text-align: center; font-weight: bold; font-size: 18px; text-shadow: 0 1px 3px rgba(0, 0, 0, .5); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .title small { display: block; font-size: 12px; font-weight: normal; opacity: .9; }
.coin-chip { display: flex; align-items: center; gap: 5px; background: rgba(0, 0, 0, .35); border: 2px solid #f3c452; border-radius: 18px; padding: 3px 10px 3px 3px; font-weight: bold; color: #ffe08a; min-width: 70px; }
.coin { width: 24px; height: 24px; border-radius: 50%; background: linear-gradient(#ffe27a, #f0b429); color: #7a4a00; display: inline-flex; align-items: center; justify-content: center; font-size: 14px; font-weight: 900; }
.coin-chip.pulse { animation: pop .4s; }

/* ---------- Board ---------- */
.board-wrap { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; padding: 8px; }
.board { position: relative; }
.cell { position: absolute; border-radius: 6px; background: rgba(6, 40, 60, .32); border: 2px solid rgba(255, 255, 255, .75); box-shadow: 0 2px 6px rgba(0, 0, 0, .15); display: flex; align-items: center; justify-content: center; font-weight: 900; color: var(--accent-dark); text-transform: uppercase; }
.cell.filled { background: var(--tile); border-color: #fff; animation: flip .35s ease backwards; }
.cell.hinted { background: #fff6d6; color: #b7791f; }
.cell.flash { animation: flash .6s; }
.cell.done { background: #d8f5e6; color: #0b6b44; }

/* ---------- Preview + messages ---------- */
.preview-row { flex-shrink: 0; height: 44px; position: relative; display: flex; justify-content: center; align-items: center; }
.preview { min-width: 10px; padding: 0 14px; height: 38px; line-height: 38px; border-radius: 19px; background: rgba(255, 255, 255, .95); color: var(--accent-dark); font-size: 22px; font-weight: 900; letter-spacing: 3px; text-transform: uppercase; box-shadow: 0 3px 10px rgba(0, 0, 0, .25); }
.preview:empty { visibility: hidden; }
.preview.bad { background: #fde2e2; color: #c0392b; animation: shake .35s; }
.preview.good { background: #d8f5e6; color: #0b6b44; }
.preview.bonus { background: #fff1c7; color: #8a5a00; }
.msg { position: absolute; top: -30px; left: 0; right: 0; text-align: center; font-weight: bold; font-size: 15px; text-shadow: 0 1px 4px rgba(0, 0, 0, .8); opacity: 0; transition: opacity .2s; pointer-events: none; }
.msg.show { opacity: 1; }

/* ---------- Wheel ---------- */
.wheel-row { flex-shrink: 0; display: flex; align-items: center; justify-content: center; gap: 6px; padding: 4px 8px calc(12px + env(safe-area-inset-bottom)); }
.side { width: 58px; display: flex; flex-direction: column; align-items: center; gap: 12px; flex-shrink: 0; }
.wheel { position: relative; border-radius: 50%; background: radial-gradient(circle at 50% 40%, rgba(255, 255, 255, .5), rgba(255, 255, 255, .28)); box-shadow: 0 6px 22px rgba(0, 0, 0, .25), inset 0 0 0 3px rgba(255, 255, 255, .55); touch-action: none; flex-shrink: 0; }
.wheel-lines { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; overflow: visible; }
.letter { position: absolute; border-radius: 50%; background: #fff; color: var(--accent-dark); font-weight: 900; text-transform: uppercase; display: flex; align-items: center; justify-content: center; box-shadow: 0 3px 8px rgba(0, 0, 0, .25); transition: transform .12s, background .12s; cursor: pointer; }
.letter.sel { background: var(--gold); color: #fff; transform: scale(1.08); }
.wheel-center { position: absolute; left: 50%; top: 50%; width: 52px; height: 52px; margin: -26px 0 0 -26px; border-radius: 50%; border: none; background: rgba(255, 255, 255, .9); font-size: 22px; cursor: pointer; box-shadow: 0 2px 6px rgba(0, 0, 0, .2); color: var(--accent); font-weight: 900; }
.wheel-center.ok { background: #17b26a; color: #fff; font-size: 26px; }
.round-btn { position: relative; width: 54px; height: 54px; border-radius: 50%; border: 2px solid rgba(255, 255, 255, .85); background: rgba(10, 60, 85, .6); color: #fff; cursor: pointer; font-family: inherit; display: flex; flex-direction: column; align-items: center; justify-content: center; box-shadow: 0 3px 10px rgba(0, 0, 0, .25); }
.round-btn.small { width: 40px; height: 40px; font-size: 16px; }
.round-btn .ico { font-size: 22px; line-height: 1; }
.round-btn .price { font-size: 11px; font-weight: bold; color: #ffe08a; margin-top: 1px; }
.round-btn .badge { position: absolute; top: -6px; right: -6px; min-width: 22px; height: 22px; border-radius: 11px; background: var(--gold); color: #fff; font-size: 12px; font-weight: bold; display: flex; align-items: center; justify-content: center; padding: 0 5px; border: 2px solid #fff; }
.round-btn:disabled { opacity: .5; }
.round-btn.pulse { animation: pop .45s; }

/* ---------- Select ---------- */
#select-screen { background: rgba(6, 34, 52, .55); }
.scroll { flex: 1; min-height: 0; overflow-y: auto; padding: 10px 12px 20px; -webkit-overflow-scrolling: touch; }
.chapter-list { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.chapter-card { position: relative; border-radius: 14px; overflow: hidden; border: 2px solid rgba(255, 255, 255, .6); background: #234; cursor: pointer; padding: 0; color: #fff; font-family: inherit; text-align: left; box-shadow: 0 4px 12px rgba(0, 0, 0, .3); aspect-ratio: 4 / 3; }
.chapter-card .art { position: absolute; inset: 0; }
.chapter-card .art svg { width: 100%; height: 100%; display: block; }
.chapter-card .info { position: absolute; left: 0; right: 0; bottom: 0; padding: 6px 8px; background: linear-gradient(transparent, rgba(0, 0, 0, .65)); }
.chapter-card .nm { font-size: 15px; font-weight: bold; text-shadow: 0 1px 3px rgba(0, 0, 0, .7); }
.chapter-card .pr { font-size: 12px; color: #ffe08a; font-weight: bold; }
.chapter-card .num { position: absolute; top: 6px; left: 8px; font-size: 12px; font-weight: bold; background: rgba(0, 0, 0, .4); border-radius: 8px; padding: 1px 7px; }
.chapter-card.locked { cursor: default; }
.chapter-card.locked .art { filter: grayscale(.85) brightness(.6); }
.chapter-card.locked .info::after { content: ' 🔒'; }
.chapter-card.head { aspect-ratio: auto; height: 120px; margin-bottom: 12px; cursor: default; }
.level-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 9px; }
.level-btn { aspect-ratio: 1; border-radius: 12px; border: 2px solid rgba(255, 255, 255, .7); background: rgba(10, 60, 85, .6); color: #fff; font-family: inherit; font-size: 18px; font-weight: bold; cursor: pointer; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.level-btn .st { font-size: 11px; color: #7dffb0; min-height: 13px; }
.level-btn.next { background: #fff; color: var(--accent); }
.level-btn.locked { opacity: .4; cursor: default; }

/* ---------- Modals ---------- */
.modal-overlay { position: absolute; inset: 0; background: rgba(0, 0, 0, .55); display: none; align-items: center; justify-content: center; z-index: 400; padding: 14px; }
.modal-overlay.show { display: flex; }
.modal { background: #fff; color: #374151; border-radius: 18px; padding: 20px 18px 0; width: 100%; max-width: 380px; max-height: 100%; overflow-y: auto; text-align: center; box-shadow: 0 15px 35px rgba(0, 0, 0, .4); animation: modalIn .25s ease; }
.modal h2 { font-size: 24px; color: var(--accent-dark); margin-bottom: 8px; }
.modal .btn-primary { background: var(--accent); color: #fff; }
.modal .btn-secondary { background: #fff; color: var(--accent); border-color: var(--accent); }
.modal-buttons { position: sticky; bottom: 0; background: #fff; padding: 8px 0 14px; margin-top: 10px; }
.modal-buttons .btn { width: 100%; max-width: 260px; }
.modal.help { text-align: left; }
.modal.help h2 { text-align: center; }
.modal.help p { font-size: 14px; line-height: 1.45; margin: 7px 0; }
.burst { font-size: 54px; color: var(--gold); line-height: 1; animation: pop .6s; text-shadow: 0 4px 12px rgba(245, 158, 11, .5); }
.word-chips { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin: 8px 0; }
.word-chips span { background: #e6f4f8; color: var(--accent-dark); border-radius: 12px; padding: 4px 10px; font-weight: bold; font-size: 14px; text-transform: uppercase; letter-spacing: 1px; }
.word-chips span.hint { background: #fff6d6; color: #b7791f; }
.word-chips span.unknown { background: #f3f4f6; color: #9ca3af; letter-spacing: 2px; }
.complete-text { font-size: 15px; font-weight: bold; color: #b7791f; }
.small-text { font-size: 13px; line-height: 1.4; margin: 4px 0; }
.small-text.strong { font-weight: bold; color: var(--accent-dark); }

/* ---------- Animations ---------- */
@keyframes flip { from { transform: scale(.3) rotate(-20deg); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes flash { 0%, 100% { transform: scale(1); } 40% { transform: scale(1.18); background: #fff1c7; } }
@keyframes shake { 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }
@keyframes pop { 0% { transform: scale(1); } 40% { transform: scale(1.25); } 100% { transform: scale(1); } }
@keyframes modalIn { from { transform: scale(.9); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.aurora { animation: aur 6s ease-in-out infinite alternate; }
@keyframes aur { from { opacity: .6; transform: translateX(-8px); } to { opacity: 1; transform: translateX(8px); } }

@media (max-height: 640px) {
    .logo svg { width: 80px; height: 80px; }
    #start-screen h1 { font-size: 32px; }
    .btn { padding: 11px 18px; font-size: 16px; margin: 4px auto; }
}
