/* ==========================================================================
   components.css — interactive UI
   Buttons, modals, exam, notes, grid, analytics, popups, accordion.
   ========================================================================== */

/* ==========================================================================
   ICON BUTTONS (top bar)
   ========================================================================== */
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  padding: 0;
  border: 1px solid var(--control-border);
  border-radius: 6px;
  background: var(--control-bg);
  color: var(--text-primary);
  transition: transform var(--dur-fast) var(--ease),
              background-color var(--dur-slow) var(--ease),
              color var(--dur-slow) var(--ease),
              border-color var(--dur-slow) var(--ease);
}
.icon-btn:hover  { transform: scale(1.08); }
.icon-btn:active { transform: scale(0.95); }

.icon-btn:hover,
.account-btn:hover {
  border-color: #6366F1;
  color: #6366F1;
}

#sidebar-toggle:hover,
#lang-toggle:hover,
#account-toggle:hover {
  border-color: var(--focus-ring);
  color: var(--focus-ring);
}

/* Account state icons */
#account-toggle .icon-logged-in,
#account-toggle.signed-in .icon-logged-out { display: none; }
#account-toggle.signed-in .icon-logged-in,
#account-toggle .icon-logged-out { display: inline-block; }

/* Theme icons (3-state) */
#theme-toggle svg { display: none !important; }
[data-theme="dark"]          #theme-toggle .icon-moon  { display: block !important; }
[data-theme="light"]         #theme-toggle .icon-sun   { display: block !important; }
[data-theme="cybersecurity"] #theme-toggle .icon-cyber { display: block !important; }

/* ==========================================================================
   ACCORDION
   ========================================================================== */
.acc-section { border-radius: 6px; overflow: hidden; flex-shrink: 0; }

.acc-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 700;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
  border-radius: 6px;
  transition: background var(--dur-fast);
}
.acc-header:hover { background: var(--bg-surface); }

.acc-chevron {
  font-size: 16px;
  color: var(--text-muted);
  transition: transform var(--dur-mid) var(--ease);
}
.acc-section.open .acc-chevron { transform: rotate(90deg); }

.acc-body {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows var(--dur-mid) var(--ease);
}
.acc-section.open .acc-body { grid-template-rows: 1fr; }

.acc-body-inner {
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 0 8px;
  min-height: 0;
}
.acc-section.open .acc-body-inner { padding: 4px 8px 8px; }

/* ==========================================================================
   FORM CONTROLS
   ========================================================================== */
.ctrl-input,
.ctrl-select {
  width: 100%;
  padding: 6px 10px;
  border: 1px solid var(--control-border);
  border-radius: 8px;
  background-color: var(--control-bg);
  color: var(--text-primary);
  font-size: 17px;
  margin-bottom: 12px;
  color-scheme: dark;
}
[data-theme="light"] .ctrl-input,
[data-theme="light"] .ctrl-select {
  color-scheme: light;
}
.ctrl-select option {
  background-color: var(--bg-surface-2);
  color: var(--text-primary);
}

.ctrl-btn {
  padding: 8px 10px;
  border: 1px solid var(--control-border);
  border-radius: 6px;
  background: var(--control-bg);
  color: var(--text-primary);
  font-size: 14px;
  font-weight: 500;
  min-height: 36px;
  transition: background var(--dur-fast), border-color var(--dur-fast);
}
.ctrl-btn:hover {
  background: var(--bg-surface-2);
  border-color: var(--text-muted);
}

.ctrl-row { display: flex; gap: 6px; }
.ctrl-row .ctrl-btn { flex: 1; }
.ctrl-row .ctrl-btn.half { flex: 0 0 calc(50% - 3px); }

.ctrl-label {
  font-size: 12px;
  color: var(--text-muted);
  margin: 0 0 8px 0;
}
.speed-value { color: var(--accent-mid); }

select:focus,
input:focus {
  border-color: var(--focus-ring);
}

