*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #f7f9fc;
  --bg2: #ffffff;
  --bg3: #ffffff;
  --border: #e3e8f0;
  --text: #0f172a;
  --text2: #5b6878;
  --text3: #64748b;
  --accent: #2563eb;
  --accent-h: #3a7ae0;
  --green: #059669;
  --yellow: #b45309;
  --red: #dc2626;
  --orange: #ea580c;
  --purple: #2563eb;
  --teal: #2dd4bf;
  --radius: 12px;
  --shadow: 0 4px 24px rgba(15,23,42,0.08);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 15px;
  line-height: 1.5;
}

.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }

/* NAV */
#nav {
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}
.nav-inner {
  max-width: 900px;
  margin: 0 auto;
  padding: 0 20px;
  height: 56px;
  display: flex;
  align-items: center;
  gap: 16px;
}
.logo {
  font-weight: 700;
  font-size: 18px;
  cursor: pointer;
  color: var(--accent);
  letter-spacing: -0.3px;
}
#nav-breadcrumb {
  color: var(--text2);
  font-size: 14px;
  flex: 1;
}

/* VIEWS */
.view { display: none; }
.view.active { display: block; }

.container {
  max-width: 900px;
  margin: 0 auto;
  padding: 32px 20px;
}

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 28px;
  flex-wrap: wrap;
}
.page-header h2 { font-size: 22px; font-weight: 700; }
.subtitle { color: var(--text2); font-size: 14px; margin-top: 2px; }
.header-actions { display: flex; gap: 10px; flex-shrink: 0; }

/* BUTTONS */
.btn-primary {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 9px 18px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-primary:hover { background: var(--accent-h); }

.btn-secondary {
  background: var(--bg3);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 18px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-secondary:hover { background: var(--border); }

.btn-ghost {
  background: none;
  color: var(--text2);
  border: none;
  font-size: 14px;
  cursor: pointer;
  padding: 6px 10px;
}
.btn-ghost:hover { color: var(--text); }

.btn-danger {
  background: none;
  color: var(--red);
  border: 1px solid rgba(248,113,113,0.3);
  border-radius: 8px;
  padding: 9px 18px;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-danger:hover { background: rgba(248,113,113,0.1); }

/* DECK GRID */
.deck-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
  margin-bottom: 32px;
}

.deck-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.1s;
  position: relative;
}
.deck-card:hover { border-color: var(--accent); transform: translateY(-1px); }

.deck-card-accent {
  width: 40px;
  height: 4px;
  border-radius: 2px;
  margin-bottom: 14px;
}
.color-blue { background: var(--accent); }
.color-green { background: var(--green); }
.color-purple { background: var(--purple); }
.color-orange { background: var(--orange); }
.color-red { background: var(--red); }
.color-teal { background: var(--teal); }

.deck-card-name {
  font-weight: 600;
  font-size: 16px;
  margin-bottom: 4px;
  color: var(--text);
}
.deck-card-desc {
  font-size: 13px;
  color: var(--text2);
  margin-bottom: 14px;
  line-height: 1.4;
}
.deck-card-meta {
  display: flex;
  gap: 12px;
  font-size: 12px;
  color: var(--text3);
  margin-bottom: 16px;
}
.deck-card-meta span { display: flex; align-items: center; gap: 4px; }

.deck-card-actions {
  display: flex;
  gap: 8px;
}
.deck-card-actions button {
  flex: 1;
  padding: 7px;
  font-size: 13px;
  border-radius: 7px;
  border: none;
  cursor: pointer;
  font-weight: 500;
  transition: background 0.15s;
}
.btn-study {
  background: var(--accent);
  color: #fff;
}
.btn-study:hover { background: var(--accent-h); }
.btn-edit {
  background: var(--bg3);
  color: var(--text2);
  border: 1px solid var(--border) !important;
}
.btn-edit:hover { background: var(--border); color: var(--text); }
.btn-stats-sm {
  background: var(--bg3);
  color: var(--text2);
  border: 1px solid var(--border) !important;
}
.btn-stats-sm:hover { background: var(--border); color: var(--text); }

/* Due badge */
.due-badge {
  position: absolute;
  top: 14px;
  right: 14px;
  background: var(--orange);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 10px;
}

/* PROGRESS IN DECK CARD */
.deck-progress {
  height: 4px;
  background: var(--bg3);
  border-radius: 2px;
  margin-bottom: 14px;
  overflow: hidden;
}
.deck-progress-fill {
  height: 100%;
  border-radius: 2px;
  transition: width 0.3s;
}

/* EMPTY STATE */
.empty-state {
  text-align: center;
  padding: 80px 20px;
  color: var(--text2);
}
.empty-icon { font-size: 56px; margin-bottom: 16px; }
.empty-state h3 { font-size: 20px; color: var(--text); margin-bottom: 8px; }
.empty-state p { margin-bottom: 24px; }

/* GLOBAL STATS */
.global-stats {
  display: flex;
  gap: 20px;
  padding: 20px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  flex-wrap: wrap;
}
.global-stat {
  flex: 1;
  min-width: 100px;
  text-align: center;
}
.global-stat-value {
  font-size: 24px;
  font-weight: 700;
  color: var(--accent);
}
.global-stat-label {
  font-size: 12px;
  color: var(--text3);
  margin-top: 2px;
}

/* DECK EDITOR */
.deck-meta-form {
  display: flex;
  gap: 10px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}
.deck-name-input {
  flex: 2;
  min-width: 200px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 10px 14px;
  font-size: 15px;
  font-weight: 600;
}
.deck-desc-input {
  flex: 3;
  min-width: 200px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 10px 14px;
  font-size: 14px;
}
.deck-color-select {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 10px 14px;
  font-size: 14px;
  cursor: pointer;
}
.deck-name-input:focus, .deck-desc-input:focus, .deck-color-select:focus {
  outline: none;
  border-color: var(--accent);
}

/* CARD LIST */
.card-list { display: flex; flex-direction: column; gap: 12px; }

.card-item {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 12px;
  align-items: start;
}
.card-item textarea {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 10px 12px;
  font-size: 14px;
  font-family: inherit;
  resize: vertical;
  min-height: 72px;
  width: 100%;
}
.card-item textarea:focus { outline: none; border-color: var(--accent); }
.card-item textarea::placeholder { color: var(--text3); }

.card-item-actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding-top: 2px;
}
.card-item-actions button {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text3);
  padding: 5px 10px;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}
