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

/* ── Tokens ── */
:root {
  --bg:          #18160f;
  --surface:     #221f17;
  --surface-2:   #2c2920;
  --surface-3:   #35312a;
  --border:      #403c33;
  --border-soft: #2c2920;

  --text:        #f2ece0;
  --text-muted:  #9c9588;
  --text-dim:    #6b6660;

  --amber:       #d4a017;
  --amber-bright:#e8b830;
  --amber-glow:  rgba(212,160,23,0.12);

  --success:     #5a9e6f;
  --success-bg:  rgba(90,158,111,0.12);
  --danger:      #c05a4a;
  --danger-bg:   rgba(192,90,74,0.12);

  --card-face:   #f4efe3;
  --card-text:   #1c1a14;
  --card-back-bg:#1e2d22;
  --card-back-text: #d4f0de;

  --radius:      14px;
  --radius-sm:   9px;
  --radius-xs:   5px;
  --transition:  0.16s ease;

  --font-display: 'Lora', Georgia, serif;
  --font-ui:      'DM Sans', system-ui, sans-serif;
}

/* ── Base ── */
html { font-size: 17px; }

body {
  font-family: var(--font-ui);
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  /* subtle warm noise texture */
  background-image:
    radial-gradient(ellipse 80% 50% at 50% -10%, rgba(212,160,23,0.06) 0%, transparent 60%);
}

/* ── Layout ── */
#app {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  max-width: 700px;
  margin: 0 auto;
}

/* ── Topbar ── */
#topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 18px 24px;
  border-bottom: 1px solid var(--border-soft);
  position: sticky;
  top: 0;
  background: rgba(24,22,15,0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  z-index: 10;
}

#topbar-title {
  flex: 1;
  font-family: var(--font-display);
  font-size: 1.1rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  color: var(--text);
}

.icon-btn {
  background: none;
  border: 1px solid transparent;
  color: var(--text-muted);
  cursor: pointer;
  padding: 8px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color var(--transition), background var(--transition), border-color var(--transition);
  flex-shrink: 0;
}
.icon-btn svg { width: 20px; height: 20px; }
.icon-btn:hover {
  color: var(--text);
  background: var(--surface-2);
  border-color: var(--border);
}
.icon-btn.active {
  color: var(--amber);
  background: var(--amber-glow);
  border-color: rgba(212,160,23,0.3);
}

/* ── Views ── */
.view { display: none; flex: 1; padding: 28px 24px; }
.view.active { display: block; }

/* ── Deck grid ── */
.deck-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
@media (max-width: 420px) {
  .deck-grid { grid-template-columns: 1fr; }
}

.deck-card {
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 22px 20px 20px;
  cursor: pointer;
  transition: background var(--transition), transform 0.2s ease, box-shadow 0.2s ease, border-color var(--transition);
  display: flex;
  flex-direction: column;
  gap: 10px;
  position: relative;
  overflow: hidden;
}
/* top accent stripe */
.deck-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: var(--amber);
  opacity: 0.5;
  transition: opacity var(--transition);
}
.deck-card:hover {
  background: var(--surface-2);
  transform: translateY(-3px);
  box-shadow: 0 8px 32px rgba(0,0,0,0.5), 0 0 0 1px var(--border);
  border-color: var(--border);
}
.deck-card:hover::before { opacity: 1; }

.deck-card-name {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.05rem;
  line-height: 1.35;
  color: var(--text);
}
.deck-card-count {
  font-size: 0.82rem;
  color: var(--text-muted);
  font-weight: 500;
  letter-spacing: 0.02em;
}

.deck-card-add {
  border: 1.5px dashed var(--border);
  background: transparent;
  color: var(--text-dim);
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  font-weight: 300;
  min-height: 90px;
}
.deck-card-add::before { display: none; }
.deck-card-add:hover {
  border-color: var(--amber);
  color: var(--amber);
  background: var(--amber-glow);
  transform: translateY(-3px);
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
}

/* ── Deck detail ── */
#deck-header { margin-bottom: 24px; }
#deck-title {
  font-family: var(--font-display);
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.2;
}
#deck-card-count {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-top: 6px;
}

.deck-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 32px;
}

.card-list { display: flex; flex-direction: column; gap: 10px; }

