:root {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-2: #334155;
  --surface-hover: #475569;
  --ink: #f8fafc;
  --muted: #94a3b8;
  --line: #475569;
  
  --brand: #2563eb;
  --brand-hover: #1d4ed8;
  --brand-tint: rgba(37, 99, 235, 0.15);
  
  --ok: #10b981;
  --ok-tint: rgba(16, 185, 129, 0.15);
  --bad: #ef4444;
  --bad-tint: rgba(239, 68, 68, 0.15);
  --warn: #f59e0b;
  --warn-tint: rgba(245, 158, 11, 0.15);
  
  --jira-blue: #0052cc;
  --jira-bg: #f4f5f7;
  --jira-ink: #172b4d;
  --jira-border: #dfe1e6;
  
  --shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.5), 0 8px 10px -6px rgba(0, 0, 0, 0.5);
  --font-sans: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans TC", sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  user-select: none;
  -webkit-user-select: none;
}

#scene {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  display: block;
  outline: none;
  cursor: grab;
}

#scene:active {
  cursor: grabbing;
}

/* 頂部 HUD */
.hud {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 10;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  background: rgba(30, 41, 59, 0.85);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}

.brand-section {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-title {
  font-weight: 700;
  font-size: 16px;
  letter-spacing: 0.02em;
  color: #38bdf8;
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand-title span {
  font-size: 11px;
  padding: 2px 6px;
  background: #0284c7;
  color: #fff;
  border-radius: 4px;
  font-weight: 600;
}

.meters {
  display: flex;
  align-items: center;
  gap: 16px;
}

.meter {
  display: flex;
  flex-direction: column;
}

.meter .m-k {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.meter .m-v {
  font-family: var(--font-mono);
  font-size: 16px;
  font-weight: 600;
}

.meter .m-v.ot { color: var(--bad); }

.snd-btn {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--ink);
  padding: 6px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 4px;
}
.snd-btn:hover { background: var(--surface-2); }

/* 下一步引導 (Guide Bar) */
.guide-bar {
  position: fixed;
  top: 66px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(15, 23, 42, 0.92);
  border: 1px solid var(--brand);
  padding: 6px 14px;
  border-radius: 30px;
  box-shadow: 0 4px 15px rgba(37, 99, 235, 0.25);
  max-width: 90vw;
}

.g-tag {
  background: var(--brand);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 12px;
}

.g-text {
  font-size: 13.5px;
  font-weight: 500;
  white-space: nowrap;
}

.g-nav {
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: #38bdf8;
  font-size: 12px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 14px;
  cursor: pointer;
  transition: all 0.2s;
}
.g-nav:hover {
  background: var(--brand);
  color: #fff;
}

/* 互動提示 (Interaction prompt near player) */
.prompt-bubble {
  position: fixed;
  z-index: 5;
  background: rgba(15, 23, 42, 0.9);
  border: 1px solid #38bdf8;
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  pointer-events: none;
  transform: translate(-50%, -100%);
  display: none;
  box-shadow: 0 4px 12px rgba(0,0,0,0.4);
}

/* 右側/底部工作面板 (Panel) */
.side-panel {
  position: fixed;
  right: 16px;
  bottom: 16px;
  width: 360px;
  max-height: calc(100vh - 84px);
  background: rgba(30, 41, 59, 0.92);
  backdrop-filter: blur(16px);
  border: 1px solid var(--line);
  border-radius: 10px;
  z-index: 10;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.panel-header {
  padding: 12px 16px;
  background: rgba(15, 23, 42, 0.5);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.panel-title {
  font-weight: 700;
  font-size: 13.5px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.chip-status {
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 4px;
  font-weight: 600;
  font-family: var(--font-mono);
}
.chip-status.blue { background: var(--brand-tint); color: #60a5fa; border: 1px solid var(--brand); }
.chip-status.red { background: var(--bad-tint); color: #f87171; border: 1px solid var(--bad); }
.chip-status.green { background: var(--ok-tint); color: #4ade80; border: 1px solid var(--ok); }

.panel-content {
  padding: 14px 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  flex: 1;
}

.task-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.task-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px;
  border-radius: 6px;
  background: var(--surface);
  border: 1px solid var(--line);
  font-size: 13px;
  transition: border-color 0.2s;
}
.task-item.active { border-color: #38bdf8; background: rgba(56, 189, 248, 0.05); }
.task-item.done { opacity: 0.6; text-decoration: line-through; }

.task-check {
  margin-top: 2px;
  width: 16px;
  height: 16px;
  border-radius: 4px;
  border: 1px solid var(--muted);
  display: grid;
  place-items: center;
  font-size: 11px;
}
.task-item.done .task-check { background: var(--ok); border-color: var(--ok); color: #fff; text-decoration: none; }

/* 對話視窗 (Dialog Box) */
.dialog-overlay {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 24px;
}
.dialog-overlay[hidden] { display: none; }

.dialog-card {
  width: min(720px, calc(100vw - 32px));
  background: var(--surface);
  border: 1px solid #38bdf8;
  border-radius: 12px;
  box-shadow: var(--shadow);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  animation: slideUp 0.25s ease-out;
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}

.dlg-header {
  padding: 10px 16px;
  background: rgba(15, 23, 42, 0.8);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.dlg-speaker {
  font-weight: 700;
  color: #38bdf8;
  display: flex;
  align-items: center;
  gap: 8px;
}
.dlg-speaker small {
  font-size: 11px;
  color: var(--muted);
  font-weight: 400;
}

.dlg-body {
  padding: 16px;
  font-size: 15px;
  line-height: 1.6;
  min-height: 70px;
}

.dlg-options {
  padding: 10px 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.dlg-opt {
  padding: 10px 14px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--ink);
  border-radius: 6px;
  cursor: pointer;
  text-align: left;
  font-size: 14px;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 10px;
}
.dlg-opt:hover {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}

/* 專有名詞 Tooltip 樣式 */
.term {
  color: #38bdf8;
  border-bottom: 1.5px dotted #38bdf8;
  cursor: pointer;
  font-weight: 600;
}
.term:hover {
  background: rgba(56, 189, 248, 0.15);
}

/* 模態彈窗 (Modal Windows: Test Terminal, JIRA Form) */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal-overlay[hidden] { display: none; }

.modal-window {
  width: 100%;
  max-width: 820px;
  max-height: 90vh;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: popIn 0.2s ease-out;
}

@keyframes popIn {
  from { opacity: 0; transform: scale(0.97); }
  to { opacity: 1; transform: scale(1); }
}

.modal-bar {
  padding: 12px 16px;
  background: #0f172a;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-bar-title {
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 10px;
}

.modal-close {
  background: transparent;
  border: 0;
  color: var(--muted);
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  padding: 4px;
}
.modal-close:hover { color: var(--ink); }

.modal-body {
  padding: 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* 小遊戲 1：測試終端機 (Automation Console) */
.console-box {
  background: #090d16;
  border: 1px solid #1e293b;
  border-radius: 6px;
  padding: 14px;
  font-family: var(--font-mono);
  font-size: 12.5px;
  color: #38bdf8;
  height: 240px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.console-line { line-height: 1.4; }
.console-line.err { color: #f87171; font-weight: 700; }
.console-line.ok { color: #4ade80; }
.console-line.warn { color: #fbbf24; }

.progress-track {
  width: 100%;
  height: 12px;
  background: var(--surface-2);
  border-radius: 6px;
  overflow: hidden;
  margin-top: 8px;
}
.progress-fill {
  height: 100%;
  width: 0%;
  background: #38bdf8;
  transition: width 0.3s;
}
.progress-fill.fail { background: var(--bad); }

/* 小遊戲 2：JIRA Form */
.jira-form {
  background: var(--jira-bg);
  color: var(--jira-ink);
  padding: 20px;
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  font-size: 13.5px;
}
.jira-header {
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 2px solid var(--jira-blue);
  padding-bottom: 8px;
}
.jira-logo {
  background: var(--jira-blue);
  color: #fff;
  font-weight: 900;
  padding: 2px 6px;
  border-radius: 3px;
  font-size: 13px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.form-group label {
  font-weight: 600;
  font-size: 12.5px;
  color: #5e6c84;
}
.form-control {
  padding: 8px 10px;
  border: 1px solid var(--jira-border);
  border-radius: 4px;
  font-family: inherit;
  font-size: 13.5px;
  color: inherit;
  background: #fff;
}
.form-control:focus {
  outline: 2px solid #4c9aff;
}
textarea.form-control {
  resize: vertical;
  min-height: 80px;
  font-family: var(--font-mono);
  font-size: 12px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 9px 18px;
  border-radius: 6px;
  font-weight: 600;
  cursor: pointer;
  border: 0;
  font-size: 14px;
  transition: all 0.2s;
}
.btn-primary {
  background: var(--brand);
  color: #fff;
}
.btn-primary:hover { background: var(--brand-hover); }
.btn-jira {
  background: var(--jira-blue);
  color: #fff;
}
.btn-jira:hover { background: #0065ff; }

/* 行話字典彈窗 (Glossary Modal) */
.glossary-card {
  padding: 14px;
  background: rgba(15, 23, 42, 0.95);
  border: 1px solid #38bdf8;
  border-radius: 8px;
  box-shadow: var(--shadow);
  max-width: 320px;
  position: fixed;
  z-index: 50;
  display: none;
}
.glossary-title {
  color: #38bdf8;
  font-weight: 700;
  font-size: 14px;
  margin-bottom: 4px;
}
.glossary-desc {
  color: #cbd5e1;
  font-size: 13px;
  line-height: 1.5;
}

/* 手機虛擬控制盤 (D-pad) */
.dpad {
  position: fixed;
  left: 20px;
  bottom: 20px;
  z-index: 15;
  display: grid;
  grid-template-columns: repeat(3, 48px);
  grid-template-rows: repeat(3, 48px);
  gap: 4px;
  display: none;
}
.dpad-btn {
  background: rgba(30, 41, 59, 0.85);
  border: 1px solid var(--line);
  color: var(--ink);
  font-size: 16px;
  border-radius: 8px;
  display: grid;
  place-items: center;
}
.dpad-btn:active { background: var(--brand); color: #fff; }
.dpad-u { grid-column: 2; grid-row: 1; }
.dpad-l { grid-column: 1; grid-row: 2; }
.dpad-r { grid-column: 3; grid-row: 2; }
.dpad-d { grid-column: 2; grid-row: 3; }

/* 小地圖 (Minimap) */
.minimap {
  position: fixed;
  left: 16px;
  top: 66px;
  width: 140px;
  height: 90px;
  background: rgba(15, 23, 42, 0.8);
  border: 1px solid var(--line);
  border-radius: 6px;
  z-index: 10;
  pointer-events: none;
}

@media (max-width: 860px) {
  .side-panel {
    left: 12px;
    right: 12px;
    width: auto;
    bottom: 12px;
    max-height: 40vh;
  }
  .dpad { display: grid; }
  .minimap { display: none; }
}
