:root {
  color-scheme: dark;
  --ink: #f8f4e8;
  --muted: #b8c2b7;
  --night: #151414;
  --panel: rgba(24, 23, 22, 0.88);
  --panel-strong: rgba(36, 34, 31, 0.94);
  --line: rgba(248, 244, 232, 0.18);
  --red: #ff5a5f;
  --mint: #45d6a3;
  --gold: #ffd166;
  --blue: #51a3ff;
  --violet: #b27cff;
  --wood: #9b5c38;
  --shadow: rgba(0, 0, 0, 0.42);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--night);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

button {
  font: inherit;
}

#app {
  position: fixed;
  inset: 0;
  min-width: 320px;
  min-height: 100dvh;
  background:
    radial-gradient(circle at 15% 18%, rgba(255, 209, 102, 0.16), transparent 28%),
    radial-gradient(circle at 82% 16%, rgba(69, 214, 163, 0.12), transparent 24%),
    linear-gradient(135deg, #171514, #252019 54%, #1a1716);
}

#gameCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

.hidden {
  display: none !important;
}

.hud {
  position: absolute;
  z-index: 4;
  top: max(14px, env(safe-area-inset-top));
  left: max(14px, env(safe-area-inset-left));
  right: max(14px, env(safe-area-inset-right));
  display: grid;
  grid-template-columns: minmax(180px, 0.8fr) minmax(300px, 1.2fr) minmax(180px, 0.8fr);
  align-items: start;
  gap: 12px;
  pointer-events: none;
}

.hud-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-width: 0;
}

.hud-group.right {
  justify-content: flex-end;
}

.hud-pill,
.icon-button {
  min-height: 40px;
  border: 1px solid var(--line);
  background: rgba(16, 15, 14, 0.68);
  color: var(--ink);
  box-shadow: 0 12px 30px var(--shadow);
  backdrop-filter: blur(12px);
}

.hud-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: 100%;
  padding: 8px 12px;
  border-radius: 8px;
  font-weight: 800;
  font-size: 14px;
  white-space: nowrap;
}

.level-pill {
  max-width: min(44vw, 340px);
}

.level-pill span:last-child {
  overflow: hidden;
  text-overflow: ellipsis;
}

.score-pill {
  color: var(--gold);
}

.hud-icon {
  color: var(--mint);
}

.hearts {
  color: var(--red);
  min-width: 122px;
  justify-content: center;
}

.icon-button {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  padding: 0;
  border-radius: 8px;
  cursor: pointer;
  pointer-events: auto;
}

.icon-button:hover,
.icon-button:focus-visible,
.primary-button:hover,
.secondary-button:hover,
.mode-card:hover,
.primary-button:focus-visible,
.secondary-button:focus-visible,
.mode-card:focus-visible,
.touch-button:focus-visible {
  outline: 2px solid rgba(255, 209, 102, 0.8);
  outline-offset: 2px;
}

.meter-stack {
  width: 100%;
  max-width: 560px;
  justify-self: center;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(16, 15, 14, 0.68);
  box-shadow: 0 12px 30px var(--shadow);
  backdrop-filter: blur(12px);
}

.meter-row {
  display: grid;
  grid-template-columns: 44px 1fr 48px;
  align-items: center;
  gap: 8px;
  min-width: 0;
  font-size: 12px;
  font-weight: 800;
}

.meter-row + .meter-row {
  margin-top: 8px;
}

.meter {
  position: relative;
  height: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(248, 244, 232, 0.14);
}

.meter i {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--mint), var(--gold), var(--red));
  transition: width 120ms linear;
}

.teeth-meter i {
  background: linear-gradient(90deg, var(--blue), var(--mint));
}

.dash-meter i {
  background: linear-gradient(90deg, var(--blue), var(--mint), var(--gold));
}

.combo-badge,
.toast,
.guide-hint {
  position: absolute;
  z-index: 6;
  left: 50%;
  transform: translateX(-50%);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(22, 20, 18, 0.78);
  box-shadow: 0 16px 38px var(--shadow);
  backdrop-filter: blur(12px);
  pointer-events: none;
}

.combo-badge {
  top: 104px;
  padding: 9px 14px;
  color: var(--gold);
  font-size: 20px;
  font-weight: 950;
}

.toast {
  bottom: 154px;
  max-width: min(560px, calc(100vw - 32px));
  padding: 12px 16px;
  font-weight: 850;
  text-align: center;
}

.guide-hint {
  top: 88px;
  width: min(520px, calc(100vw - 32px));
  padding: 12px 14px;
  color: var(--ink);
  font-size: 14px;
  font-weight: 850;
  line-height: 1.45;
}

.guide-hint strong {
  color: var(--gold);
}

.overlay {
  position: absolute;
  z-index: 8;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(rgba(18, 16, 14, 0.22), rgba(18, 16, 14, 0.52)),
    radial-gradient(circle at center, rgba(255, 209, 102, 0.08), transparent 42%);
  backdrop-filter: blur(3px);
}

.panel {
  width: min(720px, calc(100vw - 32px));
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 28px 80px rgba(0, 0, 0, 0.5);
}

