:root {
  color-scheme: dark;
  --ink: #f8f7ed;
  --muted: #a8b0c3;
  --panel: rgba(13, 18, 32, .92);
  --line: rgba(255, 255, 255, .14);
  --lime: #b9f65b;
  --cyan: #5ce1e6;
  --pink: #ff5d8f;
  --orange: #ff9e45;
}

* { box-sizing: border-box; }

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

body {
  color: var(--ink);
  font-family: Inter, ui-rounded, "Arial Rounded MT Bold", system-ui, sans-serif;
  overscroll-behavior: none;
  touch-action: none;
  user-select: none;
}

button, input { font: inherit; }
button { color: inherit; }

.game-shell, #game { position: fixed; inset: 0; width: 100%; height: 100%; }
#game { display: block; background: #101626; }

.topbar {
  position: fixed;
  z-index: 10;
  inset: 0 0 auto;
  min-height: 66px;
  padding: 12px clamp(12px, 3vw, 28px);
  display: flex;
  align-items: center;
  gap: 18px;
  background: linear-gradient(#0d1220 38%, rgba(13,18,32,.86) 76%, transparent);
  pointer-events: none;
}

.brand { color: inherit; text-decoration: none; display: flex; align-items: center; gap: 9px; font-weight: 950; letter-spacing: .09em; pointer-events: auto; }
.brand-mark { width: 30px; height: 30px; display: grid; place-items: center; border: 2px solid var(--lime); border-radius: 9px; color: #101626; background: var(--lime); transform: rotate(-4deg); }

.run-stats { margin: 0 auto; display: flex; align-items: center; gap: clamp(15px, 4vw, 44px); text-align: center; }
.run-stats span { display: grid; min-width: 48px; }
.run-stats small, .carry-pill small, .equipped-pill small { color: var(--muted); font-size: 9px; font-weight: 900; letter-spacing: .16em; }
.run-stats b { font-size: 15px; letter-spacing: .04em; }

.round-button { width: 38px; height: 38px; border: 1px solid var(--line); border-radius: 50%; background: rgba(13,18,32,.78); cursor: pointer; pointer-events: auto; font-weight: 900; }

.safe-panel {
  position: fixed;
  z-index: 12;
  left: clamp(12px, 3vw, 28px);
  bottom: clamp(12px, 3vw, 24px);
  width: min(350px, calc(100vw - 24px));
  padding: 15px;
  border: 1px solid rgba(185,246,91,.25);
  border-radius: 18px;
  background: var(--panel);
  box-shadow: 0 16px 50px rgba(0,0,0,.32);
  backdrop-filter: blur(12px);
  transition: opacity .2s, transform .2s;
}
.safe-panel.away { opacity: 0; transform: translateY(18px); pointer-events: none; }
.safe-title, .inventory-heading, .speed-control label { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.safe-title span, .inventory-heading span, .speed-control label span { font-size: 11px; font-weight: 950; letter-spacing: .14em; }
.safe-title small, .inventory-heading small { color: var(--muted); font-size: 10px; }

.train-button {
  width: 100%; margin: 12px 0; padding: 13px 15px; display: flex; justify-content: space-between;
  border: 0; border-radius: 12px; background: var(--lime); color: #14200b; font-weight: 950; letter-spacing: .06em; cursor: pointer;
  box-shadow: 0 5px 0 #668e28; transition: transform .08s, box-shadow .08s;
}
.train-button:active { transform: translateY(4px); box-shadow: 0 1px 0 #668e28; }
.train-button.training { animation: trainPulse .22s ease; }
@keyframes trainPulse { 50% { filter: brightness(1.25); } }

.speed-control { padding-bottom: 12px; border-bottom: 1px solid var(--line); }
.speed-control label b { color: var(--cyan); font-size: 12px; }
input[type="range"] { width: 100%; margin: 10px 0 0; accent-color: var(--cyan); cursor: pointer; }
.inventory-block { padding-top: 11px; }
.inventory { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; margin-top: 9px; }
.item-button { position: relative; min-width: 0; height: 43px; padding: 0; border: 1px solid var(--line); border-radius: 10px; background: rgba(255,255,255,.045); cursor: pointer; font-size: 20px; }
.item-button span { position: absolute; right: 4px; bottom: 2px; padding: 1px 3px; border-radius: 5px; background: #090d17; color: var(--ink); font-size: 9px; font-weight: 900; }
.item-button.selected { border-color: var(--lime); background: rgba(185,246,91,.14); box-shadow: inset 0 0 0 1px var(--lime); }
.item-button:disabled { opacity: .34; cursor: default; }

.carry-pill, .equipped-pill {
  position: fixed; z-index: 11; display: flex; align-items: center; gap: 12px; padding: 9px 12px; border: 1px solid var(--line); border-radius: 13px; background: var(--panel); backdrop-filter: blur(10px);
}
.carry-pill { top: 76px; left: 50%; transform: translateX(-50%); text-align: center; }
.carry-pill b { display: block; font-size: 13px; }
.equipped-pill { right: clamp(12px, 3vw, 28px); bottom: clamp(12px, 3vw, 24px); }
.equipped-pill div { display: grid; min-width: 74px; }
.equipped-pill b { font-size: 12px; }
.equipped-pill button { min-height: 42px; padding: 0 15px; border: 0; border-radius: 10px; background: var(--cyan); color: #0c1c23; font-weight: 950; cursor: pointer; }
.equipped-pill button:disabled { opacity: .35; }
.equipped-pill button span { font-size: 10px; }

.toast { position: fixed; z-index: 15; top: 92px; left: 50%; width: max-content; max-width: 88vw; padding: 10px 16px; border-radius: 999px; background: #f8f7ed; color: #121827; font-size: 12px; font-weight: 950; letter-spacing: .08em; transform: translate(-50%, -15px); opacity: 0; transition: .2s; pointer-events: none; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.joystick, .dash-button { display: none; position: fixed; z-index: 12; }

.overlay { position: fixed; z-index: 30; inset: 0; display: grid; place-items: center; padding: 20px; background: rgba(7,10,18,.78); backdrop-filter: blur(12px); overflow-y: auto; }
.overlay[hidden] { display: none; }
.intro-card, .complete-card, .menu-card { position: relative; width: min(460px, 100%); padding: clamp(25px, 6vw, 42px); overflow: hidden; border: 1px solid rgba(255,255,255,.16); border-radius: 28px; background: #151d31; box-shadow: 0 25px 80px rgba(0,0,0,.45); text-align: center; }
.intro-card h1 { position: relative; margin: 8px 0 14px; font-size: clamp(56px, 14vw, 92px); line-height: .72; letter-spacing: -.07em; text-align: left; }
.intro-card h1 span { color: var(--lime); }
.intro-card > p:not(.eyebrow):not(.controls-note) { color: #c9ceda; line-height: 1.55; text-align: left; }
.eyebrow { margin: 0 0 10px; color: var(--cyan); font-size: 11px; font-weight: 950; letter-spacing: .22em; }
.hero-core { position: absolute; width: 175px; height: 175px; top: 35px; right: -20px; opacity: .94; filter: drop-shadow(0 0 24px rgba(92,225,230,.35)); animation: float 2.8s ease-in-out infinite; }
@keyframes float { 50% { transform: translateY(-8px) rotate(4deg); } }
.primary-button, .secondary-button, .danger-button { width: 100%; min-height: 50px; margin-top: 10px; border-radius: 13px; font-weight: 950; letter-spacing: .07em; cursor: pointer; }
.primary-button { display: flex; align-items: center; justify-content: space-between; padding: 0 18px; border: 0; background: var(--lime); color: #14200b; }
.secondary-button, .danger-button { border: 1px solid var(--line); background: rgba(255,255,255,.04); }
.danger-button { color: #ff91a9; }
.controls-note { color: var(--muted); font-size: 9px; line-height: 1.6; letter-spacing: .08em; }
kbd { padding: 2px 5px; border: 1px solid var(--line); border-radius: 4px; background: #0b101d; font: inherit; }
#seed-label { color: #778197; font-size: 9px; letter-spacing: .14em; }
.compact { background: rgba(7,10,18,.65); }
.menu-card { max-width: 360px; }
.menu-card h2 { margin: 4px 0 18px; }
.complete-card { max-width: 500px; }
.complete-card h2 { margin: 5px 0 12px; font-size: clamp(28px, 8vw, 46px); line-height: .95; }
.complete-core { width: 130px; filter: drop-shadow(0 0 28px rgba(92,225,230,.55)); }
.complete-card > p:last-child { color: var(--muted); }
.result-row { display: flex; justify-content: center; gap: 30px; margin: 20px 0 8px; color: var(--muted); font-size: 10px; letter-spacing: .12em; }
.result-row b { display: block; margin-top: 4px; color: var(--ink); font-size: 16px; }

@media (pointer: coarse), (max-width: 700px) {
  .brand > span:last-child { display: none; }
  .topbar { gap: 8px; padding: 9px 10px; }
  .run-stats { gap: 12px; }
  .run-stats b { font-size: 13px; }
  .safe-panel { bottom: 10px; left: 10px; width: calc(100vw - 20px); padding: 11px; }
  .safe-title small { display: none; }
  .train-button { margin: 9px 0; padding: 11px 13px; }
  .item-button { height: 40px; }
  .equipped-pill { right: 12px; bottom: 18px; }
  .equipped-pill div { display: none; }
  .equipped-pill button { width: 70px; height: 58px; border-radius: 18px; }
  .joystick { display: block; left: 22px; bottom: 22px; width: 112px; height: 112px; border: 2px solid rgba(255,255,255,.24); border-radius: 50%; background: rgba(13,18,32,.42); backdrop-filter: blur(4px); }
  .joystick::after { content: "MOVE"; position: absolute; inset: 0; display: grid; place-items: center; color: rgba(255,255,255,.3); font-size: 9px; font-weight: 900; letter-spacing: .15em; }
  #joystick-knob { position: absolute; z-index: 2; left: 34px; top: 34px; width: 40px; height: 40px; border-radius: 50%; background: rgba(248,247,237,.9); box-shadow: 0 5px 18px rgba(0,0,0,.3); }
  .dash-button { right: 94px; bottom: 25px; width: 64px; height: 64px; border: 0; border-radius: 50%; background: var(--pink); font-size: 11px; font-weight: 950; }
  .safe-panel:not(.away) ~ .equipped-pill, .safe-panel:not(.away) ~ .joystick, .safe-panel:not(.away) ~ .dash-button { opacity: 0; pointer-events: none; }
}

@media (max-height: 650px) and (pointer: coarse) {
  .safe-panel { transform: scale(.88); transform-origin: bottom left; width: calc(114vw - 22px); }
  .safe-panel.away { transform: translateY(18px) scale(.88); }
}

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