/* ============================================================
   IELTS Writing Lab — style.css
   ============================================================ */

/* ── THEME: DARK (default) ── */
:root,
[data-theme="dark"] {
  --bg:           #0f0e0d;
  --surface:      #1a1916;
  --surface2:     #221f1c;
  --border:       #2e2b27;
  --border2:      #3d3a34;
  --text:         #e8e0d0;
  --text-dim:     #8a8070;
  --text-muted:   #4a4540;
  --accent:       #d4922a;
  --accent-light: #f0b84a;
  --accent-dim:   #7a4f10;
  --green:        #5a9e6f;
  --red:          #c0524a;
  --shadow:       rgba(0,0,0,0.4);
}

/* ── THEME: LIGHT ── */
[data-theme="light"] {
  --bg:           #f5f3ef;
  --surface:      #ffffff;
  --surface2:     #ede9e3;
  --border:       #dcd8d0;
  --border2:      #c8c2b8;
  --text:         #1e1c18;
  --text-dim:     #6b6560;
  --text-muted:   #b0a898;
  --accent:       #2a5fa8;
  --accent-light: #3a7fd8;
  --accent-dim:   #c8d8ef;
  --green:        #2e7d50;
  --red:          #c0392b;
  --shadow:       rgba(0,0,0,0.08);
}

/* ── THEME: SAGE ── */
[data-theme="sage"] {
  --bg:           #141f18;
  --surface:      #1c2b21;
  --surface2:     #243328;
  --border:       #2e4035;
  --border2:      #3d5448;
  --text:         #e2ead8;
  --text-dim:     #7a9878;
  --text-muted:   #3e5442;
  --accent:       #8ec46a;
  --accent-light: #aada88;
  --accent-dim:   #3a6030;
  --green:        #8ec46a;
  --red:          #e07060;
  --shadow:       rgba(0,0,0,0.4);
}

/* ── FONT: SERIF (default) ── */
:root,
[data-font="serif"] {
  --editor-font:   'Source Serif 4', Georgia, serif;
  --ui-font:       'JetBrains Mono', monospace;
  --display-font:  'Playfair Display', serif;
  --editor-size:   16px;
  --editor-weight: 300;
  --editor-lh:     1.85;
  --ui-size:       13px;
  --logo-size:     20px;
}

/* ── FONT: GOTHIC ── */
[data-font="gothic"] {
  --editor-font:   'DM Sans', 'Helvetica Neue', sans-serif;
  --ui-font:       'Outfit', sans-serif;
  --display-font:  'Outfit', sans-serif;
  --editor-size:   15.5px;
  --editor-weight: 400;
  --editor-lh:     1.8;
  --ui-size:       12.5px;
  --logo-size:     19px;
}

/* ── FONT: READING ── */
[data-font="reading"] {
  --editor-font:   'Literata', Georgia, serif;
  --ui-font:       'Nunito', sans-serif;
  --display-font:  'Nunito', sans-serif;
  --editor-size:   16.5px;
  --editor-weight: 300;
  --editor-lh:     1.95;
  --ui-size:       13px;
  --logo-size:     20px;
}

/* ── THEME / FONT TRANSITIONS ── */
html, body, header, .timer-bar, .stats-bar, .tabs, .tab, .task-btn,
.timer-btn, .btn-primary, .btn-secondary, .ai-config, .ai-select,
.bank-item, .spell-error-card, .modal, .ai-prompt-box,
.app, #editor, .editor-wrap {
  transition: background 0.25s, border-color 0.25s, color 0.25s;
}

/* ── RESET ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ── BASE ── */
html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--ui-font);
  font-size: var(--ui-size);
  overflow: hidden;
  transition: background 0.25s, color 0.25s, font-family 0.2s;
}

/* ── SCROLLBAR ── */
::-webkit-scrollbar        { width: 4px; height: 4px; }
::-webkit-scrollbar-track  { background: transparent; }
::-webkit-scrollbar-thumb  { background: var(--border2); border-radius: 2px; }
::-webkit-scrollbar-thumb:hover { background: var(--accent-dim); }

