:root {
  --bg: #e9edf2;
  --card: #ffffff;
  --card-subtle: #f7f9fb;
  --text: #18202b;
  --muted: #5b6675;
  --line: #d3dae2;
  --line-light: #e4e9f0;
  --accent: #1f9e8e;
  --accent-hover: #178376;
  --accent-text: #ffffff;
  --accent-subtle: rgba(31, 158, 142, 0.12);
  --danger: #c2412d;
  --danger-bg: rgba(194, 65, 45, 0.1);
  --ok: #1d8556;
  --ok-bg: rgba(29, 133, 86, 0.12);
  --warning: #b37400;
  --warning-bg: rgba(179, 116, 0, 0.1);
  --bar: #1f9e8e;
  --bar-bg: #dde3ea;
  --radius-card: 16px;
  --radius-pill: 10px;
  --radius-btn: 12px;
  --shadow: 0 2px 10px rgba(24, 32, 43, 0.05);
  --shadow-lg: 0 10px 30px rgba(24, 32, 43, 0.12);
  --font-main: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #11151c;
    --card: #1a2029;
    --card-subtle: #141920;
    --text: #e8ecf1;
    --muted: #9aa5b4;
    --line: #2c3541;
    --line-light: #202732;
    --accent: #3cc4b2;
    --accent-hover: #4fd1bf;
    --accent-text: #141a22;
    --accent-subtle: rgba(60, 196, 178, 0.15);
    --danger: #f08a74;
    --danger-bg: rgba(240, 138, 116, 0.15);
    --ok: #5ccb94;
    --ok-bg: rgba(92, 203, 148, 0.15);
    --warning: #e5a43b;
    --warning-bg: rgba(229, 164, 59, 0.15);
    --bar: #3cc4b2;
    --bar-bg: #232b37;
    --shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 10px 30px rgba(0, 0, 0, 0.5);
  }
}

:root[data-theme="dark"] {
  --bg: #11151c;
  --card: #1a2029;
  --card-subtle: #141920;
  --text: #e8ecf1;
  --muted: #9aa5b4;
  --line: #2c3541;
  --line-light: #202732;
  --accent: #3cc4b2;
  --accent-hover: #4fd1bf;
  --accent-text: #141a22;
  --accent-subtle: rgba(60, 196, 178, 0.15);
  --danger: #f08a74;
  --danger-bg: rgba(240, 138, 116, 0.15);
  --ok: #5ccb94;
  --ok-bg: rgba(92, 203, 148, 0.15);
  --warning: #e5a43b;
  --warning-bg: rgba(229, 164, 59, 0.15);
  --bar: #3cc4b2;
  --bar-bg: #232b37;
  --shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 10px 30px rgba(0, 0, 0, 0.5);
}

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

[hidden] {
  display: none !important;
}

html, body {
  width: 100%;
  min-height: 100%;
  background-color: var(--bg);
  color: var(--text);
  font-family: var(--font-main);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.tabular {
  font-variant-numeric: tabular-nums;
}

.app-container {
  width: 100%;
  max-width: 900px;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top, 16px)) max(16px, env(safe-area-inset-right, 16px)) max(48px, env(safe-area-inset-bottom, 48px)) max(16px, env(safe-area-inset-left, 16px));
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Card generic */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  padding: 18px 20px;
  box-shadow: var(--shadow);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 42px;
  padding: 0 16px;
  border-radius: var(--radius-btn);
  font-size: 0.95rem;
  font-weight: 600;
  border: 1px solid transparent;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  text-decoration: none;
  white-space: nowrap;
}

.btn:active {
  transform: scale(0.97);
}

.btn-sm {
  height: 34px;
  padding: 0 12px;
  font-size: 0.84rem;
  border-radius: var(--radius-pill);
}

.btn-primary {
  background: var(--accent);
  color: var(--accent-text);
  border-color: var(--accent);
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-secondary {
  background: var(--card);
  border-color: var(--line);
  color: var(--text);
}

.btn-secondary:hover {
  background: var(--card-subtle);
  border-color: var(--muted);
}

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--muted);
}

.btn-ghost:hover {
  background: var(--accent-subtle);
  color: var(--text);
}