.card-item {
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  padding: 16px 18px;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition);
  display: flex;
  align-items: center;
  gap: 14px;
}
.card-item:hover {
  background: var(--surface-2);
  border-color: var(--border);
}
.card-item-thumb {
  width: 44px;
  height: 44px;
  object-fit: cover;
  border-radius: var(--radius-xs);
  flex-shrink: 0;
  border: 1px solid var(--border);
}
.card-item-text { flex: 1; min-width: 0; }
.card-item-front {
  font-size: 1rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text);
}
.card-item-back {
  font-size: 0.875rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 3px;
}

/* ── Session ── */
#view-session { padding-top: 24px; }

#session-progress {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 32px;
}
#progress-bar {
  flex: 1;
  height: 5px;
  background: var(--surface-3);
  border-radius: 99px;
  overflow: hidden;
}
#progress-fill {
  height: 100%;
  background: var(--amber);
  border-radius: 99px;
  transition: width 0.4s cubic-bezier(0.4,0,0.2,1);
  box-shadow: 0 0 8px rgba(212,160,23,0.5);
}
#progress-label {
  font-size: 0.875rem;
  color: var(--text-muted);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  font-weight: 500;
}

/* ── Flash card ── */
.flashcard {
  perspective: 1400px;
  cursor: pointer;
  margin: 0 auto;
  min-height: 300px;
  outline: none;
  width: 100%;
}
.flashcard-inner {
  position: relative;
  width: 100%;
  min-height: 300px;
  transform-style: preserve-3d;
  transition: transform 0.55s cubic-bezier(0.35, 0, 0.25, 1);
}
.flashcard.flipped .flashcard-inner { transform: rotateY(180deg); }

.flashcard-front,
.flashcard-back {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  border-radius: var(--radius);
  padding: 36px 32px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  text-align: center;
}

/* Front: physical card face */
.flashcard-front {
  background: var(--card-face);
  border: 1px solid rgba(0,0,0,0.12);
  box-shadow:
    0 2px 0 rgba(0,0,0,0.1),
    0 12px 40px rgba(0,0,0,0.5),
    inset 0 1px 0 rgba(255,255,255,0.6);
}

/* Back: reveal surface */
.flashcard-back {
  transform: rotateY(180deg);
  background: var(--card-back-bg);
  border: 1px solid rgba(90,158,111,0.2);
  box-shadow: 0 12px 40px rgba(0,0,0,0.5), 0 0 0 1px rgba(90,158,111,0.1);
}

.card-image {
  max-width: 100%;
  max-height: 200px;
  object-fit: contain;
  border-radius: var(--radius-sm);
}

#card-front-text {
  font-family: var(--font-display);
  font-size: 1.3rem;
  line-height: 1.6;
  color: var(--card-text);
  white-space: pre-wrap;
}
#card-back-text {
  font-family: var(--font-display);
  font-size: 1.25rem;
  line-height: 1.65;
  color: var(--card-back-text);
  white-space: pre-wrap;
}

#flip-hint {
  text-align: center;
  margin-top: 18px;
  font-size: 0.875rem;
  color: var(--text-dim);
  letter-spacing: 0.02em;
  transition: opacity 0.2s;
}
.flashcard.flipped ~ #flip-hint { opacity: 0; pointer-events: none; }

#session-rating {
  display: flex;
  gap: 14px;
  margin-top: 24px;
  justify-content: center;
}
#session-rating .btn {
  flex: 1;
  max-width: 180px;
  padding: 15px;
  font-size: 1rem;
}

/* ── Summary ── */
#view-summary { display: none; align-items: center; justify-content: center; }
#view-summary.active { display: flex; }

.summary-card {
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 48px 36px;
  text-align: center;
  width: 100%;
  max-width: 420px;
}
.summary-score {
  font-family: var(--font-display);
  font-size: 3.5rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--amber);
  margin-bottom: 10px;
  text-shadow: 0 0 40px rgba(212,160,23,0.3);
}
.summary-message {
  color: var(--text-muted);
  margin-bottom: 32px;
  font-size: 1rem;
}
.summary-actions { display: flex; flex-direction: column; gap: 10px; }

/* ── Editor ── */
#view-editor form { display: flex; flex-direction: column; gap: 22px; }
.form-group { display: flex; flex-direction: column; gap: 8px; }
.form-group label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

