:root {
  --bg: #0f1115;
  --panel: #171a21;
  --accent: #4f9dff;
  --accent2: #38d39f;
  --text: #e8eaf0;
  --muted: #8b93a7;
  --danger: #ff6b6b;
  --radius: 14px;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "PingFang TC", "Noto Sans TC", sans-serif;
  display: flex;
  justify-content: center;
}
#app {
  width: 100%;
  max-width: 720px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 16px;
  padding-top: calc(16px + env(safe-area-inset-top));
  padding-bottom: calc(16px + env(safe-area-inset-bottom));
  gap: 12px;
}
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
header h1 { font-size: 20px; margin: 0; }
.headerBtns { display: flex; gap: 8px; }
.iconBtn {
  background: var(--panel);
  border: none;
  color: var(--text);
  font-size: 20px;
  border-radius: 10px;
  padding: 8px 12px;
  cursor: pointer;
}
#scenarioBar {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--panel);
  padding: 10px 12px;
  border-radius: var(--radius);
}
#scenarioBar label { font-size: 13px; color: var(--muted); }
select, input, button {
  font-family: inherit;
}
#scenarioSelect {
  flex: 1;
  background: #0f1115;
  color: var(--text);
  border: 1px solid #2a2f3a;
  border-radius: 8px;
  padding: 6px 8px;
}
#resetBtn {
  background: #2a2f3a;
  color: var(--text);
  border: none;
  border-radius: 8px;
  padding: 6px 10px;
  cursor: pointer;
  font-size: 13px;
}
main#chatArea {
  flex: 1;
  background: var(--panel);
  border-radius: var(--radius);
  padding: 16px;
  overflow-y: auto;
  min-height: 300px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.msg {
  max-width: 80%;
  padding: 10px 14px;
  border-radius: 14px;
  line-height: 1.5;
  font-size: 15px;
  white-space: pre-wrap;
}
.msg.user {
  align-self: flex-end;
  background: var(--accent);
  color: #06111e;
}
.msg.ai {
  align-self: flex-start;
  background: #22262f;
  color: var(--text);
}
.msg.sys {
  align-self: center;
  color: var(--muted);
  font-size: 12px;
}
#correctionPanel {
  background: var(--panel);
  border-radius: var(--radius);
  padding: 12px 16px;
  max-height: 180px;
  overflow-y: auto;
}
#correctionPanel h3 { margin: 0 0 8px; font-size: 14px; color: var(--accent2); }
.correction-item {
  border-left: 3px solid var(--accent2);
  padding: 6px 10px;
  margin-bottom: 8px;
  font-size: 13px;
  background: #11151c;
  border-radius: 6px;
}
.correction-item .orig { color: var(--danger); text-decoration: line-through; }
.correction-item .fixed { color: var(--accent2); font-weight: 600; }
.correction-item .why { color: var(--muted); display: block; margin-top: 2px; }
.placeholder { color: var(--muted); font-size: 13px; }

footer#controls {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  background: var(--panel);
  border-radius: var(--radius);
  padding: 14px;
}
#liveTranscript {
  min-height: 18px;
  font-size: 13px;
  color: var(--muted);
}
.micBtn {
  width: 100%;
  padding: 16px;
  font-size: 16px;
  font-weight: 600;
  border: none;
  border-radius: 14px;
  background: var(--accent);
  color: #06111e;
  cursor: pointer;
  user-select: none;
}
.micBtn.recording {
  background: var(--danger);
  color: white;
  animation: pulse 1s infinite;
}
@keyframes pulse { 0%{opacity:1;} 50%{opacity:0.6;} 100%{opacity:1;} }
#status { font-size: 12px; color: var(--muted); }

.modal {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
  padding: 16px;
  box-sizing: border-box;
}
.modal.hidden { display: none; }
.modalBox {
  background: var(--panel);
  border-radius: var(--radius);
  padding: 20px;
  width: 90%;
  max-width: 420px;
  max-height: 85vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.modalBox label { font-size: 12px; color: var(--muted); margin-top: 6px; }
.modalBox input, .modalBox select {
  background: #0f1115;
  color: var(--text);
  border: 1px solid #2a2f3a;
  border-radius: 8px;
  padding: 8px 10px;
}
.modalBox .hint { font-size: 11px; color: var(--muted); line-height: 1.5; }
.modalBtns { display: flex; justify-content: flex-end; gap: 8px; margin-top: 10px; }
.modalBtns button {
  padding: 8px 16px;
  border: none;
  border-radius: 8px;
  cursor: pointer;
}
#saveSettings { background: var(--accent); color: #06111e; font-weight: 600; }
#closeSettings, #closeStats { background: #2a2f3a; color: var(--text); }
.dangerBtn { background: var(--danger); color: white; }
.hidden { display: none !important; }

.statsBox { max-width: 480px; max-height: 80vh; overflow-y: auto; }
.statsSummary {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 8px 0;
}
.statCard {
  background: #11151c;
  border-radius: 10px;
  padding: 10px;
  text-align: center;
}
.statCard .num { font-size: 22px; font-weight: 700; color: var(--accent); }
.statCard .lbl { font-size: 11px; color: var(--muted); margin-top: 2px; }
.statsBox h3 { font-size: 13px; color: var(--accent2); margin: 12px 0 6px; }
.catRow {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #11151c;
  border-radius: 8px;
  padding: 6px 10px;
  margin-bottom: 6px;
  font-size: 13px;
}
.catRow .bar {
  flex: 1;
  height: 6px;
  background: #2a2f3a;
  border-radius: 4px;
  margin: 0 10px;
  overflow: hidden;
}
.catRow .bar-fill { height: 100%; background: var(--accent2); }
.recentItem {
  font-size: 12px;
  border-left: 3px solid var(--danger);
  padding: 6px 10px;
  margin-bottom: 6px;
  background: #11151c;
  border-radius: 6px;
}
.recentItem .meta { color: var(--muted); font-size: 11px; display: block; margin-top: 2px; }