.btn-danger-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--danger);
}

.btn-danger-ghost:hover {
  background: var(--danger-bg);
}

.btn-icon {
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.btn-icon-sm {
  width: 32px;
  height: 32px;
  padding: 0;
  border-radius: var(--radius-pill);
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  background: var(--bar-bg);
  color: var(--muted);
  border: 1px solid var(--line);
  line-height: 1.2;
}

.badge-accent {
  background: var(--accent-subtle);
  color: var(--accent);
  border-color: var(--accent);
}

.badge-ok {
  background: var(--ok-bg);
  color: var(--ok);
  border-color: var(--ok);
}

.badge-danger {
  background: var(--danger-bg);
  color: var(--danger);
  border-color: var(--danger);
}

/* Header */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding-bottom: 4px;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-icon {
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  border-radius: 8px;
}

.brand-titles {
  display: flex;
  flex-direction: column;
}

.app-title {
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.app-subtitle {
  font-size: 0.78rem;
  color: var(--muted);
  font-weight: 500;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* Lesson Selector Bar */
.lesson-bar {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Level Filter Pills */
.level-filter-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.level-filter-label {
  font-size: 0.82rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.level-filter-pills {
  display: inline-flex;
  background: var(--card-subtle);
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  padding: 3px;
  gap: 4px;
  flex-wrap: wrap;
}

.level-filter-pill {
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 600;
  padding: 5px 11px;
  border-radius: calc(var(--radius-pill) - 2px);
  cursor: pointer;
  transition: all 0.15s ease;
  user-select: none;
  -webkit-user-select: none;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.level-filter-pill:hover {
  color: var(--text);
}

.level-filter-pill.active {
  background: var(--card);
  color: var(--accent);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
  font-weight: 700;
}

.level-pill-count {
  font-size: 0.74rem;
  opacity: 0.75;
}

.lesson-top-row {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.lesson-select-wrap {
  flex: 1;
  min-width: 240px;
  position: relative;
}

.lesson-select {
  width: 100%;
  height: 44px;
  padding: 0 36px 0 14px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  font-size: 0.95rem;
  font-weight: 600;
  appearance: none;
  -webkit-appearance: none;
  cursor: pointer;
  outline: none;
  transition: border-color 0.15s ease;
}

.lesson-select:focus {
  border-color: var(--accent);
}

.select-arrow {
  position: absolute;
  right: 14px;
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
  color: var(--muted);
  display: flex;
}

.lesson-meta-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  padding-top: 4px;
  border-top: 1px dashed var(--line-light);
}

.lesson-meta-badges {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.lesson-manage-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

/* Tabs: Main 4 Exercises */
.exercise-tabs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

@media (max-width: 640px) {
  .exercise-tabs {
    grid-template-columns: repeat(2, 1fr);
  }
}

.ex-tab-btn {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  cursor: pointer;
  transition: all 0.15s ease;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  text-align: left;
}

.ex-tab-btn:hover {
  border-color: var(--muted);
}

.ex-tab-btn.active {
  background: var(--accent-subtle);
  border-color: var(--accent);
}

.ex-tab-title {
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--text);
}

.ex-tab-progress {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.76rem;
  color: var(--muted);
}

.ex-tab-btn.active .ex-tab-progress {
  color: var(--accent);
  font-weight: 600;
}

/* Sub-tabs for approaches / difficulty */
.subtabs-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.subtabs-pills {
  display: inline-flex;
  background: var(--card-subtle);
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  padding: 3px;
  gap: 4px;
  flex-wrap: wrap;
}

.subtab-pill {
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: calc(var(--radius-pill) - 2px);
  cursor: pointer;
  transition: all 0.15s ease;
  user-select: none;
  -webkit-user-select: none;
}

.subtab-pill:hover {
  color: var(--text);
}

.subtab-pill.active {
  background: var(--card);
  color: var(--accent);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
}

.subtab-stats {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.85rem;
  color: var(--muted);
}

.subtab-stats strong {
  color: var(--text);
}

/* Progress track */
.progress-bar-container {
  width: 100%;
  height: 6px;
  background: var(--bar-bg);
  border-radius: 999px;
  overflow: hidden;
  margin: 8px 0 16px 0;
}

.progress-bar-fill {
  height: 100%;
  width: 0%;
  background: var(--bar);
  border-radius: 999px;
  transition: width 0.25s ease;
}

/* ========================================================
   EXERCISE 1: MATCHING (Pairs)
   ======================================================== */
.matching-board {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

@media (max-width: 600px) {
  .matching-board {
    grid-template-columns: 1fr;
    gap: 12px;
  }
}

.matching-column {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.matching-column-title {
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin-bottom: 4px;
}

.match-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  min-height: 48px;
  background: var(--card);
  border: 1.5px solid var(--line);
  border-radius: var(--radius-pill);
  cursor: pointer;
  transition: all 0.15s ease;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  font-size: 0.95rem;
  line-height: 1.35;
}

.match-card:hover:not(.solved):not(.selected) {
  border-color: var(--muted);
  background: var(--card-subtle);
}

.match-card.selected {
  border-color: var(--accent);
  background: var(--accent-subtle);
  box-shadow: 0 0 0 2px var(--accent-subtle);
  font-weight: 600;
}

.match-card.solved {
  border-color: var(--ok);
  background: var(--ok-bg);
  color: var(--ok);
  cursor: default;
  font-weight: 600;
}

.match-card.shake {
  animation: shake 0.5s cubic-bezier(0.36, 0.07, 0.19, 0.97) both;
  border-color: var(--danger);
  background: var(--danger-bg);
}

@keyframes shake {
  10%, 90% { transform: translate3d(-1px, 0, 0); }
  20%, 80% { transform: translate3d(2px, 0, 0); }
  30%, 50%, 70% { transform: translate3d(-3px, 0, 0); }
  40%, 60% { transform: translate3d(3px, 0, 0); }
}

.match-index-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 6px;
  background: var(--bar-bg);
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  flex-shrink: 0;
}

.match-card.solved .match-index-badge {
  background: var(--ok);
  color: #ffffff;
}

.match-card-text {
  flex: 1;
}

/* Solved Celebration Banner */
.celebration-box {
  background: var(--ok-bg);
  border: 1px solid var(--ok);
  border-radius: var(--radius-card);
  padding: 18px 20px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  margin-top: 16px;
}

.celebration-title {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--ok);
}

/* ========================================================
   EXERCISE 2: FILL IN BLANKS
   ======================================================== */
.word-bank-card {
  background: var(--card-subtle);
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  padding: 12px 14px;
  margin-bottom: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.word-bank-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.82rem;
  color: var(--muted);
  font-weight: 600;
}

.word-bank-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.word-chip {
  display: inline-flex;
  align-items: center;
  padding: 6px 12px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  transition: all 0.15s ease;
  user-select: none;
  -webkit-user-select: none;
}

.word-chip:hover {
  border-color: var(--accent);
}

.word-chip.used {
  opacity: 0.45;
  text-decoration: line-through;
  background: transparent;
  cursor: default;
}

.blanks-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.blank-sentence-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  padding: 14px 16px;
  display: flex;
  align-items: baseline;
  gap: 10px;
  font-size: 1.05rem;
  line-height: 1.8;
}

.sentence-num {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--muted);
  background: var(--bar-bg);
  padding: 2px 8px;
  border-radius: 6px;
  flex-shrink: 0;
}

.sentence-text {
  flex: 1;
}

.blank-slot {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 90px;
  height: 32px;
  padding: 0 10px;
  margin: 0 4px;
  vertical-align: middle;
  background: var(--bg);
  border: 1.5px dashed var(--line);
  border-radius: 8px;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  transition: all 0.15s ease;
  user-select: none;
  -webkit-user-select: none;
}

.blank-slot:hover {
  border-color: var(--accent);
  background: var(--card-subtle);
}

.blank-slot.correct {
  background: var(--ok-bg);
  border: 1.5px solid var(--ok);
  color: var(--ok);
}

.blank-slot.wrong {
  background: var(--danger-bg);
  border: 1.5px solid var(--danger);
  color: var(--danger);
  animation: shake 0.4s ease;
}

.blank-slot.revealed {
  background: var(--warning-bg);
  border: 1.5px solid var(--warning);
  color: var(--warning);
}

/* ========================================================
   EXERCISE 3: QCM (Multiple Choice)
   ======================================================== */
.qcm-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.qcm-filter-pills {
  display: inline-flex;
  background: var(--card-subtle);
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  padding: 3px;
  gap: 4px;
}

.qcm-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.qcm-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: var(--shadow);
}

.qcm-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.qcm-target-badge {
  font-size: 0.95rem;
  font-weight: 700;
  padding: 4px 10px;
  background: var(--accent-subtle);
  color: var(--accent);
  border-radius: var(--radius-pill);
  border: 1px solid var(--accent);
}

.qcm-question-text {
  font-size: 1.05rem;
  font-weight: 600;
  line-height: 1.4;
}

.qcm-options-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

.qcm-option-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: var(--card-subtle);
  border: 1.5px solid var(--line);
  border-radius: var(--radius-pill);
  font-size: 0.95rem;
  color: var(--text);
  cursor: pointer;
  text-align: left;
  transition: all 0.15s ease;
  user-select: none;
  -webkit-user-select: none;
}

.qcm-option-btn:hover:not(:disabled) {
  border-color: var(--accent);
  background: var(--card);
}

.qcm-letter-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: var(--bar-bg);
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 700;
  flex-shrink: 0;
}