.menu-panel {
  max-height: calc(100dvh - 32px);
  overflow: auto;
  padding: clamp(22px, 5vw, 42px);
}

.brand-art {
  float: right;
  width: min(286px, 42vw);
  margin: -10px -6px 10px 22px;
}

.brand-art img {
  display: block;
  width: 100%;
  height: auto;
}

.result-panel,
.pause-panel {
  padding: clamp(20px, 4vw, 34px);
  text-align: center;
}

.eyebrow {
  margin: 0 0 10px;
  color: var(--mint);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  line-height: 1.02;
  letter-spacing: 0;
}

h1 {
  max-width: 11ch;
  font-size: clamp(42px, 9vw, 82px);
  text-wrap: balance;
}

h2 {
  font-size: clamp(30px, 5vw, 52px);
}

.story {
  margin: 16px 0 0;
  max-width: 64ch;
  color: rgba(248, 244, 232, 0.82);
  line-height: 1.7;
  font-size: clamp(14px, 1.8vw, 17px);
}

.mission-grid,
.result-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin: 22px 0;
}

.mission-grid div,
.result-stats div {
  min-width: 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(248, 244, 232, 0.08);
}

.mission-grid strong,
.mission-grid span,
.result-stats span,
.result-stats strong {
  display: block;
}

.mission-grid strong,
.result-stats strong {
  font-size: 18px;
}

.mission-grid span,
.result-stats span {
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
}

.result-stats strong {
  color: var(--gold);
  font-size: 26px;
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 20px;
}

.result-panel .button-row,
.pause-panel .button-row {
  justify-content: center;
}

.primary-button,
.secondary-button {
  min-height: 48px;
  border-radius: 8px;
  border: 1px solid transparent;
  padding: 0 18px;
  color: #151414;
  font-weight: 900;
  cursor: pointer;
}

.primary-button {
  background: linear-gradient(135deg, var(--gold), #ff8a5b);
}

.secondary-button {
  background: rgba(248, 244, 232, 0.12);
  border-color: var(--line);
  color: var(--ink);
}

.secondary-button:disabled {
  opacity: 0.38;
  cursor: not-allowed;
}

.primary-button span,
.secondary-button span {
  margin-right: 8px;
}

.mode-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  clear: both;
  margin-top: 22px;
}

.mode-card {
  min-height: 98px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: rgba(248, 244, 232, 0.1);
  color: var(--ink);
  text-align: left;
  cursor: pointer;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.22);
}

.mode-card.primary-mode {
  background: linear-gradient(135deg, var(--gold), #ff8a5b);
  color: #151414;
}

.mode-card > span,
.mode-card strong,
.mode-card small {
  display: block;
}

.mode-card > span {
  margin-bottom: 10px;
  font-size: 17px;
  font-weight: 950;
}

.mode-card strong {
  font-size: 17px;
  line-height: 1.2;
}

.mode-card small {
  margin-top: 6px;
  color: currentColor;
  opacity: 0.76;
  font-size: 12px;
  line-height: 1.35;
}


.level-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 18px;
}

.level-strip button {
  width: 44px;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(248, 244, 232, 0.1);
  color: var(--ink);
  font-weight: 900;
  cursor: pointer;
}

.level-strip button.unlocked {
  border-color: rgba(69, 214, 163, 0.75);
}

.level-strip button:disabled {
  opacity: 0.34;
  cursor: not-allowed;
}

.control-hint {
  margin: 16px 0 0;
  color: rgba(248, 244, 232, 0.66);
  font-size: 13px;
}

.touch-controls {
  position: absolute;
  z-index: 5;
  inset: auto 0 max(18px, env(safe-area-inset-bottom)) 0;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  padding: 0 max(18px, env(safe-area-inset-right)) 0 max(18px, env(safe-area-inset-left));
  pointer-events: none;
}

.joystick {
  width: 116px;
  height: 116px;
  position: relative;
  border: 1px solid rgba(248, 244, 232, 0.2);
  border-radius: 50%;
  background: rgba(16, 15, 14, 0.38);
  box-shadow: 0 12px 30px var(--shadow);
  backdrop-filter: blur(10px);
  pointer-events: auto;
  touch-action: none;
}

.joystick i {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 46px;
  height: 46px;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: linear-gradient(135deg, var(--mint), var(--blue));
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.32);
}

.touch-actions {
  display: flex;
  gap: 12px;
  align-items: flex-end;
  pointer-events: auto;
}

.touch-button {
  position: relative;
  isolation: isolate;
  width: 72px;
  height: 72px;
  border: 1px solid var(--line);
  border-radius: 50%;
  color: #151414;
  font-weight: 950;
  box-shadow: 0 14px 30px var(--shadow);
}

.touch-button.bite {
  background: linear-gradient(135deg, var(--gold), var(--red));
}

.touch-button.dash {
  --charge: 100%;
  width: 58px;
  height: 58px;
  overflow: hidden;
  background: conic-gradient(var(--blue) var(--charge), rgba(248, 244, 232, 0.18) 0);
}

