:root {
  --ink: #2b190c;
  --cream: #f6e7c1;
  --cream-2: #e9d3a2;
  --gold: #ffd24a;
  --gold-2: #f5a623;
  --orange: #f6a021;
  --green: #1f5d4f;
  --green-2: #2f7a66;
  --teal: #0d2b28;
  --teal-2: #123c37;
  --red: #b3271b;
  --topbar-h: 56px;
  --dock-h: 0px;
  --chrome: calc(var(--topbar-h) + var(--dock-h) + 26px);
  --font-title: Impact, "Arial Black", "Trebuchet MS", sans-serif;
  --font-body: "Trebuchet MS", Verdana, Arial, sans-serif;
  --shadow: 0 18px 40px rgba(0, 0, 0, .45);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #071514;
}

body {
  font-family: var(--font-body);
  color: var(--cream);
  -webkit-text-size-adjust: 100%;
  background:
    radial-gradient(1200px 700px at 50% -10%, #1c4a44 0%, rgba(12, 35, 33, 0) 60%),
    radial-gradient(900px 500px at 90% 110%, #4a2a20 0%, rgba(20, 12, 10, 0) 60%),
    linear-gradient(180deg, #0a1f1d 0%, #071514 55%, #0a1512 100%);
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: .22;
  background-image:
    repeating-linear-gradient(115deg, rgba(255, 220, 150, .05) 0 1px, transparent 1px 7px),
    repeating-linear-gradient(25deg, rgba(0, 0, 0, .15) 0 1px, transparent 1px 9px);
  mix-blend-mode: overlay;
}

#app {
  position: relative;
  min-height: 100dvh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  padding:
    env(safe-area-inset-top)
    env(safe-area-inset-right)
    env(safe-area-inset-bottom)
    env(safe-area-inset-left);
}

[hidden] { display: none !important; }

/* ---------- top bar ---------- */

.topbar {
  flex: 0 0 var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 12px;
  background: linear-gradient(180deg, rgba(24, 62, 57, .98), rgba(8, 27, 25, .98));
  border-bottom: 2px solid rgba(255, 205, 100, .28);
  box-shadow: 0 6px 22px rgba(0, 0, 0, .45), inset 0 1px 0 rgba(255, 240, 190, .12);
  z-index: 20;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 4px 10px 4px 6px;
  border: 0;
  background: transparent;
  color: var(--gold);
  cursor: pointer;
  border-radius: 10px;
  text-align: left;
}
.brand:hover { background: rgba(255, 220, 130, .08); }
.brand-rocket {
  font-size: 24px;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, .5));
  transform: rotate(-8deg);
}
.brand-text { display: flex; flex-direction: column; line-height: 1; }
.brand-text strong {
  font-family: var(--font-title);
  font-size: 21px;
  letter-spacing: .5px;
  color: var(--gold);
  text-shadow: 0 2px 0 #5a1c06, 0 0 12px rgba(255, 170, 40, .35);
}
.brand-text small {
  font-size: 10px;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: rgba(255, 236, 190, .72);
  margin-top: 4px;
}
.topbar-spacer { flex: 1 1 auto; }
.topbar-controls { display: flex; align-items: center; gap: 6px; }

.chip-select {
  min-height: 42px;
  max-width: 132px;
  padding: 0 30px 0 12px;
  border-radius: 10px;
  border: 1px solid rgba(255, 210, 120, .35);
  background:
    linear-gradient(180deg, rgba(66, 112, 106, .95), rgba(26, 62, 58, .95));
  color: var(--cream);
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: bold;
  appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--gold) 50%),
    linear-gradient(135deg, var(--gold) 50%, transparent 50%),
    linear-gradient(180deg, rgba(66, 112, 106, .95), rgba(26, 62, 58, .95));
  background-position: calc(100% - 16px) 18px, calc(100% - 11px) 18px, 0 0;
  background-size: 5px 5px, 5px 5px, 100% 100%;
  background-repeat: no-repeat;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .12), 0 3px 8px rgba(0, 0, 0, .3);
  cursor: pointer;
}
.chip-select:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }

