:root {
  --bg: #16110d;
  --panel: #231b15;
  --panel-2: #2d241c;
  --line: #3e3228;
  --text: #f2e8dc;
  --muted: #b3a391;
  --accent: #e8a33d;
  --accent-2: #f5c46e;
  --good: #8fd16a;
  --bad: #ff6b5b;
  --radius: 14px;
}

* { box-sizing: border-box; }

html, body { margin: 0; height: 100%; }

body {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
  background: radial-gradient(1200px 600px at 50% -10%, #3b2a1b 0%, var(--bg) 60%) fixed, var(--bg);
  color: var(--text);
  font-family: "Noto Sans TC", "Microsoft JhengHei", "PingFang TC", system-ui, sans-serif;
  line-height: 1.5;
}

button { font: inherit; color: inherit; cursor: pointer; }
button:focus-visible { outline: 2px solid var(--accent-2); outline-offset: 2px; }

kbd {
  display: inline-block;
  min-width: 1.5em;
  padding: 0 5px;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 5px;
  background: var(--panel-2);
  font: 700 0.8em/1.6 system-ui, sans-serif;
  text-align: center;
  color: var(--accent-2);
}

.neg { color: var(--bad) !important; }
.pos { color: var(--good) !important; }
.gold { color: var(--accent-2); }

/* ── 頂部 ── */
.topbar {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 6px 16px;
  padding: 10px 20px;
  background: rgba(20, 15, 11, 0.85);
  border-bottom: 1px solid var(--line);
}
.brand { font-size: 1.15rem; font-weight: 800; letter-spacing: 0.05em; }
.brand small { margin-left: 6px; color: var(--muted); font-size: 0.75rem; font-weight: 500; letter-spacing: 0.1em; }
/* 頂部的「買導線」按鈕 */
.shop-btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 16px;
  border-radius: 999px;
  background: linear-gradient(180deg, var(--accent-2), var(--accent));
  color: #2a1806; font-weight: 800; text-decoration: none;
  box-shadow: 0 0 0 0 rgba(245, 196, 110, 0.6);
  animation: glow 2.6s ease-out infinite;
}
.shop-btn:hover { filter: brightness(1.08); }
.shop-btn .short { display: none; }
@keyframes glow { 0% { box-shadow: 0 0 0 0 rgba(245, 196, 110, 0.55); } 70%, 100% { box-shadow: 0 0 0 10px rgba(245, 196, 110, 0); } }

