@font-face {
  font-family: "Wish Serif";
  src: url("assets/fonts/WishSerif-Game.woff2") format("woff2");
  font-style: normal;
  font-weight: 400;
  font-display: block;
}

@font-face {
  font-family: "Wish Serif";
  src: url("assets/fonts/WishSerif-Game.woff2") format("woff2");
  font-style: normal;
  font-weight: 600;
  font-display: block;
}

@font-face {
  font-family: "Wish Serif";
  src: url("assets/fonts/WishSerif-Game.woff2") format("woff2");
  font-style: normal;
  font-weight: 700;
  font-display: block;
}

@font-face {
  font-family: "Wish Serif";
  src: url("assets/fonts/WishSerif-Game.woff2") format("woff2");
  font-style: normal;
  font-weight: 900;
  font-display: block;
}

:root {
  color-scheme: only light;
  --font-main: "Wish Serif", serif;
  font-family: var(--font-main);
  --wine: #690c1e;
  --wine-bright: #801126;
  --wine-dark: #400611;
  --wine-black: #26030b;
  --cream: #f9e9bd;
  --ink: #f7e7bc;
  --gold: #d1ad62;
  --gold-light: #f4dda0;
  --gold-dark: #9c7438;
}

* { box-sizing: border-box; }

html:not(.fonts-ready) .game-shell { visibility: hidden; }

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 18%, rgb(124 20 41 / 58%), transparent 44%),
    linear-gradient(135deg, #3e0713, #160208 72%);
  color: var(--ink);
}

button { font: inherit; }