/* ==========================================================================
   SPEED SLIDER (inside #m-speed-popup)
   ========================================================================== */
.slider { width: 100%; }

#m-speed-popup #speed-slider {
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
  width: calc(100% - 16px);
  margin: 8px;
  outline: none;
}
#m-speed-popup #speed-slider::-webkit-slider-runnable-track {
  background: var(--focus-ring);
  height: 6px;
  border-radius: 3px;
}
#m-speed-popup #speed-slider::-moz-range-track {
  background: var(--focus-ring);
  height: 6px;
  border-radius: 3px;
}
#m-speed-popup #speed-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  background: var(--focus-ring);
  height: 18px;
  width: 18px;
  border-radius: 50%;
  margin-top: -6px;
  border: 1px solid var(--border-color);
}
#m-speed-popup #speed-slider::-moz-range-thumb {
  background: var(--bg-surface);
  height: 18px;
  width: 18px;
  border-radius: 50%;
  border: 1px solid var(--border-color);
}

/* ==========================================================================
   PLAYBACK BUTTONS
   ========================================================================== */
.pb-btn {
  width: 44px;
  height: 44px;
  border: none;
  background: transparent;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: background-color var(--dur-fast), transform 0.1s;
}
.pb-btn:hover  { background: var(--accent-soft); }
.pb-btn:active { transform: scale(0.94); }

.pb-btn svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: url(#gradB);
  stroke-width: 2.4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.pb-btn.play-pause {
  width: 30px;
  height: 26px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent-light), var(--accent-mid) 60%, var(--accent-deep));
  box-shadow: 0 3px 10px var(--accent-glow);
}
.pb-btn.play-pause svg { width: 20px; height: 20px; fill: #fff; stroke: none; }
.pb-btn.play-pause:hover {
  background: linear-gradient(135deg, var(--accent-light), var(--accent-mid) 60%, var(--accent-deep));
  transform: translateY(-1px);
}

.pb-btn.play-pause .icon-pause { display: none; }
.pb-btn.play-pause .icon-play  { display: block; }
.pb-btn.play-pause.is-playing .icon-play  { display: none; }
.pb-btn.play-pause.is-playing .icon-pause { display: block; }

.pb-btn.loop-off svg { opacity: 0.35; }
.pb-btn.loop-on      { background: var(--accent-soft); }
.pb-btn.loop-on svg  { opacity: 1; }

/* Playback bar buttons are smaller */
.mobile-playback-bar .pb-btn {
  width: 30px;
  height: 30px;
  flex: 0 0 auto;
  padding: 0;
}
.mobile-playback-bar .pb-btn svg { width: 20px; height: 20px; }

/* ==========================================================================
   MOBILE POPUPS (rendered as body-level children)
   ========================================================================== */
.mobile-popup {
  display: none;
  flex-direction: column;
  gap: 2px;
  position: fixed;
  right: 8px;
  bottom: 48px; /* 40px bar + 8px gap */
  max-height: 50vh;
  overflow-y: auto;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  box-shadow: var(--shadow-popup);
  padding: 6px;
  z-index: var(--z-topbar); /* Make sure it's above everything */
  min-width: 130px;
}
.mobile-popup.visible { display: flex; animation: pop-in 0.15s ease; transform-origin: bottom center; }

.mobile-popup-item {
  padding: 10px 14px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-primary);
  text-align: left;
  font-size: 15px;
  border-radius: 6px;
  min-height: 40px;
  cursor: pointer;
}
.mobile-popup-item:hover,
.mobile-popup-item:active {
  background: var(--accent-soft);
}

/* ==========================================================================
   HINT CARD
   ========================================================================== */
