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

:root {
  --red:     #C0392B;
  --red-lt:  #E74C3C;
  --dark:    #1a1a2e;
  --mid:     #2d2d44;
  --light:   #f5f5f0;
  --white:   #ffffff;
  --gray:    #8a8a9a;
  --border:  #e0e0d8;
  --card-bg: #ffffff;
  --shadow:  0 2px 12px rgba(0,0,0,0.08);
  --radius:  12px;
}

body { font-family: 'Segoe UI', system-ui, sans-serif; background: var(--light); color: #333; height: 100vh; overflow: hidden; }

/* ── Layout ── */
.app { display: flex; height: 100vh; }

/* ── Sidebar ── */
.sidebar { width: 260px; background: var(--dark); color: var(--white); display: flex; flex-direction: column; flex-shrink: 0; overflow-y: auto; }

.sidebar-header { padding: 28px 20px 20px; border-bottom: 1px solid rgba(255,255,255,0.08); }
.logo { font-size: 2.4rem; font-weight: 700; color: var(--red-lt); letter-spacing: 2px; }
.logo-sub { font-size: 0.95rem; font-weight: 600; color: var(--white); margin-top: 4px; }
.logo-np { font-size: 0.75rem; color: var(--gray); margin-top: 2px; }

.chapter-list { padding: 12px 0; flex: 1; }

.chapter-item { display: flex; align-items: center; gap: 12px; padding: 12px 20px; cursor: pointer; transition: background 0.15s; border-left: 3px solid transparent; }
.chapter-item:hover { background: rgba(255,255,255,0.06); }
.chapter-item.active { background: rgba(192,57,43,0.18); border-left-color: var(--red-lt); }

.chapter-num { width: 32px; height: 32px; border-radius: 8px; background: rgba(255,255,255,0.08); display: flex; align-items: center; justify-content: center; font-size: 0.8rem; font-weight: 700; color: var(--red-lt); flex-shrink: 0; }
.chapter-item.active .chapter-num { background: var(--red); color: #fff; }

.chapter-name { font-size: 0.875rem; font-weight: 500; color: var(--white); display: block; }
.chapter-count { font-size: 0.72rem; color: var(--gray); }

/* ── Main ── */
.main { flex: 1; display: flex; flex-direction: column; overflow: hidden; }

.main-header { padding: 24px 28px 16px; display: flex; align-items: flex-start; justify-content: space-between; border-bottom: 1px solid var(--border); background: var(--white); }
.main-header h1 { font-size: 1.5rem; font-weight: 700; color: var(--dark); }
.subtitle { font-size: 0.8rem; color: var(--gray); margin-top: 3px; }

.btn-add { background: var(--red); color: #fff; border: none; padding: 9px 18px; border-radius: 8px; font-size: 0.875rem; font-weight: 600; cursor: pointer; transition: background 0.15s; white-space: nowrap; }
.btn-add:hover { background: var(--red-lt); }

/* ── Section filters ── */
.section-filters { padding: 12px 28px; display: flex; gap: 8px; flex-wrap: wrap; background: var(--white); border-bottom: 1px solid var(--border); min-height: 52px; }
.filter-btn { padding: 5px 14px; border-radius: 20px; border: 1.5px solid var(--border); background: transparent; font-size: 0.8rem; cursor: pointer; transition: all 0.15s; color: #555; }
.filter-btn:hover { border-color: var(--red); color: var(--red); }
.filter-btn.active { background: var(--red); border-color: var(--red); color: #fff; }

/* ── Card Grid ── */
.card-grid { flex: 1; overflow-y: auto; padding: 24px 28px; display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; align-content: start; }

/* ── Flashcard ── */
.flashcard { perspective: 800px; height: 190px; cursor: pointer; }
.flashcard-inner { position: relative; width: 100%; height: 100%; transition: transform 0.45s; transform-style: preserve-3d; }
.flashcard.flipped .flashcard-inner { transform: rotateY(180deg); }

.card-front, .card-back { position: absolute; inset: 0; border-radius: var(--radius); backface-visibility: hidden; padding: 18px; display: flex; flex-direction: column; box-shadow: var(--shadow); }

.card-front { background: var(--card-bg); border: 1.5px solid var(--border); }
.card-back { background: var(--dark); color: var(--white); transform: rotateY(180deg); }

.card-section-tag { font-size: 0.68rem; font-weight: 600; color: var(--red); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 8px; }
.card-japanese { font-size: 2rem; font-weight: 700; color: var(--dark); line-height: 1.2; }
.card-reading { font-size: 0.8rem; color: var(--gray); margin-top: 4px; }
.card-hint { font-size: 0.7rem; color: var(--border); margin-top: auto; text-align: right; }

.card-meaning { font-size: 1.1rem; font-weight: 600; color: var(--white); margin-bottom: 8px; }
.card-example-jp { font-size: 0.82rem; color: rgba(255,255,255,0.75); margin-top: 6px; line-height: 1.4; }
.card-example-np { font-size: 0.78rem; color: rgba(255,255,255,0.5); margin-top: 4px; line-height: 1.4; }
.card-actions { display: flex; gap: 8px; margin-top: auto; justify-content: flex-end; }
.card-btn { background: rgba(255,255,255,0.12); border: none; color: #fff; padding: 4px 10px; border-radius: 6px; font-size: 0.72rem; cursor: pointer; }
.card-btn:hover { background: rgba(255,255,255,0.22); }
.card-btn.delete { background: rgba(192,57,43,0.5); }
.card-btn.delete:hover { background: rgba(192,57,43,0.8); }

/* ── Modal ── */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,0.5); display: flex; align-items: center; justify-content: center; z-index: 100; }
.modal.hidden { display: none; }
.modal-box { background: var(--white); border-radius: var(--radius); width: 480px; max-width: 95vw; max-height: 90vh; overflow-y: auto; padding: 28px; }
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.modal-header h2 { font-size: 1.2rem; font-weight: 700; }
.modal-close { background: none; border: none; font-size: 1.4rem; cursor: pointer; color: var(--gray); }

.form-row { margin-bottom: 14px; }
.form-row label { display: block; font-size: 0.8rem; font-weight: 600; color: #555; margin-bottom: 5px; }
.form-row input { width: 100%; padding: 9px 12px; border: 1.5px solid var(--border); border-radius: 8px; font-size: 0.9rem; outline: none; transition: border 0.15s; }
.form-row input:focus { border-color: var(--red); }
.japanese-input { font-size: 1.1rem; }

.form-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; }
.btn-cancel { background: none; border: 1.5px solid var(--border); padding: 8px 18px; border-radius: 8px; cursor: pointer; font-size: 0.875rem; }
.btn-save { background: var(--red); color: #fff; border: none; padding: 8px 20px; border-radius: 8px; cursor: pointer; font-size: 0.875rem; font-weight: 600; }
.btn-save:hover { background: var(--red-lt); }

/* ── Toast ── */
.toast { position: fixed; bottom: 24px; right: 24px; background: var(--dark); color: #fff; padding: 12px 20px; border-radius: 8px; font-size: 0.875rem; z-index: 200; transition: opacity 0.3s; }
.toast.hidden { opacity: 0; pointer-events: none; }

/* ── Empty state ── */
.empty { grid-column: 1/-1; text-align: center; padding: 60px 20px; color: var(--gray); }
.empty .empty-icon { font-size: 3rem; margin-bottom: 12px; }