/* ============================================================
   LAYOUT
   ============================================================ */

.app {
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  height: 100vh;
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 20px;
  overflow: hidden;
}

/* ── HEADER ── */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 0 10px;
  border-bottom: 1px solid var(--border);
}

.logo {
  font-family: var(--display-font);
  font-size: var(--logo-size);
  font-weight: 700;
  letter-spacing: -0.3px;
  color: var(--text);
  transition: font-family 0.2s;
}
.logo span { color: var(--accent); }

.header-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* ── THEME SWITCHER ── */
.theme-switcher {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 4px 6px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 20px;
}
.theme-label {
  font-size: 9px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 0 3px 0 2px;
}
.theme-dot {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid transparent;
  outline: none;
  transition: transform 0.15s, border-color 0.15s, box-shadow 0.15s;
}
.theme-dot:hover { transform: scale(1.2); }
.theme-dot.active {
  border-color: var(--text);
  box-shadow: 0 0 0 1px var(--border2);
}
.theme-dot[data-t="dark"]  { background: radial-gradient(circle at 35% 35%, #3d3a34, #0f0e0d); }
.theme-dot[data-t="light"] { background: radial-gradient(circle at 35% 35%, #f5f3ef, #c8c2b8); }
.theme-dot[data-t="sage"]  { background: radial-gradient(circle at 35% 35%, #3d5448, #141f18); }

/* ── FONT SWITCHER ── */
.font-switcher {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 6px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 20px;
}
.font-label {
  font-size: 9px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 0 3px 0 2px;
}
.font-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 22px;
  border-radius: 4px;
  cursor: pointer;
  border: 1px solid transparent;
  background: none;
  color: var(--text-dim);
  font-size: 12px;
  line-height: 1;
  outline: none;
  transition: all 0.15s;
}
.font-btn:hover { background: var(--border); color: var(--text); }
.font-btn.active {
  background: var(--border2);
  border-color: var(--accent);
  color: var(--accent);
}
.font-btn[data-f="serif"]   { font-family: 'Playfair Display', serif; font-weight: 700; }
.font-btn[data-f="gothic"]  { font-family: 'Outfit', sans-serif; font-weight: 500; letter-spacing: -0.02em; }
.font-btn[data-f="reading"] { font-family: 'Literata', serif; font-style: italic; }

/* ── TASK BUTTONS ── */
.task-btn {
  background: none;
  border: 1px solid var(--border2);
  color: var(--text-dim);
  font-family: var(--ui-font);
  font-size: 11px;
  padding: 5px 12px;
  cursor: pointer;
  border-radius: 3px;
  letter-spacing: 0.05em;
  transition: all 0.15s;
}
.task-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--bg);
  font-weight: 500;
}
.task-btn:not(.active):hover {
  border-color: var(--accent-dim);
  color: var(--text);
}

/* ── TIMER BAR ── */
.timer-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.timer-display {
  font-family: var(--display-font);
  font-size: 28px;
  font-weight: 600;
  letter-spacing: 2px;
  color: var(--text);
  min-width: 100px;
  transition: color 0.3s;
}
.timer-display.warning { color: var(--accent-light); }
.timer-display.danger  { color: var(--red); animation: pulse 1s infinite; }

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

.timer-controls { display: flex; gap: 6px; }
.timer-btn {
  background: none;
  border: 1px solid var(--border2);
  color: var(--text-dim);
  font-family: var(--ui-font);
  font-size: 10px;
  padding: 4px 9px;
  cursor: pointer;
  border-radius: 3px;
  letter-spacing: 0.05em;
  transition: all 0.15s;
}
.timer-btn:hover           { border-color: var(--accent-dim); color: var(--text); }
.timer-btn.running         { border-color: var(--accent); color: var(--accent); }

.timer-progress-wrap {
  flex: 1;
  height: 3px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
}
.timer-progress {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width 1s linear, background 0.3s;
  width: 100%;
}
.timer-progress.warning { background: var(--accent-light); }
.timer-progress.danger  { background: var(--red); }

/* ── MAIN SPLIT (vertical) ── */
.main-split {
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
  min-height: 0;
}

/* ── QUESTION PANEL (top) ── */
.question-panel {
  height: 30%;
  min-height: 80px;
  max-height: 60%;
  display: flex;
  flex-direction: column;
  border-bottom: 1px solid var(--border);
  overflow: hidden;
  flex-shrink: 0;
  transition: height 0.25s ease, opacity 0.2s, min-height 0.25s;
}
.question-panel.hidden {
  height: 0 !important;
  min-height: 0 !important;
  opacity: 0;
  pointer-events: none;
  border-bottom: none;
}

.question-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.question-panel-label {
  font-size: 9px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
  font-family: var(--ui-font);
}
.qpanel-toggle {
  background: none;
  border: 1px solid var(--border2);
  color: var(--text-muted);
  font-size: 10px;
  padding: 2px 10px;
  height: 22px;
  border-radius: 3px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 5px;
  font-family: var(--ui-font);
  letter-spacing: 0.05em;
  transition: all 0.15s;
}
.qpanel-toggle:hover { border-color: var(--accent-dim); color: var(--text); }

.question-text {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text);
  font-family: var(--editor-font);
  font-size: 14.5px;
  font-weight: var(--editor-weight);
  line-height: 1.85;
  padding: 14px 20px;
  resize: none;
  overflow-y: auto;
  caret-color: var(--accent);
  transition: font-family 0.2s;
}
.question-text::placeholder {
  color: var(--text-muted);
  font-style: italic;
  font-size: 13px;
  line-height: 1.7;
}

/* ── RESIZER (horizontal drag bar) ── */
.resizer {
  height: 5px;
  background: var(--border);
  cursor: row-resize;
  flex-shrink: 0;
  position: relative;
  transition: background 0.15s;
}
.resizer:hover,
.resizer.dragging { background: var(--accent); }
.resizer::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  height: 2px;
  width: 48px;
  border-radius: 2px;
  background: var(--border2);
}

/* ── EDITOR SECTION (bottom) ── */
.editor-section {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 10px 0 0;
  flex: 1;
  min-height: 0;
}

/* ── TABS ── */
.tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
}
.tab {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-dim);
  font-family: var(--ui-font);
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 7px 16px;
  cursor: pointer;
  margin-bottom: -1px;
  transition: all 0.15s;
}
.tab.active       { color: var(--accent); border-bottom-color: var(--accent); }
.tab:not(.active):hover { color: var(--text); }