.hint-card {
  background: linear-gradient(135deg, var(--accent-soft), rgba(11, 79, 92, 0.12));
  border: 1px solid var(--accent-mid);
  border-radius: 8px;
  padding: 12px 14px;
  position: relative;
  flex-shrink: 0;
  max-height: 26vh;
  overflow-x: hidden;
}
.hint-card h4 {
  margin: 0 0 6px;
  font-size: 14px;
  color: var(--focus-ring);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.hint-card p {
  margin: 0;
  font-size: 16px;
  line-height: 1.45;
  padding-right: 20px;
}

.hint-dismiss {
  position: absolute;
  top: 8px;
  right: 10px;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 22px;
  padding: 0;
  line-height: 1;
}
.hint-dismiss:hover { color: var(--text-primary); }

.hint-card .hint-list {
  margin: 10px 0 0;
  padding-left: 18px;
  list-style: disc;
  font-size: 15px;
  line-height: 1.6;
  color: var(--text-muted);
}
.hint-card .hint-list li { margin-bottom: 4px; }
.hint-card .hint-list strong { color: var(--text-primary); font-weight: 600; }

/* ==========================================================================
   SPREADSHEET GRID
   ========================================================================== */
.spreadsheet-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-auto-rows: min-content;
  align-content: start;
  border-top: 1px solid var(--border-strong);
  border-left: 1px solid var(--border-strong);
  background-color: var(--bg-surface);
  border-radius: 8px;
  flex: 0 1 auto;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  position: relative;
}

.cell {
  padding: 6px;
  border-right: 1px solid var(--border-strong);
  border-bottom: 1px solid var(--border-strong);
  min-height: 42px;
  font-size: 18px;
  line-height: 1.5;
  box-sizing: border-box;
}

.header-cell {
  position: sticky;
  top: 0;
  z-index: 2;
  background-color: var(--bg-surface-2);
  background-color: color-mix(in srgb, var(--bg-surface-2), #000 14%);
  color: var(--text-primary);
  font-weight: 700;
  text-align: center;
  user-select: none;
  padding: 0 10px 0 8px;
}
.header-cell .header-split-wrapper {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  height: 100%;
  gap: 6px;
}
.header-cell .header-label {
  cursor: pointer;
  font-size: 15px;
  display: block;
  flex: 1;
  text-align: left;
}
.header-cell .header-sort-btn {
  background-color: var(--control-bg);
  border: 1px solid var(--control-border);
  color: var(--text-primary);
  border-radius: 4px;
  font-size: 20px;
  font-weight: 600;
  padding: 2px 12px;
  min-height: 32px;
  transition: background var(--dur-fast);
}
.header-cell .header-sort-btn:hover { background-color: var(--bg-elevated); }
.header-cell .header-sort-btn.sort-asc::before  { content: "↑"; }
.header-cell .header-sort-btn.sort-desc::before { content: "↓"; }

.data-cell {
  outline: none;
  white-space: pre-wrap;
}
.data-cell:focus {
  background-color: var(--bg-surface);
  box-shadow: inset 0 0 0 2px var(--focus-ring);
}

.data-cell.dup-cell {
  background: var(--state-warning-soft);
  box-shadow: inset 0 -2px 0 var(--state-warning);
}

.resizer {
  position: absolute;
  top: 0;
  right: -3px;
  width: 6px;
  height: 100%;
  cursor: col-resize;
  touch-action: none;
  z-index: 3;
}
.resizer:hover,
.resizer.resizing { background-color: var(--focus-ring); }

/* Masked cells */
.recall-word.col-hidden {
  background-color: var(--bg-app);
  color: var(--bg-app);
  border-radius: 3px;
  user-select: none;
  cursor: default;
}
[data-theme="dark"] .recall-word.col-hidden,
[data-theme="cybersecurity"] .recall-word.col-hidden {
  background-color: var(--bg-surface-2);
  color: var(--bg-surface-2);
}
.data-cell:focus .recall-word.col-hidden {
  background-color: transparent;
  color: inherit;
  user-select: text;
}

/* Row delete button */
#row-delete-btn {
  position: absolute;
  display: none;
  width: 36px;
  height: 36px;
  padding: 0;
  font-size: 16px;
  line-height: 1;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--bg-surface);
  color: var(--text-muted);
  cursor: pointer;
  z-index: var(--z-exam);
  transition: background var(--dur-fast), color var(--dur-fast), border-color var(--dur-fast);
}
#row-delete-btn.visible { display: grid; place-items: center; }
#row-delete-btn:hover {
  background: var(--state-incorrect-soft);
  border-color: var(--state-incorrect);
  color: var(--state-incorrect);
}

