:root {
  --sky: #1B2238;
  --ink: #1B2238;
  --cream: #F6EFE2;
  --yellow: #F2C14E;
  --muted: #AAB3C8;
  --muted-dark: #5B6478;
  --chip: rgba(255, 255, 255, 0.12);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--sky);
}

body {
  font-family: Rubik, system-ui, -apple-system, "Segoe UI", sans-serif;
  color: #FFFFFF;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

[hidden] { display: none !important; }

/* The game is laid out at 390 x 844 and scaled to fit the window. */
#wrap {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
#frame { position: relative; overflow: hidden; }
#stage {
  position: absolute;
  left: 0;
  top: 0;
  width: 390px;
  height: 844px;
  transform-origin: 0 0;
  transform: scale(var(--s, 1));
}
#game {
  position: absolute;
  left: 0;
  top: 0;
  width: 390px;
  height: 844px;
  display: block;
  touch-action: none;
  cursor: pointer;
}

/* HUD */
.hud {
  position: absolute;
  left: 0;
  top: 0;
  width: 390px;
  height: 72px;
  padding: 12px 16px 0 20px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  pointer-events: none;
  background: rgba(12, 16, 32, 0.78);
}
.hud-stat { width: 90px; display: flex; flex-direction: column; gap: 2px; }
.hud-stat.right { width: auto; align-items: flex-end; }
.hud-next { display: flex; align-items: center; gap: 8px; padding-top: 4px; }
.hud-next img { display: block; width: 48px; height: 36px; }
.hud-right { display: flex; align-items: center; gap: 12px; }
.label { font-size: 11px; font-weight: 700; letter-spacing: 1.5px; color: var(--muted); }
.label.dark { color: var(--muted-dark); }
.value-lg { font-size: 32px; font-weight: 800; line-height: 1; }
.value-md { font-size: 20px; font-weight: 700; line-height: 1; }
.value-xl { font-size: 36px; font-weight: 800; line-height: 1; }