.card-item-actions .btn-remove:hover { color: var(--red); border-color: var(--red); }
.card-item-actions .btn-hint-toggle:hover { color: var(--accent); border-color: var(--accent); }

.card-hint-row { grid-column: 1/-1; }
.card-hint-input {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text2);
  padding: 8px 12px;
  font-size: 13px;
  width: 100%;
}
.card-hint-input:focus { outline: none; border-color: var(--yellow); }
.card-number {
  grid-column: 1/-1;
  font-size: 11px;
  color: var(--text3);
  font-weight: 600;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

.editor-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 28px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}

/* STUDY MODE */
.study-container { max-width: 680px; }

.study-header { margin-bottom: 28px; }
.study-info {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}
.study-deck-label { font-weight: 600; font-size: 15px; color: var(--text); }
.study-progress-text { font-size: 14px; color: var(--text2); }
.study-progress-bar-wrap {
  height: 6px;
  background: var(--bg3);
  border-radius: 3px;
  overflow: hidden;
}
.study-progress-bar {
  height: 100%;
  background: var(--accent);
  border-radius: 3px;
  transition: width 0.4s ease;
}

/* FLASHCARD */
.flashcard-scene {
  width: 100%;
  height: 280px;
  perspective: 1000px;
  cursor: pointer;
  margin-bottom: 24px;
  user-select: none;
}
.flashcard {
  width: 100%;
  height: 100%;
  position: relative;
  transform-style: preserve-3d;
  transition: transform 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}
.flashcard.flipped { transform: rotateY(180deg); }
.flashcard-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px 32px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow);
}
.flashcard-back { transform: rotateY(180deg); border-color: var(--accent); }
.card-side-label {
  position: absolute;
  top: 14px;
  left: 18px;
  font-size: 11px;
  font-weight: 700;
  color: var(--text3);
  text-transform: uppercase;
  letter-spacing: 0.8px;
}
.card-text {
  font-size: 22px;
  font-weight: 600;
  text-align: center;
  line-height: 1.4;
  color: var(--text);
}
.card-hint {
  font-size: 13px;
  color: var(--text3);
  margin-top: 12px;
  font-style: italic;
}
.flip-hint {
  position: absolute;
  bottom: 14px;
  font-size: 11px;
  color: var(--text3);
}