.tab-badge {
  display: inline-block;
  background: var(--accent);
  color: var(--bg);
  font-size: 9px;
  padding: 1px 5px;
  border-radius: 10px;
  margin-left: 5px;
  font-weight: 600;
}

/* ── SHOW QUESTION BUTTON ── */
.qpanel-show {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--accent);
  font-family: var(--ui-font);
  font-size: 10px;
  letter-spacing: 0.08em;
  padding: 7px 14px;
  cursor: pointer;
  margin-left: auto;
  margin-bottom: -1px;
  opacity: 0.8;
  transition: all 0.15s;
}
.qpanel-show:hover { opacity: 1; }

/* ── PANELS ── */
.panel { display: none; flex: 1; overflow: hidden; flex-direction: column; }
.panel.active { display: flex; }

/* WRITE PANEL */
#panel-write { overflow: hidden; }

.editor-wrap {
  flex: 1;
  overflow: auto;
  padding: 20px 0;
}

#editor {
  width: 100%;
  min-height: 100%;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text);
  font-family: var(--editor-font);
  font-size: var(--editor-size);
  line-height: var(--editor-lh);
  font-weight: var(--editor-weight);
  resize: none;
  caret-color: var(--accent);
  letter-spacing: 0.01em;
  transition: font-family 0.2s, font-size 0.2s, line-height 0.2s;
}
#editor::placeholder {
  color: var(--text-muted);
  font-style: italic;
  font-size: 15px;
}
#editor:focus { outline: none; }

