:root {
  --primary: #1890ff;
  --primary-dark: #096dd9;
  --primary-light: #e6f7ff;
  --primary-border: #91d5ff;
  --bg: #f0f5fa;
  --panel-bg: #ffffff;
  --text: #1f2d3d;
  --text-light: #5a6d7e;
  --border: #d9e2ef;
  --success: #52c41a;
  --warning: #faad14;
  --danger: #f5222d;
  --shadow: 0 2px 8px rgba(24, 144, 255, 0.15);
  --font-size: 15px;
  --radius: 6px;
  --gap: 12px;
}

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

html, body {
  width: 100%; height: 100%; overflow: hidden;
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: var(--font-size); color: var(--text); background: var(--bg);
}

body {
  display: grid;
  grid-template-areas:
    "top    top"
    "view   log"
    "bottom bottom";
  grid-template-rows: 56px 1fr auto;
  grid-template-columns: 1fr 320px;
  height: 100vh;
}

#top-bar {
  grid-area: top;
  background: linear-gradient(180deg, #ffffff 0%, var(--primary-light) 100%);
  border-bottom: 2px solid var(--primary);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 var(--gap); box-shadow: var(--shadow); z-index: 10;
}

.mode-switcher { display: flex; gap: 8px; }

.mode-btn {
  padding: 8px 18px; border: 1px solid var(--primary-border);
  background: #fff; color: var(--text); font-size: 14px;
  border-radius: var(--radius); cursor: pointer; transition: all 0.2s;
}
.mode-btn:hover { border-color: var(--primary); color: var(--primary); }
.mode-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }

.status-display { display: flex; align-items: center; gap: 8px; }
.status-label { color: var(--text-light); }

.status-value {
  font-weight: 600; padding: 4px 12px; border-radius: 4px;
  background: var(--primary-light); color: var(--primary);
}
.status-normal { background: #f6ffed; color: var(--success); }
.status-fire {
  background: #fff1f0; color: var(--danger);
  animation: pulse-danger 1s ease-in-out infinite;
}
.status-fault { background: #fffbe6; color: var(--warning); }

@keyframes pulse-danger { 0%,100%{opacity:1} 50%{opacity:0.6} }

#viewport {
  grid-area: view; position: relative;
  background: #0a1a2a; overflow: hidden;
}

#three-canvas { display: block; width: 100%; height: 100%; cursor: grab; }
#three-canvas:active { cursor: grabbing; }

.overlay-tip {
  position: absolute; bottom: 16px; left: 50%; transform: translateX(-50%);
  background: rgba(24, 144, 255, 0.85); color: #fff;
  padding: 8px 16px; border-radius: 20px; font-size: 14px;
  pointer-events: none; transition: opacity 0.4s;
}

#event-log-panel {
  grid-area: log; background: var(--panel-bg);
  border-left: 1px solid var(--border);
  display: flex; flex-direction: column; overflow: hidden;
}

.log-header {
  padding: 10px var(--gap); border-bottom: 1px solid var(--border);
  background: var(--primary-light);
  display: flex; justify-content: space-between; align-items: center;
}
.log-header h3 { font-size: 15px; color: var(--primary); }
.log-actions { display: flex; gap: 6px; }

