:root {
  --ink: #1B2C35;
  --ink-soft: #42545E;
  --cream: #FFF9EC;
  --cream-2: #F5E6C9;
  --cream-3: #F2DFB8;
  --orange: #FF8A3D;
  --orange-deep: #D96320;
  --teal: #6FBDB5;
  --panel: #162A35;
  --panel-deep: #0E1C24;
  --line: #2A424F;
  --muted: #8FA6B1;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  background: #08141A;
  color: var(--cream);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

body {
  background:
    radial-gradient(900px 520px at 50% -8%, rgba(255, 138, 61, .16), transparent 62%),
    radial-gradient(700px 500px at 88% 108%, rgba(111, 189, 181, .12), transparent 60%),
    #08141A;
}

button { font-family: inherit; -webkit-appearance: none; appearance: none; }

#app {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 560px;
  height: 100vh;
  height: 100dvh;
  margin: 0 auto;
  overflow: hidden;
  background: #0D1B23;
  isolation: isolate;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

#stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  background: #0D1B23;
}

#game {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

/* ---------------- HUD ---------------- */

.hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 8;
  display: none;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  padding: calc(8px + env(safe-area-inset-top, 0px)) 12px 0;
  pointer-events: none;
}

#app.in-game .hud { display: flex; }

.hud-side {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.hud-pill {
  display: flex;
  align-items: baseline;
  gap: 5px;
  padding: 4px 9px;
  border: 2px solid #1B2C35;
  border-radius: 11px;
  background: linear-gradient(180deg, #FFF9EC, #F1E0BE);
  box-shadow: 0 3px 0 rgba(0, 0, 0, .3);
  color: #1B2C35;
  line-height: 1;
}

.hud-k {
  font-size: 10px;
  font-weight: 800;
  color: #8B7250;
  letter-spacing: .5px;
}

.hud-pill b {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 15px;
  font-weight: 800;
  letter-spacing: .5px;
}

.hud-score {
  background: linear-gradient(180deg, #FFA362, #FF7E2E);
  border-color: #3A2418;
  box-shadow: 0 3px 0 rgba(0, 0, 0, .32);
}

.hud-score .hud-k { color: #713615; }
.hud-score b { color: #2B1A10; }

.hud-progress {
  position: absolute;
  top: calc(47px + env(safe-area-inset-top, 0px));
  left: 14px;
  right: 14px;
  z-index: 8;
  height: 4px;
  border-radius: 999px;
  background: rgba(10, 24, 31, .7);
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, .5);
  overflow: hidden;
  display: none;
  pointer-events: none;
}
#app.in-game .hud-progress { display: block; }
.hud-progress i {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #FFB478, #FF7E2E);
  transition: width .25s ease;
}

.pause-btn {
  pointer-events: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  width: 42px;
  height: 37px;
  padding: 0;
  border: 2px solid #1B2C35;
  border-radius: 11px;
  background: linear-gradient(180deg, #FFF9EC, #EEDCB8);
  box-shadow: 0 3px 0 rgba(0, 0, 0, .3);
  cursor: pointer;
  touch-action: manipulation;
}

.pause-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 rgba(0, 0, 0, .3); }
.pause-btn i { display: block; width: 4px; height: 13px; border-radius: 2px; background: #1B2C35; }
.pause-btn:disabled { opacity: .45; }

/* ---------------- dock & controls ---------------- */

.dock {
  flex: 0 0 auto;
  display: none;
  padding: 8px 16px calc(10px + env(safe-area-inset-bottom, 0px));
  background: linear-gradient(180deg, #172B36, #0E1C24 70%);
  border-top: 2px solid #29424F;
  box-shadow: 0 -12px 30px rgba(0, 0, 0, .38);
  z-index: 10;
}

#app.in-game .dock { display: block; }

.dock-status {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 7px;
  font-size: 12px;
  color: var(--muted);
  min-height: 18px;
}

.stat {
  display: flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
}

.stat em {
  font-style: normal;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .5px;
  color: #7E97A3;
}

.stat b {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
  font-weight: 800;
  color: #FFF1D6;
}

.pips { display: inline-flex; gap: 3px; align-items: center; }
.pips i {
  width: 14px;
  height: 7px;
  border-radius: 2px;
  background: linear-gradient(180deg, #FFA362, #FF7E2E);
  box-shadow: inset 0 -2px 0 rgba(72, 34, 12, .35);
  transition: background .2s;
}
.pips i.off { background: #344A56; box-shadow: none; }
.pips i.low {
  background: linear-gradient(180deg, #FF7A62, #E5482F);
  animation: pipPulse 1s ease-in-out infinite;
}
@keyframes pipPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: .42; }
}

.shield-stat { color: #8FE6EE; display: none; }
.shield-stat em { color: #6FC6CE; }
.shield-stat b { color: #B9F5FA; }

#app:not(.is-play) .dock-controls { opacity: .4; pointer-events: none; }

.dock-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 2px 2px 0;
  transition: opacity .2s;
}

.stick {
  position: relative;
  width: 128px;
  height: 128px;
  flex: 0 0 auto;
  border-radius: 50%;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  background:
    radial-gradient(circle at 50% 44%, rgba(83, 123, 139, .28), rgba(14, 28, 36, .82) 68%),
    #10222B;
  border: 2px solid #31505F;
  box-shadow:
    inset 0 5px 18px rgba(0, 0, 0, .55),
    0 6px 16px rgba(0, 0, 0, .3);
}

.stick-ring {
  position: absolute;
  inset: 14px;
  border-radius: 50%;
  border: 1px dashed rgba(160, 199, 213, .22);
}

.stick-arrows { position: absolute; inset: 0; pointer-events: none; }
.ar {
  position: absolute;
  width: 0;
  height: 0;
  border: 5px solid transparent;
  opacity: .55;
}
.ar-up { top: 8px; left: 50%; margin-left: -5px; border-top-width: 0; border-bottom-color: #9CB7C3; }
.ar-down { bottom: 8px; left: 50%; margin-left: -5px; border-bottom-width: 0; border-top-color: #9CB7C3; }
.ar-left { left: 8px; top: 50%; margin-top: -5px; border-left-width: 0; border-right-color: #9CB7C3; }
.ar-right { right: 8px; top: 50%; margin-top: -5px; border-right-width: 0; border-left-color: #9CB7C3; }

.stick-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 56px;
  height: 56px;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background:
    radial-gradient(circle at 36% 30%, #FFC08A, #FF8A3D 58%, #E66D22);
  border: 2px solid #35200F;
  box-shadow:
    0 4px 0 #A94A14,
    0 8px 16px rgba(0, 0, 0, .35),
    inset 0 3px 5px rgba(255, 255, 255, .35);
  transition: transform .1s ease-out;
  will-change: transform;
}
.stick.dragging .stick-knob { transition: none; }

.fire-btn {
  position: relative;
  flex: 0 0 auto;
  width: 94px;
  height: 94px;
  padding: 0;
  border-radius: 50%;
  border: 3px solid #2C1B12;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #2A180E;
  background:
    radial-gradient(circle at 35% 26%, #FFBE8C, #FF8A3D 54%, #E86C22);
  box-shadow:
    0 6px 0 #A94A14,
    0 14px 24px rgba(0, 0, 0, .36),
    inset 0 4px 7px rgba(255, 255, 255, .35);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  cursor: pointer;
  transition: transform .06s, box-shadow .06s, filter .1s;
}

.fire-btn::after {
  content: "";
  position: absolute;
  inset: -9px;
  border-radius: 50%;
  border: 2px solid rgba(255, 138, 61, .3);
  animation: firePulse 2.2s ease-out infinite;
  pointer-events: none;
}

.fire-btn.down {
  transform: translateY(5px);
  box-shadow: 0 1px 0 #A94A14, 0 6px 12px rgba(0, 0, 0, .3), inset 0 3px 7px rgba(0, 0, 0, .18);
  filter: brightness(.96);
}

.fire-main { font-size: 23px; font-weight: 900; letter-spacing: 2px; line-height: 1; }
.fire-sub { margin-top: 3px; font-size: 8px; font-weight: 800; letter-spacing: 2.5px; opacity: .55; }

@keyframes firePulse {
  0% { transform: scale(.94); opacity: .8; }
  70% { transform: scale(1.1); opacity: 0; }
  100% { transform: scale(1.1); opacity: 0; }
}

/* ---------------- toast ---------------- */

.toast {
  position: absolute;
  left: 50%;
  top: calc(56px + env(safe-area-inset-top, 0px));
  z-index: 12;
  max-width: 90%;
  padding: 8px 14px;
  border: 1px solid #3D5A69;
  border-radius: 999px;
  background: rgba(18, 34, 43, .95);
  color: #FFF3DA;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  opacity: 0;
  visibility: hidden;
  transform: translate(-50%, -8px);
  transition: opacity .18s, transform .18s, visibility .18s;
  pointer-events: none;
}
.toast.show { opacity: 1; visibility: visible; transform: translate(-50%, 0); }

/* ---------------- screens ---------------- */

.screen {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow-y: auto;
  padding: calc(18px + env(safe-area-inset-top, 0px)) 16px calc(18px + env(safe-area-inset-bottom, 0px));
  background: rgba(6, 15, 20, .62);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity .2s ease, visibility .2s ease;
}

.screen.is-open {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.menu-screen {
  position: absolute;
  inset: 0;
  z-index: 60;
  background:
    radial-gradient(560px 380px at 50% 18%, rgba(255, 138, 61, .16), transparent 70%),
    rgba(6, 15, 20, .58);
}

.screen-card {
  position: relative;
  width: 100%;
  max-width: 348px;
  margin: auto;
  padding: 22px 20px 20px;
  border: 2px solid #1B2C35;
  border-radius: 24px;
  background: linear-gradient(180deg, #FFFBEF, #F5E6C9);
  box-shadow:
    0 8px 0 rgba(0, 0, 0, .28),
    0 28px 60px rgba(0, 0, 0, .45);
  color: #1B2C35;
}

.screen-card::before {
  content: "";
  position: absolute;
  left: 22px;
  right: 22px;
  top: -2px;
  height: 6px;
  border-radius: 0 0 8px 8px;
  background: linear-gradient(90deg, #FF8A3D, #FFB56B 46%, #6FBDB5);
  opacity: .95;
}

.screen.is-open .screen-card {
  animation: cardIn .32s cubic-bezier(.2, .9, .3, 1.15);
}

@keyframes cardIn {
  from { opacity: 0; transform: translateY(18px) scale(.97); }
  to { opacity: 1; transform: none; }
}

.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 12px;
  padding: 4px 9px;
  border-radius: 999px;
  background: #F2DFB8;
  color: #8A6A48;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 1.3px;
}

.eyebrow .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #FF8A3D;
  box-shadow: 0 0 0 3px rgba(255, 138, 61, .18);
}

.eyebrow.danger { background: #F7D9D0; color: #A33B2B; }
.eyebrow.danger .dot { background: #E4553C; box-shadow: 0 0 0 3px rgba(228, 85, 60, .16); }

.game-title {
  margin: 0 0 10px;
  font-size: 42px;
  line-height: 1.02;
  font-weight: 900;
  letter-spacing: 3px;
  color: #1B2C35;
  text-shadow: 0 3px 0 rgba(255, 138, 61, .22);
}
.game-title span { color: #F5731F; }

.screen-title {
  margin: 0 0 6px;
  font-size: 28px;
  font-weight: 900;
  letter-spacing: 1px;
  color: #1B2C35;
}

.screen-sub {
  margin: 0 0 16px;
  font-size: 12px;
  line-height: 1.65;
  color: #7A6A52;
}

.lead {
  margin: 0 0 14px;
  font-size: 12.5px;
  line-height: 1.7;
  color: #6B6353;
}

.record-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 0 0 16px;
}

.record {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 8px 10px;
  border: 1px solid #E0CBA4;
  border-radius: 12px;
  background: #F3E4C7;
}
.record span { font-size: 10px; font-weight: 700; color: #93795A; letter-spacing: .4px; }
.record b {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 19px;
  font-weight: 800;
  color: #1B2C35;
}

.btn {
  display: block;
  width: 100%;
  padding: 12px 14px;
  border: 2px solid #1B2C35;
  border-radius: 14px;
  font-size: 16px;
  font-weight: 900;
  letter-spacing: 1px;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform .08s, box-shadow .08s, filter .12s;
}

.btn-primary {
  margin-top: 4px;
  background: linear-gradient(180deg, #FFA15C, #FF8A3D);
  color: #2A180E;
  box-shadow: 0 5px 0 #C15A1C, 0 10px 18px rgba(199, 89, 27, .26);
}
.btn-primary:active {
  transform: translateY(4px);
  box-shadow: 0 1px 0 #C15A1C, 0 4px 8px rgba(199, 89, 27, .2);
  filter: brightness(.98);
}

.btn-lg { padding: 15px; font-size: 18px; letter-spacing: 3px; }

.btn-ghost {
  margin-top: 10px;
  background: #FFF8E7;
  color: #1B2C35;
  box-shadow: 0 4px 0 #D9C29A;
}
.btn-ghost:active { transform: translateY(3px); box-shadow: 0 1px 0 #D9C29A; }

.btn-quiet {
  margin-top: 8px;
  padding: 8px;
  border-color: transparent;
  background: transparent;
  box-shadow: none;
  color: #8B7556;
  font-size: 13px;
  letter-spacing: 1px;
}

.legend-title {
  margin: 16px 0 8px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .5px;
  color: #8A6A48;
}

.legend {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px 8px;
}

.legend span {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 7px;
  border: 1px solid #E8D6B6;
  border-radius: 8px;
  background: #F7ECD7;
  color: #5F5A4E;
  font-size: 11px;
  font-weight: 600;
}

.lg { flex: 0 0 auto; width: 9px; height: 9px; border-radius: 3px; }
.lg-star { background: #FFB13B; }
.lg-shield { background: #4FB3C8; }
.lg-bomb { background: #384A57; }
.lg-clock { background: #6C7FA8; }
.lg-shovel { background: #B98352; }
.lg-life { background: #F26D6D; }

.hint {
  margin: 12px 0 0;
  font-size: 10px;
  line-height: 1.5;
  text-align: center;
  letter-spacing: .3px;
  color: #9A8060;
}

.result-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin: 0 0 16px;
}
.result-grid.two { grid-template-columns: 1fr 1fr; }

.result-grid > div {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 8px 5px;
  border: 1px solid #E0CBA4;
  border-radius: 10px;
  background: #F3E4C7;
  text-align: center;
}

.result-grid span { font-size: 9px; font-weight: 700; color: #93795A; }
.result-grid b {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 17px;
  font-weight: 800;
  color: #1B2C35;
}
.result-grid b.accent { color: #E8722A; }

.side-card { max-width: 330px; }
.side-card .btn { margin-top: 12px; }
.side-card .btn-quiet { margin-top: 4px; }

/* ---------------- responsive ---------------- */

@media (max-height: 720px) {
  .dock { padding-top: 6px; padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px)); }
  .dock-status { margin-bottom: 4px; }
  .stick { width: 108px; height: 108px; }
  .stick-knob { width: 48px; height: 48px; }
  .fire-btn { width: 80px; height: 80px; }
  .fire-main { font-size: 19px; }
  .screen-card { padding: 18px 16px 16px; border-radius: 20px; }
  .game-title { font-size: 35px; }
  .screen-title { font-size: 24px; }
  .legend-title { margin-top: 12px; }
  .hint { margin-top: 9px; }
}

@media (max-height: 640px) {
  .stick { width: 92px; height: 92px; }
  .stick-knob { width: 42px; height: 42px; }
  .fire-btn { width: 70px; height: 70px; }
  .fire-main { font-size: 17px; }
  .fire-sub { display: none; }
  .legend, .lead, .legend-title { display: none; }
  .screen-card { max-width: 320px; }
}

@media (max-width: 359px) {
  .hud { padding-left: 8px; padding-right: 8px; }
  .hud-pill { padding: 3px 7px; }
  .hud-k { font-size: 9px; }
  .hud-pill b { font-size: 13px; }
  .legend { grid-template-columns: 1fr; }
  .dock { padding-left: 12px; padding-right: 12px; }
}

@media (min-width: 600px) {
  #app {
    border-left: 1px solid #1D333F;
    border-right: 1px solid #1D333F;
    box-shadow: 0 0 90px rgba(0, 0, 0, .65);
  }
}

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