:root {
  --bark: #2a1a0e;
  --wood: #5a381c;
  --wood-hi: #8a5a2c;
  --parch: #f6e7c1;
  --parch-d: #d9c391;
  --gold: #ffd45a;
  --gold-d: #a2701a;
  --green: #4fbf5a;
  --red: #e0584c;
  --ink: #2b1b0c;
  --display: "Palatino Linotype", Palatino, "Book Antiqua", "Hoefler Text", Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; }
body { background: radial-gradient(900px 600px at 50% 0%, #3b2614, #1a0f07); color: var(--parch); font-family: var(--sans); overflow: hidden; overscroll-behavior: none; touch-action: manipulation; user-select: none; -webkit-user-select: none; }
body.game-page .portal-h1 { color:var(--parch); text-shadow:0 2px 8px rgba(0,0,0,.5); }
body.game-page .portal-crumbs { color:#d1b98b; }
body.game-page .portal-crumbs a { color:#9ce3ed; }
button { font: inherit; color: inherit; cursor: pointer; }
button:focus-visible { outline: 3px solid #7be0ff; outline-offset: 2px; }

#app { height: 100vh; height: 100dvh; max-width: 1280px; margin: 0 auto; display: flex; flex-direction: column; position: relative; padding: env(safe-area-inset-top) 8px env(safe-area-inset-bottom); gap: 6px; }

/* ---------- HUD ---------- */
#hud { flex: none; display: flex; align-items: center; gap: 8px; padding: 6px 10px; margin-top: 6px; border-radius: 14px; background: linear-gradient(180deg, var(--wood-hi), var(--wood) 55%, #3d2512); box-shadow: 0 3px 0 #1a0f07, inset 0 1px 0 rgba(255, 220, 160, .35); }
.stat { display: flex; align-items: center; gap: 7px; padding: 4px 10px; border-radius: 10px; background: rgba(20, 10, 4, .55); box-shadow: inset 0 2px 5px rgba(0, 0, 0, .6); font-family: var(--display); }
.stat b { font-size: 20px; min-width: 2ch; font-variant-numeric: tabular-nums; color: var(--parch); }
.stat em { font-style: normal; opacity: .65; font-size: 14px; }
.stat span { font-size: 12px; letter-spacing: .12em; text-transform: uppercase; opacity: .75; }
.stat.wave b { color: var(--gold); }
.ico { width: 24px; height: 24px; flex: none; }
.ico.s { width: 20px; height: 20px; }
.bar { width: 86px; height: 12px; border-radius: 6px; background: rgba(0, 0, 0, .6); overflow: hidden; box-shadow: inset 0 1px 3px #000; }
.bar i { display: block; height: 100%; width: 100%; background: linear-gradient(180deg, #8dee8d, #3fb34f); transition: width .25s, background .3s; }
.bar i.mid { background: linear-gradient(180deg, #ffe27a, #e0a82a); }
.bar i.low { background: linear-gradient(180deg, #ff8a7a, #d63a2c); }
#coins-box.bump b { animation: bump .3s; }
@keyframes bump { 40% { transform: scale(1.3); color: var(--gold); } }
#stat-hp.hurt, .stat.hp.hurt { animation: hurt .4s; }
@keyframes hurt { 25% { transform: translateX(-4px); background: rgba(160, 20, 10, .7); } 60% { transform: translateX(4px); } }
.hud-btns { margin-left: auto; display: flex; gap: 6px; }
.round { width: 40px; height: 40px; border-radius: 50%; border: 2px solid var(--gold-d); background: radial-gradient(circle at 35% 25%, #8a5a2c, #3d2512); color: var(--parch); display: inline-grid; place-items: center; font: 700 14px var(--display); box-shadow: 0 2px 0 #1a0f07; padding: 0; }
.round:hover { filter: brightness(1.2); }
.round:active { transform: translateY(1px); }
.round.small { width: 34px; height: 34px; }
.round.yes { background: radial-gradient(circle at 35% 25%, #7ee08a, #2c8c3a); border-color: #c8ffd0; font-size: 22px; }
.round.no { background: radial-gradient(circle at 35% 25%, #ff9a8a, #b03020); border-color: #ffd0c8; }
.pause-ico { width: 14px; height: 16px; border-left: 5px solid var(--parch); border-right: 5px solid var(--parch); }
#btn-sound.off #snd-waves { display: none; }
#btn-sound.off { opacity: .6; }

/* ---------- stage ---------- */
#stage { flex: 1 1 auto; min-height: 0; display: grid; place-items: center; }
#field { position: relative; background: #24401f; border-radius: 16px; overflow: hidden; box-shadow: 0 0 0 4px #4a2f17, 0 0 0 6px var(--gold-d), 0 14px 34px rgba(0, 0, 0, .6); }
#game { display: block; touch-action: none; cursor: default; }
#field.placing #game { cursor: crosshair; }

#banner { position: absolute; left: 0; right: 0; top: 16%; text-align: center; pointer-events: none; display: grid; gap: 2px; opacity: 0; font-family: var(--display); text-shadow: 0 3px 0 rgba(30, 14, 4, .85), 0 0 24px rgba(0, 0, 0, .6); }
#banner small { font-size: clamp(11px, 2.4vw, 16px); letter-spacing: .4em; text-transform: uppercase; color: #fff1c4; }
#banner strong { font-size: clamp(34px, 8vw, 78px); color: var(--gold); line-height: 1; letter-spacing: .04em; }
#banner span { font-size: clamp(14px, 3vw, 24px); color: #fff; font-style: italic; }
#banner.show { animation: banner 2.6s cubic-bezier(.2, .8, .2, 1) both; }
#banner.boss strong { color: #ff7a6a; text-shadow: 0 3px 0 #4a0f08, 0 0 30px rgba(255, 60, 40, .8); }
@keyframes banner { 0% { opacity: 0; transform: translateY(-30px) scale(.7); } 14% { opacity: 1; transform: none; } 78% { opacity: 1; } 100% { opacity: 0; transform: translateY(14px) scale(1.04); } }

#toast { position: absolute; left: 50%; bottom: 12px; transform: translate(-50%, 20px); max-width: 90%; padding: 8px 16px; border-radius: 999px; background: rgba(30, 14, 4, .88); border: 1px solid var(--gold-d); font-size: 14px; opacity: 0; transition: opacity .25s, transform .25s; pointer-events: none; text-align: center; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.bad { background: rgba(90, 20, 14, .92); border-color: #ff8a7a; }

#confirm { position: absolute; left: 50%; top: 10px; z-index: 4; transform: translateX(-50%); display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-radius: 16px; background: linear-gradient(180deg, #4a2f17, #2a1a0e); border: 2px solid var(--gold-d); box-shadow: 0 6px 18px rgba(0, 0, 0, .55); max-width: 96%; }
#confirm[hidden] { display: none; }
#confirm-icon { width: 46px; height: 46px; background: rgba(255, 255, 255, .1); border-radius: 10px; }
.c-text { display: grid; line-height: 1.2; min-width: 8em; }
.c-text b { font-family: var(--display); }
.c-text span { font-size: 12px; color: var(--parch-d); }
.c-text span.bad { color: #ff9a8a; }
#confirm .round { width: 46px; height: 46px; }

#tutorial { position: absolute; left: 50%; top: 10px; transform: translateX(-50%); width: min(420px, 94%); padding: 14px 16px 12px; border-radius: 16px; background: linear-gradient(180deg, var(--parch), var(--parch-d)); color: var(--ink); box-shadow: 0 8px 26px rgba(0, 0, 0, .6), 0 0 0 3px var(--gold-d); animation: pop .35s cubic-bezier(.2, 1.3, .4, 1); z-index: 5; }
#tutorial[hidden] { display: none; }
#tutorial b { font: 700 18px var(--display); }
#tutorial p { margin: 6px 0 10px; font-size: 14px; line-height: 1.45; }
.tut-foot { display: flex; align-items: center; gap: 10px; }
#tut-dots { margin-right: auto; display: flex; gap: 5px; }
#tut-dots i { width: 8px; height: 8px; border-radius: 50%; background: rgba(60, 35, 10, .3); }
#tut-dots i.on { background: var(--gold-d); }
@keyframes pop { from { opacity: 0; transform: translateX(-50%) scale(.85); } }
.link { background: none; border: 0; color: #6b4a22; text-decoration: underline; font-size: 13px; padding: 6px; }
.glow { animation: glow 1s ease-in-out infinite alternate; position: relative; z-index: 3; }
@keyframes glow { to { box-shadow: 0 0 0 3px #7be0ff, 0 0 22px 4px rgba(123, 224, 255, .8); } }

/* ---------- dock ---------- */
#dock { flex: none; min-height: 92px; padding: 8px; margin-bottom: 6px; border-radius: 14px; background: linear-gradient(180deg, #4a2f17, #2e1c0d); box-shadow: 0 -2px 0 rgba(255, 220, 160, .15), inset 0 1px 0 rgba(255, 220, 160, .25), 0 3px 0 #1a0f07; }
#dock { display: flex; gap: 10px; align-items: stretch; }
.slot { flex: 1; min-width: 0; display: flex; align-items: center; }
#build, #info { width: 100%; }
#build[hidden], #info[hidden] { display: none; }
.cards { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.card { position: relative; display: grid; grid-template-rows: auto auto auto; justify-items: center; gap: 1px; padding: 5px 4px 6px; border-radius: 12px; border: 2px solid #6b4423; background: linear-gradient(180deg, #7a5230, #4a2f17); box-shadow: 0 3px 0 #1a0f07; transition: transform .12s, border-color .15s, opacity .2s; min-width: 0; }
.card canvas { width: 52px; height: 52px; }
.card .nm { font: 700 12px var(--display); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.card .pr { font: 700 14px var(--display); color: var(--gold); display: flex; align-items: center; gap: 4px; }
.card .pr::before { content: ""; width: 11px; height: 11px; border-radius: 50%; background: radial-gradient(circle at 35% 30%, #fff1a8, var(--gold) 55%, var(--gold-d)); }
.card kbd { position: absolute; top: 3px; left: 5px; font: 600 10px var(--sans); opacity: .55; display: none; }
@media (hover: hover) and (min-width: 800px) { .card kbd { display: block; } }
.card:hover:not(:disabled) { transform: translateY(-2px); border-color: var(--gold); }
.card.active { border-color: #7be0ff; background: linear-gradient(180deg, #5c7a8a, #34505e); transform: translateY(-3px); box-shadow: 0 3px 0 #1a0f07, 0 0 16px rgba(123, 224, 255, .6); }
.card.poor { opacity: .55; }
.card.poor .pr { color: #ff9a8a; }
.wavebox { flex: 0 0 auto; width: min(24%, 230px); display: grid; gap: 6px; align-content: stretch; }
.btn { appearance: none; border: 2px solid var(--gold-d); border-radius: 12px; padding: 10px 16px; font: 700 16px var(--display); letter-spacing: .03em; color: var(--ink); background: linear-gradient(180deg, #fff1b8, var(--gold) 55%, #d9a02a); box-shadow: 0 3px 0 #6f4a10; transition: transform .08s, filter .2s; min-height: 44px; }
.btn:hover:not(:disabled) { filter: brightness(1.08); }
.btn:active:not(:disabled) { transform: translateY(2px); box-shadow: 0 1px 0 #6f4a10; }
.btn:disabled { opacity: .45; cursor: not-allowed; filter: grayscale(.5); }
.btn.go { color: #06280d; background: linear-gradient(180deg, #a6f5a8, var(--green) 55%, #2f9a3b); border-color: #1d6b27; box-shadow: 0 3px 0 #14501c; }
.btn.go.pulse { animation: pulse 1.1s ease-in-out infinite alternate; }
@keyframes pulse { to { box-shadow: 0 3px 0 #14501c, 0 0 20px 3px rgba(120, 255, 130, .75); } }
.btn.bad { color: #fff; background: linear-gradient(180deg, #ff9a8a, var(--red) 55%, #b03020); border-color: #7a1d12; box-shadow: 0 3px 0 #5a140c; }
.btn.ghost { color: var(--parch); background: rgba(0, 0, 0, .3); border-color: rgba(255, 212, 90, .55); box-shadow: none; }
.btn.small { padding: 6px 12px; font-size: 14px; min-height: 38px; }
.btn.big { font-size: 22px; padding: 14px 28px; min-height: 56px; }
#btn-wave { font-size: 16px; padding: 8px 10px; flex: 1; min-height: 44px; }
#preview { display: flex; flex-wrap: wrap; gap: 4px; justify-content: center; min-height: 26px; }
.pv { display: inline-flex; align-items: center; gap: 2px; padding: 0 6px 0 0; border-radius: 999px; background: rgba(0, 0, 0, .35); font: 700 12px var(--display); }
.pv canvas { width: 24px; height: 24px; }
.pv.air { box-shadow: inset 0 0 0 1px #9b6be0; }
.pv.boss { box-shadow: inset 0 0 0 1px #ff7a6a; color: #ffb4aa; }

#info { display: flex; align-items: center; gap: 12px; }
#info-icon { width: 76px; height: 76px; flex: none; background: radial-gradient(circle, rgba(255, 255, 255, .16), transparent 70%); border-radius: 12px; }
.i-main { flex: 1; min-width: 0; }
.i-title { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.i-title b { font: 700 18px var(--display); }
.i-title span { color: var(--gold); font: 700 13px var(--display); letter-spacing: .08em; }
.i-stats { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 13px; margin-top: 4px; color: var(--parch-d); }
.i-stats i { font-style: normal; color: var(--parch); font-weight: 700; }
.i-stats .up { color: #8dee8d; }
.i-actions { display: grid; grid-template-columns: auto auto; gap: 6px; align-items: center; }
.i-actions .round { grid-row: 1 / span 1; grid-column: 2; justify-self: end; }
#i-target { grid-column: 1 / 2; }

/* ---------- screens ---------- */
.screen { position: absolute; inset: 0; display: none; place-items: center; padding: 16px; background: radial-gradient(900px 600px at 50% 40%, rgba(40, 24, 10, .55), rgba(10, 5, 2, .88)); backdrop-filter: blur(3px); z-index: 20; overflow: auto; }
[data-screen="start"] #screen-start, [data-screen="paused"] #screen-pause, [data-screen="over"] #screen-over, [data-screen="won"] #screen-win { display: grid; }
.panel { width: min(480px, 100%); padding: 24px 26px 26px; border-radius: 22px; text-align: center; background: linear-gradient(180deg, #5a381c, #33200f); border: 3px solid var(--gold-d); box-shadow: 0 0 0 3px #1a0f07, 0 24px 60px rgba(0, 0, 0, .7), inset 0 2px 0 rgba(255, 220, 160, .25); animation: rise .5s cubic-bezier(.2, 1.1, .3, 1) both; }
@keyframes rise { from { opacity: 0; transform: translateY(26px) scale(.94); } }
.panel h1 { margin: 2px 0 6px; font: 700 clamp(42px, 11vw, 66px)/1 var(--display); color: var(--gold); letter-spacing: .02em; text-shadow: 0 4px 0 #6f4a10, 0 0 30px rgba(255, 212, 90, .35); }
.panel h1 span { display: block; color: #fff1c4; font-style: italic; letter-spacing: .12em; font-size: .72em; text-shadow: 0 3px 0 #6b4423; }
.panel h2 { margin: 0 0 8px; font: 700 34px var(--display); color: var(--gold); text-shadow: 0 3px 0 #6f4a10; }
.panel.defeat h2 { color: #ff8a7a; text-shadow: 0 3px 0 #5a140c; }
.panel.victory h2 { font-size: 52px; animation: victory 1.4s ease-in-out infinite alternate; }
@keyframes victory { to { text-shadow: 0 3px 0 #6f4a10, 0 0 36px rgba(255, 220, 120, .9); transform: scale(1.04); } }
.eyebrow { margin: 0; font-size: 12px; letter-spacing: .34em; text-transform: uppercase; color: var(--parch-d); }
.lead { margin: 8px 0 14px; line-height: 1.5; color: var(--parch); }
.menu { display: grid; gap: 10px; margin-top: 10px; }
.best { margin: 14px 0 0; font-size: 13px; color: var(--parch-d); }
.results { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 10px 0 16px; }
.results div { padding: 8px 4px; border-radius: 12px; background: rgba(0, 0, 0, .3); box-shadow: inset 0 2px 5px rgba(0, 0, 0, .5); }
.results dt { font-size: 11px; letter-spacing: .14em; text-transform: uppercase; color: var(--parch-d); }
.results dd { margin: 2px 0 0; font: 700 24px var(--display); color: var(--gold); }

/* ---------- small screens ---------- */
@media (max-width: 720px) {
  #app { padding-inline: 4px; gap: 4px; }
  #hud { padding: 4px 6px; gap: 4px; margin-top: 4px; }
  .stat { padding: 3px 7px; gap: 4px; }
  .stat b { font-size: 17px; }
  .stat span { font-size: 9px; letter-spacing: .06em; }
  .stat { white-space: nowrap; }
  .bar { width: 52px; }
  .round { width: 38px; height: 38px; }
  .hud-btns { gap: 4px; }
  #dock { padding: 6px; flex-direction: column; gap: 6px; }
  .slot { display: block; }
  .wavebox { width: auto; grid-template-columns: 1fr auto; align-items: center; }
  #preview { justify-content: flex-start; }
  .card { grid-template-rows: auto auto; grid-template-columns: auto; padding: 4px 2px; }
  .card canvas { width: 40px; height: 40px; }
  .card .nm { display: none; }
  #info { flex-wrap: wrap; gap: 8px; }
  #info-icon { width: 56px; height: 56px; }
  .i-actions { width: 100%; grid-template-columns: 1fr 1fr 1fr auto; }
  #i-target { grid-column: auto; }
  .i-actions .round { grid-column: auto; }
}
@media (max-width: 460px) {
  .stat.wave span { display: none; }
  .stat em { font-size: 12px; margin-left: -3px; }
  .round { width: 34px; height: 34px; }
  .hud-btns { gap: 3px; }
  .bar { width: 36px; }
}
@media (max-width: 400px) {
  .bar { display: none; }
  .stat.hp { gap: 5px; }
}
@media (max-height: 520px) and (orientation: landscape) {
  #app { flex-direction: row; flex-wrap: wrap; align-content: flex-start; }
  #hud { width: 100%; margin-top: 2px; padding: 2px 6px; }
  .round { width: 32px; height: 32px; }
  #stage { flex: 1 1 0; }
  #dock { width: 150px; margin-bottom: 4px; overflow-y: auto; flex-direction: column; }
  .slot { display: block; }
  .cards { grid-template-columns: 1fr 1fr; gap: 4px; }
  .card canvas { width: 34px; height: 34px; }
  .wavebox { width: auto; grid-template-columns: 1fr; }
  #preview { display: none; }
  #info { flex-direction: column; align-items: stretch; }
  #info-icon { display: none; }
  .i-actions { grid-template-columns: 1fr 1fr; }
  .panel { padding: 14px; }
  .panel h1 { font-size: 40px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
}
