/*
  Colour tokens — all colours live here.
  To add a dark theme later, duplicate this block under:
    [data-theme="dark"] { ... }  or  @media (prefers-color-scheme: dark) { ... }
*/
:root {
  /* Backgrounds */
  --bg: #f4f7fa;
  --surface: #ffffff;
  --surface2: #edf1f6;

  /* Borders */
  --border: #dce3ed;

  /* Brand blue */
  --accent: #06507F;
  --accent-hover: #054570;

  /* Secondary blue (focus rings, highlights) */
  --accent2: #1a8fd1;

  /* Teal (help tips) */
  --accent3: #0891b2;

  /* Text */
  --text: #1a2535;
  --muted: #60748a;

  /* Feedback */
  --danger: #dc2626;
  --success: #16a34a;

  --radius: 10px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'DM Sans', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
}

/* ── Header ── */
header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 18px 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
}

.logo {
  font-family: 'Syne', sans-serif;
  font-weight: 800;
  font-size: 1.3rem;
  letter-spacing: -0.5px;
}
.logo span { color: var(--accent); }

.header-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* ── Layout ── */
.app {
  display: grid;
  grid-template-columns: 380px 1fr;
  gap: 0;
  min-height: calc(100vh - 120px);
}

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 24px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.main {
  padding: 28px 32px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  overflow-y: auto;
}

/* ── Mobile tab bar ── */
.mobile-tabs {
  display: none;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 16px;
}
.mobile-tab {
  font-family: 'Syne', sans-serif;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--muted);
  padding: 12px 16px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  background: none;
  border-top: none;
  border-left: none;
  border-right: none;
  transition: all 0.15s;
}
.mobile-tab.active { color: var(--accent); border-bottom-color: var(--accent); }

@media (max-width: 768px) {
  header { padding: 14px 16px; }
  .logo { font-size: 1.1rem; }
  .header-actions .btn-sm { padding: 7px 10px; font-size: 0.78rem; }

  .mobile-tabs { display: flex; }

  .app {
    grid-template-columns: 1fr;
    min-height: unset;
  }

  .sidebar {
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding: 16px;
    gap: 16px;
  }

  .main { padding: 16px; gap: 16px; }

  .sidebar.hidden, .main.hidden { display: none; }

  .type-grid { grid-template-columns: 1fr 1fr; }

  .pair-row { grid-template-columns: 1fr 1fr auto; }

  #quiz-name-input { font-size: 1.1rem; }

  .xml-code { font-size: 0.72rem; padding: 14px; }

  .question-card { padding: 12px 14px; gap: 10px; }
}

@media (max-width: 480px) {
  .header-actions { gap: 5px; }
  .header-actions .btn { font-size: 0.72rem; padding: 6px 8px; }
  .type-grid { grid-template-columns: 1fr 1fr; gap: 6px; }
  .type-btn { padding: 8px 5px; font-size: 0.72rem; }
  .form-card { padding: 14px; }
  .pair-row { grid-template-columns: 1fr; gap: 6px; }
  .pair-row .btn-danger { width: fit-content; }
}

/* ── Buttons ── */
.btn {
  font-family: 'DM Sans', sans-serif;
  font-size: 0.875rem;
  font-weight: 500;
  padding: 9px 18px;
  border-radius: var(--radius);
  border: none;
  cursor: pointer;
  transition: all 0.15s ease;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  white-space: nowrap;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); transform: translateY(-1px); }
