:root {
  color-scheme: dark;
  --ink: #fff4df;
  --muted: rgba(255, 229, 198, 0.65);
  --ember: #ff9d4d;
  --panel: rgba(29, 18, 11, 0.7);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #15100b;
  color: var(--ink);
  overscroll-behavior: none;
}

body {
  position: fixed;
  inset: 0;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

button { font: inherit; }

#game-shell, #game-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

#game-shell {
  isolation: isolate;
  background:
    radial-gradient(circle at 70% 22%, rgba(223, 111, 43, 0.17), transparent 34%),
    linear-gradient(155deg, #21160e 0%, #0e0d0c 72%);
}

#game-canvas {
  display: block;
  z-index: 0;
  touch-action: none;
  cursor: crosshair;
}

#game-shell::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background:
    linear-gradient(to bottom, rgba(7, 5, 3, 0.45), transparent 24%, transparent 72%, rgba(7, 5, 3, 0.58)),
    radial-gradient(circle at center, transparent 36%, rgba(4, 3, 2, 0.34) 100%);
}

.brand {
  position: absolute;
  z-index: 3;
  top: max(22px, env(safe-area-inset-top));
  left: max(22px, env(safe-area-inset-left));
  pointer-events: none;
  text-shadow: 0 2px 18px rgba(0, 0, 0, 0.72);
}

.brand__eyebrow {
  display: block;
  margin-bottom: 5px;
  color: var(--ember);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.32em;
}

.brand h1 {
  margin: 0;
  font-family: "Songti SC", "STSong", serif;
  font-size: clamp(25px, 5vw, 42px);
  font-weight: 800;
  letter-spacing: 0.06em;
}

.brand p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.16em;
}

.stats {
  position: absolute;
  z-index: 4;
  left: max(18px, env(safe-area-inset-left));
  bottom: max(25px, calc(env(safe-area-inset-bottom) + 14px));
  display: flex;
  gap: 7px;
  padding: 7px;
  border: 1px solid rgba(255, 207, 151, 0.14);
  border-radius: 16px;
  background: var(--panel);
  box-shadow: 0 15px 45px rgba(0, 0, 0, 0.27);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  pointer-events: none;
}

.stat {
  min-width: 58px;
  padding: 5px 9px;
  text-align: center;
  border-right: 1px solid rgba(255, 255, 255, 0.08);
}

.stat:last-child { border-right: 0; }
.stat strong { display: block; font-size: 17px; font-variant-numeric: tabular-nums; }
.stat span { display: block; margin-top: 2px; color: var(--muted); font-size: 10px; }

.combo {
  position: absolute;
  z-index: 4;
  top: 31%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.7);
  color: #ffd28f;
  font-family: Georgia, serif;
  font-size: clamp(36px, 10vw, 72px);
  font-style: italic;
  font-weight: 900;
  opacity: 0;
  text-shadow: 0 4px 0 #7d3516, 0 10px 30px rgba(255, 108, 36, 0.55);
  transition: opacity 150ms ease, transform 180ms cubic-bezier(.2, .9, .3, 1.35);
  pointer-events: none;
}

.combo.is-active { opacity: 1; transform: translate(-50%, -50%) scale(1); }

.interaction-hint {
  position: absolute;
  z-index: 3;
  left: 50%;
  bottom: max(86px, calc(env(safe-area-inset-bottom) + 74px));
  transform: translateX(-50%);
  width: max-content;
  max-width: calc(100vw - 40px);
  margin: 0;
  padding: 9px 14px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 999px;
  background: rgba(8, 7, 6, 0.45);
  color: rgba(255, 239, 216, 0.72);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-align: center;
  backdrop-filter: blur(8px);
  pointer-events: none;
  transition: color 150ms ease, border-color 150ms ease;
}

.interaction-hint.is-alert { color: #ffd08f; border-color: rgba(255, 157, 77, 0.42); }

.state-indicator {
  position: absolute;
  z-index: 3;
  right: max(18px, env(safe-area-inset-right));
  bottom: max(88px, calc(env(safe-area-inset-bottom) + 76px));
  display: flex;
  align-items: center;
  gap: 8px;
  color: rgba(255, 235, 208, 0.62);
  font-size: 10px;
  letter-spacing: 0.1em;
  pointer-events: none;
}

.state-indicator i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #75d39b;
  box-shadow: 0 0 12px rgba(117, 211, 155, 0.6);
}

.state-indicator__busy { display: none; }
body:not([data-game-state="idle"]) .state-indicator__idle { display: none; }
body:not([data-game-state="idle"]) .state-indicator__busy { display: inline; }
body:not([data-game-state="idle"]) .state-indicator i { background: var(--ember); box-shadow: 0 0 12px rgba(255, 157, 77, 0.7); }

.loading {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 9px;
  background: radial-gradient(circle at center, #302015, #100c09 68%);
  transition: opacity 500ms ease, visibility 500ms ease;
}

.loading__mark { font-size: 42px; animation: loading-chop 800ms ease-in-out infinite alternate; }
.loading strong { font-family: "Songti SC", serif; font-size: 20px; letter-spacing: 0.08em; }
.loading span { color: var(--muted); font-size: 11px; }
.is-ready .loading { opacity: 0; visibility: hidden; }

@keyframes loading-chop {
  from { transform: translateY(-4px) rotate(-18deg); }
  to { transform: translateY(5px) rotate(12deg); }
}

.game-error {
  position: absolute;
  z-index: 30;
  top: 50%;
  left: 50%;
  width: min(340px, calc(100vw - 36px));
  padding: 24px;
  transform: translate(-50%, -50%);
  border: 1px solid rgba(255, 172, 96, 0.3);
  border-radius: 20px;
  background: rgba(29, 18, 11, 0.94);
  text-align: center;
}

.game-error h2 { margin: 0 0 8px; }
.game-error p { color: var(--muted); }
.game-error button { padding: 10px 18px; border: 0; border-radius: 10px; background: var(--ember); color: #231208; font-weight: 800; }

noscript { position: fixed; z-index: 50; inset: 0; display: grid; place-content: center; background: #15100b; }

@media (max-width: 620px) {
  .brand p { display: none; }
  .brand { top: max(16px, env(safe-area-inset-top)); left: max(16px, env(safe-area-inset-left)); }
  .stats { left: max(10px, env(safe-area-inset-left)); bottom: max(12px, env(safe-area-inset-bottom)); }
  .stat { min-width: 49px; padding-inline: 5px; }
  .state-indicator { right: max(12px, env(safe-area-inset-right)); bottom: max(88px, calc(env(safe-area-inset-bottom) + 76px)); }
  .interaction-hint { bottom: max(78px, calc(env(safe-area-inset-bottom) + 66px)); }
}

@media (orientation: landscape) and (max-height: 520px) {
  .brand h1 { font-size: 24px; }
  .brand p { display: none; }
  .interaction-hint { bottom: 18px; }
  .stats { bottom: 14px; }
  .state-indicator { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}