/* ==========================================================================
   GRID FOOTER + START TEST
   ========================================================================== */
.grid-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-shrink: 0;
  margin-top: auto;
  padding: 16px;
  background: var(--bg-app);
  border-radius: 8px;
  position: sticky;
  bottom: 0;
  z-index: var(--z-sticky);
}

.grid-helper {
  font-size: 16px;
  color: var(--text-muted);
  text-align: center;
}

.start-test-btn {
  padding: 6px 18px;
  white-space: nowrap;
  flex-shrink: 0;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 700;
  border: none;
  background: linear-gradient(135deg, var(--accent-light), var(--accent-mid) 60%, var(--accent-deep));
  color: #fff;
  letter-spacing: 0.03em;
  transition: transform var(--dur-fast), opacity var(--dur-fast);
}
.start-test-btn:hover:not(:disabled) { transform: translateY(-1px); }
.start-test-btn:disabled {
  background: var(--bg-surface);
  color: var(--text-muted);
  border: 1px solid var(--border-strong);
  cursor: not-allowed;
  opacity: 0.6;
}

/* ==========================================================================
   NOTES
   ========================================================================== */
#note-area {
  flex: 0 0 auto;
  width: 100%;
  height: 50vh;
  min-height: 80px;
  max-height: 70vh;
  padding: 10px;
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  background-color: var(--bg-surface);
  color: var(--text-primary);
  font-size: 16px;
  line-height: 1.5;
  resize: none;
}
#note-area:focus {
  outline: none;
  box-shadow: inset 0 0 0 2px var(--focus-ring);
}

#note-resizer {
  flex: 0 0 auto;
  height: 8px;
  margin-top: -4px;
  cursor: row-resize;
  touch-action: none;
  position: relative;
  z-index: 2;
}
#note-resizer::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 40px;
  height: 4px;
  border-radius: 2px;
  background-color: var(--border-strong);
}
#note-resizer:hover::after,
#note-resizer.resizing::after { background-color: var(--focus-ring); }

/* ==========================================================================
   PRIVACY VIEW CONTENT
   ========================================================================== */
#privacy-workspace {
  padding: 20px;
  color: var(--text-primary);
}
#privacy-workspace h1 {
  font-size: 24px;
  margin-bottom: 16px;
}
#privacy-workspace h2 {
  font-size: 16px;
  margin: 20px 0 8px;
}
#privacy-workspace p,
#privacy-workspace li {
  font-size: 15px;
  line-height: 1.6;
  color: var(--text-muted);
  margin-bottom: 12px;
}
#privacy-workspace a {
  color: var(--focus-ring);
  text-decoration: underline;
}

.privacy-link {
  color: var(--text-muted);
  text-decoration: underline;
  font-size: 13px;
  margin-left: 8px;
}
.privacy-link:hover { color: var(--accent-mid); }

/* ==========================================================================
   EXAM — TOPBAR
   ========================================================================== */
.exam-topbar {
  display: none; /* list dropdown hidden during tests */
  align-items: flex-end;
  gap: 8px;
  padding: 10px 4px;
  flex-shrink: 0;
}
.exam-list-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
  min-width: 0;
}
.exam-list-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
}
.exam-list-picker {
  flex: 1;
  padding: 10px 12px;
  background: var(--bg-surface-2);
  border: 1px solid var(--control-border);
  border-radius: 6px;
  color: var(--text-primary);
  font-size: 14px;
  font-weight: 600;
}
.exam-back-btn {
  padding: 10px 14px;
  background: var(--bg-surface-2);
  border: 1px solid var(--control-border);
  border-radius: 6px;
  color: var(--text-primary);
  font-size: 14px;
  font-weight: 600;
  flex-shrink: 0;
}
.exam-back-btn:hover { border-color: var(--accent-mid); }