.btn-secondary { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--border); }
.btn-success { background: var(--success); color: #fff; font-weight: 600; }
.btn-success:hover { opacity: 0.9; transform: translateY(-1px); }
.btn-danger { background: transparent; color: var(--danger); border: 1px solid var(--danger); padding: 5px 10px; font-size: 0.8rem; }
.btn-danger:hover { background: var(--danger); color: #fff; }
.btn-sm { padding: 6px 12px; font-size: 0.8rem; }
.btn-full { width: 100%; justify-content: center; }
.btn-yellow { background: var(--accent); color: #fff; font-weight: 600; }
.btn-yellow:hover { background: var(--accent-hover); }

/* ── Section Labels ── */
.section-label {
  font-family: 'Syne', sans-serif;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 8px;
}

/* ── Form Elements ── */
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group label {
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--muted);
}

input[type="text"], input[type="number"], textarea, select {
  font-family: 'DM Sans', sans-serif;
  font-size: 0.9rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 10px 13px;
  width: 100%;
  transition: border-color 0.15s;
  resize: vertical;
}
input:focus, textarea:focus, select:focus {
  outline: 3px solid rgba(26, 143, 209, 0.35);
  outline-offset: 2px;
  border-color: var(--accent2);
}
textarea { min-height: 80px; }
select option { background: var(--surface); }

/* ── Question Type Selector ── */
.type-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.type-btn {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 8px;
  cursor: pointer;
  text-align: center;
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--muted);
  transition: all 0.15s;
  font-family: 'DM Sans', sans-serif;
  line-height: 1.3;
}
.type-btn:hover { border-color: var(--accent); color: var(--text); }
.type-btn.active { border-color: var(--accent); background: rgba(6, 80, 127, 0.08); color: var(--accent); }
.type-btn .icon { font-size: 1.2rem; display: block; margin-bottom: 4px; }

/* ── Form Card ── */
.form-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.form-card-title {
  font-family: 'Syne', sans-serif;
  font-weight: 700;
  font-size: 1rem;
  color: var(--accent);
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

/* ── Answer rows ── */
.answer-row {
  display: flex;
  gap: 8px;
  align-items: flex-start;
}
.answer-row input[type="text"] { flex: 1; }
.answer-row input[type="checkbox"], .answer-row input[type="radio"] {
  width: 18px; height: 18px;
  margin-top: 12px;
  cursor: pointer;
  accent-color: var(--accent);
  flex-shrink: 0;
}

.answers-list { display: flex; flex-direction: column; gap: 8px; }

/* ── Question list ── */
.question-list { display: flex; flex-direction: column; gap: 12px; }

.question-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  display: flex;
  gap: 14px;
  align-items: flex-start;
  transition: border-color 0.15s;
}
.question-card:hover { border-color: var(--accent); }

.q-number {
  font-family: 'DM Mono', monospace;
  font-size: 0.75rem;
  background: var(--accent);
  color: #fff;
  border-radius: 6px;
  padding: 3px 8px;
  flex-shrink: 0;
  margin-top: 2px;
}

.q-info { flex: 1; min-width: 0; }
.q-type {
  font-size: 0.72rem;
  color: var(--accent2);
  font-weight: 500;
  font-family: 'DM Mono', monospace;
  margin-bottom: 2px;
  text-transform: uppercase;
  letter-spacing: 1px;
}
.q-text {
  font-size: 0.9rem;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.q-actions { display: flex; gap: 6px; flex-shrink: 0; }

/* ── XML output ── */
.xml-output {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.xml-header {
  background: var(--surface2);
  padding: 12px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
}

.xml-header span {
  font-family: 'DM Mono', monospace;
  font-size: 0.8rem;
  color: var(--muted);
}

/* Code area stays dark — conventional for output/terminal panels */
.xml-code {
  font-family: 'DM Mono', monospace;
  font-size: 0.78rem;
  color: #a8d8b9;
  background: #0f1c2e;
  padding: 20px;
  overflow-x: auto;
  white-space: pre;
  max-height: 450px;
  overflow-y: auto;
  line-height: 1.7;
}

/* ── Matching pairs ── */
.pair-row {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 8px;
  align-items: center;
}

/* ── Select Missing Word — blank sections ── */
.blank-section {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 10px;
}

.blank-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.blank-label {
  font-family: 'DM Mono', monospace;
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--accent);
  letter-spacing: 0.5px;
}

.blank-section .form-group { margin-bottom: 10px; }
.blank-section .form-group:last-child { margin-bottom: 0; }

/* ── Empty states ── */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--muted);
}
.empty-state .icon { font-size: 3rem; margin-bottom: 12px; display: block; }
.empty-state p { font-size: 0.9rem; }

/* ── Tags / badges ── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 0.72rem;
  font-weight: 600;
  font-family: 'DM Mono', monospace;
}
.badge-accent { background: rgba(6, 80, 127, 0.1); color: var(--accent); }
.badge-yellow { background: rgba(26, 143, 209, 0.12); color: var(--accent2); }

/* ── Toast ── */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--success);
  color: #fff;
  font-weight: 600;
  padding: 12px 20px;
  border-radius: 10px;
  font-size: 0.875rem;
  z-index: 999;
  transform: translateY(80px);
  opacity: 0;
  transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.toast.show { transform: translateY(0); opacity: 1; }

/* ── Help tip ── */
.help-tip {
  background: rgba(8, 145, 178, 0.07);
  border: 1px solid rgba(8, 145, 178, 0.22);
  border-radius: 8px;
  padding: 10px 13px;
  font-size: 0.82rem;
  color: var(--accent3);
  line-height: 1.5;
}

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

.btn:focus-visible, .type-btn:focus-visible, .mobile-tab:focus-visible {
  outline: 3px solid rgba(26, 143, 209, 0.5);
  outline-offset: 2px;
}

.skip-link {
  position: absolute;
  top: -40px;
  left: 8px;
  background: var(--accent);
  color: #fff;
  padding: 8px 16px;
  border-radius: var(--radius);
  font-weight: 700;
  text-decoration: none;
  z-index: 9999;
  transition: top 0.15s;
}
.skip-link:focus { top: 8px; outline: 3px solid var(--accent2); outline-offset: 3px; }

.divider { border: none; border-top: 1px solid var(--border); }

.flex-row { display: flex; gap: 10px; align-items: center; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }

#quiz-name-input {
  font-family: 'Syne', sans-serif;
  font-size: 1.4rem;
  font-weight: 700;
  background: transparent;
  border: none;
  border-bottom: 2px solid var(--border);
  border-radius: 0;
  padding: 4px 0;
  color: var(--text);
  width: 100%;
}
#quiz-name-input:focus { border-bottom-color: var(--accent); outline: 3px solid rgba(26, 143, 209, 0.35); outline-offset: 2px; }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}

.counter-bar {
  font-family: 'DM Mono', monospace;
  font-size: 0.78rem;
  color: var(--muted);
  padding: 6px 0;
}
