:root {
  --bg1: #3b1f4f; --bg2: #1b1028; --ink: #fff6e8; --dim: #c9b4d8; --accent: #ffc94d;
  --good: #5fe39a; --bad: #ff6b81; --panel: rgba(255,255,255,.08);
  --font: ui-rounded, "SF Pro Rounded", "Nunito", system-ui, -apple-system, "Segoe UI", sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; overscroll-behavior: none; }
html { background-color: #1b1028; } /* solid color: iOS Safari tints the status bar and toolbar from it; a gradient gives white */
body {
  background: radial-gradient(120% 80% at 50% 0%, var(--bg1), var(--bg2) 70%);
  color: var(--ink); font-family: var(--font); -webkit-user-select: none; user-select: none;
  position: fixed; inset: 0; -webkit-touch-callout: none;
}
button { font-family: inherit; color: inherit; touch-action: manipulation; }
svg { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

#app {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center;
  padding: max(env(safe-area-inset-top), 8px) max(env(safe-area-inset-right), 3px) max(env(safe-area-inset-bottom), 8px) max(env(safe-area-inset-left), 3px);
}

/* HUD */
#hud { width: 100%; max-width: 560px; padding: 0 6px; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; height: 54px; flex: none; }
.hud-left { justify-self: start; } .hud-right { justify-self: end; display: flex; gap: 8px; align-items: center; }
.hud-mid { text-align: center; }
.score { font-size: 32px; font-weight: 800; line-height: 1; letter-spacing: -.02em; font-variant-numeric: tabular-nums; transition: transform .15s; }
.score.bump { transform: scale(1.15); color: var(--accent); }
.best { font-size: 12px; color: var(--dim); margin-top: 3px; font-weight: 600; }
.level { position: relative; width: 46px; height: 46px; display: grid; place-items: center; align-content: center; }
.level .lv-label { font-size: 9px; font-weight: 800; color: var(--dim); letter-spacing: .1em; line-height: 1; }
.level #lv-num { font-size: 19px; font-weight: 800; line-height: 1; }
.level .ring { position: absolute; inset: 0; transform: rotate(-90deg); }
.ring-bg { stroke: rgba(255,255,255,.12); stroke-width: 3.5; }
.ring-fg { stroke: var(--accent); stroke-width: 3.5; stroke-dasharray: 97.4; stroke-dashoffset: 97.4; transition: stroke-dashoffset .5s; }
.level.pop { animation: pop .6s; }
.icon-btn { width: 44px; height: 44px; border-radius: 14px; border: 0; background: var(--panel); display: grid; place-items: center; cursor: pointer; }
.icon-btn svg { width: 22px; height: 22px; }
.streak { display: flex; align-items: center; gap: 2px; padding: 5px 9px 5px 6px; border-radius: 999px; background: linear-gradient(135deg, #ff8a3d, #ff4f6d); font-weight: 800; font-size: 14px; box-shadow: 0 2px 10px rgba(255,90,80,.4); }
.streak[hidden] { display: none; }
.streak svg { width: 16px; height: 16px; fill: #ffe08a; stroke: #ffe08a; }
.streak.pop { animation: pop .4s; }

/* word bar */
/* the word being spelled sits over the header's middle, so the board gets that row */
#wordbar { position: absolute; z-index: 5; top: max(env(safe-area-inset-top), 8px); left: 50%; transform: translateX(-50%); width: min(calc(100% - 130px), 430px); height: 54px;
  display: flex; align-items: center; justify-content: center; gap: 8px; pointer-events: none; border-radius: 16px; background: transparent; }
#wordbar.on { background: #321a44; box-shadow: 0 0 0 1px rgba(255,255,255,.08); }
.word { font-size: 26px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; color: var(--dim); min-height: 1em; }
.word.valid { color: var(--good); text-shadow: 0 0 18px rgba(95,227,154,.45); }
.word.nope { color: var(--bad); animation: wiggle .35s; }
.word-pts { font-size: 15px; font-weight: 800; color: var(--good); background: rgba(95,227,154,.14); padding: 3px 9px; border-radius: 999px; }
.word-pts:empty { display: none; }

/* board */
#stage { flex: 1; width: 100%; min-height: 0; display: flex; align-items: center; justify-content: center; position: relative; }
#shake { position: relative; }
#board { display: block; touch-action: none; }
#fx { position: absolute; inset: 0; pointer-events: none; overflow: visible; }
.float { position: absolute; transform: translate(-50%, -50%); font-weight: 900; font-size: 26px; color: #fff; text-shadow: 0 2px 0 rgba(0,0,0,.35), 0 0 16px rgba(255,201,77,.8); animation: floatUp 1.1s ease-out forwards; white-space: nowrap; }
.callout { position: absolute; left: 50%; top: 38%; transform: translate(-50%, -50%); font-size: 46px; font-weight: 900; white-space: nowrap; letter-spacing: -.01em; text-align: center;
  background: linear-gradient(180deg, #fff3b0, #ffb93d 55%, #ff7a3d); -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 3px 0 #7a2c4a) drop-shadow(0 8px 18px rgba(0,0,0,.45)); animation: callout 1.3s cubic-bezier(.2,1.4,.4,1) forwards; }
.callout.small { font-size: 34px; }
.callout.danger { background: linear-gradient(180deg, #fff, #ff9aa8 50%, #ff4f6d); -webkit-background-clip: text; background-clip: text; }
.callout .sub { display: block; font-size: 17px; text-align: center; letter-spacing: .04em; margin-top: 2px; }

/* powers */
#powers { flex: none; display: flex; gap: 10px; width: 100%; max-width: 560px; padding: 6px 6px 0; justify-content: center; }
.power { position: relative; flex: 1; max-width: 140px; height: 52px; border: 0; border-radius: 16px; background: var(--panel); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; cursor: pointer; box-shadow: inset 0 -3px 0 rgba(0,0,0,.25); transition: transform .1s, background .2s; }
.power:active { transform: scale(.95); }
.power svg { width: 24px; height: 24px; }
.power .p-name { font-size: 12px; font-weight: 700; color: var(--dim); }
.power .count { position: absolute; top: -6px; right: -4px; min-width: 22px; height: 22px; padding: 0 6px; border-radius: 999px; background: var(--accent); color: #3a1f10; font-size: 13px; font-weight: 900; display: grid; place-items: center; }
.power.empty { opacity: .4; }
.power.empty .count { background: #6d5a7d; color: #fff; }
.power.armed { background: linear-gradient(135deg, #ff8a3d, #ff4f6d); animation: pulse 1s infinite; }
.power.armed .p-name { color: #fff; }
.power.gain { animation: pop .6s; }

/* sheets (modals) */
.sheet-wrap { position: fixed; inset: 0; background: rgba(15,6,24,.72); display: grid; place-items: center; z-index: 10; padding: 20px; -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px); animation: fade .2s; }
.sheet-wrap[hidden] { display: none; }
.sheet { width: 100%; max-width: 380px; max-height: 88vh; overflow: auto; background: linear-gradient(180deg, #4a2a63, #2c1840); border: 1px solid rgba(255,255,255,.12); border-radius: 26px; padding: 26px 22px 22px; text-align: center; box-shadow: 0 20px 60px rgba(0,0,0,.5); animation: rise .3s cubic-bezier(.2,1.3,.4,1); }
.sheet h1 { margin: 0; font-size: 44px; font-weight: 900; letter-spacing: -.02em; line-height: 1;
  background: linear-gradient(180deg, #fff3b0, #ffb93d 60%, #ff7a3d); -webkit-background-clip: text; background-clip: text; color: transparent; }
.sheet h2 { margin: 0 0 6px; font-size: 30px; font-weight: 900; }
.sheet p { color: var(--dim); margin: 8px 0; line-height: 1.4; font-size: 15px; }
.sheet .tag { color: var(--dim); font-weight: 700; margin: 6px 0 18px; }
.btn { display: block; width: 100%; height: 54px; margin-top: 10px; border: 0; border-radius: 16px; font-size: 19px; font-weight: 800; cursor: pointer; background: var(--panel); box-shadow: inset 0 -3px 0 rgba(0,0,0,.25); }
.btn.primary { background: linear-gradient(180deg, #ffd166, #ff9f43); color: #3a1f10; box-shadow: inset 0 -4px 0 rgba(150,60,0,.35), 0 6px 20px rgba(255,160,60,.3); }
.btn:active { transform: scale(.97); }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 16px 0 6px; }
.stat { background: var(--panel); border-radius: 14px; padding: 10px 6px; }
.stat b { display: block; font-size: 20px; text-transform: uppercase; overflow-wrap: anywhere; }
.stat span { font-size: 12px; color: var(--dim); font-weight: 700; }
.big-score { font-size: 56px; font-weight: 900; line-height: 1; margin: 8px 0 2px; font-variant-numeric: tabular-nums; }
.newbest { display: inline-block; margin-top: 6px; padding: 4px 12px; border-radius: 999px; background: var(--accent); color: #3a1f10; font-weight: 900; font-size: 14px; animation: pop .6s .3s both; }
.howto { text-align: left; margin: 10px 0 4px; padding: 0; list-style: none; }
.howto li { display: flex; gap: 10px; margin: 10px 0; font-size: 15px; line-height: 1.35; color: #eadcf3; }
.howto .chip { flex: none; width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center; font-weight: 900; font-size: 13px; color: #3a2346; background: #fff4e0; }
.chip.gem { background: #63e0d3; } .chip.gold { background: #ffc23d; } .chip.star { background: #c3a2ff; } .chip.rare { box-shadow: inset 0 0 0 3px #ff6b6b; } .chip.stone { background: #7a7088; color: #fff; }
.wb { margin-top: 14px; display: flex; justify-content: center; }
.row2 { display: flex; gap: 10px; } .row2 .btn { flex: 1; }

/* toasts */
#toasts { position: fixed; left: 0; right: 0; top: calc(max(env(safe-area-inset-top), 8px) + 66px); display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: none; z-index: 20; }
.toast { max-width: 92vw; text-align: center; background: rgba(20,10,30,.92); border: 1px solid rgba(255,255,255,.15); padding: 9px 16px; border-radius: 999px; font-weight: 800; font-size: 15px; animation: toast 2.2s forwards; }
.toast.gold { background: linear-gradient(135deg, #ffd166, #ff9f43); color: #3a1f10; border: 0; }

@keyframes pop { 0% { transform: scale(1); } 35% { transform: scale(1.3); } 100% { transform: scale(1); } }
@keyframes pulse { 50% { transform: scale(1.04); } }
@keyframes wiggle { 20% { transform: translateX(-8px); } 40% { transform: translateX(7px); } 60% { transform: translateX(-5px); } 80% { transform: translateX(3px); } }
@keyframes floatUp { 0% { opacity: 0; transform: translate(-50%, -30%) scale(.6); } 15% { opacity: 1; transform: translate(-50%, -60%) scale(1.15); } 100% { opacity: 0; transform: translate(-50%, -190%) scale(1); } }
@keyframes callout { 0% { opacity: 0; transform: translate(-50%, -50%) scale(.3) rotate(-8deg); } 25% { opacity: 1; transform: translate(-50%, -50%) scale(1.08) rotate(2deg); } 75% { opacity: 1; transform: translate(-50%, -55%) scale(1) rotate(0); } 100% { opacity: 0; transform: translate(-50%, -75%) scale(.95); } }
@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { opacity: 0; transform: translateY(30px) scale(.95); } }
@keyframes toast { 0% { opacity: 0; transform: translateY(-10px); } 10%, 80% { opacity: 1; transform: none; } 100% { opacity: 0; transform: translateY(-6px); } }
@keyframes shake { 10%, 90% { transform: translate(-2px, 1px); } 20%, 80% { transform: translate(4px, -2px); } 30%, 50%, 70% { transform: translate(-6px, 2px); } 40%, 60% { transform: translate(6px, -1px); } }
.shaking { animation: shake .4s; }
.shaking-big { animation: shake .6s; }

/* tutorial: the header swaps for a progress bar, the instruction sits in the empty top of the tower */
#tuthud { display: none; width: 100%; max-width: 560px; padding: 0 6px; height: 54px; flex: none; align-items: center; justify-content: space-between; gap: 10px; }
body.tut #hud { display: none; }
body.tut #tuthud { display: flex; }
.tut-title { font-size: 22px; font-weight: 900; }
.tut-count { font-size: 18px; font-weight: 800; color: var(--dim); margin-left: auto; font-variant-numeric: tabular-nums; }
.tut-count b { color: var(--accent); }
.tut-btns { display: flex; gap: 8px; align-items: center; }
.tut-skip { height: 44px; padding: 0 16px; border: 0; border-radius: 14px; background: var(--panel); font-size: 15px; font-weight: 800; cursor: pointer; }
#tut-panel { display: none; position: absolute; left: 0; right: 0; top: 6%; padding: 0 18px; text-align: center; pointer-events: none; }
body.tut #tut-panel { display: block; }
#tut-text { font-size: 21px; font-weight: 800; line-height: 1.35; color: #fff6e8; text-shadow: 0 2px 10px rgba(0,0,0,.4); }
#tut-text b { color: var(--accent); }
#tut-text .t-gem { color: #63e0d3; } #tut-text .t-gold { color: #ffc23d; } #tut-text .t-star { color: #c3a2ff; }
#tut-text.in { animation: rise .45s cubic-bezier(.2,1.3,.4,1); }
#tut-text.done { opacity: .35; transition: opacity .4s; }
#tut-next { pointer-events: auto; max-width: 260px; margin: 22px auto 0; }
#tut-next[hidden] { display: none; }
body.tut .power.empty { opacity: .25; }