/* SPELL CHECK PANEL */
#panel-spell {
  padding: 16px 0;
  overflow: hidden;
}
.spell-actions {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
  align-items: center;
}
.spell-status {
  font-size: 11px;
  color: var(--text-dim);
  margin-left: auto;
}
.spell-results {
  flex: 1;
  overflow-y: auto;
}
.spell-empty {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
  font-style: italic;
  font-family: var(--display-font);
  font-size: 14px;
}
.spell-error-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--red);
  border-radius: 3px;
  padding: 12px 14px;
  margin-bottom: 8px;
  animation: fadeIn 0.2s ease;
}
@keyframes fadeIn { from { opacity:0; transform:translateX(-4px) } to { opacity:1; transform:none } }

.spell-word {
  font-family: var(--ui-font);
  font-size: 15px;
  color: var(--red);
  font-weight: 500;
  margin-bottom: 4px;
}
.spell-context {
  font-family: var(--editor-font);
  font-size: 12px;
  color: var(--text-dim);
  line-height: 1.5;
}
.spell-context em {
  color: var(--red);
  font-style: normal;
  background: rgba(192,82,74,0.15);
  padding: 0 2px;
  border-radius: 2px;
}
.spell-actions-row { display: flex; gap: 6px; margin-top: 8px; }
.spell-save-btn {
  background: none;
  border: 1px solid var(--border2);
  color: var(--text-dim);
  font-family: var(--ui-font);
  font-size: 10px;
  padding: 3px 9px;
  cursor: pointer;
  border-radius: 2px;
  transition: all 0.15s;
}
.spell-save-btn:hover { border-color: var(--accent-dim); color: var(--accent); }
.spell-save-btn.saved { border-color: var(--green); color: var(--green); }

.spell-all-clear {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(90,158,111,0.1);
  border: 1px solid var(--green);
  border-radius: 3px;
  padding: 16px 20px;
  color: var(--green);
  font-size: 13px;
}

/* AI SCRIPT PANEL */
#panel-ai { padding: 16px 0; overflow: hidden; gap: 12px; }

.ai-config {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 14px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.ai-config-item label {
  display: block;
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-dim);
  margin-bottom: 5px;
}
.ai-select {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  font-family: var(--ui-font);
  font-size: 11px;
  padding: 6px 8px;
  border-radius: 2px;
  cursor: pointer;
  outline: none;
}
.ai-select:focus { border-color: var(--accent-dim); }

.ai-output-wrap {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.ai-prompt-box {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 14px;
  font-family: var(--editor-font);
  font-size: 13px;
  color: var(--text-dim);
  line-height: 1.7;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-word;
  transition: font-family 0.2s;
}
.ai-prompt-box.generated { color: var(--text); }

.ai-copy-row { display: flex; gap: 8px; align-items: center; }
.copy-notice {
  font-size: 10px;
  color: var(--green);
  opacity: 0;
  transition: opacity 0.3s;
}
.copy-notice.show { opacity: 1; }

/* WORD BANK PANEL */
#panel-bank { padding: 16px 0; overflow: hidden; gap: 12px; }

.bank-header { display: flex; align-items: center; gap: 10px; }
.bank-search {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  font-family: var(--ui-font);
  font-size: 11px;
  padding: 7px 12px;
  border-radius: 3px;
  outline: none;
  transition: border-color 0.15s;
}
.bank-search:focus       { border-color: var(--border2); }
.bank-search::placeholder { color: var(--text-muted); }

.bank-list { flex: 1; overflow-y: auto; }
.bank-empty {
  text-align: center;
  padding: 40px;
  color: var(--text-muted);
  font-style: italic;
  font-family: var(--display-font);
  font-size: 14px;
  line-height: 2;
}
.bank-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 12px 14px;
  margin-bottom: 6px;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  animation: fadeIn 0.2s ease;
}
.bank-word-col { flex: 1; }
.bank-word {
  font-family: var(--ui-font);
  font-size: 14px;
  color: var(--accent);
  font-weight: 500;
}
.bank-meta { font-size: 10px; color: var(--text-muted); margin-top: 3px; }
.bank-review-count {
  display: inline-block;
  background: color-mix(in srgb, var(--accent) 15%, transparent);
  color: var(--accent);
  font-size: 9px;
  padding: 2px 6px;
  border-radius: 10px;
  margin-top: 4px;
}
.bank-quiz-area { display: flex; align-items: center; gap: 6px; margin-top: 6px; }
.bank-quiz-input {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  font-family: var(--ui-font);
  font-size: 11px;
  padding: 4px 8px;
  border-radius: 2px;
  width: 120px;
  outline: none;
}
.bank-quiz-input.correct { border-color: var(--green); color: var(--green); }
.bank-quiz-input.wrong   { border-color: var(--red);   color: var(--red); }
.bank-quiz-btn {
  background: none;
  border: 1px solid var(--border2);
  color: var(--text-dim);
  font-family: var(--ui-font);
  font-size: 10px;
  padding: 4px 8px;
  cursor: pointer;
  border-radius: 2px;
  transition: all 0.15s;
}
.bank-quiz-btn:hover { border-color: var(--accent-dim); color: var(--accent); }
.bank-del-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  padding: 2px 4px;
  border-radius: 2px;
  flex-shrink: 0;
  transition: color 0.15s;
}
.bank-del-btn:hover { color: var(--red); }