.icon-btn {
  pointer-events: auto;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 14px;
  background: var(--chip);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

/* Effect panel (bottom tray) */
.fx-tray {
  position: absolute;
  left: 16px;
  right: 16px;
  bottom: 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  pointer-events: none;
}
.fx-panel {
  min-height: 44px;
  padding: 6px 12px 6px 10px;
  border-radius: 14px;
  background: rgba(10, 14, 28, 0.86);
  border: 1.5px solid var(--c, #FFFFFF);
  display: flex;
  align-items: center;
  gap: 10px;
  animation: fx-in 0.35s ease-out;
}
@keyframes fx-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .fx-panel { animation: none; } }
.fx-icon { flex: 0 0 auto; display: block; width: 28px; height: 28px; }
.fx-meter .wind { font-size: 13px; }
.fx-icon.wide { width: 40px; height: 30px; }
.fx-text { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.fx-text b { font-size: 14px; font-weight: 700; color: var(--c, #FFFFFF); }
.fx-text span { font-size: 12px; color: #D3D8E4; line-height: 1.3; }
.fx-meter { flex: 0 0 64px; display: flex; flex-direction: column; align-items: flex-end; gap: 5px; }
.fx-meter span { font-size: 11px; font-weight: 700; color: #FFFFFF; }
.fx-bar { width: 64px; height: 6px; border-radius: 3px; background: rgba(255, 255, 255, 0.15); overflow: hidden; }
.fx-bar i { display: block; height: 100%; width: 100%; border-radius: 3px; background: var(--c, #FFFFFF); transition: width 0.3s ease; }

/* First-time explainer card */
.card.info-card { --accent: #FFC93C; align-items: center; padding-top: 24px; }
.info-tag {
  align-self: center;
  padding: 4px 10px;
  border-radius: 10px;
  background: #1B2238;
  color: #FFFFFF;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
}
.info-icon { display: block; width: 72px; height: 72px; margin: 4px 0; }
.info-points {
  align-self: stretch;
  margin: 2px 0 6px;
  padding: 12px 14px;
  list-style: none;
  border-radius: 14px;
  background: #FFFFFF;
  border: 2px solid var(--accent);
  display: flex;
  flex-direction: column;
  gap: 8px;
  text-align: left;
  font-size: 14px;
  line-height: 1.35;
}
.info-points li { display: flex; gap: 8px; }
.info-points li::before { content: ""; flex: 0 0 8px; height: 8px; margin-top: 6px; border-radius: 50%; background: var(--ink); }
.card.info-card .btn { align-self: stretch; }

/* Time-of-day chip */
.clock {
  position: absolute;
  left: 16px;
  top: 104px;
  height: 30px;
  padding: 0 12px 0 6px;
  border-radius: 15px;
  background: rgba(10, 14, 28, 0.72);
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 700;
  color: #FFFFFF;
  pointer-events: none;
}
.clock img { display: block; }
.clock.tick { animation: clock-tick 0.6s ease-out; }
@keyframes clock-tick { 0% { transform: scale(1); } 40% { transform: scale(1.12); } 100% { transform: scale(1); } }
@media (prefers-reduced-motion: reduce) { .clock.tick { animation: none; } }

/* Sway gauge */
.sway {
  position: absolute;
  left: 8px;
  top: 352px;
  width: 44px;
  padding: 8px 0 10px;
  border-radius: 14px;
  background: rgba(10, 14, 28, 0.55);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  pointer-events: none;
}
.sway .label { font-size: 9px; letter-spacing: 1px; }
.sway-track {
  position: relative;
  width: 10px;
  height: 180px;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.12);
  overflow: hidden;
}
.sway-fill {
  position: absolute;
  left: 0;
  bottom: 0;
  width: 100%;
  height: 0%;
  border-radius: 5px;
  background: #F2C14E;
}
.sway.warn .sway-fill { background: #FF5A4E; }
.sway.warn .label { color: #FF8A80; }

.hint {
  position: absolute;
  left: 95px;
  top: 440px;
  width: 200px;
  height: 44px;
  border-radius: 22px;
  background: rgba(10, 14, 28, 0.66);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 15px;
  font-weight: 500;
  pointer-events: none;
}

/* Screens */
.screen { position: absolute; left: 0; top: 0; width: 390px; height: 844px; }
.screen.start { pointer-events: none; }
.screen.start button { pointer-events: auto; }
.screen.dim {
  background: rgba(10, 14, 28, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
}

.start-title {
  position: absolute;
  left: 0;
  top: 344px;
  width: 390px;
  padding: 0 32px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.start-title h1 { margin: 0; font-size: 52px; font-weight: 800; line-height: 1; letter-spacing: -1px; text-shadow: 0 3px 0 rgba(10, 14, 28, 0.45), 0 2px 18px rgba(10, 14, 28, 0.55); }
.start-title p { margin: 0 auto; padding: 4px 12px; border-radius: 12px; background: rgba(10, 14, 28, 0.5); font-size: 16px; color: #FFFFFF; }

.start-actions {
  position: absolute;
  left: 0;
  top: 450px;
  width: 390px;
  padding: 0 32px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.steps {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}
.steps li {
  padding: 12px 6px;
  border-radius: 14px;
  background: rgba(10, 14, 28, 0.6);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  color: #D3D8E4;
}
.step-n { font-size: 18px; font-weight: 800; color: var(--yellow); }

.card {
  width: 310px;
  padding: 28px 24px 24px;
  border-radius: 24px;
  background: var(--cream);
  color: var(--ink);
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 12px;
  text-align: center;
}
.card h2 { margin: 0; font-size: 26px; font-weight: 800; }
.card-sub { margin: 0; font-size: 15px; color: var(--muted-dark); }
.stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin: 8px 0; }
.stat { padding: 14px 8px; border-radius: 16px; background: #FFFFFF; display: flex; flex-direction: column; gap: 4px; }

/* Buttons */
.btn {
  height: 56px;
  border-radius: 16px;
  font-family: inherit;
  font-size: 18px;
  font-weight: 700;
  color: var(--ink);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  cursor: pointer;
}
.btn-primary { border: 0; background: var(--yellow); box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.15); }
.btn-primary:active { box-shadow: inset 0 -1px 0 rgba(0, 0, 0, 0.15); transform: translateY(2px); }
.btn-outline { height: 52px; border: 2px solid var(--ink); background: transparent; font-size: 16px; }
.btn-xl { height: 64px; border-radius: 20px; font-size: 20px; font-weight: 800; box-shadow: inset 0 -5px 0 rgba(0, 0, 0, 0.15); }
.btn:focus-visible, .icon-btn:focus-visible { outline: 3px solid #FFFFFF; outline-offset: 3px; }
.card .btn:focus-visible { outline-color: var(--ink); }

/* Coins and combo */
.purse {
  position: absolute;
  right: 16px;
  top: 104px;
  display: flex;
  align-items: center;
  gap: 6px;
  pointer-events: none;
}
.coins {
  height: 30px;
  padding: 0 12px 0 6px;
  border-radius: 15px;
  background: rgba(10, 14, 28, 0.72);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  font-weight: 800;
  color: #FFE08A;
}
.coins img { display: block; }
.coins.bump { animation: bump 0.4s ease-out; }
.combo {
  height: 30px;
  padding: 0 10px;
  border-radius: 15px;
  background: #FFC93C;
  color: var(--ink);
  display: inline-flex;
  align-items: center;
  font-size: 14px;
  font-weight: 800;
}
.combo.bump { animation: bump 0.4s ease-out; }
@keyframes bump { 0% { transform: scale(1); } 40% { transform: scale(1.18); } 100% { transform: scale(1); } }
@media (prefers-reduced-motion: reduce) { .coins.bump, .combo.bump { animation: none; } }

/* Start screen extras */
.start-top { position: absolute; right: 16px; top: 20px; }
.btn-ghost { height: 52px; border: 2px solid rgba(255, 255, 255, 0.85); background: rgba(10, 14, 28, 0.55); color: #FFFFFF; font-size: 17px; }
.btn-ghost img { display: block; }
.boost-note {
  margin: -4px 0 0;
  padding: 6px 12px;
  border-radius: 12px;
  background: rgba(91, 203, 110, 0.22);
  border: 1.5px solid #5BCB6E;
  font-size: 13px;
  font-weight: 600;
  text-align: center;
  color: #FFFFFF;
}

/* Game over extras */
.earn {
  padding: 10px 12px;
  border-radius: 16px;
  background: #FFF4D1;
  border: 2px solid #FFC93C;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.earn-coins { display: inline-flex; align-items: center; gap: 6px; font-size: 20px; font-weight: 800; color: #8A5A00; }
.earn-coins img { display: block; }
.earn-note { font-size: 12px; color: var(--muted-dark); text-align: right; }
.row-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }

/* Shop */
.screen.shop {
  background: var(--cream);
  color: var(--ink);
  display: flex;
  flex-direction: column;
}
.shop-head {
  flex: 0 0 auto;
  height: 72px;
  padding: 14px 16px 0;
  display: flex;
  align-items: center;
  gap: 12px;
}
.shop-head h2 { margin: 0; flex: 1 1 auto; font-size: 26px; font-weight: 800; }
.icon-btn.dark { background: #FFFFFF; border: 2px solid var(--ink); }
.chip.light { background: var(--ink); }
.shop-body {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 8px 16px 28px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.shop-body h3 { margin: 12px 0 2px; font-size: 13px; font-weight: 700; letter-spacing: 1px; text-transform: uppercase; color: var(--muted-dark); }
.shop-item {
  padding: 10px 12px;
  border-radius: 16px;
  background: #FFFFFF;
  display: flex;
  align-items: center;
  gap: 12px;
}
.shop-item.on { box-shadow: inset 0 0 0 2px var(--ink); }
.shop-icon { flex: 0 0 auto; width: 52px; height: 44px; display: flex; align-items: center; justify-content: center; }
.shop-icon img { display: block; max-width: 52px; max-height: 44px; }
.swatch { width: 44px; height: 18px; border-radius: 4px; border: 2px solid var(--ink); background-image: repeating-linear-gradient(135deg, transparent 0 7px, rgba(27, 34, 56, 0.35) 7px 11px); }
.shop-text { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.shop-text b { font-size: 15px; }
.shop-text span { font-size: 12px; color: var(--muted-dark); line-height: 1.3; }
.shop-btn {
  flex: 0 0 auto;
  min-width: 86px;
  height: 40px;
  padding: 0 12px;
  border: 0;
  border-radius: 12px;
  background: var(--yellow);
  font-family: inherit;
  font-size: 14px;
  font-weight: 800;
  color: var(--ink);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  cursor: pointer;
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.15);
}
.shop-btn img { display: block; }
.shop-btn.alt { background: #FFFFFF; box-shadow: inset 0 0 0 2px var(--ink); }
.shop-btn:disabled { background: #E7E1D4; color: #5B6478; box-shadow: none; cursor: default; }
.shop-btn:focus-visible { outline: 3px solid var(--ink); outline-offset: 2px; }
.shop-msg { margin: 0; min-height: 18px; font-size: 13px; font-weight: 600; text-align: center; color: #1F6B34; }