.loading-screen {
  position: fixed;
  z-index: 100;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  color: var(--gold-light);
  background:
    radial-gradient(circle at 50% 24%, rgb(132 20 42 / 68%), transparent 42%),
    repeating-linear-gradient(0deg, rgb(255 255 255 / 1.4%) 0 1px, transparent 1px 4px),
    linear-gradient(145deg, #5c0919, #25030a 76%);
  opacity: 1;
  visibility: visible;
  transition: opacity 380ms ease, visibility 380ms ease;
}

html.assets-ready .loading-screen {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.loading-card {
  width: min(86vw, 340px);
  padding: 34px 28px 30px;
  text-align: center;
  border: 1px solid var(--gold);
  outline: 1px solid rgb(83 6 20 / 94%);
  background:
    radial-gradient(circle at 50% 12%, rgb(145 24 46 / 72%), transparent 58%),
    linear-gradient(145deg, rgb(112 10 29 / 98%), rgb(72 5 18 / 98%));
  box-shadow:
    inset 0 0 0 5px rgb(91 7 23 / 92%),
    inset 0 0 0 6px rgb(209 173 98 / 72%),
    0 22px 60px rgb(13 0 4 / 52%);
}

.loading-eyebrow {
  margin: 0;
  color: var(--gold);
  font-size: 11px;
  letter-spacing: .12em;
}

.loading-crown {
  margin: 15px 0 3px;
  color: var(--gold-light);
  font-size: 24px;
  animation: loading-crown-pulse 1.35s ease-in-out infinite;
}

.loading-card h1 {
  margin: 3px 0 23px;
  color: var(--gold-light);
  font-size: clamp(24px, 7vw, 30px);
  line-height: 1.2;
  letter-spacing: .08em;
}

.loading-track {
  height: 10px;
  overflow: hidden;
  border: 1px solid var(--gold-dark);
  border-radius: 999px;
  background: rgb(35 2 9 / 72%);
  box-shadow: inset 0 1px 3px rgb(0 0 0 / 44%);
}

.loading-fill {
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #a97836, #f2d58e 62%, #fff0b9);
  box-shadow: 0 0 10px rgb(244 221 160 / 65%);
  transition: width 160ms ease-out;
}

.loading-status {
  margin: 11px 0 7px;
  color: var(--gold-light);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.loading-card small {
  color: rgb(244 221 160 / 68%);
  font-size: 11px;
}

@keyframes loading-crown-pulse {
  0%, 100% { opacity: .58; transform: translateY(0) scale(.96); }
  50% { opacity: 1; transform: translateY(-2px) scale(1.05); text-shadow: 0 0 12px rgb(244 221 160 / 46%); }
}

.game-shell {
  width: min(100vw, 430px, calc(100dvh * 0.5294118));
  height: auto;
  max-height: 100dvh;
  aspect-ratio: 9 / 17;
  margin: 0 auto;
  display: grid;
  grid-template-rows: auto 1fr auto;
  overflow: hidden;
  background: var(--wine-dark);
  border-inline: 1px solid rgb(209 173 98 / 45%);
  box-shadow: 0 0 55px rgb(0 0 0 / 58%), 0 0 0 1px rgb(209 173 98 / 20%);
}

.hud {
  position: relative;
  z-index: 4;
  display: grid;
  grid-template-columns: minmax(116px, 1fr) auto auto;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  min-height: 66px;
  padding: max(10px, env(safe-area-inset-top)) 57px 10px 14px;
  color: var(--gold-light);
  background:
    repeating-linear-gradient(0deg, rgb(255 255 255 / 1.8%) 0 1px, transparent 1px 4px),
    radial-gradient(circle at 50% 0, var(--wine-bright), transparent 68%),
    linear-gradient(135deg, #741022, var(--wine));
  border-bottom: 3px double var(--gold);
  box-shadow: inset 0 -1px 0 rgb(71 5 17 / 85%);
}

.dowry-hud { display: flex; width: min(100%, 126px); flex-direction: column; gap: 5px; }

.dowry-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .14em;
}

.hud-icon-button {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  z-index: 3;
  display: grid;
  place-items: center;
  width: 31px;
  height: 31px;
  padding: 0;
  border: 1px solid rgb(244 221 160 / 70%);
  border-radius: 50%;
  background: rgb(55 3 13 / 58%);
  color: var(--gold-light);
  font-family: var(--font-main);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  box-shadow: inset 0 0 0 1px rgb(122 14 34 / 72%), 0 0 8px rgb(0 0 0 / 24%);
  -webkit-tap-highlight-color: transparent;
}

.hud-icon-button:active { transform: scale(.9); }
.hud-icon-button:focus-visible { outline: 2px solid #fff0b9; outline-offset: 2px; }
.pause-toggle { top: 50%; right: 15px; transform: translateY(-50%); }
.pause-toggle:active { transform: translateY(-50%) scale(.9); }
.pause-toggle::before {
  width: 11px;
  height: 14px;
  background: linear-gradient(90deg, currentColor 0 3px, transparent 3px 8px, currentColor 8px 11px);
  content: "";
}
.pause-toggle[aria-pressed="true"]::before {
  width: 0;
  height: 0;
  margin-left: 2px;
  border-top: 7px solid transparent;
  border-bottom: 7px solid transparent;
  border-left: 11px solid currentColor;
  background: none;
}
.hud-icon-button[aria-pressed="true"] { background: rgb(35 2 9 / 82%); color: rgb(244 221 160 / 72%); }
.pause-toggle[disabled] { cursor: default; opacity: .45; }

.game-shell.is-paused canvas,
.game-shell.is-paused .token-pickup-flight,
.game-shell.is-paused .currency-display,
.game-shell.is-paused .token-item {
  animation-play-state: paused !important;
}

.dowry-heading strong { color: var(--gold-light); font-family: var(--font-main); font-size: 15px; font-variant-numeric: tabular-nums; }

.dowry-track {
  height: 12px;
  overflow: hidden;
  border: 1px solid var(--gold-dark);
  border-radius: 999px;
  background: rgb(47 3 12 / 72%);
  box-shadow: inset 0 1px 3px rgb(0 0 0 / 35%);
}

.dowry-fill {
  width: 100%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #a97836, #f2d58e 62%, #fff0b9);
  box-shadow: 0 0 8px rgb(244 221 160 / 52%);
  transition: width 180ms ease, background 180ms ease;
}

.dowry-track.low .dowry-fill { background: linear-gradient(90deg, #9e1328, #e94a50); }

.time-display {
  min-width: 66px;
  text-align: right;
  font-size: 21px;
  font-variant-numeric: tabular-nums;
  color: var(--gold-light);
  font-family: var(--font-main);
  font-weight: 700;
  line-height: 1;
  letter-spacing: .04em;
}

.currency-display {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-width: 45px;
  color: var(--gold-light);
  font-family: var(--font-main);
  font-variant-numeric: tabular-nums;
}

.currency-display img { display: block; width: 23px; height: 23px; object-fit: contain; }

.currency-display strong { min-width: 12px; font-size: 15px; }
.currency-display.currency-arrived { animation: currency-arrived 360ms ease-out; }
.currency-display.currency-invincible {
  position: relative;
  z-index: 1;
  animation: currency-invincible-pulse 720ms ease-in-out infinite;
  filter:
    drop-shadow(0 0 5px rgb(218 255 199 / 95%))
    drop-shadow(0 0 12px rgb(153 237 121 / 82%));
}

.currency-display.currency-invincible::before {
  content: "";
  position: absolute;
  z-index: -1;
  inset: -9px -11px;
  border: 1px solid rgb(224 255 210 / 76%);
  border-radius: 999px;
  background: radial-gradient(circle, rgb(197 255 171 / 32%), transparent 72%);
  box-shadow: 0 0 15px rgb(168 244 136 / 68%);
}

@keyframes currency-arrived {
  0%, 100% { transform: scale(1); }
  45% { transform: scale(1.2); filter: drop-shadow(0 0 6px rgb(224 255 202 / 65%)); }
}

@keyframes currency-invincible-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.16); }
}

.game-stage {
  position: relative;
  min-height: 0;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  background: #fff;
}

.game-stage:focus { outline: none; }

#game-canvas { display: block; width: 100%; height: 100%; }

.damage-flash {
  position: absolute;
  z-index: 2;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  background: rgb(142 12 31 / 28%);
  transition: opacity 100ms ease;
}

.damage-flash.active { opacity: 1; }

.game-stage.impact-shake canvas { animation: impact-shake 180ms linear both; }

@keyframes impact-shake {
  0%, 100% { transform: translate(0); }
  25% { transform: translate(-3px, 1px); }
  50% { transform: translate(3px, -1px); }
  75% { transform: translate(-1px, 1px); }
}

.panel {
  position: absolute;
  z-index: 5;
  inset: 50% auto auto 50%;
  width: min(87%, 350px);
  padding: 28px 22px 24px;
  text-align: center;
  color: var(--gold-light);
  border: 1px solid var(--gold);
  outline: 1px solid rgb(83 6 20 / 94%);
  border-radius: 2px;
  background:
    repeating-linear-gradient(0deg, rgb(255 255 255 / 1.5%) 0 1px, transparent 1px 4px),
    radial-gradient(circle at 50% 10%, rgb(142 21 43 / 64%), transparent 58%),
    linear-gradient(145deg, rgb(112 10 29 / 98%), rgb(78 6 20 / 98%));
  box-shadow:
    inset 0 0 0 5px rgb(91 7 23 / 92%),
    inset 0 0 0 6px rgb(209 173 98 / 72%),
    0 18px 48px rgb(18 0 5 / 48%);
  transform: translate(-50%, -50%);
}

.panel::before,
.panel::after {
  position: absolute;
  width: auto;
  height: auto;
  color: var(--gold);
  font-family: var(--font-main);
  font-size: 25px;
  line-height: 1;
  text-shadow: 0 1px 0 var(--wine-dark);
  content: "❦";
}

.panel::before { top: 8px; left: 10px; transform: rotate(-42deg); }
.panel::after { right: 10px; bottom: 8px; transform: rotate(138deg); }
.panel[hidden] { display: none; }

.panel h1,
.panel h2 {
  margin: 6px 0 10px;
  color: var(--gold-light);
  font-family: var(--font-main);
  font-size: clamp(30px, 10vw, 42px);
  line-height: 1.08;
  letter-spacing: .08em;
  text-shadow: 0 2px 0 #5b0717, 0 0 12px rgb(244 221 160 / 18%);
}

.panel h1::before,
.panel h2::before {
  display: block;
  margin-bottom: 5px;
  color: var(--gold);
  font-family: var(--font-main);
  font-size: 18px;
  line-height: 1;
  letter-spacing: 0;
  content: "♕";
}

.panel h2 { font-size: 28px; }
.panel p { margin: 8px 0 15px; line-height: 1.55; }

.panel .eyebrow {
  margin: 0;
  color: var(--gold);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .18em;
}

.panel .eyebrow::after {
  display: block;
  width: 62%;
  height: 1px;
  margin: 9px auto 0;
  background: linear-gradient(90deg, transparent, var(--gold), transparent);
  content: "";
}

.start-panel { padding: 30px 22px 26px; }
.start-panel .eyebrow { font-size: 12px; letter-spacing: .07em; }
.start-panel h1 {
  margin: 10px 0 13px;
  font-size: clamp(32px, 9.4vw, 40px);
  letter-spacing: .12em;
}
.start-panel > p:not(.eyebrow) { margin: 0 auto 17px; max-width: 292px; font-size: 14px; line-height: 1.65; }
.start-panel .control-hint { margin: 0 0 19px; gap: 10px; }
.start-panel .control-hint span { padding: 11px 6px; font-size: 13px; line-height: 1.55; }
.start-panel .theme-credit {
  margin-top: 14px;
  color: rgb(244 221 160 / 62%);
  font-family: var(--font-main);
  font-size: 10px;
  letter-spacing: .055em;
  line-height: 1.4;
}

.control-hint {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 17px 0;
}

.control-hint span {
  padding: 9px 6px;
  border: 1px solid rgb(209 173 98 / 68%);
  background: rgb(67 3 15 / 42%);
  color: var(--gold-light);
  font-size: 12px;
  line-height: 1.45;
}

.primary-button {
  width: 100%;
  min-height: 48px;
  border: 1px solid #f6dda0;
  border-radius: 3px;
  background: linear-gradient(180deg, #f2d58d, #bd9148);
  color: #5a0717;
  font-weight: 700;
  letter-spacing: .12em;
  cursor: pointer;
  box-shadow: 0 4px 0 #6a3d19, inset 0 1px 0 rgb(255 255 255 / 55%);
}

.primary-button:active { transform: translateY(3px); box-shadow: 0 1px 0 #6a3d19; }
.panel small { display: block; margin-top: 13px; color: rgb(244 221 160 / 68%); }

.lane-feedback {
  position: absolute;
  z-index: 4;
  left: 50%;
  bottom: 17px;
  max-width: 88%;
  padding: 7px 13px;
  border: 1px solid rgb(209 173 98 / 76%);
  border-radius: 999px;
  background: rgb(85 6 22 / 92%);
  color: var(--gold-light);
  font-size: 12px;
  opacity: 0;
  pointer-events: none;
  transform: translateX(-50%) translateY(5px);
  transition: opacity 140ms ease, transform 140ms ease;
  white-space: nowrap;
}

.lane-feedback.visible { opacity: 1; transform: translateX(-50%) translateY(0); }

.token-bar {
  z-index: 4;
  padding: 7px 9px max(8px, env(safe-area-inset-bottom));
  color: var(--gold-light);
  background:
    repeating-linear-gradient(0deg, rgb(255 255 255 / 1.5%) 0 1px, transparent 1px 4px),
    linear-gradient(180deg, #650c1d, #420612);
  border-top: 3px double var(--gold);
}

.token-list { display: grid; grid-template-columns: repeat(6, 1fr); gap: 3px; }
.token-item { min-width: 0; text-align: center; }
.token-icon { display: block; width: 25px; height: 25px; margin: -2px auto 0; object-fit: contain; }
.token-name { display: block; overflow: hidden; color: var(--gold); font-size: 8px; letter-spacing: .04em; opacity: .88; text-overflow: ellipsis; white-space: nowrap; }
.token-count { display: block; color: var(--gold-light); font-family: var(--font-main); font-size: 14px; line-height: 1.1; font-variant-numeric: tabular-nums; }

.token-pickup-flight {
  position: fixed;
  z-index: 30;
  width: 52px;
  height: 52px;
  pointer-events: none;
  animation: token-fly-to-bar 820ms cubic-bezier(.22, .78, .25, 1) both;
}

.token-pickup-flight::before,
.token-pickup-flight::after {
  position: absolute;
  color: #fff7bf;
  font-size: 14px;
  line-height: 1;
  text-shadow: 0 0 5px #dcae34;
  content: "✦";
}

.token-pickup-flight::before { top: -8px; right: -7px; }
.token-pickup-flight::after { bottom: -7px; left: -6px; font-size: 9px; }
.token-pickup-flight img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 2px 2px rgb(72 38 51 / 28%)) drop-shadow(0 0 8px #ffe99b);
}

@keyframes token-fly-to-bar {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(.2) rotate(-12deg);
  }
  20% {
    opacity: 1;
    transform: translate(-50%, calc(-50% - 34px)) scale(1.28) rotate(6deg);
  }
  36% {
    opacity: 1;
    transform: translate(-50%, calc(-50% - 24px)) scale(1) rotate(-2deg);
  }
  46% {
    opacity: 1;
    transform: translate(-50%, calc(-50% - 28px)) scale(1.05) rotate(0);
  }
  100% {
    opacity: .18;
    transform: translate(calc(-50% + var(--fly-x)), calc(-50% + var(--fly-y))) scale(.32);
  }
}

.token-item.token-arrived { animation: token-arrived 400ms ease-out; }

@keyframes token-arrived {
  0%, 100% { transform: scale(1); filter: none; }
  42% { transform: scale(1.2); filter: drop-shadow(0 0 6px #ffe89a); }
}

.result-subtitle { margin: -1px 0 11px !important; color: rgb(244 221 160 / 78%); font-size: 13px; }

.result-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
  margin: 13px 0 10px;
}

.result-grid div { padding: 9px; border: 1px solid rgb(209 173 98 / 62%); background: rgb(64 3 14 / 42%); }
.result-grid span, .result-grid strong { display: block; }
.result-grid span { color: rgb(244 221 160 / 68%); font-size: 10px; }
.result-grid strong { margin-top: 2px; color: var(--gold-light); font-family: var(--font-main); font-size: 21px; font-variant-numeric: tabular-nums; }
.favorite-line { margin: 7px 0 !important; font-size: 13px; }

.result-token-list {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 5px;
  margin-bottom: 14px;
  font-size: 10px;
}

.result-token-list span {
  padding: 4px 7px;
  border: 1px solid rgb(209 173 98 / 62%);
  border-radius: 999px;
  background: rgb(66 3 15 / 46%);
  color: var(--gold-light);
}

@media (max-height: 650px) {
  .hud { min-height: 58px; padding-top: 8px; padding-bottom: 8px; }
  .panel { padding: 16px 18px; }
  .control-hint { margin: 10px 0; }
  .panel p { margin-bottom: 9px; }
  .panel h1 { font-size: 31px; }
  .token-icon { width: 21px; height: 21px; }
}

@media (max-width: 430px) and (orientation: portrait) {
  .game-shell {
    width: 100vw;
    height: 100dvh;
    max-height: none;
    aspect-ratio: auto;
  }
}
