:root {
  --bg: #070b0f;
  --panel: rgba(10, 16, 22, 0.78);
  --line: rgba(190, 220, 225, 0.13);
  --text: #e8f2f1;
  --muted: #8ea4a7;
  --faint: #5f7478;
  --mint: #71f0dc;
  --gold: #ffd166;
  --danger: #ff5c4d;
  --font: "Segoe UI", "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: #070b0f;
}

body {
  min-height: 100%;
  margin: 0;
  color: var(--text);
  font-family: var(--font);
  background:
    radial-gradient(circle at 15% 0%, rgba(66, 145, 136, 0.13), transparent 34rem),
    radial-gradient(circle at 85% 100%, rgba(142, 86, 42, 0.11), transparent 30rem),
    linear-gradient(160deg, #0b1218 0%, #070b0f 55%, #05080b 100%);
  background-attachment: fixed;
}

body::before {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  content: "";
  opacity: 0.22;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.025) 1px, transparent 1px);
  background-size: 44px 44px;
  mask-image: linear-gradient(to bottom, black, transparent 85%);
}

.shell {
  width: min(1120px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 22px;
}

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
  padding: 0 2px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.14em;
}

.brand-mark {
  display: inline-grid;
  width: 24px;
  height: 24px;
  place-items: center;
  color: var(--mint);
  font-size: 18px;
  line-height: 1;
  border: 1px solid rgba(113, 240, 220, 0.32);
  border-radius: 7px;
  box-shadow: 0 0 18px rgba(113, 240, 220, 0.12);
}

.tag {
  padding: 3px 6px;
  color: var(--faint);
  font-size: 8px;
  font-weight: 600;
  letter-spacing: 0.18em;
  border: 1px solid var(--line);
  border-radius: 4px;
}

.site-note {
  color: var(--faint);
  font-size: 11px;
  letter-spacing: 0.08em;
}

.game-container {
  position: relative;
  width: min(100%, max(320px, calc((100vh - 138px) * 3 / 2)));
  aspect-ratio: 3 / 2;
  margin: 0 auto;
  overflow: hidden;
  isolation: isolate;
  touch-action: none;
  user-select: none;
  background: #0a1015;
  border: 1px solid rgba(190, 220, 225, 0.16);
  border-radius: 20px;
  box-shadow:
    0 30px 90px rgba(0, 0, 0, 0.48),
    0 0 0 1px rgba(0, 0, 0, 0.35) inset,
    0 0 70px rgba(57, 150, 139, 0.055);
}

#game {
  display: block;
  width: 100%;
  height: 100%;
}

.hud {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 16px;
  pointer-events: none;
  transition: opacity 0.35s ease;
}

.game-container.overlay-open .hud {
  opacity: 0;
}

.hud-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.hud-card {
  min-width: 0;
  padding: 8px 12px;
  background:
    linear-gradient(150deg, rgba(19, 30, 37, 0.86), rgba(6, 11, 15, 0.72));
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.18);
  backdrop-filter: blur(10px);
}

.hud-label {
  display: block;
  color: var(--faint);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.keys-card {
  min-width: 158px;
}

.key-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 6px;
}

.key-pip {
  width: 9px;
  height: 9px;
  border: 1px solid rgba(255, 209, 102, 0.38);
  border-radius: 50%;
  background: rgba(255, 209, 102, 0.06);
  transition:
    background 0.25s ease,
    box-shadow 0.25s ease,
    transform 0.25s ease;
}

.key-pip.filled {
  transform: scale(1.18);
  background: var(--gold);
  box-shadow: 0 0 12px rgba(255, 209, 102, 0.65);
}

.key-count {
  margin-left: 5px;
  color: var(--muted);
  font-size: 10px;
  font-variant-numeric: tabular-nums;
}

.objective-card {
  flex: 1;
  max-width: 390px;
  text-align: center;
}

.objective-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.level-label {
  padding: 2px 6px;
  color: var(--gold);
  font-size: 8px;
  font-weight: 700;
  letter-spacing: 0.08em;
  background: rgba(255, 209, 102, 0.07);
  border: 1px solid rgba(255, 209, 102, 0.18);
  border-radius: 4px;
  white-space: nowrap;
}

#objective {
  display: block;
  margin-top: 5px;
  overflow: hidden;
  color: #dcebea;
  font-size: 11px;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lure-row {
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 5px;
  padding-top: 5px;
  border-top: 1px solid rgba(190, 220, 225, 0.08);
}

