:root {
  --yellow: #ffe14a;
  --ink: #1b1408;
  --panel: rgba(18, 14, 8, 0.86);
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #0b1a12;
  color: #fff8dc;
  font-family: "Segoe UI", "Hiragino Sans", sans-serif;
  touch-action: none;
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

#game-root,
#c {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.hidden {
  display: none !important;
}

#hud {
  position: fixed;
  top: calc(10px + env(safe-area-inset-top));
  left: calc(10px + env(safe-area-inset-left));
  right: calc(88px + env(safe-area-inset-right));
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
  pointer-events: none;
  z-index: 5;
}

.hud-left {
  min-width: 0;
  flex: 1 1 auto;
  max-width: min(420px, calc(100% - 72px));
  padding: 6px 10px;
  border-radius: 12px;
  background: var(--panel);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.28);
}

.hud-line {
  display: flex;
  align-items: center;
  gap: 8px;
}

#stage-text {
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.03em;
  white-space: nowrap;
}

.bar-label {
  width: auto;
  font-size: 11px;
  font-weight: 700;
  opacity: 0.85;
  flex-shrink: 0;
}

.bar {
  flex: 1 1 88px;
  min-width: 56px;
  max-width: 140px;
  height: 10px;
  border-radius: 99px;
  background: #2a2418;
  overflow: hidden;
}

.bar i {
  display: block;
  height: 100%;
  width: 100%;
  transform-origin: left center;
  transform: scaleX(1);
}

.bar.hp i {
  background: linear-gradient(90deg, #e23d3d, #ff7a7a);
}

.bar.st i {
  background: linear-gradient(90deg, #2f9bff, #7ad0ff);
}

.bar-num {
  width: 32px;
  font-size: 12px;
  font-weight: 800;
  text-align: right;
  flex-shrink: 0;
}

.remain-num {
  min-width: 48px;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
  flex-shrink: 0;
  opacity: 0.92;
}

.hud-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  pointer-events: auto;
  flex-shrink: 0;
}

.upgrades-toggle {
  min-width: 52px;
  height: 36px;
  padding: 0 10px;
  border-radius: 12px;
  background: var(--panel);
  color: #fff8dc;
  border: 1px solid rgba(242, 200, 75, 0.5);
  font-size: 12px;
  font-weight: 800;
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.28);
}

.hud-weapons {
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: flex-end;
}

.chip {
  background: var(--panel);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(4, 10, 8, 0.62);
  z-index: 24;
  padding: 16px;
  pointer-events: auto;
  touch-action: manipulation;
}

.overlay input,
.overlay button,
.overlay label,
.overlay * {
  touch-action: manipulation;
  pointer-events: auto;
}

.panel {
  width: min(560px, 100%);
  max-height: min(92vh, 760px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: rgba(16, 12, 8, 0.92);
  border: 2px solid #f2c84b;
  border-radius: 18px;
  padding: 22px 22px 18px;
  text-align: center;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.4);
}

.upgrade-panel {
  width: min(760px, 100%);
}

.upgrade-picked {
  min-height: 1.35em;
  margin: -4px 0 12px;
  font-weight: 800;
  font-size: 15px;
  color: var(--yellow);
  line-height: 1.45;
}

.upgrade-picked:empty {
  display: none;
}

h1 {
  margin: 0 0 8px;
  font-size: clamp(28px, 7vw, 46px);
  color: var(--yellow);
  letter-spacing: 0.04em;
}

h2 {
  margin: 0 0 8px;
  color: var(--yellow);
}

.eyebrow {
  margin: 0;
  letter-spacing: 0.18em;
  font-size: 11px;
  opacity: 0.7;
}

.lead {
  margin: 0 0 14px;
  opacity: 0.88;
  line-height: 1.5;
}

.howto {
  text-align: left;
  margin: 0 0 12px;
  padding-left: 18px;
  line-height: 1.7;
  font-size: 13px;
  opacity: 0.92;
}

.settings {
  text-align: left;
  margin: 0 0 16px;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(255, 225, 74, 0.08);
  border: 1px solid rgba(242, 200, 75, 0.35);
}

.settings-title {
  margin: 0 0 8px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  opacity: 0.85;
}

.settings-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px 10px;
}

.settings label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  cursor: pointer;
}

.settings input[type="checkbox"] {
  width: 22px;
  height: 22px;
  accent-color: #ffe14a;
  flex-shrink: 0;
}