.exam-counter {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  letter-spacing: 0.04em;
}

/* ==========================================================================
   EXAM — QUESTION BODY
   ========================================================================== */
.mode-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 8px 0;
}

.mode-btn {
  position: relative;
  flex: 1 1 auto;
  padding: 6px 8px;
  font-size: 15px;
  font-weight: 500;
  text-align: center;
  background: var(--bg-elevated);
  color: var(--text-primary);
  border: none;
  border-radius: 6px;
  min-height: 32px;
  cursor: pointer;
  transition: background-color var(--dur-fast), color var(--dur-fast);
}
.mode-btn::after {
  content: "";
  position: absolute;
  left: 0;
  bottom: 0;
  width: 100%;
  height: 3px;
  background-color: var(--state-incorrect);
  transform: scaleX(0);
  transform-origin: left;
}
.mode-btn.active { color: var(--state-incorrect); font-weight: 600; }
.mode-btn.active::after { animation: underline-draw 1s ease forwards; }

.dir-btn {
  padding: 8px 14px;
  margin: 0 0 16px;
  background: var(--bg-surface-2);
  border: 1px solid var(--control-border);
  border-radius: 6px;
  color: var(--text-primary);
  font-size: 14px;
  font-weight: 600;
}
.dir-btn:hover { border-color: var(--accent-mid); }

.prompt-line { margin-bottom: 30px; font-size: 16px; }

.answer-btn {
  display: block;
  width: 100%;
  margin-bottom: 8px;
  padding: 14px 18px;
  background: var(--bg-surface-2);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  font-size: 15px;
  text-align: left;
  color: var(--text-primary);
  cursor: pointer;
  transition: background var(--dur-fast), border-color var(--dur-fast), transform 0.1s;
}
.answer-btn:hover {
  background: var(--bg-elevated);
  border-color: var(--border-strong);
}
.answer-btn:active { transform: scale(0.99); }
.answer-btn:disabled { opacity: 0.7; cursor: not-allowed; }
.answer-btn.correct {
  background: var(--state-correct-soft);
  border-color: var(--state-correct);
  color: var(--state-correct);
}
.answer-btn.wrong {
  background: var(--state-incorrect-soft);
  border-color: var(--state-incorrect);
  color: var(--state-incorrect);
}
.answer-btn.primary {
  background: linear-gradient(135deg, var(--accent-light), var(--accent-mid) 60%, var(--accent-deep));
  color: #fff;
  border: none;
  text-align: center;
}

.answer-input {
  width: 100%;
  padding: 14px 18px;
  background: var(--bg-surface-2);
  border: none;
  border-radius: 10px;
  font-size: 15px;
  color: var(--text-primary);
  outline: none;
  box-sizing: border-box;
  margin-bottom: 10px;
}
.answer-input:focus { box-shadow: inset 0 0 0 2px var(--focus-ring); }

.tf-statement {
  padding: 16px 18px;
  background: var(--bg-surface-2);
  border-radius: 10px;
  font-size: 15px;
  margin-bottom: 12px;
}

.exam-feedback {
  margin-top: 14px;
  font-size: 14px;
  line-height: 1.5;
  min-height: 20px;
}
.exam-feedback .ok  { color: var(--state-correct); font-weight: 600; }
.exam-feedback .bad { color: var(--state-incorrect); font-weight: 600; }

.next-row {
  display: flex;
  gap: 8px;
  margin-top: 16px;
}
.next-row .answer-btn { width: auto; text-align: center; }
.next-row .answer-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.next-row #exam-skip-btn { flex: 0 0 30%; }
.next-row #exam-next-btn { flex: 1; }

/* ==========================================================================
   EXAM — RESULTS SCREEN
   ========================================================================== */