.lure-row.visible {
  display: flex;
}

.lure-count {
  color: var(--gold);
  font-size: 10px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.danger-card {
  min-width: 172px;
}

.danger-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 6px;
}

#seeker-state {
  overflow: hidden;
  color: var(--mint);
  font-size: 11px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition: color 0.25s ease;
}

.danger-meter {
  flex: 0 0 76px;
  height: 5px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 999px;
}

#danger-fill {
  display: block;
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, #6fe6c8, #ffd166 55%, #ff5c4d);
  border-radius: inherit;
  transition: width 0.16s linear;
}

.danger-card.danger-elevated #seeker-state {
  color: var(--gold);
}

.danger-card.danger-high {
  border-color: rgba(255, 92, 77, 0.36);
}

.danger-card.danger-high #seeker-state {
  color: #ff9a8f;
}

.toast {
  position: absolute;
  top: 92px;
  left: 50%;
  max-width: min(520px, calc(100% - 32px));
  padding: 8px 14px;
  color: #e9fffb;
  font-size: 12px;
  font-weight: 600;
  text-align: center;
  background: rgba(7, 15, 18, 0.86);
  border: 1px solid rgba(113, 240, 220, 0.22);
  border-radius: 999px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.26);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, -8px);
  transition:
    opacity 0.22s ease,
    transform 0.22s ease;
}

.toast.visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

.hud-bottom {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 5px 12px;
  padding: 6px 12px;
  color: rgba(202, 226, 226, 0.56);
  font-size: 10px;
  background: rgba(5, 10, 14, 0.62);
  border: 1px solid rgba(190, 220, 225, 0.09);
  border-radius: 999px;
  backdrop-filter: blur(8px);
}

kbd {
  display: inline-block;
  min-width: 16px;
  padding: 1px 4px;
  color: rgba(232, 255, 251, 0.8);
  font-family: inherit;
  font-size: 9px;
  text-align: center;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 4px;
}

.prompt {
  min-height: 34px;
  padding: 8px 16px;
  color: var(--mint);
  font-size: 12px;
  font-weight: 650;
  text-align: center;
  background: rgba(5, 12, 15, 0.84);
  border: 1px solid rgba(113, 240, 220, 0.2);
  border-radius: 999px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.26);
  opacity: 0;
  transform: translateY(4px);
  transition:
    opacity 0.18s ease,
    transform 0.18s ease;
}

.prompt.visible {
  opacity: 1;
  transform: translateY(0);
}

.prompt.danger {
  color: #ffc3bb;
  border-color: rgba(255, 92, 77, 0.34);
}

.overlay {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 22px;
  background:
    radial-gradient(circle at 50% 30%, rgba(48, 111, 104, 0.14), transparent 26rem),
    rgba(4, 8, 11, 0.72);
  backdrop-filter: blur(8px);
  transition:
    opacity 0.35s ease,
    visibility 0.35s ease;
}

.overlay.hidden {
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
}

.panel {
  width: min(740px, 100%);
  max-height: 100%;
  padding: clamp(24px, 4vw, 44px);
  overflow: auto;
  background:
    linear-gradient(145deg, rgba(18, 29, 36, 0.97), rgba(7, 12, 16, 0.97));
  border: 1px solid rgba(190, 220, 225, 0.16);
  border-radius: 22px;
  box-shadow:
    0 30px 100px rgba(0, 0, 0, 0.52),
    0 0 0 1px rgba(255, 255, 255, 0.025) inset;
  scrollbar-color: rgba(113, 240, 220, 0.3) transparent;
}

.eyebrow {
  margin: 0 0 13px;
  color: var(--gold);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.22em;
}

.panel h1 {
  margin: 0;
  color: #f2fffc;
  font-size: clamp(40px, 6vw, 66px);
  font-weight: 750;
  letter-spacing: 0.08em;
  line-height: 0.98;
  text-shadow: 0 0 44px rgba(113, 240, 220, 0.16);
}

.subtitle {
  max-width: 58ch;
  margin: 17px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.75;
}

.overlay-content {
  margin-top: 24px;
}

.instruction-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.instruction {
  padding: 14px;
  background: rgba(255, 255, 255, 0.025);
  border: 1px solid rgba(190, 220, 225, 0.09);
  border-radius: 14px;
}

.instruction-number {
  display: block;
  margin-bottom: 10px;
  color: var(--gold);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.18em;
}

