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

:root {
  --bg: #faf9f6;
  --card: #fff;
  --text: #1a1a2e;
  --text-secondary: #374151;
  --accent: #6366f1;
  --accent-hover: #4f46e5;
  --accent-light: #eef2ff;
  --accent-glow: rgba(99,102,241,0.15);
  --border: #e8e5e0;
  --muted: #78716c;
  --success: #10b981;
  --danger: #ef4444;
  --warning: #f59e0b;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 1px 3px rgba(0,0,0,0.04);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg); color: var(--text); line-height: 1.6; min-height: 100vh;
}

.app { min-height: 100vh; display: flex; flex-direction: column; }

/* Header */
.header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 28px; height: 56px; background: rgba(250,249,246,0.92);
  backdrop-filter: blur(8px); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 100;
}
.header-left { display: flex; align-items: center; gap: 10px; }
.header-left h1 { font-size: 16px; font-weight: 700; letter-spacing: -0.3px; display: flex; align-items: center; gap: 8px; }
.badge {
  display: inline-block; background: linear-gradient(135deg, #a78bfa, #6366f1);
  color: #fff; font-size: 10px; padding: 2px 8px; border-radius: 20px; font-weight: 600; letter-spacing: 0.5px;
}
.header-nav { display: flex; gap: 4px; }
.nav-link {
  padding: 7px 14px; border: none; background: transparent; color: var(--muted);
  font-size: 13px; cursor: pointer; border-radius: 8px; font-weight: 500;
  display: flex; align-items: center; gap: 5px; font-family: inherit; transition: all 0.15s;
}
.nav-link:hover { background: var(--accent-light); color: var(--accent); }

/* API Status */
.api-status {
  display: flex; align-items: center; gap: 6px; padding: 8px 28px;
  font-size: 12px; color: var(--muted); max-width: 1440px; margin: 0 auto; width: 100%;
}
.status-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--warning); }
.api-status.online .status-dot { background: var(--success); }
.api-status.mock .status-dot { background: var(--accent); }
.api-status.offline .status-dot { background: var(--danger); }

/* Main Layout */
.main {
  flex: 1; display: grid; grid-template-columns: 45fr 55fr;
  gap: 24px; padding: 24px 28px; max-width: 1440px; margin: 0 auto; width: 100%;
}

/* Panels */
.panel { display: flex; flex-direction: column; gap: 20px; min-width: 0; }
.panel-left { min-height: 0; }
.panel-right {
  background: var(--card); border-radius: var(--radius); border: 1px solid var(--border);
  padding: 24px; box-shadow: var(--shadow); height: fit-content; position: sticky; top: 80px;
}

/* Config Sections */
.config-section { margin-bottom: 4px; }
.section-label {
  font-size: 12px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 1.2px; color: var(--muted); margin-bottom: 10px;
  display: flex; align-items: center; gap: 8px;
}
.section-label::after { content: ''; flex: 1; height: 1px; background: var(--border); }

