:root {
  --ink: #e9f2f0;
  --muted: #8fa8a3;
  --bg: #0b1210;
  --panel: #121c19f2;
  --line: #2a3f38;
  --accent: #3dd6a5;
  --accent-2: #f0c75e;
  --danger: #ef6b6b;
  --glass: rgba(180, 230, 210, 0.12);
  --font: "Noto Sans SC", "Segoe UI", sans-serif;
  --display: "ZCOOL KuaiLe", "Noto Sans SC", cursive;
  --lab-bg: #15241f;
  --tilt: 0deg;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  overflow: hidden;
}

#app {
  height: 100%;
  display: grid;
  grid-template-rows: auto 1fr auto;
}

/* —— Topbar —— */
.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #14201c, #0e1613);
  z-index: 5;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mark {
  width: 36px; height: 36px; border-radius: 50%;
  background:
    radial-gradient(circle at 35% 30%, #fff8, transparent 40%),
    radial-gradient(circle at 50% 55%, #3dd6a5, #1a6b52);
  box-shadow: 0 0 0 2px #2a4a40, 0 6px 16px #0006;
  flex-shrink: 0;
}
.brand h1 {
  margin: 0;
  font-family: var(--display);
  font-size: 1.35rem;
  letter-spacing: 0.04em;
  color: #b8ffe0;
  line-height: 1.1;
}
.tagline { margin: 0; font-size: 0.72rem; color: var(--muted); }

.hud { display: flex; flex-wrap: wrap; gap: 8px; flex: 1; justify-content: center; }
.hud-pill {
  display: flex; align-items: baseline; gap: 6px;
  padding: 6px 12px;
  border-radius: 999px;
  background: #0a1210;
  border: 1px solid var(--line);
  font-size: 0.9rem;
}
.hud-k { color: var(--muted); font-size: 0.72rem; }
.hud-pill strong { color: var(--accent); font-variant-numeric: tabular-nums; }
.hud-sub { color: var(--muted); font-size: 0.72rem; }
.fuel-pill strong { color: var(--accent-2); }
.fuel-pill.low strong { color: var(--danger); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: 0.55; } }

.top-actions { display: flex; gap: 6px; }
button.ghost {
  appearance: none;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--ink);
  border-radius: 10px;
  padding: 8px 12px;
  cursor: pointer;
  font: inherit;
}
button.ghost:hover { border-color: var(--accent); color: var(--accent); }