/* RATING BUTTONS */
.rating-btns { text-align: center; margin-bottom: 12px; }
.rating-label {
  font-size: 13px;
  color: var(--text2);
  margin-bottom: 12px;
}
.rating-row { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.rating-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 12px 20px;
  border: none;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.1s, opacity 0.15s;
  min-width: 80px;
  color: #fff;
}
.rating-btn:hover { transform: translateY(-2px); opacity: 0.9; }
.rating-btn:active { transform: translateY(0); }
.rating-key {
  font-size: 10px;
  opacity: 0.7;
  font-weight: 400;
}
.rating-btn.again { background: #ef4444; }
.rating-btn.hard   { background: var(--orange); }
.rating-btn.good   { background: var(--accent); }
.rating-btn.easy   { background: var(--green); color: #0a2015; }

.flip-btn-wrap { text-align: center; }
.flip-btn-wrap .btn-primary { padding: 12px 36px; font-size: 15px; }

/* COMPLETE */
.study-complete { text-align: center; padding: 40px 20px; }
.complete-icon { font-size: 64px; margin-bottom: 16px; }
.study-complete h2 { font-size: 26px; margin-bottom: 8px; }
.study-complete p { color: var(--text2); margin-bottom: 24px; }
.session-stats {
  display: flex;
  gap: 16px;
  justify-content: center;
  margin-bottom: 28px;
  flex-wrap: wrap;
}
.session-stat {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 24px;
  text-align: center;
}
.session-stat-value { font-size: 28px; font-weight: 700; }
.session-stat-label { font-size: 12px; color: var(--text3); margin-top: 4px; }
.complete-actions { display: flex; gap: 12px; justify-content: center; }

/* STATS VIEW */
.stats-content { display: flex; flex-direction: column; gap: 20px; }
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
}
.stat-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  text-align: center;
}
.stat-card-value { font-size: 32px; font-weight: 700; }
.stat-card-label { font-size: 12px; color: var(--text3); margin-top: 4px; }
.stat-card.green .stat-card-value { color: var(--green); }
.stat-card.yellow .stat-card-value { color: var(--yellow); }
.stat-card.red .stat-card-value { color: var(--red); }
.stat-card.blue .stat-card-value { color: var(--accent); }
.stat-card.purple .stat-card-value { color: var(--purple); }

.card-breakdown {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}
.card-breakdown h3 { font-size: 15px; margin-bottom: 16px; }
.breakdown-bar {
  display: flex;
  height: 12px;
  border-radius: 6px;
  overflow: hidden;
  margin-bottom: 12px;
}
.breakdown-bar-seg { transition: width 0.5s; }
.breakdown-legend {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  font-size: 13px;
  color: var(--text2);
}
.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
  margin-right: 5px;
}

/* MODAL */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15,23,42,0.12);
  z-index: 200;
  align-items: center;
  justify-content: center;
}
.modal-overlay.active { display: flex; }
.modal {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px;
  max-width: 400px;
  width: 90%;
  box-shadow: var(--shadow);
}
.modal h3 { font-size: 18px; margin-bottom: 12px; }
.modal p { color: var(--text2); margin-bottom: 20px; font-size: 14px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; }
.modal input {
  width: 100%;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 10px 14px;
  font-size: 14px;
  margin-bottom: 16px;
}
.modal input:focus { outline: none; border-color: var(--accent); }

/* RESPONSIVE */
@media (max-width: 600px) {
  .card-item {
    grid-template-columns: 1fr;
  }
  .card-item-actions { flex-direction: row; }
  .rating-btn { padding: 10px 14px; min-width: 68px; font-size: 13px; }
  .card-text { font-size: 18px; }
  .flashcard-scene { height: 240px; }
  .deck-grid { grid-template-columns: 1fr; }
  .deck-meta-form { flex-direction: column; }
  .complete-actions { flex-direction: column; }
}