.icon-btn {
  width: 44px;
  height: 44px;
  min-width: 44px;
  border-radius: 10px;
  border: 1px solid rgba(255, 210, 120, .32);
  background: linear-gradient(180deg, rgba(67, 112, 106, .95), rgba(22, 54, 51, .95));
  color: var(--gold);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .12), 0 3px 8px rgba(0, 0, 0, .3);
  transition: transform .08s ease, filter .15s ease, background .15s ease;
}
.icon-btn:hover { filter: brightness(1.14); }
.icon-btn:active { transform: translateY(1px); }
.icon-btn.muted { color: #9bb0ac; filter: saturate(.4); }
.brand-badge {
  display: inline-flex;
  align-items: center;
  height: 30px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid rgba(255, 210, 120, .35);
  color: rgba(255, 232, 180, .9);
  font-size: 11px;
  font-weight: bold;
  letter-spacing: .4px;
  text-decoration: none;
  background: rgba(255, 180, 60, .08);
}
.brand-badge:hover { background: rgba(255, 180, 60, .18); color: #fff3c8; }

/* ---------- stage ---------- */

.stage {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
  position: relative;
}

.frame {
  position: relative;
  width: min(96vw, calc((100dvh - var(--chrome)) * 4 / 3), 1280px);
  aspect-ratio: 4 / 3;
  border-radius: 16px;
  overflow: hidden;
  border: 2px solid rgba(255, 205, 110, .28);
  box-shadow:
    0 0 0 6px rgba(8, 26, 24, .65),
    0 0 0 8px rgba(255, 205, 110, .12),
    0 30px 70px rgba(0, 0, 0, .6),
    inset 0 0 60px rgba(0, 0, 0, .35);
  background: #0c211f;
  isolation: isolate;
}

.frame::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  border-radius: 14px;
  box-shadow: inset 0 0 34px rgba(0, 0, 0, .18);
}

canvas#game {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  background: #0b1c2e;
}

/* Keep HTML modals legible in software-composited headless/GPU-disabled
   browsers where a canvas layer can incorrectly paint above fixed overlays. */