/* Topic Tags */
.topic-tags { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.tag-btn {
  padding: 8px 14px; border: 2px solid var(--border); border-radius: 24px;
  background: var(--card); color: var(--text); font-size: 13px; font-weight: 500;
  cursor: pointer; font-family: inherit; transition: all 0.15s;
}
.tag-btn:hover { border-color: var(--accent); color: var(--accent); }
.tag-btn.selected { border-color: var(--accent); background: var(--accent-light); color: var(--accent); font-weight: 600; }

.topic-input {
  width: 100%; padding: 10px 16px; border: 2px solid var(--border); border-radius: 12px;
  font-size: 13px; font-family: inherit; outline: none; background: var(--card);
  transition: border-color 0.2s;
}
.topic-input:focus { border-color: var(--accent); }
.topic-input::placeholder { color: #b0aca5; }

.topic-merged {
  margin-top: 10px; padding: 10px 14px; background: var(--accent-light);
  border-radius: 10px; font-size: 13px; color: var(--accent);
}

/* Card Options (Difficulty & Type) */
.card-row { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.card-option {
  background: var(--card); border: 2px solid var(--border); border-radius: 14px;
  padding: 18px 14px; cursor: pointer; transition: all 0.18s;
  text-align: center; position: relative; font-family: inherit;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
}
.card-option:hover { border-color: var(--accent); transform: translateY(-1px); box-shadow: 0 6px 16px rgba(0,0,0,0.05); }
.card-option.selected { border-color: var(--accent); background: #eef2ff; box-shadow: 0 0 0 4px var(--accent-glow); }
.card-option .card-emoji { font-size: 26px; }
.card-option .card-name { font-size: 14px; font-weight: 600; color: var(--text); }
.card-option .card-hint { font-size: 11px; color: var(--muted); line-height: 1.3; }

/* Generate Button */
.generate-btn {
  width: 100%; padding: 14px 24px; background: linear-gradient(135deg, var(--accent), var(--accent-hover));
  border: none; color: #fff; font-size: 15px; font-weight: 700; cursor: pointer; border-radius: 12px;
  transition: all 0.2s; display: flex; align-items: center; justify-content: center; gap: 8px; font-family: inherit;
  box-shadow: 0 4px 16px rgba(99,102,241,0.25);
}
.generate-btn:hover { transform: translateY(-1px); box-shadow: 0 6px 20px rgba(99,102,241,0.35); }
.generate-btn:disabled { opacity: 0.35; cursor: not-allowed; transform: none; box-shadow: none; }

/* Preview Area */
.preview-area {
  background: var(--card); border-radius: var(--radius); border: 1px solid var(--border);
  box-shadow: var(--shadow); overflow: hidden; flex: 1;
}
.preview-placeholder {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 72px 24px; color: var(--muted); gap: 14px;
}
.preview-placeholder p { font-size: 14px; }
.preview-loading {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 72px 24px; gap: 16px; color: var(--muted);
}
.spinner {
  width: 36px; height: 36px; border: 3px solid var(--border);
  border-top-color: var(--accent); border-radius: 50%; animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.preview-content { padding: 24px; font-size: 14px; line-height: 1.9; color: var(--text-secondary); max-height: 500px; overflow-y: auto; }
.preview-actions {
  display: flex; gap: 10px; padding: 14px 24px; border-top: 1px solid var(--border);
  background: #faf9f6;
}

/* Buttons */
.btn {
  padding: 10px 20px; border-radius: 10px; font-size: 13px; font-weight: 600;
  cursor: pointer; transition: all 0.15s; border: none; font-family: inherit;
  display: flex; align-items: center; gap: 6px; justify-content: center;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-outline { background: #fff; color: var(--text-secondary); border: 1px solid var(--border); }
.btn-outline:hover { border-color: var(--accent); color: var(--accent); }
.btn-full { width: 100%; padding: 12px 24px; }

/* Basket Header */
.basket-header { display: flex; flex-direction: column; gap: 10px; }
.basket-header h2 { font-size: 18px; font-weight: 700; letter-spacing: -0.3px; }
.exam-title-input {
  width: 100%; padding: 11px 16px; border: 2px solid var(--border); border-radius: 12px;
  font-size: 14px; font-family: inherit; outline: none; background: #faf9f6; transition: border-color 0.2s;
}
.exam-title-input:focus { border-color: var(--accent); }

/* Basket List */
.basket-list { flex: 1; min-height: 200px; }
.basket-empty {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 64px 24px; color: var(--muted); gap: 12px;
}
.basket-empty p { font-size: 13px; }

.basket-item {
  display: flex; align-items: center; gap: 12px; padding: 14px 16px;
  background: #faf9f6; border: 1px solid var(--border); border-radius: 12px;
  margin-bottom: 10px; transition: all 0.15s; animation: slideIn 0.25s ease;
}
@keyframes slideIn { from { opacity:0; transform: translateY(-8px); } to { opacity:1; transform: translateY(0); } }
.basket-item:hover { border-color: var(--accent); box-shadow: var(--shadow); }
.basket-item.sortable-ghost { opacity: 0.4; background: var(--accent-light); border: 2px dashed var(--accent); }
.basket-item.sortable-chosen { box-shadow: 0 8px 24px rgba(0,0,0,0.1); }

.drag-handle {
  cursor: grab; color: var(--muted); padding: 4px; flex-shrink: 0;
  display: flex; flex-direction: column; gap: 2px; align-items: center;
}
.drag-handle:active { cursor: grabbing; }
.drag-handle span {
  width: 18px; height: 2px; background: var(--muted); border-radius: 1px;
}
.basket-item-info { flex: 1; min-width: 0; }
.basket-item-info .bi-type { font-size: 14px; font-weight: 600; color: var(--text); }
.basket-item-info .bi-meta { font-size: 12px; color: var(--muted); margin-top: 2px; display: flex; gap: 8px; }

.basket-item-remove {
  background: none; border: none; color: var(--muted); cursor: pointer;
  font-size: 18px; padding: 4px 8px; border-radius: 6px; transition: all 0.15s;
  line-height: 1; flex-shrink: 0;
}
.basket-item-remove:hover { color: var(--danger); background: #fef2f2; }

/* Basket Stats */
.basket-stats {
  display: flex; align-items: center; gap: 12px; padding: 14px 16px;
  background: var(--accent-light); border-radius: 12px; font-size: 13px; color: var(--accent);
  flex-wrap: wrap;
}


/* Basket Actions */
.basket-actions { display: flex; flex-direction: column; gap: 8px; }

/* Preview content styles */
.preview-passage {
  padding: 20px; background: #faf9f6; border-radius: 12px; line-height: 2;
  margin-bottom: 18px; font-size: 14px; text-align: justify;
}
.preview-question {
  margin: 14px 0; padding: 14px 16px; background: #faf9f6; border-radius: 10px;
}
.preview-answer {
  margin-top: 16px; padding: 14px 16px; background: #ecfdf5;
  border-left: 3px solid var(--success); border-radius: 0 10px 10px 0; font-size: 13px;
}
.preview-token { border-bottom: 2px solid var(--accent); padding: 0 12px; color: var(--accent); font-weight: 600; }

/* Toast */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(100px);
  background: var(--text); color: #fff; padding: 12px 24px; border-radius: 10px;
  font-size: 13px; font-weight: 500; z-index: 1000; opacity: 0;
  transition: all 0.3s ease; box-shadow: 0 8px 24px rgba(0,0,0,0.15);
  pointer-events: none;
}
.toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }

/* Modal */
.modal {
  display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.4);
  backdrop-filter: blur(4px); z-index: 200; align-items: center; justify-content: center;
}
.modal.show { display: flex; }
.modal-card {
  background: #fff; border-radius: var(--radius); width: 90%; max-width: 640px;
  max-height: 80vh; display: flex; flex-direction: column; animation: modalIn 0.25s ease;
  box-shadow: 0 16px 48px rgba(0,0,0,0.12);
}
@keyframes modalIn { from { opacity:0; transform: scale(0.96); } to { opacity:1; transform: scale(1); } }
.modal-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 18px 24px; border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 16px; font-weight: 700; }
.modal-close {
  background: none; border: none; font-size: 24px; color: var(--muted);
  cursor: pointer; padding: 4px 8px; border-radius: 6px; line-height: 1; transition: all 0.15s;
}
.modal-close:hover { background: #f3f4f6; color: var(--text); }
.modal-body { padding: 24px; overflow-y: auto; max-height: 60vh; }

.modal-empty { text-align: center; padding: 48px 24px; color: var(--muted); }
.modal-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; border: 1px solid var(--border); border-radius: 12px; margin-bottom: 10px;
}
.modal-item-info h4 { font-size: 14px; font-weight: 600; }
.modal-item-info p { font-size: 12px; color: var(--muted); margin-top: 4px; }
.modal-item-actions { display: flex; gap: 6px; flex-shrink: 0; }

/* Password Gate */
.gate-overlay {
  position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  z-index: 9999;
}
.gate-card {
  background: var(--card); border-radius: 20px; padding: 48px 40px;
  max-width: 400px; width: 90%; text-align: center;
  box-shadow: 0 4px 24px rgba(0,0,0,0.06), 0 1px 4px rgba(0,0,0,0.04);
}
.gate-card h2 { font-size: 20px; color: var(--text); margin: 20px 0 8px; }
.gate-card p { font-size: 14px; color: var(--muted); margin-bottom: 24px; }
.gate-card input {
  width: 100%; padding: 12px 16px; border: 2px solid var(--border);
  border-radius: 12px; font-size: 16px; text-align: center;
  font-family: monospace; letter-spacing: 2px;
  outline: none; transition: border-color .2s;
}
.gate-card input:focus { border-color: var(--accent); }
.gate-card button {
  width: 100%; margin-top: 16px; padding: 12px;
  background: var(--accent); color: #fff; border: none;
  border-radius: 12px; font-size: 15px; font-weight: 600;
  cursor: pointer; transition: background .2s;
}
.gate-card button:hover { background: var(--accent-hover); }
.gate-card button:disabled { background: #9ca3af; cursor: not-allowed; }
.gate-error { color: var(--danger); font-size: 13px; margin-top: 12px; display: none; }
.gate-error.show { display: block; }
.gate-card input.shake {
  border-color: var(--danger);
  animation: gateShake .4s ease;
}
@keyframes gateShake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}

/* Responsive */
@media (max-width: 900px) {
  .main { grid-template-columns: 1fr; }
  .panel-right { position: static; }
  .card-row { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 600px) {
  .header { padding: 0 16px; }
  .header-left h1 { font-size: 14px; }
  .nav-link { font-size: 12px; padding: 6px 10px; }
  .main { padding: 16px; }
  .card-row { grid-template-columns: repeat(2, 1fr); }
  .preview-content { max-height: 350px; }
}
