/* ---------- Theme tokens: dark (default) ---------- */
:root {
  --bg: #0f1420;
  --panel: #1a2233;
  --panel-2: #212c42;
  --accent: #4f8cff;
  --green: #34d399;
  --orange: #fbbf24;
  --red: #f87171;
  --text: #e7ecf5;
  --muted: #93a1b8;
  --border: #33405c;
  --radius: 14px;
}

/* ---------- Light theme (system preference) ---------- */
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #eef2f9;
    --panel: #ffffff;
    --panel-2: #e8eef8;
    --accent: #2f6fed;
    --green: #0e9f6e;
    --orange: #d97706;
    --red: #dc2626;
    --text: #1a2233;
    --muted: #5b6b84;
    --border: #c6d2e4;
  }
}

/* ---------- Manual overrides (toggle) ---------- */
:root[data-theme="dark"] {
  --bg: #0f1420;
  --panel: #1a2233;
  --panel-2: #212c42;
  --accent: #4f8cff;
  --green: #34d399;
  --orange: #fbbf24;
  --red: #f87171;
  --text: #e7ecf5;
  --muted: #93a1b8;
  --border: #33405c;
}
:root[data-theme="light"] {
  --bg: #eef2f9;
  --panel: #ffffff;
  --panel-2: #e8eef8;
  --accent: #2f6fed;
  --green: #0e9f6e;
  --orange: #d97706;
  --red: #dc2626;
  --text: #1a2233;
  --muted: #5b6b84;
  --border: #c6d2e4;
}

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

html, body {
  height: 100%;
}

body {
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  height: 100dvh; /* mobile: track the visible viewport, not the one behind the toolbar */
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* Compact header: the Siri orb floats above it (Dynamic Island style) only
   while the mic/teacher is active, so no idle space is reserved for it. */
header {
  text-align: center;
  padding: 22px 16px 4px;
  flex-shrink: 0;
}
header h1 { font-size: 1.3rem; letter-spacing: -0.5px; }
.subtitle { color: var(--muted); margin-top: 2px; font-size: 0.85rem; }

.header-controls {
  margin-top: 6px;
  display: flex;
  gap: 10px;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  font-size: 0.85rem;
  color: var(--muted);
}
.header-controls select, .header-controls input[type="range"] { accent-color: var(--accent); }

select, input[type="text"], input[type="password"] {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 0.9rem;
}

#aiPanel {
  position: absolute;
  top: 104px;
  left: 50%;
  transform: translateX(-50%);
  width: min(720px, 92vw);
  z-index: 50;
  box-shadow: 0 12px 40px rgba(0,0,0,0.55);
  padding: 16px;
  background: var(--panel);
  border-radius: var(--radius);
  font-size: 0.9rem;
}
#aiPanel h2 { font-size: 1.1rem; margin-bottom: 6px; }
#aiPanel p { color: var(--muted); margin-bottom: 10px; }
.ai-form { display: flex; flex-direction: column; gap: 8px; }

.modes {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin: 8px 0;
  flex-shrink: 0;
}
.mode-btn {
  padding: 10px 18px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.95rem;
  transition: all 0.15s;
}
.mode-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

main {
  width: min(860px, 96vw);
  margin: 0 auto 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex: 1;
  min-height: 0;
}

.panel {
  background: var(--panel);
  border-radius: var(--radius);
  padding: 16px 20px;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

/* Practice mode */
.level-row {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 10px;
  color: var(--muted);
}

.target-card {
  background: var(--panel-2);
  border-left: 4px solid var(--accent);
  border-radius: 10px;
  padding: 16px;
}
.label { color: var(--muted); font-size: 0.85rem; margin-bottom: 6px; }
.target-sentence { font-size: 1.3rem; line-height: 1.35; margin-bottom: 10px; }
.target-actions { display: flex; gap: 8px; flex-wrap: wrap; }

button.primary-btn {
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 8px;
  padding: 8px 16px;
  cursor: pointer;
  font-weight: 600;
}
button.primary-btn:hover { filter: brightness(1.1); }

button.ghost-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 7px 14px;
  cursor: pointer;
  font-size: 0.9rem;
}
button.ghost-btn:hover { border-color: var(--accent); }

/* Progress card + chart */
.progress-card {
  margin-top: 14px;
  background: var(--panel-2);
  border-radius: 10px;
  padding: 14px 16px;
}
.progress-head {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}
.progress-head h3 { font-size: 1rem; }
.progress-stats {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: 0.82rem;
  flex: 1;
}
.progress-stats b { color: var(--text); }
.ghost-btn.small { padding: 4px 8px; font-size: 0.8rem; }
.score-chart {
  width: 100%;
  height: 150px;
  display: block;
}


