:root {
  --bg: #0c0d12;
  --bg-2: #14161d;
  --card: #1a1c25;
  --raised: #22242e;
  --line: rgba(243, 234, 216, 0.08);
  --text: #f3ead8;
  --muted: #9a917f;
  --gold: #e0b15b;
  --gold-2: #c4892a;
  --teal: #3ec6c6;
  --teal-dim: #1d6d6d;
  --danger: #c4453a;
  --ok: #7dbe6a;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --pop: cubic-bezier(0.34, 1.56, 0.64, 1);
  --radius: 14px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: #0c0d12;
  background-image:
    radial-gradient(ellipse at 50% 42%, transparent 46%, rgba(8, 9, 14, 0.52) 100%),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='g'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0.9  0 0 0 0 0.84  0 0 0 0 0.68  0 0 0 0.055 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23g)'/%3E%3C/svg%3E");
  background-size: auto, 180px 180px;
  color: #f3ead8;
  font-family: "Cairo", system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.55;
  user-select: none;
  touch-action: none;
}

img { display: block; max-width: 100%; }

#game-root {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  z-index: 0;
  background: #0c0d12;
  color: #f3ead8;
  overflow: hidden;
}

#game-root canvas {
  display: block;
  width: 100vw !important;
  height: 100vh !important;
}

#vignette {
  pointer-events: none;
  position: fixed;
  inset: 0;
  z-index: 1;
  background:
    radial-gradient(ellipse at 50% 40%, transparent 40%, rgba(8, 9, 14, 0.45) 100%);
}

.hidden { display: none !important; }

.overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: stretch;
  justify-content: center;
  background: #0c0d12;
  color: #f3ead8;
  overflow: auto;
}

.overlay.dim {
  background: rgba(8, 9, 14, 0.72);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  align-items: center;
  padding: 24px 16px;
}

#loading-screen { z-index: 50; align-items: center; }
#menu-screen {
  z-index: 30;
  background-color: #0c0d12;
  color: #f3ead8;
  background-image:
    radial-gradient(ellipse 68% 46% at 50% 20%, rgba(224, 177, 91, 0.22) 0%, rgba(62, 198, 198, 0.08) 36%, transparent 66%),
    radial-gradient(ellipse at 50% 108%, rgba(8, 9, 14, 0.62) 0%, transparent 52%),
    radial-gradient(ellipse at 50% 42%, transparent 48%, rgba(8, 9, 14, 0.42) 100%),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='g'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0.9  0 0 0 0 0.84  0 0 0 0 0.68  0 0 0 0.055 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23g)'/%3E%3C/svg%3E");
  background-size: auto, auto, auto, 180px 180px;
}
#howto-overlay { z-index: 40; align-items: center; padding: 24px 16px; background: rgba(8, 9, 14, 0.88); }
#pause-overlay { z-index: 60; }
#result-overlay { z-index: 70; }
#error-screen { z-index: 80; align-items: center; padding: 24px 16px; }

.display {
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.2;
  margin: 0;
  font-size: 34px;
  color: #f3ead8;
}
.display.sm { font-size: 24px; }

.eyebrow {
  margin: 0 0 8px;
  font-size: 13px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #e0b15b;
  font-weight: 700;
}