.exam-complete-card { text-align: center; padding: 24px 8px; }
.exam-complete-card h3 { font-size: 20px; margin: 0 0 8px; font-weight: 700; }
.exam-complete-card h4 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  margin: 20px 0 10px;
  font-weight: 700;
}
.exam-complete-card .result-title {
  margin: 0 0 10px;
  color: var(--text-muted);
  font-size: 14px;
}
.exam-complete-card .exam-complete-subtitle {
  margin-top: 16px;
  font-size: 12px;
  color: var(--text-muted);
}
.exam-complete-card .answer-btn { margin: 6px 4px; }

.mode-chips {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  margin-bottom: 18px;
}
.mode-chip {
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  color: var(--accent-light);
  background: var(--accent-soft);
}

.score-ring {
  position: relative;
  width: 140px;
  height: 140px;
  margin: 0 auto 8px;
}
.score-ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.score-ring circle { fill: none; stroke-width: 10; }
.score-ring .ring-bg { stroke: var(--border-color); }
.score-ring .ring-fg { stroke-linecap: round; transition: stroke-dashoffset 0.9s ease; }
.score-ring.ring-good .ring-fg { stroke: var(--state-correct); }
.score-ring.ring-mid  .ring-fg { stroke: var(--state-warning); }
.score-ring.ring-low  .ring-fg { stroke: var(--state-incorrect); }
.score-ring .ring-text {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
}
.score-ring .ring-pct {
  font-size: 30px;
  font-weight: 700;
  color: var(--text-primary);
}

.ring-sub {
  margin: 0 0 16px;
  color: var(--text-muted);
  font-size: 14px;
}

.stat-tiles {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-bottom: 8px;
}
.stat-tile {
  flex: 1;
  max-width: 110px;
  padding: 10px 6px;
  border-radius: 10px;
  background: var(--bg-surface-2);
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.stat-tile strong { font-size: 20px; }
.stat-tile span   { font-size: 12px; color: var(--text-muted); }
.stat-tile.tile-good strong { color: var(--state-correct); }
.stat-tile.tile-bad  strong { color: var(--state-incorrect); }
.stat-tile.tile-skip strong { color: var(--state-warning); }

.missed-list {
  list-style: none;
  padding: 0;
  margin: 0 0 20px;
  text-align: left;
}
.missed-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  background: var(--bg-surface-2);
  border-radius: 8px;
  margin-bottom: 6px;
  font-size: 14px;
  line-height: 1.4;
}
.skip-badge {
  flex: 0 0 auto;
  font-style: normal;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  color: var(--state-warning);
  background: var(--state-warning-soft);
}

.perfect-msg { margin: 16px 0; font-weight: 700; color: var(--state-correct); }

.result-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 8px;
}
.result-actions .answer-btn { margin: 0; width: 100%; }

/* ==========================================================================
   MODALS
   ========================================================================== */
/* Force modal hidden until JS adds .visible */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: var(--overlay-bg);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: var(--z-modal);
  padding: 20px;
}
.modal-overlay.visible { display: flex !important; animation: fade-in 0.15s ease; }

.modal-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 22px 24px 18px;
  max-width: 420px;
  width: 100%;
  box-shadow: var(--shadow-modal);
  animation: pop-in 0.18s ease;
}
.modal-title { font-size: 17px; font-weight: 700; margin: 0 0 8px; }
.modal-message {
  font-size: 14px;
  color: var(--text-muted);
  margin: 0 0 20px;
  line-height: 1.5;
}
.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  flex-wrap: wrap;
}
.modal-btn {
  padding: 9px 18px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  border: 1px solid var(--control-border);
  background: var(--control-bg);
  color: var(--text-primary);
  transition: background var(--dur-fast), border-color var(--dur-fast);
}
.modal-btn:hover {
  background: var(--bg-surface-2);
  border-color: var(--text-muted);
}
.modal-btn.confirm {
  background: linear-gradient(135deg, var(--accent-light), var(--accent-mid) 60%, var(--accent-deep));
  color: #fff;
  border: 1px solid transparent;
}
.modal-btn.confirm:hover {
  transform: translateY(-1px);
}
.modal-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.modal-input {
  border: 1px solid var(--border-color);
  margin: 4px 0 14px;
}