.qcm-option-btn.selected-correct {
  border-color: var(--ok);
  background: var(--ok-bg);
  color: var(--ok);
  font-weight: 600;
}

.qcm-option-btn.selected-correct .qcm-letter-badge {
  background: var(--ok);
  color: #ffffff;
}

.qcm-option-btn.selected-wrong {
  border-color: var(--danger);
  background: var(--danger-bg);
  color: var(--danger);
  animation: shake 0.4s ease;
}

.qcm-option-btn.selected-wrong .qcm-letter-badge {
  background: var(--danger);
  color: #ffffff;
}

.qcm-option-btn.reveal-correct {
  border-color: var(--ok);
  background: var(--ok-bg);
  color: var(--ok);
}

.qcm-explanation {
  background: var(--card-subtle);
  border-left: 3px solid var(--accent);
  border-radius: 0 8px 8px 0;
  padding: 10px 14px;
  font-size: 0.88rem;
  color: var(--text);
  display: flex;
  flex-direction: column;
  gap: 4px;
  animation: fadeIn 0.25s ease;
}

.qcm-explanation-label {
  font-size: 0.76rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

/* ========================================================
   EXERCISE 4: TRANSLATION (RU -> EN)
   ======================================================== */
.translation-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.tr-card {
  background: var(--card);
  border: 1.5px solid var(--line);
  border-radius: var(--radius-card);
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: var(--shadow);
  transition: border-color 0.15s ease;
}

.tr-card.status-correct {
  border-color: var(--ok);
}

.tr-card.status-wrong {
  border-color: var(--danger);
}

.tr-ru-header {
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.tr-num-badge {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--muted);
  background: var(--bar-bg);
  padding: 2px 8px;
  border-radius: 6px;
  flex-shrink: 0;
}

.tr-ru-text {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text);
  line-height: 1.4;
}