.muted { color: #9a917f; margin: 8px 0 0; font-size: 15px; }
.lede { color: #cfc6b2; margin: 0 0 16px; font-size: 15px; line-height: 1.65; }
.tiny { font-size: 13px; color: #9a917f; margin: 8px 0 0; }
.tiny-label {
  display: block;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #9a917f;
  font-weight: 700;
}

.load-card, .sheet, .menu-shell {
  width: min(440px, 100%);
}

.load-card {
  text-align: center;
  padding: 32px 24px;
}

.crest {
  width: 72px;
  height: 72px;
  margin: 0 auto 20px;
  border-radius: 50%;
  border: 1px solid rgba(224, 177, 91, 0.35);
  background:
    radial-gradient(circle at 50% 40%, rgba(62, 198, 198, 0.35), transparent 60%),
    #14161d;
  display: grid;
  place-items: center;
  box-shadow: 0 0 32px rgba(62, 198, 198, 0.18);
  color: #3ec6c6;
}
.crest-gem {
  width: 22px;
  height: 22px;
  background: linear-gradient(160deg, #7ee8e8, #1a8f8f);
  transform: rotate(45deg);
  border-radius: 4px;
  box-shadow: 0 0 16px rgba(62, 198, 198, 0.7);
}

.load-track {
  margin-top: 24px;
  height: 8px;
  border-radius: 99px;
  background: #1a1c25;
  color: #f3ead8;
  overflow: hidden;
  border: 1px solid var(--line);
}
#load-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #e0b15b, #c4892a);
  border-radius: 99px;
  transition: width 220ms var(--ease);
}

.menu-shell {
  width: min(520px, 100%);
  margin: 0 auto;
  min-height: 100%;
  display: flex;
  flex-direction: column;
}

.hero-wrap {
  position: relative;
  height: min(42vh, 340px);
  overflow: hidden;
  background: #14161d;
  color: #f3ead8;
}
.hero-art {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center 40%;
}
.hero-fade {
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg,
    rgba(12, 13, 18, 0.1) 0%,
    rgba(12, 13, 18, 0.22) 28%,
    rgba(12, 13, 18, 0.62) 64%,
    rgba(12, 13, 18, 0.92) 86%,
    #0c0d12 100%);
  pointer-events: none;
}
.hero-copy {
  position: absolute;
  inset-inline: 20px;
  bottom: 18px;
}
.hero-copy .display {
  color: #f3ead8;
  text-shadow:
    0 0 22px rgba(126, 232, 232, 0.34),
    0 0 8px rgba(62, 198, 198, 0.28),
    0 2px 14px rgba(8, 9, 14, 0.88);
}

.menu-body { padding: 8px 20px 32px; }

.stat-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 20px;
}
.stat {
  background: linear-gradient(180deg, #1f212b 0%, #161820 100%);
  color: #f3ead8;
  border: 1px solid rgba(224, 177, 91, 0.4);
  border-radius: 12px;
  padding: 12px 8px;
  text-align: center;
  box-shadow:
    0 8px 18px rgba(0, 0, 0, 0.28),
    inset 0 1px 0 rgba(243, 234, 216, 0.16);
}
.stat-k {
  display: block;
  font-size: 11px;
  letter-spacing: 0.06em;
  color: #9a917f;
  font-weight: 700;
}
.stat-v {
  display: block;
  margin-top: 4px;
  font-size: 18px;
  font-weight: 800;
  color: #e0b15b;
}

.menu-actions, .stack {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.menu-actions-row {
  display: flex;
  gap: 10px;
  align-items: stretch;
}
.menu-actions-row .btn-ghost { flex: 1; min-width: 0; }

.btn {
  appearance: none;
  border: 0;
  cursor: pointer;
  min-height: 52px;
  border-radius: 14px;
  font-family: inherit;
  font-size: 16px;
  font-weight: 700;
  padding: 12px 18px;
  transition: transform 120ms ease-out, filter 180ms var(--ease), background 180ms var(--ease), box-shadow 180ms var(--ease);
  color: #1a1408;
  background: #cfc6b2;
}
.btn:active { transform: scale(0.97); }
.btn:focus-visible { outline: 2px solid #e0b15b; outline-offset: 3px; }
.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
  filter: grayscale(0.3);
}

.btn-gold {
  background: linear-gradient(180deg, #f3cc7c 0%, #e0b15b 42%, #c4892a 100%);
  color: #1a1408;
  border-radius: 16px;
  box-shadow:
    0 0 28px rgba(224, 177, 91, 0.38),
    0 8px 22px rgba(196, 137, 42, 0.3),
    inset 0 1px 0 rgba(255, 244, 214, 0.82);
}
.btn-gold:active {
  transform: scale(0.97);
  background: linear-gradient(180deg, #c4892a 0%, #a06e1e 55%, #7a5314 100%);
  color: #1a1408;
  box-shadow:
    0 0 10px rgba(196, 137, 42, 0.16),
    0 2px 8px rgba(0, 0, 0, 0.28),
    inset 0 1px 0 rgba(255, 236, 190, 0.22);
}
.btn-ghost {
  background: linear-gradient(180deg, #1e212b 0%, #171922 100%);
  color: #f3ead8;
  border: 1px solid rgba(224, 177, 91, 0.42);
  box-shadow:
    0 6px 16px rgba(0, 0, 0, 0.22),
    inset 0 1px 0 rgba(243, 234, 216, 0.1);
}
.btn-quiet {
  background: transparent;
  color: #9a917f;
  min-height: 44px;
}
.btn-mute-pill {
  flex: 0 0 52px;
  width: 52px;
  min-width: 52px;
  min-height: 52px;
  padding: 0;
  border-radius: 999px;
  background: linear-gradient(180deg, #1e212b 0%, #171922 100%);
  color: #e0b15b;
  border: 1px solid rgba(224, 177, 91, 0.42);
  display: grid;
  place-items: center;
  box-shadow:
    0 6px 16px rgba(0, 0, 0, 0.22),
    inset 0 1px 0 rgba(243, 234, 216, 0.1);
}
.btn-mute-pill .ico-muted { display: none; }
.btn-mute-pill.is-muted .ico-sound { display: none; }
.btn-mute-pill.is-muted .ico-muted { display: block; }
.btn-mute-pill:active { transform: scale(0.96); }

.sheet {
  background: #14161d;
  color: #f3ead8;
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 24px 20px 20px;
  box-shadow: var(--shadow);
  width: min(420px, 100%);
}
.sheet.slim { width: min(360px, 100%); }

.howto-list {
  list-style: none;
  margin: 16px 0 20px;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.howto-list li {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}
.howto-list p { margin: 2px 0 0; color: #9a917f; font-size: 14px; }
.howto-list strong { color: #f3ead8; font-size: 15px; }
.step {
  flex: 0 0 32px;
  width: 32px;
  height: 32px;
  border-radius: 10px;
  background: #22242e;
  color: #e0b15b;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 13px;
}

#hud {
  position: fixed;
  inset: 0;
  z-index: 10;
  pointer-events: none;
  color: #f3ead8;
}

.hud-top {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 12px 0;
  max-width: 100vw;
}

.pill {
  background: rgba(20, 22, 29, 0.86);
  color: #f3ead8;
  border: 1px solid var(--line);
  border-radius: 999px;
  min-height: 40px;
  padding: 6px 14px;
  display: flex;
  align-items: center;
  font-weight: 800;
  font-size: 13px;
  backdrop-filter: blur(12px);
}
.pill-score {
  flex: 1;
  justify-content: space-between;
  min-width: 0;
  gap: 8px;
}
.pill-score #hud-score { font-size: 18px; color: #e0b15b; }

.icon-btn {
  pointer-events: auto;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(20, 22, 29, 0.86);
  color: #f3ead8;
  display: grid;
  place-items: center;
  cursor: pointer;
  flex: 0 0 44px;
}
.icon-btn:active { transform: scale(0.96); }
.icon-btn:focus-visible { outline: 2px solid #e0b15b; outline-offset: 2px; }

.hud-mid {
  pointer-events: none;
  display: flex;
  gap: 8px;
  padding: 8px 12px 0;
  max-width: 100vw;
}
.meter-card {
  background: rgba(20, 22, 29, 0.8);
  color: #f3ead8;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px 10px;
  backdrop-filter: blur(10px);
}
#gem-card { flex: 1; min-width: 0; }
#clock-card { flex: 0 0 auto; min-width: 76px; text-align: center; }
#hud-clock { font-size: 16px; color: #f3ead8; }

.meter {
  margin-top: 6px;
  height: 7px;
  border-radius: 99px;
  background: #22242e;
  overflow: hidden;
}
#gem-bar {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, #7ee8e8, #1a8f8f);
  border-radius: 99px;
  transform-origin: right center;
  transition: width 200ms var(--ease);
}

.alert-banner {
  pointer-events: none;
  margin: 10px auto 0;
  width: min(360px, calc(100vw - 24px));
  background: rgba(196, 69, 58, 0.92);
  color: #f3ead8;
  border-radius: 12px;
  padding: 10px 14px;
  text-align: center;
  font-weight: 700;
  font-size: 14px;
  box-shadow: 0 10px 24px rgba(196, 69, 58, 0.25);
}
.catch-toast {
  pointer-events: none;
  position: absolute;
  left: 50%;
  top: 38%;
  transform: translate(-50%, -50%);
  background: rgba(224, 177, 91, 0.92);
  color: #1a1408;
  font-weight: 800;
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 13px;
  white-space: nowrap;
}

#controls {
  pointer-events: none;
  position: absolute;
  left: 0;
  right: 0;
  bottom: 12px;
  height: 168px;
}

#joystick-wrap {
  pointer-events: auto;
  position: absolute;
  left: 12px;
  bottom: 8px;
  width: 132px;
  height: 132px;
}

#joystick-base {
  width: 132px;
  height: 132px;
  border-radius: 50%;
  background: rgba(20, 22, 29, 0.55);
  border: 1px solid rgba(243, 234, 216, 0.1);
  position: relative;
  backdrop-filter: blur(8px);
}
#joystick-ring {
  position: absolute;
  inset: 18px;
  border-radius: 50%;
  border: 1px dashed rgba(224, 177, 91, 0.28);
}
#joystick-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 56px;
  height: 56px;
  margin: -28px 0 0 -28px;
  border-radius: 50%;
  background: linear-gradient(180deg, #f0c36e, #c4892a);
  box-shadow: 0 6px 16px rgba(196, 137, 42, 0.35);
  pointer-events: none;
}

#action-cluster {
  pointer-events: auto;
  position: absolute;
  right: 12px;
  bottom: 12px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 10px;
}

.act-btn {
  appearance: none;
  border: 0;
  cursor: pointer;
  color: #f3ead8;
  background: rgba(20, 22, 29, 0.88);
  border: 1px solid rgba(243, 234, 216, 0.1);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-family: inherit;
  font-weight: 700;
  font-size: 11px;
  letter-spacing: 0.04em;
  backdrop-filter: blur(10px);
}
.act-btn:active { transform: scale(0.96); }
.act-btn:focus-visible { outline: 2px solid #e0b15b; outline-offset: 2px; }
.act-btn:disabled { opacity: 0.38; cursor: not-allowed; transform: none; }
.act-btn.pressed { filter: brightness(1.15); }

.act-alarm {
  width: 76px;
  height: 76px;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 30%, #d45a4e, #8a2a24);
  color: #f3ead8;
  border-color: rgba(243, 180, 170, 0.25);
}
.act-gate {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: rgba(26, 28, 37, 0.92);
  color: #e0b15b;
}

@media (max-width: 430px) {
  .display { font-size: 30px; }
  .hud-top { gap: 6px; }
  .pill { padding: 6px 10px; font-size: 12px; }
  #joystick-wrap, #joystick-base { width: 120px; height: 120px; }
  .act-alarm { width: 70px; height: 70px; }
}

@media (min-width: 900px) {
  .menu-shell {
    width: min(1120px, calc(100vw - 40px));
    padding-top: 16px;
    padding-bottom: 12px;
  }
  .hero-wrap {
    border-radius: 20px;
    height: min(44vh, 400px);
    box-shadow:
      0 0 70px 18px rgba(224, 177, 91, 0.16),
      0 0 120px 36px rgba(62, 198, 198, 0.07);
  }
  .lede { margin: 0 0 10px; }
  .stat-row { margin-bottom: 14px; }
  .menu-body {
    padding: 6px 12px 18px;
    width: min(640px, 100%);
    margin-inline: auto;
  }
  #joystick-wrap { left: 36px; bottom: 28px; }
  #action-cluster { right: 36px; bottom: 32px; }
}

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

@media (prefers-reduced-motion: no-preference) {
  .crest-gem { animation: gemspin 8s linear infinite; }
  @keyframes gemspin {
    from { transform: rotate(45deg) scale(1); }
    50% { transform: rotate(225deg) scale(1.08); }
    to { transform: rotate(405deg) scale(1); }
  }
}