body.modal-open #game { visibility: hidden; }
body.modal-open .stage {
  background:
    radial-gradient(700px 460px at 50% 42%, #1c4a42 0%, rgba(10, 26, 24, 0) 72%),
    linear-gradient(180deg, #0a1f1d, #071514);
}

.rotate-hint {
  position: absolute;
  left: 50%;
  bottom: 10px;
  transform: translateX(-50%);
  padding: 7px 14px;
  border-radius: 999px;
  background: rgba(6, 18, 17, .82);
  border: 1px solid rgba(255, 205, 110, .35);
  color: var(--cream);
  font-size: 11px;
  white-space: nowrap;
  pointer-events: none;
  z-index: 3;
}

/* ---------- mobile dock ---------- */

.dock {
  display: none;
  flex: 0 0 var(--dock-h);
  align-items: stretch;
  gap: 6px;
  padding: 6px 8px 8px;
  background: linear-gradient(0deg, rgba(10, 30, 28, .98), rgba(18, 50, 46, .92));
  border-top: 1px solid rgba(255, 205, 110, .25);
  z-index: 20;
}
.dock-btn {
  flex: 1 1 0;
  min-height: 48px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  border-radius: 10px;
  border: 1px solid rgba(255, 210, 120, .28);
  background: linear-gradient(180deg, rgba(66, 110, 104, .95), rgba(20, 52, 49, .95));
  color: var(--cream);
  font-family: var(--font-body);
  font-size: 10px;
  font-weight: bold;
  letter-spacing: .3px;
  cursor: pointer;
}
.dock-btn .dock-glyph { font-size: 19px; color: var(--gold); line-height: 1; }
.dock-btn:active { transform: translateY(1px); filter: brightness(1.15); }
.dock-btn.active { border-color: var(--gold); box-shadow: 0 0 0 1px rgba(255, 210, 74, .4) inset; }

/* ---------- modals ---------- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  padding-top: max(16px, env(safe-area-inset-top));
  padding-bottom: max(16px, env(safe-area-inset-bottom));
  background:
    radial-gradient(900px 500px at 50% 0%, rgba(40, 90, 82, .28), transparent 70%),
    rgba(3, 10, 10, .84);
}

.modal {
  position: relative;
  width: 100%;
  max-width: 560px;
  max-height: 88dvh;
  overflow: auto;
  overscroll-behavior: contain;
  border-radius: 18px;
  color: var(--ink);
  background:
    linear-gradient(160deg, #fdf3d8 0%, #f4e2b8 55%, #e6cf9e 100%);
  border: 3px solid #1f5d4f;
  box-shadow:
    0 0 0 6px rgba(8, 26, 24, .6),
    0 0 0 8px rgba(255, 205, 110, .15),
    0 30px 80px rgba(0, 0, 0, .65);
}
.modal.wide { max-width: 720px; }
.modal.small { max-width: 400px; }
.modal.paper::before {
  content: "";
  position: absolute;
  inset: 8px;
  border-radius: 12px;
  border: 1px solid rgba(120, 84, 30, .28);
  pointer-events: none;
}
.modal-head {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px 10px 20px;
  background: linear-gradient(180deg, rgba(253, 243, 216, .98) 70%, rgba(244, 226, 184, .9));
  border-bottom: 1px solid rgba(90, 58, 24, .2);
}
.modal-head h2 {
  flex: 1;
  margin: 0;
  font-family: var(--font-title);
  font-size: 26px;
  letter-spacing: .5px;
  color: #7a1f05;
  text-shadow: 0 1px 0 rgba(255, 235, 180, .8);
}
.modal-close {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 2px solid rgba(90, 58, 24, .35);
  background: rgba(255, 245, 215, .8);
  color: #7a1f05;
  font-size: 18px;
  font-weight: bold;
  cursor: pointer;
}
.modal-close:hover { background: #ffe6a6; }
.modal-body { padding: 14px 20px 22px; }

.field { margin: 12px 0 16px; }
.field-label {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 7px;
  font-size: 13px;
  font-weight: bold;
  color: #4a2e14;
  letter-spacing: .2px;
}
.field-label b { color: #8a4a10; font-variant-numeric: tabular-nums; }
.hint { margin: 4px 0 0; font-size: 11.5px; line-height: 1.45; color: #6b4a22; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  min-height: 44px;
  padding: 0 14px;
  border-radius: 10px;
  border: 2px solid rgba(90, 58, 24, .35);
  background: linear-gradient(180deg, #fff7df, #eedcae);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: bold;
  cursor: pointer;
}
.chip:hover { border-color: #b9781a; }
.chip.active {
  border-color: #b9781a;
  background: linear-gradient(180deg, #ffe486, #f5a623);
  color: #3b1704;
  box-shadow: 0 0 0 2px rgba(255, 210, 74, .35);
}

.range {
  width: 100%;
  height: 34px;
  accent-color: #d88417;
  cursor: pointer;
}

.switch-row {
  display: flex;
  flex-wrap: wrap;
  gap: 18px;
  margin: 6px 0 14px;
}
.switch {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  min-height: 44px;
  font-size: 13px;
  font-weight: bold;
  color: #4a2e14;
  cursor: pointer;
}
.switch input {
  width: 22px;
  height: 22px;
  accent-color: #d88417;
  cursor: pointer;
}

.stats-box {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 14px;
  padding: 12px 14px;
  margin: 14px 0;
  border-radius: 12px;
  background: rgba(120, 84, 30, .09);
  border: 1px dashed rgba(120, 84, 30, .35);
  font-size: 12px;
}
.stats-box div { display: flex; justify-content: space-between; gap: 8px; }
.stats-box b { color: #7a1f05; font-variant-numeric: tabular-nums; }

.save-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.save-actions.center { justify-content: center; margin-top: 16px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 10px 16px;
  border-radius: 10px;
  border: 2px solid rgba(20, 20, 10, .35);
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: bold;
  letter-spacing: .2px;
  text-decoration: none;
  cursor: pointer;
  transition: transform .08s ease, filter .15s ease;
}
.btn:active { transform: translateY(1px); }
.btn.stone {
  background: linear-gradient(180deg, #538c85, #245850);
  color: #ffedb0;
  border-color: #0c2a26;
  text-shadow: 0 1px 2px rgba(0, 0, 0, .55);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .18);
}
.btn.stone:hover { filter: brightness(1.1); }
.btn.gold {
  background: linear-gradient(180deg, #ffe486, #f5a623 60%, #d77c0d);
  color: #3b1704;
  border-color: #8a4308;
  box-shadow: inset 0 1px 0 rgba(255, 250, 210, .7);
}
.btn.gold:hover { filter: brightness(1.05); }
.btn.danger {
  background: linear-gradient(180deg, #c9503d, #8e2519);
  color: #ffe8d6;
  border-color: #52100a;
}
.btn.tiny { min-height: 34px; padding: 6px 12px; font-size: 12px; }

.portal-box {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px dashed rgba(120, 84, 30, .35);
  flex-wrap: wrap;
}
.portal-link {
  color: #0d5a4a;
  font-size: 12.5px;
  font-weight: bold;
  text-decoration: none;
  word-break: break-word;
}
.portal-link:hover { color: #b3271b; text-decoration: underline; }

/* how to play */
.goal-banner {
  padding: 12px 14px;
  border-radius: 12px;
  background: linear-gradient(180deg, rgba(255, 180, 60, .22), rgba(255, 180, 60, .08));
  border: 1px solid rgba(180, 110, 20, .35);
  color: #6b2a08;
  font-size: 13px;
  font-weight: bold;
  line-height: 1.45;
}
.tutorial-list {
  margin: 14px 0 8px;
  padding: 0;
  list-style: none;
  counter-reset: tut;
  display: grid;
  gap: 10px;
}
.tutorial-list li {
  position: relative;
  padding: 8px 10px 8px 42px;
  border-radius: 10px;
  background: rgba(255, 250, 235, .5);
  border: 1px solid rgba(120, 84, 30, .16);
  font-size: 12.5px;
  line-height: 1.45;
  color: #3f2a14;
  counter-increment: tut;
}
.tutorial-list li::before {
  content: counter(tut);
  position: absolute;
  left: 10px;
  top: 8px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: linear-gradient(180deg, #ffd24a, #e79015);
  color: #3b1704;
  font-family: var(--font-title);
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid #8a4308;
}
.bonus-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 12px 0;
}
.bonus-card {
  padding: 9px 10px;
  border-radius: 10px;
  background: rgba(120, 84, 30, .08);
  border: 1px solid rgba(120, 84, 30, .18);
  font-size: 11.5px;
  line-height: 1.4;
  color: #4a2e14;
}
.bonus-card b { display: block; color: #7a1f05; font-size: 12px; margin-bottom: 2px; }
.hint-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.hint-pill {
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(31, 93, 79, .12);
  border: 1px solid rgba(31, 93, 79, .25);
  color: #1f5d4f;
  font-size: 11px;
  font-weight: bold;
}

/* about / easter */
.about-body { text-align: center; }
.about-logo {
  font-family: var(--font-title);
  font-size: 34px;
  color: #7a1f05;
  letter-spacing: 1px;
  text-shadow: 0 2px 0 rgba(255, 230, 150, .7);
  margin: 4px 0 10px;
}
.about-body p { font-size: 12.5px; line-height: 1.55; color: #4a2e14; margin: 8px 0; }
.about-body p.muted { color: #6b4a22; font-size: 11.5px; }
.easter { max-width: 480px; }
.easter-body { text-align: center; }
.easter-fireworks { font-size: 38px; letter-spacing: 6px; margin: 6px 0 10px; animation: float 2.6s ease-in-out infinite; }
.easter-body p { font-size: 13px; line-height: 1.55; color: #4a2e14; }
.easter-body .btn { margin-top: 14px; }
.confirm-text { font-size: 14px; line-height: 1.5; color: #3f2a14; text-align: center; margin: 10px 4px 4px; }
.name-title { font-family: var(--font-title); font-size: 30px; color: #b3271b; text-align: center; margin: 6px 0 4px; }
.name-score { text-align: center; font-size: 15px; font-weight: bold; color: #7a1f05; margin: 0 0 14px; }
.text-input {
  width: 100%;
  min-height: 46px;
  padding: 8px 12px;
  border-radius: 10px;
  border: 2px solid rgba(90, 58, 24, .4);
  background: #fff9e9;
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 16px;
}
.text-input:focus { outline: 2px solid var(--gold-2); outline-offset: 1px; }

/* ---------- toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--dock-h) + 18px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(10px);
  z-index: 200;
  max-width: min(92vw, 520px);
  padding: 10px 18px;
  border-radius: 999px;
  background: linear-gradient(180deg, rgba(20, 55, 51, .98), rgba(8, 28, 26, .98));
  border: 1px solid rgba(255, 205, 110, .45);
  color: var(--cream);
  font-size: 13px;
  font-weight: bold;
  text-align: center;
  box-shadow: 0 12px 30px rgba(0, 0, 0, .55);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.good { border-color: rgba(110, 230, 160, .6); }
.toast.warn { border-color: rgba(255, 150, 80, .7); color: #ffe0b0; }

/* ---------- responsive ---------- */

@media (max-width: 900px) {
  .brand-badge { display: none; }
  .brand-text small { display: none; }
  .brand-text strong { font-size: 19px; }
}

@media (max-width: 700px), (pointer: coarse) {
  :root { --topbar-h: 50px; --dock-h: 66px; --chrome: calc(var(--topbar-h) + var(--dock-h) + 22px); }
  .dock { display: flex; }
  .topbar { gap: 6px; padding: 4px 8px; }
  .brand { padding: 2px 6px; gap: 7px; }
  .brand-rocket { font-size: 20px; }
  .brand-text strong { font-size: 15px; letter-spacing: 0; }
  .chip-select { max-width: 96px; min-height: 40px; font-size: 12px; padding-left: 9px; padding-right: 24px; background-position: calc(100% - 13px) 17px, calc(100% - 9px) 17px, 0 0; }
  .icon-btn { width: 42px; height: 42px; min-width: 42px; font-size: 16px; }
  .icon-btn#btnHelp { display: none; }
  #btnFullscreen { display: none; }
  .stage { padding: 3px; }
  .frame { width: min(98vw, calc((100dvh - var(--chrome)) * 4 / 3)); border-radius: 10px; }
  .modal-head h2 { font-size: 22px; }
  .modal-body { padding: 12px 14px 18px; }
  .stats-box { grid-template-columns: 1fr; }
  .bonus-grid { grid-template-columns: 1fr; }
  .save-actions .btn { flex: 1 1 40%; }
}

@media (orientation: portrait) and (max-width: 700px) {
  .rotate-hint { display: block; }
}

@media (max-height: 520px) and (orientation: landscape) and (pointer: coarse) {
  :root { --topbar-h: 46px; --dock-h: 56px; }
  .dock-btn { min-height: 42px; font-size: 9px; }
  .dock-btn .dock-glyph { font-size: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}

/* focus visibility */
button:focus-visible, a:focus-visible, select:focus-visible, input:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

/* scrollbars inside modals */
.modal::-webkit-scrollbar { width: 10px; }
.modal::-webkit-scrollbar-thumb { background: rgba(90, 58, 24, .35); border-radius: 8px; }
.modal::-webkit-scrollbar-track { background: transparent; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes popIn { from { opacity: 0; transform: translateY(8px) scale(.97); } to { opacity: 1; transform: none; } }
@keyframes float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-6px); } }