.instruction strong {
  display: block;
  margin-bottom: 5px;
  color: #e7f5f2;
  font-size: 13px;
}

.instruction p {
  margin: 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.7;
}

.rules-line {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin: 15px 0 0;
  color: var(--faint);
  font-size: 11px;
  line-height: 1.6;
}

.dot {
  flex: 0 0 5px;
  width: 5px;
  height: 5px;
  margin-top: 6px;
  background: var(--gold);
  border-radius: 50%;
  box-shadow: 0 0 10px rgba(255, 209, 102, 0.55);
}

.overlay.level-complete .panel {
  padding: clamp(20px, 3vw, 32px);
}

.overlay.level-complete .panel h1 {
  font-size: clamp(34px, 5vw, 52px);
}

.overlay.level-complete .subtitle {
  margin-top: 10px;
}

.overlay.level-complete .level-intro {
  margin-top: 18px;
}

.overlay.level-complete .overlay-stats {
  margin: 16px 0 4px;
}

.overlay.level-complete .primary-button {
  margin-top: 14px;
  padding: 12px 18px;
}

.level-intro {
  display: none;
  margin-top: 24px;
}

.level-intro.visible {
  display: block;
}

.level-intro .instruction-grid {
  margin-top: 0;
}

.level-intro-note {
  margin: 12px 0 0;
  color: var(--faint);
  font-size: 11px;
  line-height: 1.65;
}

.overlay-stats {
  display: none;
  gap: 10px;
  margin: 24px 0 6px;
}

.overlay-stats > div {
  flex: 1;
  padding: 13px 14px;
  background: rgba(255, 255, 255, 0.025);
  border: 1px solid rgba(190, 220, 225, 0.09);
  border-radius: 13px;
}

.overlay-stats span {
  display: block;
  margin-bottom: 5px;
  color: var(--faint);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.14em;
}

.overlay-stats strong {
  color: #e8fffb;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.primary-button {
  width: 100%;
  margin-top: 20px;
  padding: 14px 20px;
  color: #06110f;
  font-family: inherit;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.1em;
  cursor: pointer;
  background: linear-gradient(135deg, #9cfbef, #55cfbf);
  border: 1px solid rgba(220, 255, 250, 0.7);
  border-radius: 12px;
  box-shadow:
    0 12px 30px rgba(65, 210, 190, 0.18),
    0 0 0 1px rgba(0, 0, 0, 0.18) inset;
  transition:
    transform 0.16s ease,
    box-shadow 0.16s ease,
    filter 0.16s ease;
}

.primary-button:hover {
  filter: brightness(1.08);
  box-shadow:
    0 16px 38px rgba(65, 210, 190, 0.24),
    0 0 0 1px rgba(0, 0, 0, 0.18) inset;
  transform: translateY(-1px);
}

.primary-button:active {
  transform: translateY(0);
}

.primary-button:focus-visible {
  outline: 2px solid #ffffff;
  outline-offset: 3px;
}

.overlay-hint {
  margin: 11px 0 0;
  color: var(--faint);
  font-size: 10px;
  text-align: center;
  letter-spacing: 0.08em;
}

.site-footer {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 2px 0;
  color: var(--faint);
  font-size: 10px;
  letter-spacing: 0.04em;
}

@media (max-width: 820px) {
  .hud-top {
    flex-wrap: wrap;
  }

  .objective-card {
    flex-basis: 100%;
    order: 3;
    max-width: none;
  }

  .danger-card {
    margin-left: auto;
  }

  .instruction-grid {
    grid-template-columns: 1fr;
  }

  .panel {
    width: min(600px, 100%);
  }
}

@media (max-width: 600px) {
  .shell {
    width: calc(100% - 20px);
    padding-top: 14px;
  }

  .site-note,
  .controls,
  .tag {
    display: none;
  }

  .site-footer {
    flex-direction: column;
    gap: 3px;
  }

  .game-container {
    border-radius: 14px;
  }

  .hud {
    padding: 9px;
  }

  .hud-card {
    padding: 7px 9px;
    border-radius: 9px;
  }

  .keys-card {
    min-width: 128px;
  }

  .danger-card {
    min-width: 145px;
  }

  .toast {
    top: 82px;
  }

  .overlay {
    padding: 10px;
  }

  .panel {
    padding: 22px 18px;
    border-radius: 16px;
  }

  .subtitle {
    font-size: 12px;
  }

  .overlay-stats {
    flex-direction: column;
  }
}

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