.mini-btn {
  padding: 4px 10px; font-size: 12px;
  border: 1px solid var(--primary-border); background: #fff;
  color: var(--primary); border-radius: 4px; cursor: pointer;
}
.mini-btn:hover { background: var(--primary); color: #fff; }

.event-log-list { list-style: none; flex: 1; overflow-y: auto; padding: 8px var(--gap); }
.event-log-list li {
  padding: 6px 8px; border-bottom: 1px dashed var(--border);
  font-size: 13px; color: var(--text); display: flex; gap: 8px;
}
.event-log-list li .log-time {
  color: var(--text-light); font-family: "Consolas", monospace; white-space: nowrap;
}
.event-log-list li.log-fire { background: #fff1f0; color: var(--danger); }
.event-log-list li.log-fault { background: #fffbe6; color: #ad6800; }
.event-log-list li.log-info { background: var(--primary-light); color: var(--primary); }

#bottom-bar {
  grid-area: bottom;
  background: linear-gradient(180deg, var(--primary-light) 0%, #ffffff 100%);
  border-top: 2px solid var(--primary);
  padding: var(--gap);
  display: flex; justify-content: space-between; align-items: center; gap: var(--gap);
}

.action-buttons { display: flex; gap: 10px; flex-wrap: wrap; }

.action-btn {
  padding: 10px 22px; border: 1px solid var(--primary);
  background: #fff; color: var(--primary);
  font-size: 14px; font-weight: 500;
  border-radius: var(--radius); cursor: pointer;
  transition: all 0.2s; min-width: 80px;
}
.action-btn:hover {
  background: var(--primary); color: #fff;
  box-shadow: 0 2px 6px rgba(24, 144, 255, 0.3);
}
.action-btn:active { transform: scale(0.97); }

.clock-display { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; }
.clock-label { font-size: 12px; color: var(--text-light); }
.clock-value {
  font-family: "Consolas", monospace; font-size: 18px;
  color: var(--primary); font-weight: 600;
}

#modal-container { position: fixed; inset: 0; pointer-events: none; z-index: 1000; }

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.45);
  display: flex; align-items: center; justify-content: center;
  z-index: 1001; animation: fadeIn 0.2s ease-out;
  pointer-events: auto;
}

.modal {
  background: #fff; border-radius: 10px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.2);
  min-width: 360px; max-width: 560px; padding: 24px;
  animation: slideUp 0.25s ease-out; border-top: 4px solid var(--primary);
}

.modal h3 { color: var(--primary); margin-bottom: 12px; font-size: 17px; }
.modal p { line-height: 1.6; margin-bottom: 16px; }

.modal-actions { display: flex; justify-content: flex-end; gap: 10px; }

.modal-btn {
  padding: 8px 20px; border-radius: var(--radius); cursor: pointer;
  font-size: 14px; border: 1px solid var(--primary);
  background: #fff; color: var(--primary); transition: all 0.2s;
}
.modal-btn.primary { background: var(--primary); color: #fff; }
.modal-btn:hover { opacity: 0.85; }

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

#guide-container { position: fixed; inset: 0; pointer-events: none; z-index: 800; }

.guide-bubble {
  position: absolute;
  background: linear-gradient(180deg, #fff 0%, var(--primary-light) 100%);
  border: 2px solid var(--success); border-radius: 10px;
  padding: 12px 16px; max-width: 280px; color: var(--text); font-size: 14px;
  box-shadow: 0 4px 16px rgba(82, 196, 26, 0.3);
  pointer-events: auto; animation: pulseGuide 2s ease-in-out infinite;
}
.guide-bubble.error {
  border-color: var(--danger);
  box-shadow: 0 4px 16px rgba(245, 34, 45, 0.3);
}
.guide-bubble::before {
  content: "下一步"; display: block; font-size: 12px;
  color: var(--success); font-weight: 600; margin-bottom: 4px;
}
.guide-bubble.error::before { content: "操作错误"; color: var(--danger); }

@keyframes pulseGuide {
  0%,100% { box-shadow: 0 4px 16px rgba(82,196,26,0.3); }
  50% { box-shadow: 0 4px 24px rgba(82,196,26,0.6); }
}

.hidden { display: none !important; }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--primary-border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--primary); }

/* ============= 启动欢迎弹窗 ============= */
.modal.welcome {
  max-width: 640px;
  border-top-color: #52c41a;
}

.modal.welcome h3 {
  color: #1890ff;
  font-size: 20px;
  border-bottom: 2px solid #e6f7ff;
  padding-bottom: 8px;
  margin-bottom: 16px;
}

.modal.welcome p {
  white-space: pre-line;
  line-height: 1.7;
  color: #1f2d3d;
}

/* ============= 键盘提示 ============= */
.action-btn::after {
  content: attr(data-key);
  position: absolute;
  top: 2px;
  right: 4px;
  font-size: 10px;
  color: rgba(24, 144, 255, 0.5);
  font-weight: normal;
}

.action-btn {
  position: relative;
}

/* ============= 视口光泽效果 ============= */
#viewport::after {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at 50% 30%, rgba(24, 144, 255, 0.08) 0%, transparent 60%);
  pointer-events: none;
}