textarea,
input[type="text"],
input[type="password"] {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 1rem;
  font-family: var(--font-ui);
  padding: 13px 16px;
  width: 100%;
  transition: border-color var(--transition), box-shadow var(--transition);
  resize: vertical;
  line-height: 1.6;
}
textarea:focus,
input[type="text"]:focus,
input[type="password"]:focus {
  outline: none;
  border-color: var(--amber);
  box-shadow: 0 0 0 3px rgba(212,160,23,0.12);
}
textarea::placeholder,
input::placeholder {
  color: var(--text-dim);
}

#image-preview-wrap {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  flex-wrap: wrap;
}
#image-preview {
  max-height: 120px;
  max-width: 200px;
  object-fit: contain;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}
input[type="file"] {
  color: var(--text-muted);
  font-size: 0.9rem;
  padding: 4px 0;
}

.form-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 4px; }

/* ── Import ── */
#view-import form { display: flex; flex-direction: column; gap: 22px; }
#import-status {
  padding: 13px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  line-height: 1.5;
}
#import-status.success {
  background: var(--success-bg);
  color: #7ecf96;
  border: 1px solid rgba(90,158,111,0.25);
}
#import-status.error {
  background: var(--danger-bg);
  color: #e08070;
  border: 1px solid rgba(192,90,74,0.25);
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 11px 20px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-family: var(--font-ui);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition), transform var(--transition),
              opacity var(--transition), box-shadow var(--transition);
  text-decoration: none;
  white-space: nowrap;
  letter-spacing: 0.01em;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.btn-primary {
  background: var(--amber);
  color: #0e0d0a;
  border-color: var(--amber);
}
.btn-primary:hover:not(:disabled) {
  background: var(--amber-bright);
  box-shadow: 0 0 20px rgba(212,160,23,0.3);
}

.btn-secondary {
  background: var(--surface-2);
  color: var(--text);
  border-color: var(--border);
}
.btn-secondary:hover:not(:disabled) {
  background: var(--surface-3);
  border-color: var(--border);
}

.btn-success {
  background: var(--success);
  color: #fff;
  border-color: var(--success);
}
.btn-success:hover:not(:disabled) {
  background: #6ab87e;
  box-shadow: 0 0 20px rgba(90,158,111,0.3);
}

.btn-danger {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}
.btn-danger:hover:not(:disabled) {
  background: #d06050;
  box-shadow: 0 0 20px rgba(192,90,74,0.3);
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border-color: transparent;
}
.btn-ghost:hover:not(:disabled) {
  color: var(--text);
  background: var(--surface-2);
  border-color: var(--border);
}

.btn-sm { padding: 7px 13px; font-size: 0.85rem; }

/* ── Modal ── */
#modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 24px;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px 28px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 24px 64px rgba(0,0,0,0.6);
}
.modal h3 {
  font-family: var(--font-display);
  font-size: 1.25rem;
  font-weight: 600;
  margin-bottom: 20px;
  color: var(--text);
}
.modal input { margin-bottom: 14px; }

/* ── Misc ── */
.hint {
  font-size: 0.875rem;
  color: var(--text-muted);
  line-height: 1.6;
}
.hint code {
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 0.82em;
  background: var(--surface-3);
  color: var(--amber);
  padding: 2px 6px;
  border-radius: var(--radius-xs);
}
.error {
  font-size: 0.9rem;
  color: #e08070;
}
.empty-state {
  text-align: center;
  padding: 72px 24px;
  color: var(--text-muted);
}
.empty-state p {
  line-height: 2;
  font-size: 1rem;
}
.hidden { display: none !important; }

/* ── Offline banner ── */
#offline-banner {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: #3d2a0a;
  color: #f5c842;
  text-align: center;
  font-size: 0.875rem;
  font-weight: 500;
  padding: 10px;
  z-index: 200;
  border-top: 1px solid rgba(245,200,66,0.2);
  letter-spacing: 0.02em;
}

/* ── Deck card edit badge ── */
.deck-card-edit {
  position: absolute;
  top: 12px; right: 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  padding: 4px 8px;
  font-size: 0.72rem;
  color: var(--text-dim);
  cursor: pointer;
  transition: color var(--transition), background var(--transition);
  font-weight: 500;
  letter-spacing: 0.04em;
}
.deck-card-edit:hover { color: var(--text); background: var(--surface-3); }

/* ── Focus ring ── */
:focus-visible {
  outline: 2px solid var(--amber);
  outline-offset: 2px;
}