.op-overlay {
  position: fixed;
  inset: 0;
  z-index: 16;
  pointer-events: none;
}

.op-skip {
  position: fixed;
  top: calc(12px + env(safe-area-inset-top));
  right: calc(12px + env(safe-area-inset-right));
  min-width: 88px;
  height: 48px;
  padding: 0 14px;
  border-radius: 14px;
  z-index: 26;
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.35);
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 0.04em;
  pointer-events: auto;
  touch-action: manipulation;
}

.op-fade {
  position: absolute;
  inset: 0;
  background: #000;
  opacity: 1;
}

.op-copy {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px;
  text-shadow: 0 6px 28px rgba(0, 0, 0, 0.85);
}

.op-eyebrow {
  margin: 0 0 10px;
  letter-spacing: 0.28em;
  font-size: 12px;
  opacity: 0.8;
}

.op-copy h2 {
  margin: 0 0 10px;
  font-size: clamp(22px, 5vw, 40px);
  color: #fff8dc;
}

.op-sub {
  margin: 0;
  opacity: 0.72;
  letter-spacing: 0.04em;
}

button {
  appearance: none;
  border: 0;
  border-radius: 999px;
  background: var(--yellow);
  color: var(--ink);
  font-weight: 800;
  font-size: 16px;
  padding: 12px 22px;
  cursor: pointer;
}

button.selected,
button.ghost.selected {
  box-shadow: 0 0 0 3px #ffe14a;
}

.row-btns {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}

.cards {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.card {
  background: #2a2112;
  border: 2px solid #d7b14a;
  border-radius: 14px;
  padding: 10px 8px;
  cursor: pointer;
  color: inherit;
  text-align: center;
  min-height: 108px;
}

.card.picked {
  opacity: 0.38;
  pointer-events: none;
  outline: 3px solid #8adf7a;
  transform: none;
}

.card:hover,
.card:focus,
.card.selected {
  background: #3a2e16;
  outline: 3px solid #ffe14a;
  transform: translateY(-2px);
}

.card b {
  display: block;
  margin: 6px 0 4px;
  font-size: 15px;
}

.card span {
  display: block;
  font-size: 12px;
  opacity: 0.85;
  line-height: 1.4;
}

.settings-btn {
  position: fixed;
  top: calc(12px + env(safe-area-inset-top));
  right: calc(12px + env(safe-area-inset-right));
  min-width: 64px;
  height: 48px;
  padding: 0 12px;
  border-radius: 14px;
  z-index: 25;
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.35);
  font-size: 15px;
  letter-spacing: 0.04em;
  touch-action: manipulation;
}

.slider-label {
  display: block;
  margin-top: 12px;
  font-size: 13px;
  touch-action: manipulation;
}

.slider-label input[type="range"] {
  width: 100%;
  margin-top: 8px;
  height: 36px;
  touch-action: manipulation;
}

.set-row.focused {
  outline: 3px solid #ffe14a;
  outline-offset: 4px;
  border-radius: 10px;
  background: rgba(255, 225, 74, 0.12);
}

.joy-zone {
  position: fixed;
  left: 0;
  bottom: 0;
  width: 46%;
  height: 42%;
  z-index: 7;
}

.joy-base {
  position: absolute;
  left: calc(18px + env(safe-area-inset-left));
  bottom: calc(18px + env(safe-area-inset-bottom));
  width: 122px;
  height: 122px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
  border: 2px solid rgba(255, 255, 255, 0.28);
}

.joy-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 54px;
  height: 54px;
  margin: -27px 0 0 -27px;
  border-radius: 50%;
  background: rgba(255, 225, 74, 0.9);
}

.look-zone {
  position: fixed;
  right: 0;
  top: 20%;
  width: 54%;
  height: 80%;
  z-index: 6;
}

.debug-bar {
  position: fixed;
  left: 8px;
  bottom: 8px;
  z-index: 30;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.debug-bar button {
  font-size: 11px;
  padding: 6px 8px;
}

@media (max-width: 720px) {
  .cards {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .upgrade-panel {
    padding: 14px 12px 12px;
  }

  .card {
    min-height: 96px;
    padding: 8px 6px;
  }

  .card b {
    font-size: 13px;
  }

  .card span {
    font-size: 11px;
  }
}

@media (min-width: 901px) {
  .joy-zone,
  .look-zone {
    display: none !important;
  }
}