/* ============= 指示灯 LED 增强 ============= */
.guide-bubble {
  max-width: 320px;
  font-size: 14px;
  line-height: 1.6;
}

/* ============= 演练触发按钮 ============= */
.drill-actions { display: flex; align-items: center; gap: 8px; }
.drill-label { color: var(--text-light); font-size: 13px; }
.drill-btn {
  padding: 7px 14px; font-size: 14px; cursor: pointer;
  border-radius: var(--radius); background: #fff; transition: all 0.2s;
}
.drill-btn.fire { border: 1px solid #ff7875; color: #f5222d; }
.drill-btn.fire:hover { background: #f5222d; color: #fff; border-color: #f5222d; }
.drill-btn.fault { border: 1px solid #ffd666; color: #d48806; }
.drill-btn.fault:hover { background: #faad14; color: #fff; border-color: #faad14; }

/* ============= 火警红色频闪叠加 ============= */
body.alarm-active #viewport::after {
  content: '';
  position: absolute; inset: 0; pointer-events: none;
  box-shadow: inset 0 0 120px rgba(245,34,45,0.55);
  animation: alarmFlash 0.7s ease-in-out infinite;
}
@keyframes alarmFlash {
  0%,100% { opacity: 0.35; }
  50% { opacity: 0.9; }
}

/* ============= 移动端 / 窄屏自适应 ============= */
@media (max-width: 820px) {
  html, body { height: auto; min-height: 100%; }

  body {
    grid-template-areas:
      "top"
      "view"
      "bottom"
      "log";
    grid-template-rows: auto auto auto auto;
    grid-template-columns: 1fr;
    height: auto;
    overflow-y: auto;
    -webkit-text-size-adjust: 100%;
  }

  #top-bar {
    height: auto; flex-wrap: wrap; gap: 8px;
    padding: 8px 10px; justify-content: center;
  }
  .mode-switcher { flex: 1 1 100%; justify-content: center; }
  .mode-btn { flex: 1; padding: 8px 6px; font-size: 13px; text-align: center; }
  .drill-actions { flex: 1 1 auto; justify-content: center; }
  .drill-label { display: none; }
  .status-display { font-size: 13px; }

  #viewport { height: 52vh; min-height: 260px; }
  .overlay-tip {
    font-size: 12px; padding: 6px 12px; bottom: 10px;
    width: 92%; text-align: center; white-space: normal;
  }

  #event-log-panel { border-left: none; border-top: 1px solid var(--border); }
  .event-log-list { max-height: 220px; }

  #bottom-bar { flex-wrap: wrap; gap: 8px; padding: 10px; justify-content: center; }
  .action-buttons { flex: 1 1 100%; justify-content: center; gap: 8px; }
  .action-btn { flex: 1 1 28%; min-width: 0; padding: 10px 4px; font-size: 14px; }
  .clock-display { width: 100%; flex-direction: row; align-items: center; justify-content: center; gap: 8px; }

  /* 弹窗自适应 */
  .modal { min-width: 0; width: 90vw; max-width: 92vw; padding: 18px; }
  .modal h3 { font-size: 16px; }
  .modal.welcome { max-width: 92vw; }
  .modal-actions { flex-wrap: wrap; }
  .modal-btn { flex: 1; padding: 10px; }
  .guide-bubble { max-width: 78vw; font-size: 13px; }
}

@media (max-width: 400px) {
  .action-btn { flex: 1 1 44%; }
  .mode-btn { font-size: 12px; padding: 8px 4px; }
}
/* 触屏拖动交给 3D 控制器,禁止页面滚动/缩放冲突 */
#three-canvas { touch-action: none; -webkit-tap-highlight-color: transparent; }