/* 左側的賣場卡片 */
.promo {
  flex: none;
  display: flex; flex-direction: column; gap: 8px;
  padding: 14px 16px;
  border-radius: var(--radius);
  background: linear-gradient(160deg, #2b2416 0%, #1f2a44 100%);
  border: 1px solid var(--accent);
  color: var(--text); text-decoration: none;
  transition: transform 0.15s, box-shadow 0.15s;
}
.promo:hover { transform: translateY(-2px); box-shadow: 0 10px 24px rgba(0, 0, 0, 0.4); }
.promo-kicker { color: var(--accent-2); font-size: 0.85rem; font-weight: 700; }
.promo-title { font-size: 1.15rem; letter-spacing: 0.02em; }
.promo-items { display: flex; flex-wrap: wrap; gap: 5px; }
.promo-items span { padding: 2px 8px; border-radius: 6px; background: rgba(255, 255, 255, 0.08); font-size: 0.8rem; }
.promo-note { color: var(--muted); font-size: 0.8rem; }
.promo-cta {
  align-self: stretch; padding: 8px; border-radius: 10px; text-align: center;
  background: linear-gradient(180deg, var(--accent-2), var(--accent));
  color: #2a1806; font-weight: 800;
}

.hud { display: flex; flex-wrap: wrap; gap: 4px 18px; color: var(--muted); }
.hud b { color: var(--text); font-variant-numeric: tabular-nums; }

/* ── 主畫面 ── */
.main { flex: 1; min-height: 0; display: flex; gap: 16px; padding: 16px; }

.side { flex: none; width: 260px; min-height: 0; display: flex; flex-direction: column; gap: 12px; }
.order-card {
  flex: 0 1 auto; min-height: 0;
  overflow: auto;
  padding: 16px;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
}
.card-empty { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 10px 0; text-align: center; }
.card-empty .big { font-size: 2rem; }
.card-empty span:last-child { color: var(--muted); font-size: 0.85rem; }
.card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.card-head small { display: block; color: var(--muted); font-size: 0.8rem; }
.avatar {
  display: grid; place-items: center; flex: none;
  width: 44px; height: 44px; border-radius: 50%;
  background: var(--panel-2); border: 1px solid var(--line);
  font-size: 1.5rem;
}
.card-row { display: flex; justify-content: space-between; padding: 5px 0; border-bottom: 1px dashed var(--line); font-size: 0.9rem; }
.card-row span { color: var(--muted); }
.card-row b { font-variant-numeric: tabular-nums; }
.tags { margin-top: 10px; }
.tag {
  display: inline-block; margin: 0 5px 5px 0; padding: 2px 9px;
  border-radius: 999px; font-size: 0.8rem;
  background: rgba(232, 163, 61, 0.15); border: 1px solid rgba(232, 163, 61, 0.45); color: var(--accent-2);
}
.tag-pref { background: rgba(91, 192, 235, 0.12); border-color: rgba(91, 192, 235, 0.45); color: #9fdaf3; }
.progress { display: flex; flex-direction: column; gap: 3px; margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--line); font-size: 0.85rem; }
.progress-title { color: var(--muted); font-size: 0.8rem; margin-bottom: 2px; }
.step { color: var(--muted); }
.step.done { color: var(--good); }

.game-wrap { position: relative; flex: 1; min-width: 0; min-height: 0; display: flex; align-items: center; justify-content: center; }
.stage {
  position: relative;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 0 0 1px var(--line), 0 20px 50px rgba(0, 0, 0, 0.5);
}
.stage canvas { display: block; width: 100%; height: 100%; }

/* 設備名牌：平常淡淡的，靠近時亮起來並顯示 E，目標設備有跳動的箭頭 */
.tags-layer { position: absolute; inset: 0; pointer-events: none; transition: opacity 0.15s; }
.tags-layer.hidden { opacity: 0; }
/* 平常不顯示，靠近或是「下一步」的目標才出現，讓畫面保持乾淨 */
.st-tag {
  position: absolute;
  display: flex; flex-direction: column; align-items: center;
  transform: translate(-50%, -100%);
  white-space: nowrap;
  opacity: 0;
  transition: opacity 0.2s;
}
.st-tag.is-near, .st-tag.is-target { opacity: 1; }
.st-label {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 9px;
  border-radius: 999px;
  background: rgba(20, 15, 11, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.18);
  font-size: 0.78rem; font-weight: 700;
  color: rgba(242, 232, 220, 0.85);
  transition: transform 0.15s, background 0.15s, border-color 0.15s;
}
.st-label kbd { display: none; }
.st-arrow { display: none; color: var(--accent-2); font-size: 0.9rem; line-height: 1; text-shadow: 0 1px 2px #000; }

.st-tag.is-target .st-label { border-color: var(--accent); color: var(--accent-2); }
.st-tag.is-target .st-arrow { display: block; animation: bob 0.9s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(3px); } }

.st-tag.is-near { z-index: 2; }
.st-tag.is-near .st-label {
  transform: scale(1.12);
  background: var(--accent);
  border-color: var(--accent-2);
  color: #2a1806;
}
.st-tag.is-near .st-label kbd { display: inline-block; background: #2a1806; border-color: #2a1806; color: var(--accent-2); }

.compact .st-name { display: none; }
.compact .st-tag.is-near .st-name, .compact .st-tag.is-target .st-name { display: inline; }
.compact .st-label { padding: 1px 6px; font-size: 0.72rem; }

/* 下一步 */
.objective {
  position: absolute; left: 50%; bottom: 8px; transform: translateX(-50%);
  display: flex; align-items: center; gap: 8px;
  max-width: calc(100% - 16px);
  padding: 5px 14px 5px 5px;
  border-radius: 999px;
  background: rgba(20, 15, 11, 0.88);
  border: 1px solid var(--accent);
  font-size: 0.9rem; font-weight: 700;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  pointer-events: none;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.4);
}
.obj-label { flex: none; padding: 1px 9px; border-radius: 999px; background: var(--accent); color: #2a1806; font-size: 0.78rem; }
.busy .objective { opacity: 0; }

.footer { display: flex; justify-content: center; align-items: center; gap: 20px; padding: 0 16px 12px; color: var(--muted); font-size: 0.85rem; }
.keys-help kbd { margin: 0 1px; }
.link { background: none; border: none; color: var(--muted); text-decoration: underline; font-size: 0.85rem; }

/* ── 對話框 ── */
.dialog {
  position: fixed; z-index: 20;
  left: 50%; bottom: 20px; transform: translateX(-50%);
  width: min(720px, calc(100% - 32px));
  display: flex; gap: 14px;
  padding: 16px 18px;
  background: rgba(24, 18, 13, 0.97);
  border: 2px solid var(--accent);
  border-radius: 14px;
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.6);
  cursor: pointer;
  animation: rise 0.18s ease-out;
}
.dialog[hidden] { display: none; }
@keyframes rise { from { transform: translate(-50%, 10px); opacity: 0; } to { transform: translateX(-50%); opacity: 1; } }
.dlg-avatar {
  flex: none; display: grid; place-items: center;
  width: 64px; height: 64px; border-radius: 12px;
  background: var(--panel-2); border: 1px solid var(--line);
  font-size: 2.2rem;
}
.dlg-main { position: relative; flex: 1; min-width: 0; }
.dlg-name { color: var(--accent-2); font-weight: 800; }
.dlg-text { margin: 4px 0 0; min-height: 3em; font-size: 1.02rem; }
.dlg-choices { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.choice {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 8px 14px;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--panel-2);
  font-weight: 700;
}
.choice:hover, .choice:focus-visible { border-color: var(--accent); background: rgba(232, 163, 61, 0.16); outline: none; }
.choice .num { color: var(--muted); font-size: 0.8rem; }
.dlg-next { position: absolute; right: 0; bottom: -6px; color: var(--accent); animation: blink 1s steps(2) infinite; }
.dlg-next[hidden] { display: none; }
@keyframes blink { 50% { opacity: 0; } }
.ledger { display: flex; flex-wrap: wrap; gap: 4px 16px; margin-top: 8px; color: var(--muted); font-size: 0.9rem; }
.ledger b { color: var(--text); font-variant-numeric: tabular-nums; }

/* ── 設備面板 ── */
.panel {
  position: fixed; z-index: 15; top: 0; right: 0; bottom: 0;
  width: min(440px, 100%);
  display: flex; flex-direction: column;
  background: var(--panel);
  border-left: 1px solid var(--line);
  box-shadow: -20px 0 50px rgba(0, 0, 0, 0.5);
  animation: slide 0.2s ease-out;
}
.panel[hidden] { display: none; }
@keyframes slide { from { transform: translateX(30px); opacity: 0; } to { transform: none; opacity: 1; } }
.panel-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.panel-head h2 { margin: 0; font-size: 1.1rem; }
.panel-close { padding: 6px 12px; border: 1px solid var(--line); border-radius: 999px; background: var(--panel-2); }
.panel-body { flex: 1; overflow: auto; padding: 14px 16px 24px; }
.panel-desc { margin: 0 0 12px; color: var(--muted); font-size: 0.9rem; }

.workbench { display: grid; grid-template-columns: 96px 1fr; gap: 14px; align-items: center; padding: 12px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 12px; }
.mini-preview svg { display: block; width: 100%; height: auto; }
.mini-stats { display: grid; gap: 7px; }
.stat { display: grid; grid-template-columns: 34px 1fr 30px; align-items: center; gap: 8px; font-size: 0.85rem; }
.stat-label { color: var(--muted); }
.stat-val { text-align: right; font-variant-numeric: tabular-nums; }
.bar { position: relative; height: 10px; border-radius: 5px; background: #120d0a; }
.fill { display: block; height: 100%; border-radius: 5px; transition: width 0.3s ease; }
.target { position: absolute; top: -4px; bottom: -4px; width: 3px; margin-left: -1.5px; background: #fff; border-radius: 2px; box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.6); }
.legend { display: flex; align-items: center; gap: 6px; margin: 2px 0 0; color: var(--muted); font-size: 0.75rem; }
.legend-mark { display: inline-block; width: 3px; height: 11px; background: #fff; border-radius: 2px; }

.slot-title { margin: 18px 0 8px; font-size: 0.95rem; color: var(--accent-2); }
.options { display: grid; gap: 8px; }
.opt {
  display: flex; flex-direction: column; gap: 4px;
  padding: 10px 12px;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px;
  text-align: left;
  transition: border-color 0.15s, background 0.15s;
}
.opt:hover:not(:disabled) { border-color: var(--accent); }
.opt.selected { border-color: var(--accent); background: rgba(232, 163, 61, 0.14); box-shadow: inset 3px 0 0 var(--accent); }
.opt:disabled { opacity: 0.45; cursor: not-allowed; }
.opt-head { display: flex; align-items: center; gap: 8px; }
.opt-name { flex: 1; font-weight: 700; }
.opt-price { color: var(--accent-2); font-size: 0.85rem; font-variant-numeric: tabular-nums; }
.opt-desc { color: var(--muted); font-size: 0.82rem; }
.opt-stats { display: flex; flex-wrap: wrap; gap: 4px; }
.mini {
  padding: 1px 7px; border-radius: 6px; font-size: 0.75rem;
  background: color-mix(in srgb, var(--c) 18%, transparent);
  color: color-mix(in srgb, var(--c) 70%, white);
}
.swatch { flex: none; width: 18px; height: 18px; border-radius: 50%; border: 1px solid rgba(255, 255, 255, 0.25); }

.amp-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 14px; }
.btn {
  padding: 9px 16px;
  border: 1px solid var(--line); border-radius: 999px;
  background: var(--panel-2);
  font-weight: 700;
}
.btn:hover { border-color: var(--accent); }
.btn:active { transform: scale(0.97); }
.amp { display: flex; align-items: center; gap: 4px; padding: 3px 3px 3px 12px; border: 1px solid var(--line); border-radius: 999px; }
.amp > span { margin-right: 4px; color: var(--muted); font-size: 0.85rem; }
.seg { padding: 5px 11px; border: none; border-radius: 999px; background: transparent; color: var(--muted); }
.seg.active { background: var(--accent); color: #2a1806; font-weight: 700; }

.cost { margin-top: 16px; padding-top: 10px; border-top: 1px solid var(--line); }
.cost div { display: flex; justify-content: space-between; padding: 3px 0; }
.cost span { color: var(--muted); }
.cost b { font-variant-numeric: tabular-nums; }

/* ── 手機操作 ── */
.touch { display: none; }
@media (pointer: coarse) {
  .touch {
    position: fixed; z-index: 10; left: 0; right: 0; bottom: 0;
    display: flex; justify-content: space-between; align-items: flex-end;
    padding: 0 20px calc(20px + env(safe-area-inset-bottom));
    pointer-events: none;
  }
  .busy .touch { display: none; }
  .joy {
    position: relative; width: 120px; height: 120px; border-radius: 50%;
    background: rgba(255, 255, 255, 0.08); border: 2px solid rgba(255, 255, 255, 0.18);
    pointer-events: auto; touch-action: none;
  }
  .joy-knob {
    position: absolute; left: 50%; top: 50%; width: 52px; height: 52px; margin: -26px 0 0 -26px;
    border-radius: 50%; background: rgba(245, 196, 110, 0.85);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
  }
  .act-btn {
    min-width: 84px; height: 84px; padding: 0 12px; border-radius: 42px;
    background: rgba(45, 36, 28, 0.9); border: 2px solid var(--line);
    font-weight: 800; color: var(--muted);
    pointer-events: auto; touch-action: manipulation;
  }
  .act-btn.ready { background: var(--accent); border-color: var(--accent-2); color: #2a1806; }
  .keys-help { display: none; }
}

/* ── 窄螢幕 ── */
@media (max-width: 900px) {
  .topbar { padding: 8px 16px; }
  .brand small { display: none; }
  .main { flex-direction: column; gap: 10px; padding: 10px 16px; }
  .side { width: 100%; }
  .order-card { max-height: 28vh; padding: 10px 12px; }
  .promo { display: none; }
  .shop-btn { padding: 4px 12px; font-size: 0.9rem; }
  .shop-btn .long { display: none; }
  .shop-btn .short { display: inline; }
  .card-empty { flex-direction: row; flex-wrap: wrap; justify-content: center; padding: 0; }
  .card-empty .big { font-size: 1.3rem; }
  .game-wrap { align-items: flex-start; }
  .panel { top: auto; height: 72vh; width: 100%; border-left: none; border-top: 1px solid var(--line); border-radius: 18px 18px 0 0; }
  .dialog { bottom: calc(12px + env(safe-area-inset-bottom)); padding: 12px; gap: 10px; }
  .dlg-avatar { width: 46px; height: 46px; font-size: 1.6rem; }
}

/* ── 頂部小按鈕（怎麼玩、換角色）── */
.top-actions { display: flex; gap: 6px; }
.top-btn {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 5px 12px;
  border: 1px solid var(--line); border-radius: 999px;
  background: var(--panel-2);
  font-size: 0.85rem; font-weight: 700;
}
.top-btn:hover { border-color: var(--accent); }

/* ── 像素頭像 ── */
img.px { display: block; width: 100%; height: 100%; object-fit: contain; image-rendering: pixelated; }
.avatar img.px { width: 86%; height: 86%; }

/* ── 說明卡、選角色 ── */
.modal {
  position: fixed; inset: 0; z-index: 30;
  display: grid; place-items: center;
  padding: 16px;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(3px);
}
.modal[hidden] { display: none; }
.modal-card {
  width: min(600px, 100%);
  max-height: calc(100dvh - 32px); overflow: auto;
  padding: 22px;
  background: var(--panel); border: 1px solid var(--accent); border-radius: 18px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
  animation: pop-in 0.22s ease-out;
}
@keyframes pop-in { from { transform: scale(0.96); opacity: 0; } to { transform: none; opacity: 1; } }
.help-title { margin: 0 0 4px; font-size: 1.3rem; }
.help-lead { margin: 0 0 14px; color: var(--muted); }

.flow { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.flow li {
  position: relative;
  display: grid; grid-template-columns: 26px 30px 1fr; align-items: center; gap: 8px;
  padding: 8px 12px;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px;
}
.flow li b { display: block; }
.flow li small { color: var(--muted); font-size: 0.85rem; }
.flow-num {
  display: grid; place-items: center; width: 24px; height: 24px; border-radius: 50%;
  background: var(--line); font-size: 0.8rem; font-weight: 800;
}
.flow-icon { font-size: 1.3rem; text-align: center; }
.flow li.key { border-color: var(--accent); background: rgba(232, 163, 61, 0.14); }
.flow li.key .flow-num { background: var(--accent); color: #2a1806; }
.flow li.key small { color: var(--accent-2); font-weight: 700; }
.help-tips { margin: 14px 0 0; padding-left: 20px; color: var(--muted); font-size: 0.9rem; }
.help-tips b { color: var(--text); }
.help-keys { display: flex; flex-wrap: wrap; gap: 6px 18px; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line); color: var(--muted); font-size: 0.85rem; }

.chars { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.char {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 10px 6px;
  background: var(--panel-2); border: 2px solid var(--line); border-radius: 12px;
  font-weight: 700;
}
.char img.px { width: 100%; height: auto; aspect-ratio: 24 / 30; }
.char:hover { border-color: var(--accent); }
.char.selected { border-color: var(--accent-2); background: rgba(232, 163, 61, 0.16); box-shadow: 0 0 0 3px rgba(245, 196, 110, 0.25); }

/* ── 設備面板裡的試音提示、進度說明 ── */
.amp-hint {
  margin: 16px 0 0; padding: 10px 12px;
  border: 1px dashed var(--accent); border-radius: 10px;
  background: rgba(232, 163, 61, 0.08);
  color: var(--accent-2); font-size: 0.88rem; font-weight: 700;
}
.step small { margin-left: 6px; font-size: 0.75rem; opacity: 0.8; }

@media (max-width: 900px) {
  .top-btn span { display: none; }
  .top-btn { padding: 4px 9px; }
  .chars { grid-template-columns: repeat(3, 1fr); }
  .char img.px { width: 70%; }
}

.modal-card .btn.primary {
  display: block; width: 100%; margin-top: 16px; padding: 12px;
  border: none; border-radius: 12px;
  background: linear-gradient(180deg, var(--accent-2), var(--accent));
  color: #2a1806; font-size: 1.05rem; font-weight: 800;
}