.tr-input-row {
  display: flex;
  gap: 10px;
}

.tr-input {
  flex: 1;
  height: 44px;
  padding: 0 14px;
  font-size: 1rem;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.tr-input:focus {
  border-color: var(--accent);
}

.tr-feedback-box {
  padding: 10px 14px;
  border-radius: var(--radius-pill);
  font-size: 0.88rem;
  line-height: 1.4;
  display: flex;
  flex-direction: column;
  gap: 6px;
  animation: fadeIn 0.2s ease;
}

.tr-feedback-correct {
  background: var(--ok-bg);
  color: var(--ok);
  border: 1px solid var(--ok);
}

.tr-feedback-wrong {
  background: var(--danger-bg);
  color: var(--danger);
  border: 1px solid var(--danger);
}

.tr-alternatives {
  font-size: 0.82rem;
  color: var(--text);
  opacity: 0.88;
  margin-top: 2px;
}

.tr-feedback-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 4px;
}

/* ========================================================
   MODALS
   ======================================================== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  animation: fadeIn 0.15s ease;
}

.modal-dialog {
  width: 100%;
  max-width: 580px;
  max-height: 90vh;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: modalPop 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes modalPop {
  0% { transform: scale(0.96) translateY(6px); opacity: 0; }
  100% { transform: scale(1) translateY(0); opacity: 1; }
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line-light);
}

.modal-title {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text);
}

.modal-close-btn {
  background: transparent;
  border: none;
  font-size: 1.5rem;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
  padding: 4px;
  display: flex;
}

.modal-close-btn:hover {
  color: var(--text);
}

.modal-body {
  padding: 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.modal-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--line-light);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  background: var(--card-subtle);
}

/* Modal Form Controls */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-label {
  font-size: 0.86rem;
  font-weight: 600;
  color: var(--text);
}

