:root {
  --bg: #0c0f14;
  --panel: #141a22;
  --panel-2: #10151c;
  --line: #26303e;
  --text: #eef2f8;
  --muted: #8e9aab;
  --accent: #7dd3c0;
  --accent-2: #f0b429;
  --danger: #ff6b7a;
  --ok: #63d391;
  --radius: 10px;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font-family: "Segoe UI", "Noto Sans TC", sans-serif; height: 100%; overflow: hidden; }
button, input { font: inherit; }

/* ============ Topbar (56px) ============ */
.topbar {
  height: 56px;
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; padding: 0 16px;
  background: var(--panel); border-bottom: 1px solid var(--line);
}
.tb-left { display: flex; align-items: center; gap: 16px; min-width: 0; }
.tb-brand { display: flex; align-items: center; gap: 8px; }
.tb-dot { width: 10px; height: 10px; border-radius: 99px; background: var(--accent); box-shadow: 0 0 8px rgba(125,211,192,.6); }
.tb-title { font-weight: 700; font-size: 14px; letter-spacing: .02em; }
.tb-center { display: flex; align-items: baseline; gap: 10px; min-width: 0; flex: 1; overflow: hidden; }
.tb-card { font-size: 15px; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tb-sub { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tb-right { display: flex; align-items: center; gap: 10px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; flex: none; }
.seg-btn { background: transparent; color: var(--muted); border: 0; padding: 6px 12px; cursor: pointer; font-size: 12px; }
.seg-btn.active { background: #243041; color: var(--text); }
.progress-wrap { width: 130px; text-align: right; color: var(--muted); font-size: 11px; }
.progress { margin-top: 3px; height: 6px; background: #222833; border-radius: 99px; overflow: hidden; }
.progress i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), #6aa8ff); }
.tb-btn {
  border: 1px solid var(--line); background: #1b2230; color: var(--text);
  border-radius: 8px; padding: 6px 12px; cursor: pointer; font-size: 12px;
}
.tb-btn.accent { background: #16352f; border-color: #2f7d6f; color: #d9fff5; }
.tb-btn:hover { border-color: #4a5a75; }

/* ============ Main stage: fills remaining viewport ============ */
.stage {
  height: calc(100vh - 56px);
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto auto;
  gap: 10px; padding: 10px 12px;
}

/* Row 1: passport + frames */
.row-frames {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 10px; min-height: 0;
}
.passport {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 10px; overflow-y: auto;
}
.passport-grid { display: grid; gap: 10px; }
.passport-art {
  width: 100%; aspect-ratio: 5/7; border-radius: 8px; border: 1px solid var(--line);
  background: #0a0d12 center/contain no-repeat;
}
.passport-facts { display: grid; gap: 6px; }
.fact .k { color: var(--muted); font-size: 10px; margin-bottom: 1px; }
.fact .v { font-size: 12px; font-weight: 600; word-break: break-word; }
.fact .v.big { font-size: 16px; color: var(--accent); }

.frames-strip {
  display: grid;
  grid-template-columns: 1fr 1fr 1.1fr;
  gap: 10px; min-height: 0;
}
.frame {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden; display: flex; flex-direction: column; min-height: 0;
}
.frame-head {
  padding: 6px 10px; border-bottom: 1px solid var(--line);
  display: flex; align-items: baseline; gap: 8px;
}
.frame-kicker { color: var(--accent); font-size: 10px; letter-spacing: .08em; font-weight: 700; }
.frame-title { font-size: 13px; font-weight: 600; }
.rank-stage { padding: 8px; display: grid; gap: 5px; overflow: auto; }
.rank-row {
  display: grid; grid-template-columns: 20px 34px 1fr auto;
  gap: 6px; align-items: center; padding: 4px 6px;
  border-radius: 6px; background: #151a22; border: 1px solid #243041;
}
.rank-row.current { border-color: var(--accent); background: #172029; }
.rank-row .rk { color: var(--muted); font-size: 10px; text-align: right; }
.rank-row .nm { font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rank-row .px { color: var(--accent); font-size: 10px; font-weight: 650; }
.ship-thumb {
  width: 34px; height: 48px; border-radius: 3px; overflow: hidden; background: #0a0d12;
  display: flex; align-items: center; justify-content: center; flex: none;
  border: 1px solid #2a3140;
}
.ship-thumb img { width: 100%; height: 100%; object-fit: contain; display: block; }

.heat-stage {
  padding: 10px; display: grid; grid-template-columns: 1fr 1.1fr; gap: 8px;
  align-items: center; flex: 1; min-height: 0;
}
.heat-tile {
  --tile-w: 120px; --tile-h: 140px; --card-aspect: 0.714; --card-pct: 0.62;
  position: relative; width: var(--tile-w); height: var(--tile-h); margin: 0 auto;
  border-radius: 4px; overflow: hidden; background: #17b576;
}
.heat-tile.down { background: #dc567c; }
.heat-tile .tile-card {
  position: absolute; left: 50%; top: 50%;
  width: calc(var(--tile-h) * var(--card-pct) * var(--card-aspect));
  height: calc(var(--tile-h) * var(--card-pct));
  transform: translate(-50%, -50%);
  border-radius: 4px; overflow: hidden; background: #0a0d12;
  box-shadow: 0 2px 8px rgba(8,8,8,.22), 0 0 0 1px rgba(255,255,255,.1);
}
.heat-tile .tile-card img { width: 100%; height: 100%; object-fit: contain; display: block; }
.heat-tile .move { position: absolute; top: 4px; right: 5px; z-index: 3; font-size: 10px; font-weight: 800; color: #fff; text-shadow: 0 1px 2px rgba(0,0,0,.5); }
.heat-preview {
  border-radius: 8px; background: rgba(30,30,28,.97); border: 1px solid var(--line);
  overflow: hidden; display: grid; grid-template-columns: 80px 1fr; min-height: 120px;
}
.heat-preview .preview-image {
  padding: 8px; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(145deg, #1f1f1c, #121212);
}
.heat-preview .preview-image img { max-width: 100%; max-height: 100px; object-fit: contain; display: block; }
.heat-preview .preview-copy { color: var(--muted); font-size: 10px; line-height: 1.35; padding: 8px 8px 8px 0; }
.heat-preview .preview-copy strong { display: block; color: var(--text); font-size: 12px; margin-bottom: 2px; }

.detail-stage { padding: 8px; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; flex: 1; min-height: 0; }
.detail-art {
  border-radius: 8px; background: linear-gradient(155deg, #151922, #0c1016);
  border: 1px solid var(--line); display: flex; align-items: center; justify-content: center;
  padding: 6px; min-height: 0; overflow: hidden;
}
.detail-art img { max-width: 100%; max-height: 100%; object-fit: contain; display: block; }
.detail-copy h4 { margin: 0 0 4px; font-size: 14px; }
.detail-copy .line { color: var(--muted); font-size: 10px; margin: 0 0 2px; }
.detail-metrics { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; margin-top: 6px; }
.metric { background: #151a22; border: 1px solid var(--line); border-radius: 6px; padding: 5px 6px; }
.metric .k { color: var(--muted); font-size: 9px; }
.metric .v { font-size: 12px; font-weight: 700; margin-top: 1px; }

/* Row 2: wardrobe strip */
.row-wardrobe {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 8px 10px;
}
.wardrobe-head {
  display: flex; align-items: center; gap: 14px; margin-bottom: 8px;
}
.w-title { font-size: 13px; font-weight: 600; }
.w-hint { color: var(--muted); font-size: 11px; flex: 1; }
.w-status {
  border: 1px solid var(--line); border-radius: 999px; padding: 3px 10px;
  color: var(--muted); font-size: 11px; white-space: nowrap;
}
.w-status.on { color: #d9fff5; border-color: #2f7d6f; background: #16352f; }
.w-status.locked { color: #fff4d0; border-color: #8a6a1d; background: #3a2d10; }
.grid {
  display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px;
  scrollbar-width: thin;
}
.cand {
  position: relative; flex: 0 0 auto; width: 130px;
  border: 2px solid var(--line); border-radius: 8px; background: #0a0d12;
  overflow: hidden; cursor: pointer; transition: border-color .12s ease, transform .12s ease;
  text-align: left; color: inherit; padding: 0;
}
.cand:hover { border-color: #4a5a75; transform: translateY(-2px); }
.cand.trying { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.cand.locked { border-color: var(--accent-2); box-shadow: 0 0 0 1px rgba(240,180,41,.6); }
.cand.wronged { border-color: #7a3342; opacity: .65; }
.cand .hero {
  width: 130px; height: 170px; display: flex; align-items: center; justify-content: center;
  padding: 6px; position: relative;
}
.cand .hero img { max-width: 100%; max-height: 100%; object-fit: contain; display: block; }
.cand .cap {
  padding: 5px 8px; display: grid; gap: 1px; border-top: 1px solid var(--line);
  background: #10151c;
}
.cand .cap .title { font-size: 11px; font-weight: 650; }
.cand .cap .dims { color: var(--muted); font-size: 10px; }
.cand .hotkey {
  position: absolute; top: 6px; right: 6px; width: 20px; height: 20px; border-radius: 5px;
  display: grid; place-items: center; background: #1d2430; border: 1px solid var(--line);
  font-size: 10px; z-index: 2;
}
.cand .zoom-btn {
  position: absolute; top: 6px; left: 6px; border: 1px solid var(--line); background: rgba(27,34,48,.92);
  color: var(--text); border-radius: 5px; font-size: 9px; padding: 3px 6px; cursor: pointer; z-index: 2;
}
.cand .badge-try, .cand .badge-lock, .cand .badge-wrong {
  position: absolute; bottom: 34px; right: 6px; z-index: 2;
  border-radius: 999px; font-size: 10px; padding: 3px 7px; font-weight: 700;
}
.cand .badge-try { background: rgba(22,53,47,.95); color: #d9fff5; border: 1px solid #2f7d6f; }
.cand .badge-lock { background: rgba(58,45,16,.95); color: #fff4d0; border: 1px solid #8a6a1d; }
.cand .badge-wrong { background: rgba(74,31,40,.95); color: #ffd0d6; border: 1px solid #7a3342; }
.cand .stamp {
  position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none; z-index: 4;
  opacity: 0; transform: scale(1.2); transition: .15s ease;
}
.cand.locked .stamp.ok, .cand.wronged .stamp.bad, .cand.just-ok .stamp.ok, .cand.just-bad .stamp.bad {
  opacity: 1; transform: scale(1);
}
.stamp i {
  width: 56px; height: 56px; border-radius: 999px; display: grid; place-items: center;
  font-size: 30px; font-weight: 900; border: 3px solid currentColor;
  background: rgba(0,0,0,.4); backdrop-filter: blur(2px);
}
.stamp.ok { color: #63d391; }
.stamp.bad { color: #ff6b7a; }

/* Row 3: opsbar */
.opsbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 8px 12px;
}
.ops-left, .ops-right { display: flex; gap: 8px; }
.ops-mid { flex: 1; display: flex; justify-content: center; }
.note-inline { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 11px; }
.note-inline input {
  width: 240px; border: 1px solid var(--line); background: #0f131a; color: var(--text);
  border-radius: 6px; padding: 6px 10px; font-size: 12px;
}
.btn {
  border-radius: 8px; border: 1px solid var(--line); background: #1b2230; color: var(--text);
  padding: 8px 14px; cursor: pointer; font-size: 13px;
}
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: #1d4f46; border-color: #2f7d6f; }
.btn.danger { background: #4a1f28; border-color: #7a3342; }
.btn.ghost { background: transparent; }

/* Popover */
.popover {
  position: fixed; top: 64px; right: 16px; width: 280px; max-height: 60vh;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: 0 12px 40px rgba(0,0,0,.5); z-index: 90; display: flex; flex-direction: column;
}
.popover[hidden] { display: none !important; }
.pop-head { display: flex; justify-content: space-between; align-items: center; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.pop-close { border: 1px solid var(--line); background: #1b2230; color: var(--text); border-radius: 6px; padding: 4px 8px; cursor: pointer; font-size: 11px; }
.pop-list { margin: 0; padding: 10px 12px 10px 28px; color: var(--muted); font-size: 11px; overflow: auto; }
.pop-list li { margin: 0 0 6px; }

/* Lightbox */
.lightbox {
  position: fixed; inset: 0; background: rgba(5,8,12,.88); z-index: 100;
  display: grid; place-items: center; padding: 18px;
}
.lightbox[hidden] { display: none !important; }
.lightbox-card {
  width: min(920px, 96vw); background: #121820; border: 1px solid var(--line);
  border-radius: 12px; padding: 14px; box-shadow: 0 12px 40px rgba(0,0,0,.5);
}
.lightbox-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.lightbox img { display: block; max-width: 100%; max-height: calc(100vh - 180px); margin: 0 auto; object-fit: contain; }
.lb-close { border: 1px solid var(--line); background: #1b2230; color: var(--text); border-radius: 8px; padding: 8px 12px; cursor: pointer; }
.lb-meta { color: var(--muted); font-size: 12px; text-align: center; margin-top: 10px; }

/* FX burst */
.fx-layer { position: fixed; inset: 0; pointer-events: none; z-index: 95; display: grid; place-items: center; }
.fx-burst {
  width: 120px; height: 120px; border-radius: 999px;
  display: grid; place-items: center; font-size: 72px; font-weight: 900;
  opacity: 0; transform: scale(.6); animation: burst .7s ease forwards;
}
.fx-burst.ok { color: #63d391; text-shadow: 0 0 30px rgba(99,211,145,.6); }
.fx-burst.bad { color: #ff6b7a; text-shadow: 0 0 30px rgba(255,107,122,.55); }
@keyframes burst {
  0% { opacity: 0; transform: scale(.6); }
  25% { opacity: 1; transform: scale(1.15); }
  70% { opacity: 1; transform: scale(1); }
  100% { opacity: 0; transform: scale(.9); }
}

/* Toast */
.toast {
  position: fixed; right: 16px; bottom: 80px; background: #16352f; border: 1px solid #2f7d6f;
  color: #d9fff5; padding: 8px 12px; border-radius: 8px; opacity: 0; transform: translateY(8px);
  transition: .2s ease; pointer-events: none; z-index: 98; font-size: 12px;
}
.toast.show { opacity: 1; transform: none; }
.toast.bad { background: #4a1f28; border-color: #7a3342; color: #ffd0d6; }
.toast.ok { background: #16352f; border-color: #2f7d6f; color: #d9fff5; }

/* Responsive: stack on narrow */
@media (max-width: 1100px) {
  html, body { overflow: auto; height: auto; }
  .stage { height: auto; grid-template-rows: auto auto auto; }
  .row-frames { grid-template-columns: 1fr; }
  .frames-strip { grid-template-columns: 1fr; }
  .tb-center { display: none; }
}

/* Shared memory badge + private log note */
.sync-badge {
  font-size: 11px; color: var(--muted); border: 1px solid var(--line);
  border-radius: 999px; padding: 4px 8px; white-space: nowrap;
}
.sync-badge.ok { color: #b9f0d3; border-color: #2f7d6f; background: #12352d; }
.sync-badge.bad { color: #ffd0d6; border-color: #7a3342; background: #3a1a22; }
.pop-note { margin: 0; padding: 8px 12px 0; color: var(--muted); font-size: 11px; line-height: 1.45; }