/* —— Stage —— */
.stage {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 0;
  overflow: hidden;
}
.lab-bg {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse 80% 60% at 50% 40%, color-mix(in srgb, var(--lab-bg) 90%, #000), transparent 70%),
    linear-gradient(180deg, #0d1512 0%, #08100c 100%);
  transition: background 0.6s ease;
}
.lab-bg::after {
  content: "";
  position: absolute;
  inset: 0;
  background-image:
    radial-gradient(circle at 20% 30%, #ffffff06 0 1px, transparent 1.5px),
    radial-gradient(circle at 70% 60%, #ffffff05 0 1px, transparent 1.5px);
  background-size: 48px 48px, 72px 72px;
  opacity: 0.5;
  pointer-events: none;
}

.dish-wrap {
  position: relative;
  z-index: 1;
  width: min(72vh, 640px, 92vw);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  transform: rotate(var(--tilt));
  transition: transform 0.35s cubic-bezier(.2,.8,.2,1);
}

.dish-glass {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  border-radius: 50%;
}
#dish {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  display: block;
  cursor: crosshair;
  background:
    radial-gradient(circle at 38% 28%, rgba(255,255,255,0.14), transparent 42%),
    radial-gradient(circle at 50% 55%, color-mix(in srgb, var(--lab-bg) 70%, #1a3028), #0a1411);
  box-shadow:
    inset 0 0 60px rgba(0,0,0,0.45),
    inset 0 -20px 40px rgba(0,40,30,0.25);
}
.dish-rim {
  pointer-events: none;
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  border: 3px solid color-mix(in srgb, var(--accent) 45%, #6a8);
  box-shadow:
    0 0 0 1px rgba(255,255,255,0.08),
    0 18px 50px rgba(0,0,0,0.5),
    inset 0 0 30px rgba(255,255,255,0.05);
}

.env-strip {
  font-size: 0.8rem;
  color: var(--muted);
  text-align: center;
  padding: 6px 14px;
  border-radius: 999px;
  background: #0a1210cc;
  border: 1px solid var(--line);
}
.env-strip .dot { margin: 0 4px; opacity: 0.4; }
.env-strip b { color: var(--ink); }

#hoverTip {
  position: absolute;
  z-index: 4;
  pointer-events: none;
  padding: 6px 10px;
  border-radius: 8px;
  background: #0a1210ee;
  border: 1px solid var(--accent-2);
  font-size: 0.78rem;
  white-space: nowrap;
  transform: translate(-50%, -120%);
}

#fuseFx {
  position: absolute;
  inset: 0;
  display: none;
  place-items: center;
  pointer-events: none;
  z-index: 5;
}
#fuseFx.on { display: grid; }
#fuseFx .fx {
  min-width: 160px;
  max-width: 80%;
  padding: 16px 18px;
  border-radius: 20px;
  text-align: center;
  white-space: pre-line;
  font-family: var(--display);
  font-size: 1.05rem;
  background: radial-gradient(circle, #ffffff44, #3dd6a544 40%, transparent 70%);
  border: 2px solid #fff8;
  animation: fusePop 1.7s ease-out forwards;
  text-shadow: 0 2px 10px #000;
}
@keyframes fusePop {
  0% { transform: scale(0.3); opacity: 0; }
  18% { opacity: 1; transform: scale(1.05); }
  75% { opacity: 1; }
  100% { transform: scale(1.3); opacity: 0; }
}

.tutorial {
  position: absolute;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 6;
  max-width: min(520px, 92vw);
  padding: 10px 16px;
  border-radius: 12px;
  background: #121c19f0;
  border: 1px solid var(--accent-2);
  color: #ffe9b0;
  font-size: 0.88rem;
  text-align: center;
  box-shadow: 0 10px 30px #0006;
}
.tutorial:empty { display: none; }

#toast {
  position: absolute;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 7;
  padding: 10px 16px;
  border-radius: 12px;
  background: #0e1815f2;
  border: 1px solid var(--accent);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s;
  max-width: 90vw;
}
#toast.show { opacity: 1; }

/* —— Dock —— */
.dock {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  justify-content: center;
  padding: 10px 12px 14px;
  border-top: 1px solid var(--line);
  background: linear-gradient(0deg, #0a100e, #121c19);
  z-index: 5;
}
.dock-sep {
  width: 1px;
  height: 28px;
  background: var(--line);
  margin: 0 4px;
}
.dock-btn {
  appearance: none;
  border: 1px solid var(--line);
  background: #15221e;
  color: var(--ink);
  border-radius: 14px;
  padding: 10px 12px;
  min-width: 64px;
  cursor: pointer;
  font: inherit;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  transition: border-color 0.15s, transform 0.1s, background 0.15s;
}
.dock-btn .ico { font-size: 1.15rem; line-height: 1; }
.dock-btn span:last-child { font-size: 0.72rem; color: var(--muted); }
.dock-btn:hover { border-color: var(--accent); }
.dock-btn:active { transform: scale(0.96); }
.dock-btn.active {
  border-color: var(--accent);
  background: #1a3a30;
  box-shadow: 0 0 0 1px var(--accent);
}
.dock-btn.primary {
  background: linear-gradient(180deg, #2a9a6e, #1d6f4f);
  border-color: #4ae0ad;
}
.dock-btn.primary span:last-child { color: #d8ffe8; }
.dock-btn.subtle { min-width: auto; padding: 10px 14px; }
.dock-btn.subtle span { color: var(--muted); font-size: 0.78rem; }
.dock-btn.danger:hover { border-color: var(--danger); color: var(--danger); }
.dock-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* —— Drawers —— */
.scrim {
  position: fixed;
  inset: 0;
  background: #0008;
  z-index: 40;
}
.drawer {
  position: fixed;
  top: 0;
  bottom: 0;
  width: min(380px, 92vw);
  background: var(--panel);
  border-right: 1px solid var(--line);
  z-index: 50;
  display: flex;
  flex-direction: column;
  padding: 14px;
  gap: 10px;
  transform: translateX(-105%);
  transition: transform 0.28s cubic-bezier(.2,.8,.2,1);
}
.drawer.right {
  left: auto;
  right: 0;
  border-right: none;
  border-left: 1px solid var(--line);
  transform: translateX(105%);
}
.drawer.open { transform: translateX(0); }
.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.drawer-head h2 {
  margin: 0;
  font-family: var(--display);
  font-size: 1.2rem;
  color: #b8ffe0;
}
.icon-x {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 1.6rem;
  cursor: pointer;
  line-height: 1;
}
.scroll {
  flex: 1;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 0;
}
.tabs { display: flex; flex-wrap: wrap; gap: 4px; }
.tabs button {
  appearance: none;
  border: 1px solid var(--line);
  background: #0e1613;
  color: var(--muted);
  border-radius: 8px;
  padding: 6px 10px;
  font: inherit;
  font-size: 0.78rem;
  cursor: pointer;
}
.tabs button.active {
  color: var(--ink);
  border-color: var(--accent);
  background: #1a3a30;
}
.progress {
  height: 6px;
  border-radius: 999px;
  background: #0a100e;
  overflow: hidden;
}
.progress > i {
  display: block;
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, #3dd6a5, #f0c75e);
}
.card {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  background: #0e1613;
  cursor: pointer;
}
.card:hover { border-color: #4a6a5e; }
.card.locked { opacity: 0.45; }
.card.owned { border-color: #3dd6a555; }
.card.active { box-shadow: inset 0 0 0 1px var(--accent); }
.card .row { display: flex; justify-content: space-between; gap: 8px; }
.card .name { font-weight: 600; }
.card .meta { font-size: 0.75rem; color: var(--muted); margin-top: 4px; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.chip {
  font-size: 0.68rem;
  padding: 2px 7px;
  border-radius: 999px;
  background: #1a2c26;
  border: 1px solid #2f4a40;
  color: #c5e8dc;
}
.dex-item {
  display: grid;
  grid-template-columns: 40px 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 6px;
  border-radius: 10px;
  cursor: pointer;
  border: 1px solid transparent;
}
.dex-item:hover { background: #15221e; }
.dex-item.selected { border-color: var(--accent); background: #152a24; }
.dex-swatch {
  width: 40px; height: 40px; border-radius: 50%;
  display: grid; place-items: center;
  border: 2px solid #fff3;
  position: relative;
  font-size: 0.8rem;
}
.dex-swatch.unknown { background: #222 !important; color: #666; }
.badge-mat {
  position: absolute; top: -3px; right: -3px;
  width: 11px; height: 11px; border-radius: 2px;
  background: var(--accent-2); border: 1px solid #000;
}
.detail {
  font-size: 0.8rem;
  color: var(--muted);
  line-height: 1.5;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #0a1210;
}
.detail strong { color: var(--ink); }
.search-label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.78rem;
  color: var(--muted);
}
.search-label input {
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #0a1210;
  color: var(--ink);
  font: inherit;
}
.hint { font-size: 0.75rem; color: var(--muted); margin: 0; line-height: 1.45; }

/* —— Modal —— */
.modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: #000a;
  z-index: 60;
  padding: 16px;
}
.modal[hidden] { display: none !important; }
.modal .box {
  width: min(480px, 100%);
  background: #15221e;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 20px;
  box-shadow: 0 24px 60px #0008;
}
.modal h3 {
  margin: 0 0 12px;
  font-family: var(--display);
  color: #b8ffe0;
}
.modal ol {
  margin: 0 0 16px;
  padding-left: 1.2rem;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.55;
}
.modal b { color: var(--ink); }
button.primary.wide {
  width: 100%;
  appearance: none;
  border: 1px solid #4ae0ad;
  background: linear-gradient(180deg, #2a9a6e, #1d6f4f);
  color: #fff;
  border-radius: 12px;
  padding: 12px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

@media (max-width: 720px) {
  .brand .tagline { display: none; }
  .hud-pill .hud-sub { display: none; }
  .dock-btn { min-width: 52px; padding: 8px; }
  .dock-sep { display: none; }
}