.form-control {
  width: 100%;
  height: 42px;
  padding: 0 14px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  font-size: 0.95rem;
  color: var(--text);
  outline: none;
  transition: border-color 0.15s ease;
}

.form-control:focus {
  border-color: var(--accent);
}

textarea.form-control {
  height: 120px;
  padding: 10px 14px;
  font-family: inherit;
  resize: vertical;
}

/* Drag and Drop Zone */
.dropzone {
  border: 2px dashed var(--line);
  border-radius: var(--radius-card);
  padding: 28px 20px;
  text-align: center;
  background: var(--bg);
  cursor: pointer;
  transition: all 0.15s ease;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.dropzone:hover, .dropzone.dragover {
  border-color: var(--accent);
  background: var(--accent-subtle);
}

.dropzone-icon {
  width: 42px;
  height: 42px;
  color: var(--muted);
}

.dropzone-text {
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--text);
}

.dropzone-subtext {
  font-size: 0.8rem;
  color: var(--muted);
}

/* Prompt preview block */
.prompt-preview-block {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  padding: 12px;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  line-height: 1.45;
  color: var(--text);
  max-height: 160px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

/* Step instruction list */
.step-guide-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.step-guide-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  font-size: 0.88rem;
}

.step-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--accent-subtle);
  color: var(--accent);
  font-weight: 700;
  font-size: 0.8rem;
  flex-shrink: 0;
  margin-top: 1px;
}

/* ========================================================
   WORD PICKER POPOVER (For Blanks)
   ======================================================== */
.word-picker-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.3);
  z-index: 1200;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

@media (min-width: 600px) {
  .word-picker-overlay {
    align-items: center;
  }
}

.word-picker-dialog {
  width: 100%;
  max-width: 480px;
  background: var(--card);
  border-top-left-radius: var(--radius-card);
  border-top-right-radius: var(--radius-card);
  border: 1px solid var(--line);
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: var(--shadow-lg);
  max-height: 75vh;
  overflow-y: auto;
}

@media (min-width: 600px) {
  .word-picker-dialog {
    border-radius: var(--radius-card);
  }
}

.word-picker-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text);
}

.word-picker-words {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.word-picker-option {
  padding: 8px 14px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  transition: all 0.15s ease;
}

.word-picker-option:hover {
  background: var(--accent);
  color: var(--accent-text);
  border-color: var(--accent);
}

/* Toast container */
.toast-container {
  position: fixed;
  bottom: max(16px, env(safe-area-inset-bottom, 16px));
  right: 16px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  padding: 10px 16px;
  box-shadow: var(--shadow-lg);
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
  animation: toastIn 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.toast.toast-ok {
  border-color: var(--ok);
  color: var(--ok);
}

.toast.toast-error {
  border-color: var(--danger);
  color: var(--danger);
}

@keyframes toastIn {
  from { opacity: 0; transform: translateY(12px) scale(0.95); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

/* Empty State Card */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

.empty-icon {
  width: 56px;
  height: 56px;
  color: var(--muted);
}

.empty-title {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text);
}

.empty-desc {
  font-size: 0.92rem;
  color: var(--muted);
  max-width: 440px;
  line-height: 1.5;
}