/* ── SHARED BUTTONS ── */
.btn-primary {
  background: var(--accent);
  border: none;
  color: var(--bg);
  font-family: var(--ui-font);
  font-size: 11px;
  font-weight: 500;
  padding: 7px 16px;
  cursor: pointer;
  border-radius: 3px;
  letter-spacing: 0.05em;
  transition: all 0.15s;
}
.btn-primary:hover { background: var(--accent-light); }

.btn-secondary {
  background: none;
  border: 1px solid var(--border2);
  color: var(--text-dim);
  font-family: var(--ui-font);
  font-size: 11px;
  padding: 6px 14px;
  cursor: pointer;
  border-radius: 3px;
  letter-spacing: 0.05em;
  transition: all 0.15s;
}
.btn-secondary:hover { border-color: var(--accent-dim); color: var(--text); }

/* ── STATS BAR ── */
.stats-bar {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 10px 0;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.stat        { display: flex; align-items: baseline; gap: 5px; }
.stat-value  { font-family: var(--display-font); font-size: 18px; font-weight: 600; color: var(--text); line-height: 1; }
.stat-label  { font-size: 9px; text-transform: uppercase; letter-spacing: 0.1em; color: var(--text-muted); }
.stat-divider { width: 1px; height: 18px; background: var(--border); }
.stat-target { font-size: 10px; color: var(--text-muted); margin-left: auto; }
.stat-target span { color: var(--accent); }

/* ── MODAL ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15,14,13,0.85);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}
.modal-overlay.visible { opacity: 1; pointer-events: all; }
.modal {
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: 4px;
  padding: 28px 32px;
  width: 360px;
  transform: translateY(10px);
  transition: transform 0.2s;
}
.modal-overlay.visible .modal { transform: none; }
.modal h3 { font-family: var(--display-font); font-size: 18px; margin-bottom: 6px; }
.modal p   { color: var(--text-dim); font-size: 12px; margin-bottom: 18px; line-height: 1.6; }
.modal-input {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  font-family: var(--ui-font);
  font-size: 12px;
  padding: 8px 12px;
  border-radius: 2px;
  outline: none;
  margin-bottom: 16px;
}
.modal-input:focus { border-color: var(--accent-dim); }
.modal-row { display: flex; gap: 8px; justify-content: flex-end; }

/* ── NOTIFICATION ── */
.notif {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--surface2);
  border: 1px solid var(--border2);
  border-left: 3px solid var(--accent);
  color: var(--text);
  font-family: var(--ui-font);
  font-size: 11px;
  padding: 10px 16px;
  border-radius: 3px;
  z-index: 200;
  opacity: 0;
  transform: translateY(8px);
  transition: all 0.25s;
  pointer-events: none;
}
.notif.show { opacity: 1; transform: none; }