.result-card {
  margin-top: 14px;
  background: var(--panel-2);
  border-radius: 10px;
  padding: 16px;
}
.score-row { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
.score-badge {
  background: var(--accent);
  color: white;
  font-weight: 700;
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 1rem;
}
.score-badge.good { background: var(--green); }
.score-badge.mid { background: var(--orange); color: #1a2233; }
.score-badge.bad { background: var(--red); }
.score-text { color: var(--muted); }

.said-words {
  font-size: 0.95rem;
  color: var(--muted);
  background: color-mix(in srgb, var(--panel-2) 60%, transparent);
  border: 1px solid color-mix(in srgb, var(--border) 45%, transparent);
  border-radius: 8px;
  padding: 6px 10px;
  margin: 6px 0;
  word-break: break-word;
}
.word-by-word { font-size: 1.25rem; line-height: 1.8; margin: 8px 0; }
.word-by-word .ok { color: var(--green); }
.word-by-word .wrong { color: var(--red); text-decoration: line-through; }
.word-by-word .missing { color: var(--red); opacity: 0.85; }

.feedback { color: var(--text); font-style: italic; }

/* Conversation */
#conversationMode {
  display: flex;
  flex-direction: column;
}
#conversationMode.hidden { display: none !important; }
.chat-log {
  display: flex;
  flex-direction: column;
  gap: 12px;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}
.msg { max-width: 80%; padding: 12px 16px; border-radius: 14px; line-height: 1.45; }
.msg.teacher { background: var(--panel-2); align-self: flex-start; border-bottom-left-radius: 4px; }
.msg.student { background: var(--accent); color: white; align-self: flex-end; border-bottom-right-radius: 4px; }
.msg .msg-text b { color: inherit; }
.correction { color: var(--orange); font-size: 0.9rem; margin-top: 6px; }
.msg .replay { margin-top: 6px; background: none; border: none; color: var(--muted); cursor: pointer; font-size: 0.8rem; }
.msg .replay:hover { color: var(--text); }

/* Siri orb — original canvas orb: a glowing sphere with a thin rainbow
   rim, shown only while the mic or the teacher is active (no idle space
   reserved for it). Transparent: no dark sphere background. */
.siri-orb {
  position: fixed;
  top: 5px;
  left: 50%;
  width: 86px;
  height: 86px;
  transform: translateX(-50%) scale(0.5);
  opacity: 0;
  pointer-events: none;
  z-index: 30;
  transition: opacity 0.35s ease, transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
  /* No drop-shadow filter: it would cast a square halo around the canvas.
     The glow is drawn as a circular radial gradient inside the canvas. */
}
.siri-orb.active {
  opacity: 1;
  transform: translateX(-50%) scale(1);
}

/* Mic bar */
.mic-bar {
  position: sticky;
  bottom: 0;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 16px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 10px 20px;
  box-shadow: 0 8px 30px rgba(0,0,0,0.45);
}
.mic-btn {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: white;
  font-size: 1.5rem;
  cursor: pointer;
  transition: transform 0.15s, background 0.15s;
  flex-shrink: 0;
}
.mic-btn.listening {
  background: var(--red);
  animation: pulse 1.2s infinite;
}
@keyframes pulse {
  0%   { box-shadow: 0 0 0 0 rgba(248,113,113,0.6); }
  70%  { box-shadow: 0 0 0 18px rgba(248,113,113,0); }
  100% { box-shadow: 0 0 0 0 rgba(248,113,113,0); }
}
.mic-status { flex: 1; min-width: 0; }
.live-transcript {
  color: var(--muted);
  font-size: 0.95rem;
  margin-top: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

footer {
  text-align: center;
  color: var(--muted);
  font-size: 0.72rem;
  padding: 4px 12px 8px;
  flex-shrink: 0;
}
footer kbd {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 0 5px;
  font-family: inherit;
  font-size: 0.9em;
}
footer .credit {
  margin-top: 4px;
  font-size: 0.7rem;
  color: var(--muted);
}
footer .credit a {
  color: var(--muted);
  text-decoration: none;
  border-bottom: 1px dotted var(--muted);
}
footer .credit a:hover { color: var(--accent); border-color: var(--accent); }

/* Liquid glass accents (Apple-style translucent surfaces) */
.mic-bar {
  background: color-mix(in srgb, var(--panel-2) 72%, transparent);
  backdrop-filter: blur(14px) saturate(1.4);
  -webkit-backdrop-filter: blur(14px) saturate(1.4);
  border: 1px solid color-mix(in srgb, var(--border) 60%, transparent);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.08),
    0 8px 30px rgba(0, 0, 0, 0.35);
}
.target-card,
.result-card,
.progress-card {
  background: color-mix(in srgb, var(--panel-2) 82%, transparent);
  backdrop-filter: blur(10px) saturate(1.2);
  -webkit-backdrop-filter: blur(10px) saturate(1.2);
  border: 1px solid color-mix(in srgb, var(--border) 55%, transparent);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
}
.target-card { border-left: 4px solid var(--accent); }

.hidden { display: none !important; }

/* Keep the app-shell layout (panel scrolls internally, mic bar + footer stay
   pinned) even on short/narrow windows. Making the whole page scroll here used
   to let the panel content spill over the mic bar and the footer. */
@media (max-width: 600px), (max-height: 700px) {
  .target-sentence { font-size: 1.1rem; }
  .word-by-word { font-size: 1rem; }
}

/* Slim, theme-aware scrollbars (no arrows, no white track) */
* {
  scrollbar-width: thin;
  scrollbar-color: color-mix(in srgb, var(--muted) 45%, transparent) transparent;
}
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: color-mix(in srgb, var(--muted) 40%, transparent);
  border-radius: 8px;
}
::-webkit-scrollbar-thumb:hover {
  background: color-mix(in srgb, var(--muted) 60%, transparent);
}
::-webkit-scrollbar-button {
  display: none;
  height: 0;
  width: 0;
}