/* Launcher + contact form */
.launcher-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 20px;
}
.launcher-item {
  width: 100%;
  padding: 12px 16px;
  text-align: left;
  background: var(--bg-surface-2);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  color: var(--text-primary);
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--dur-fast), border-color var(--dur-fast);
}
.launcher-item:hover {
  background: var(--bg-surface);
  border-color: var(--accent-mid);
}

.launcher-form {
  display: flex;
  flex-direction: column;
  gap: 0;
}
.launcher-form .ctrl-input,
.launcher-form .ctrl-select {
  margin-bottom: 10px;
  font-size: 14px;
}
.launcher-check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-muted);
  margin: 4px 0 12px;
}
.launcher-check a {
  color: var(--focus-ring);
  text-decoration: underline;
}

/* ==========================================================================
   SEGMENTED TOGGLE
   ========================================================================== */
.view-switch {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex-shrink: 0;
}
.view-switch-top {
  display: flex;
  gap: 4px;
  justify-content: space-between;
}

.seg-toggle {
  display: flex;
  background: transparent;
  padding: 3px;
  gap: 4px;
}
.seg-btn {
  position: relative;
  padding: 8px 12px;
  white-space: nowrap;
  text-align: center;
  font-size: 15px;
  font-weight: 600;
  border-radius: 0;
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  transition: color var(--dur-slow);
}
.seg-btn::after {
  content: "";
  position: absolute;
  left: 0;
  bottom: 0;
  width: 100%;
  height: 1px;
  background-color: var(--focus-ring);
  transform: scaleX(0);
  transform-origin: left;
}
.seg-btn.active { color: var(--focus-ring); }
.seg-btn.active::after { animation: underline-draw 1s ease forwards; }

/* ==========================================================================
   VIEW ROW + DROPDOWN
   ========================================================================== */
.view-row {
  position: relative;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

#view-select { display: none; }

.vs-dd {
  position: relative;
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
}
.vs-btn {
  text-align: left;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 0 !important;
}
.vs-list {
  display: none;
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 4px);
  max-height: 240px;
  overflow-y: auto;
  padding: 4px;
  z-index: var(--z-popup);
  background: var(--bg-surface-2);
  border: 1px solid var(--control-border);
  border-radius: 8px;
  box-shadow: var(--shadow-popup);
}
.vs-list.open { display: block; }

.vs-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
}
.vs-item:hover,
.vs-item.active { background: var(--accent-soft); }

.vs-label {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.vs-edit {
  border: 1px solid transparent;
  border-radius: 5px;
  background: transparent;
  color: var(--text-primary);
  font-size: 16px;
  cursor: pointer;
  padding: 4px 8px;
}
.vs-edit:hover { background: var(--accent-soft); }

/* ==========================================================================
   MANAGEMENT MENU
   ========================================================================== */
.mgmt-group {
  display: none;
  flex-direction: column;
  gap: 2px;
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  min-width: 150px;
  padding: 6px;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  box-shadow: var(--shadow-popup);
  z-index: var(--z-popup);
}
.mgmt-group.open {
  display: flex;
  animation: pop-in 0.15s ease;
  transform-origin: top right;
}
.mgmt-group .mgmt-btn {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  width: 100%;
  height: auto;
  min-height: 40px;
  padding: 0 14px;
  border: none;
  background: transparent;
  font-size: 15px;
  text-align: left;
}
.mgmt-group .mgmt-btn:hover { background: var(--accent-soft); }
.mgmt-group #mgmt-delete-btn { color: var(--state-incorrect); }

.mgmt-btn {
  min-width: 38px;
  height: 38px;
  padding: 0 8px;
  border: 1px solid var(--control-border);
  border-radius: 8px;
  background: var(--bg-surface);
  color: var(--text-primary);
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: background var(--dur-fast), border-color var(--dur-fast);
}
.mgmt-btn:hover {
  background: var(--bg-surface-2);
  border-color: var(--text-muted);
}

/* Privacy page back button: natural size, not stretched */
#privacy-back-btn {
  align-self: flex-start;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: auto;
  min-width: 0;
  height: auto;
  min-height: 40px;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 600;
  flex-shrink: 0;
}

