:root {
  color-scheme: dark;
  --navy: #0d2332;
  --navy-2: #16384a;
  --cream: #f4ead4;
  --gold: #d9b56f;
  --gold-2: #f4d897;
  --glass: rgba(8, 24, 34, 0.72);
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; background: #07151e; }
body { font-family: Georgia, 'Times New Roman', serif; color: var(--cream); }
button, kbd { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }

#app, #game-shell { position: relative; width: 100%; height: 100%; }
#game-shell { display: grid; place-items: center; overflow: hidden; background: radial-gradient(circle at 50% 30%, #24485a 0%, #07151e 70%); }
canvas { display: block; width: 100%; height: 100%; object-fit: contain; touch-action: none; }

#hud {
  position: absolute;
  inset: max(18px, env(safe-area-inset-top)) max(18px, env(safe-area-inset-right)) auto max(18px, env(safe-area-inset-left));
  display: grid;
  grid-template-columns: minmax(190px, 0.9fr) minmax(220px, 1.6fr) minmax(110px, 0.7fr);
  gap: 16px;
  align-items: center;
  z-index: 5;
  transition: opacity .3s ease;
}
#hud.hidden { opacity: 0; pointer-events: none; }
.hud-card { min-height: 62px; padding: 12px 18px; border: 1px solid rgba(244,216,151,.35); background: linear-gradient(180deg, rgba(13,35,50,.82), rgba(7,21,30,.72)); backdrop-filter: blur(12px); box-shadow: 0 14px 35px rgba(0,0,0,.24); }
.hud-card strong { display: block; color: #fff6df; font-size: clamp(16px, 1.5vw, 23px); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.eyebrow { display: block; font: 700 9px/1.2 Arial, sans-serif; letter-spacing: .24em; color: var(--gold-2); margin-bottom: 4px; }
.coin-card { justify-self: end; display: flex; align-items: center; gap: 7px; min-width: 108px; }
.coin-card strong { display: inline; font-size: 24px; }
.coin-card span:last-child { color: rgba(244,234,212,.72); }
.coin-mini { width: 31px; height: 31px; display: grid; place-items: center; border-radius: 50%; color: #6d4a16; background: radial-gradient(circle at 35% 30%, #fff0b1, #c58d31 70%); box-shadow: 0 0 0 2px #f0cf83 inset, 0 3px 12px rgba(0,0,0,.3); }
.hud-center { align-self: center; }
.route-line { height: 4px; background: rgba(244,234,212,.18); position: relative; overflow: hidden; }
.route-line span { position: absolute; inset: 0 auto 0 0; width: 0%; background: linear-gradient(90deg, #b78a3d, #ffe1a0); box-shadow: 0 0 15px rgba(244,216,151,.4); transition: width .15s linear; }
.route-dots { display: flex; justify-content: space-between; margin-top: -8px; }
.route-dots i { display: block; width: 12px; height: 12px; border-radius: 50%; border: 2px solid rgba(244,234,212,.62); background: #183748; transition: .25s ease; }
.route-dots i.active, .route-dots i.done { border-color: #ffe1a0; background: #d4a557; transform: scale(1.15); box-shadow: 0 0 12px rgba(255,225,160,.55); }

.overlay { position: absolute; inset: 0; z-index: 10; display: grid; place-items: center; padding: 24px; background: radial-gradient(circle at 50% 35%, rgba(33,71,87,.48), rgba(4,14,21,.84)); opacity: 0; visibility: hidden; transition: opacity .5s ease, visibility .5s ease; }
.overlay.visible { opacity: 1; visibility: visible; }
.panel { width: min(680px, 94vw); padding: clamp(28px, 4vw, 54px); text-align: center; border: 1px solid rgba(244,216,151,.43); background: linear-gradient(180deg, rgba(14,39,53,.92), rgba(6,19,28,.94)); box-shadow: 0 30px 90px rgba(0,0,0,.48), inset 0 0 70px rgba(216,181,111,.04); position: relative; overflow: hidden; }
.panel::before, .panel::after { content: ''; position: absolute; width: 90px; height: 90px; border-color: rgba(244,216,151,.35); }
.panel::before { left: 12px; top: 12px; border-left: 1px solid; border-top: 1px solid; }
.panel::after { right: 12px; bottom: 12px; border-right: 1px solid; border-bottom: 1px solid; }
.seal { width: 92px; height: 92px; margin: 0 auto 20px; display: grid; place-items: center; border-radius: 50%; border: 2px solid #e5c37d; outline: 1px solid rgba(229,195,125,.4); outline-offset: 6px; background: radial-gradient(circle at 35% 28%, #f6dda5, #b77f2f 72%); color: #422b0e; box-shadow: 0 10px 34px rgba(0,0,0,.38); }
.seal span { font-size: 29px; font-weight: 700; letter-spacing: .08em; }
.kicker { margin: 0 0 10px; color: var(--gold-2); font: 700 11px/1.3 Arial, sans-serif; letter-spacing: .32em; }
h1, h2 { margin: 0; font-weight: 400; line-height: .96; text-wrap: balance; }
h1 { font-size: clamp(54px, 8vw, 88px); }
.finish-panel h2 { font-size: clamp(38px, 6vw, 62px); }
.subtitle, #finish-message { color: rgba(244,234,212,.79); font-size: clamp(17px, 2.1vw, 21px); line-height: 1.55; max-width: 560px; margin: 22px auto; }
.controls-grid { display: flex; justify-content: center; gap: 26px; flex-wrap: wrap; margin: 26px 0 30px; color: rgba(244,234,212,.72); font: 12px/1.3 Arial, sans-serif; }
.controls-grid div { display: flex; align-items: center; gap: 7px; }
kbd { min-width: 30px; padding: 6px 8px; border: 1px solid rgba(244,216,151,.38); border-bottom-width: 3px; background: #102c3b; color: #fff0c8; box-shadow: none; }
.primary-button, .secondary-button { min-height: 52px; padding: 0 28px; border-radius: 0; cursor: pointer; letter-spacing: .14em; font: 700 12px/1 Arial, sans-serif; transition: transform .18s ease, filter .18s ease; }
.primary-button { border: 1px solid #f3d89b; color: #38250d; background: linear-gradient(180deg, #f5dda6, #c8943e); box-shadow: 0 12px 28px rgba(0,0,0,.3); }
.secondary-button { border: 1px solid rgba(244,216,151,.45); color: #f5e7c5; background: rgba(15,43,58,.7); }
.primary-button:hover, .secondary-button:hover { transform: translateY(-2px); filter: brightness(1.08); }
.small-note { margin: 16px 0 0; color: rgba(244,234,212,.48); font: 11px Arial, sans-serif; }
.finish-actions { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }
.finish-seal { width: 112px; height: 112px; margin: 28px auto 12px; border-radius: 50%; display: grid; place-content: center; border: 2px solid #edcf8c; background: radial-gradient(circle at 35% 25%, #ffe9b1, #bd8230 70%); color: #3c270c; box-shadow: 0 12px 35px rgba(0,0,0,.38); }
.finish-seal span { font-size: 38px; line-height: .8; font-weight: 700; }
.finish-seal small { margin-top: 8px; font: 800 9px Arial, sans-serif; letter-spacing: .16em; }

.chapter-card { position: absolute; z-index: 7; left: 50%; top: 48%; width: min(620px, 88vw); padding: 28px 34px; transform: translate(-50%, -50%) scale(.96); text-align: center; color: #fff3d3; background: linear-gradient(90deg, rgba(7,21,30,0), rgba(7,21,30,.82) 20%, rgba(7,21,30,.82) 80%, rgba(7,21,30,0)); opacity: 0; visibility: hidden; transition: .35s ease; pointer-events: none; }
.chapter-card.visible { opacity: 1; visibility: visible; transform: translate(-50%, -50%) scale(1); }
.chapter-card p { margin: 0 0 7px; font: 700 10px Arial, sans-serif; letter-spacing: .28em; color: #f2d08a; }
.chapter-card h2 { font-size: clamp(42px, 7vw, 78px); }
.chapter-card span { display: block; margin-top: 10px; font-style: italic; color: rgba(244,234,212,.74); }

#toast { position: absolute; z-index: 9; left: 50%; bottom: 14%; transform: translate(-50%, 18px); padding: 12px 20px; border: 1px solid rgba(244,216,151,.4); background: rgba(7,21,30,.88); color: #f9e7bd; font: 700 12px Arial, sans-serif; letter-spacing: .08em; opacity: 0; transition: .25s ease; pointer-events: none; white-space: nowrap; }
#toast.visible { opacity: 1; transform: translate(-50%, 0); }

#mobile-controls { position: absolute; z-index: 6; inset: auto max(18px, env(safe-area-inset-right)) max(18px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left)); display: none; justify-content: space-between; align-items: end; pointer-events: none; }
#mobile-controls button { pointer-events: auto; width: 68px; height: 68px; border-radius: 50%; border: 1px solid rgba(244,216,151,.44); background: rgba(8,27,38,.66); color: #ffe2a1; font-size: 25px; backdrop-filter: blur(8px); box-shadow: 0 10px 22px rgba(0,0,0,.24); }
.move-controls { display: flex; gap: 12px; }
#mobile-controls .jump-control { width: 78px; height: 78px; }
#mobile-controls button.pressed { transform: scale(.94); background: rgba(199,145,57,.72); color: #fff; }
#sound-toggle { position: absolute; right: max(18px, env(safe-area-inset-right)); bottom: max(18px, env(safe-area-inset-bottom)); z-index: 8; width: 42px; height: 42px; border-radius: 50%; border: 1px solid rgba(244,216,151,.4); background: rgba(6,21,30,.68); color: #f8d995; cursor: pointer; }

@media (pointer: coarse), (max-width: 900px) {
  #mobile-controls { display: flex; }
  #sound-toggle { bottom: max(108px, calc(env(safe-area-inset-bottom) + 100px)); }
  #hud { grid-template-columns: minmax(150px, 1fr) 1fr auto; gap: 9px; }
  .hud-card { min-height: 54px; padding: 10px 12px; }
  .hud-card strong { font-size: 15px; }
  .hud-center { display: none; }
  .controls-grid { display: none; }
}

@media (max-height: 640px) {
  .panel { padding: 22px 32px; }
  .seal { width: 66px; height: 66px; margin-bottom: 13px; }
  h1 { font-size: 52px; }
  .subtitle { margin: 12px auto; font-size: 15px; }
  .controls-grid { margin: 14px 0 18px; }
}