.touch-button.dash::before {
  content: "";
  position: absolute;
  inset: 5px;
  z-index: -1;
  border-radius: inherit;
  background: linear-gradient(135deg, var(--mint), var(--blue));
}

.touch-button.dash.is-charging {
  color: rgba(248, 244, 232, 0.78);
  filter: saturate(0.75);
}

.touch-button.dash.is-ready {
  box-shadow: 0 0 0 3px rgba(81, 163, 255, 0.22), 0 14px 30px var(--shadow);
}

.touch-button > span {
  position: relative;
  z-index: 1;
}

@media (hover: hover) and (pointer: fine) {
  .touch-controls {
    display: none;
  }
}

@media (max-width: 760px) {
  .hud {
    grid-template-columns: 1fr auto;
    gap: 8px;
  }

  .hud-group:first-child {
    grid-column: 1 / 2;
  }

  .hud-group.right {
    grid-column: 2 / 3;
  }

  .meter-stack {
    grid-column: 1 / -1;
    grid-row: 2;
    max-width: none;
  }

  .touch-controls {
    display: flex;
  }

  .hud-pill {
    min-height: 36px;
    padding: 7px 9px;
    font-size: 12px;
  }

  .score-pill {
    display: none;
  }

  .icon-button {
    width: 38px;
    height: 38px;
  }

  .result-stats {
    grid-template-columns: 1fr;
  }

  .mission-grid,
  .mode-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .mission-grid div {
    padding: 10px;
  }

  .mission-grid strong {
    font-size: 15px;
  }

  .mission-grid span,
  .mode-card small {
    font-size: 11px;
  }

  .mode-card {
    min-height: 84px;
    padding: 10px;
  }

  .mode-card strong {
    font-size: 14px;
  }

  .menu-panel {
    max-height: calc(100dvh - 32px);
    overflow: auto;
  }

  .brand-art {
    float: none;
    width: min(320px, 100%);
    margin: -6px 0 12px;
  }

  .primary-button,
  .secondary-button {
    flex: 1 1 150px;
  }

  .toast {
    bottom: 170px;
  }

  .guide-hint {
    top: 138px;
    font-size: 13px;
  }
}

@media (max-width: 420px) {
  #app {
    min-height: 100dvh;
  }

  .overlay {
    padding: 16px;
  }

  .control-hint {
    font-size: 12px;
  }

  .joystick {
    width: 98px;
    height: 98px;
  }

  .touch-button {
    width: 64px;
    height: 64px;
  }

  .touch-button.dash {
    width: 52px;
    height: 52px;
  }
}

@media (max-height: 520px) and (orientation: landscape) {
  .hud {
    grid-template-columns: minmax(150px, 0.8fr) minmax(260px, 1fr) minmax(160px, 0.8fr);
    top: 8px;
    left: 10px;
    right: 10px;
    gap: 8px;
  }

  .hud-pill,
  .icon-button {
    min-height: 34px;
  }

  .hud-pill {
    padding: 6px 8px;
    font-size: 12px;
  }

  .icon-button {
    width: 36px;
    height: 36px;
  }

  .meter-stack {
    padding: 7px 9px;
  }

  .meter-row {
    grid-template-columns: 38px 1fr 44px;
    font-size: 11px;
  }

  .overlay {
    place-items: start center;
    padding: 10px;
  }

  .panel {
    width: min(900px, calc(100vw - 20px));
  }

  .result-panel,
  .pause-panel {
    max-height: calc(100dvh - 20px);
    overflow: auto;
    padding: 16px;
  }

  .menu-panel {
    max-height: calc(100dvh - 20px);
    padding: 16px;
  }

  .brand-art {
    float: right;
    width: min(190px, 28vw);
    margin: -8px 0 4px 16px;
  }

  h1 {
    font-size: clamp(34px, 7vw, 54px);
  }

  h2 {
    font-size: clamp(28px, 5vw, 42px);
  }

  .story {
    margin-top: 10px;
    max-width: 56ch;
    line-height: 1.42;
    font-size: 13px;
  }

  .mission-grid {
    clear: both;
    margin: 10px 0;
  }

  .result-stats {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    margin: 12px 0;
  }

  .mission-grid div,
  .result-stats div {
    padding: 10px;
  }

  .mission-grid span {
    margin-top: 4px;
  }

  .mode-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    margin-top: 12px;
  }

  .mode-card {
    min-height: 70px;
    padding: 10px;
  }

  .mode-card > span {
    margin-bottom: 5px;
  }

  .level-strip {
    margin-top: 10px;
  }

  .level-strip button {
    width: 38px;
    height: 34px;
  }

  .control-hint {
    margin-top: 10px;
  }

  .joystick {
    width: 82px;
    height: 82px;
  }

  .touch-controls {
    display: flex;
    bottom: 10px;
    padding-inline: 12px;
  }

  .touch-button {
    width: 58px;
    height: 58px;
  }

  .touch-button.dash {
    width: 48px;
    height: 48px;
  }

  .toast {
    bottom: 92px;
  }

  .guide-hint {
    top: auto;
    bottom: 22px;
    width: min(430px, calc(100vw - 280px));
    padding: 9px 12px;
    font-size: 12px;
  }
}