/* ==========================================================================
   ANALYTICS DASHBOARD
   ========================================================================== */
#analytics-workspace {
  width: 100%;
  margin-top: 1.5rem;
  box-sizing: border-box;
  overflow: auto;
}

.analytics-summary-grid {
  display: flex;
  gap: 1rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.stat-card {
  flex: 1;
  min-width: 200px;
  background-color: var(--bg-surface-2);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 1.25rem;
  box-sizing: border-box;
}
.stat-card h3 {
  margin: 0 0 0.5rem;
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  opacity: 0.8;
}
.stat-number {
  margin: 0;
  font-size: 2.25rem;
  font-weight: 700;
  color: var(--accent-light);
}

.trouble-list-card { width: 100%; }
.trouble-list-card ul {
  list-style: none;
  padding: 0;
  margin: 0.5rem 0 0;
}
.trouble-list-card li {
  display: flex;
  justify-content: space-between;
  padding: 0.75rem 0.5rem;
  border-bottom: 1px solid var(--border-color);
}
.trouble-list-card li:last-child { border-bottom: none; }
.missed-word-text { font-family: monospace; font-size: 0.95rem; }
.missed-count { font-size: 0.85rem; color: var(--state-incorrect); font-weight: 600; }

.empty-state,
.success-message {
  text-align: center;
  padding: 2rem;
  opacity: 0.7;
  font-style: italic;
}

/* ==========================================================================
   ANIMATIONS
   ========================================================================== */
@keyframes fade-up {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: none; }
}
@keyframes fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}
@keyframes pop-in {
  from { opacity: 0; transform: scale(0.96); }
  to   { opacity: 1; transform: none; }
}
@keyframes pulse-correct {
  0%   { transform: scale(1); }
  40%  { transform: scale(1.03); }
  100% { transform: scale(1); }
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}
@keyframes underline-draw {
  from { transform: scaleX(0); }
  to   { transform: scaleX(1); }
}

.exam-question-wrapper .prompt-line,
.exam-question-wrapper .exam-body { animation: fade-up 0.25s ease both; }
.exam-feedback > * { animation: fade-up 0.25s ease both; }
.answer-btn.correct { animation: pulse-correct 0.35s ease; }
.answer-btn.wrong   { animation: shake 0.35s ease; }
.exam-complete-card { animation: fade-up 0.3s ease both; }

/* Account Pill Styling */
.account-btn {
  width: auto !important; /* Allow button to expand */
  padding: 4px 6px;
  border-radius: 6px;
}

.account-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #6366F1; /* Indigo color for both icon and text */
  white-space: nowrap; /* Prevent wrapping */
}

#account-role-label {
  font-weight: 600;
  font-size: 14px;
}

/* Modal Role Buttons */
.role-opt {
  display: flex; align-items: center; gap: 12px; padding: 12px; 
  border: 2px solid var(--border-color, #333); background: transparent; 
  border-radius: 8px; cursor: pointer; color: var(--text-primary, #fff); 
  width: 100%; font-size: 16px; transition: border-color 0.2s;
}

.role-opt:hover, .role-opt.active {
  border-color: #6366F1;
  color: #6366F1;
}

.modal-btn:hover {
  border-color: #6366F1;
  color: #6366F1;
}

/* Optional: If you have a 'confirm' or primary button that should stay filled */
.modal-btn.confirm:hover {
  opacity: 0.8; /* or slightly darken the background */
}

#confirm-modal {
  z-index: calc(var(--z-modal) + 1);
}