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

:root {
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-display: 'Manrope', 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --bg: #0b0f14;
  --surface: #11161d;
  --surface-2: #171d26;
  --surface-3: #1d2530;
  --border: rgba(148, 163, 184, 0.16);
  --border-strong: rgba(148, 163, 184, 0.24);
  --text: #e8edf3;
  --text-2: #b7c2cf;
  --text-3: #7d8a9b;
  --accent: #74d6c0;
  --accent-soft: rgba(116, 214, 192, 0.12);
  --danger: #f28b82;
  --danger-soft: rgba(242, 139, 130, 0.14);
  --warn: #f2c879;
  --warn-soft: rgba(242, 200, 121, 0.14);
  --info: #7dd3fc;
  --info-soft: rgba(125, 211, 252, 0.14);
  --success: #86efac;
  --success-soft: rgba(134, 239, 172, 0.14);
  --shadow: none;
  --radius: 14px;
  --radius-md: 12px;
  --radius-sm: 10px;
  --radius-xs: 8px;
  --transition: 160ms ease;
}

html { color-scheme: dark; }

button:disabled { opacity: 0.55; cursor: wait; }
.form-error { color: var(--danger); white-space: pre-wrap; }
.form-error:empty { display: none; }
.form-error:not(:empty) { margin: 12px 0; }
.review-panel { max-width: 880px; margin: 0 auto; }
.review-heading { display: flex; justify-content: space-between; gap: 20px; align-items: center; margin-bottom: 20px; }
.review-heading h2 { font-family: var(--font-display); }
.review-heading p, .review-meta, #review-status { color: var(--text-2); }
.review-controls { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto; gap: 12px; align-items: end; margin-bottom: 12px; }
.source-link { display: block; width: fit-content; margin-top: 6px; color: var(--accent); }
button kbd { font-size: 0.75em; font-weight: 500; opacity: 0.8; }
#review-card { margin-top: 20px; padding: 28px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.review-category { color: var(--accent); overflow-wrap: anywhere; }
.review-image { display: block; max-width: 100%; max-height: 560px; object-fit: contain; margin: 20px auto; border-radius: var(--radius-xs); }
.review-meta { font-size: 0.85rem; margin: 12px 0; }
#review-answer { border-top: 1px solid var(--border); margin-top: 20px; padding-top: 20px; }
#review-answer h4 { margin-top: 20px; }
.table-note, #review-concept, #review-prompt { white-space: pre-wrap; overflow-wrap: anywhere; }
.review-note { max-width: 68ch; margin-top: 6px; color: var(--text-2); overflow-wrap: anywhere; }
.review-note > * + * { margin-top: 0.55em; }
.table-note ul, .review-note ul { padding-inline-start: 1.3em; }
.review-note li + li { margin-top: 0.3em; }
.table-note li::marker, .review-note li::marker { color: var(--accent); }
#review-prompt { scroll-margin-top: 160px; }
#review-outcomes { border: 0; margin-top: 24px; }
#review-outcomes legend { font-weight: 600; margin-bottom: 12px; }
.review-actions { display: flex; flex-wrap: wrap; gap: 10px; }
#review-history { margin-top: 24px; color: var(--text-2); }
#review-history summary { cursor: pointer; }
#review-history-list { margin: 12px 0 0 20px; }
@media (max-width: 600px) {
  .review-heading { align-items: flex-start; flex-direction: column; }
  .review-controls { grid-template-columns: minmax(0, 1fr); }
  #review-card { padding: 18px; }
  .tab-nav { max-width: 100%; overflow-x: auto; }
  .tab-btn { flex-shrink: 0; }
}

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

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

.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(11, 15, 20, 0.92);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.header-inner {
  max-width: 1280px;
  margin: 0 auto;
  padding: 18px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
}

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

.brand-icon {
  width: 24px;
  height: 24px;
  color: var(--accent);
  flex: none;
}

.header-brand h1,
.table-section h2,
.form-title,
.edit-modal-content h2,
.delete-modal-content h2 {
  font-family: var(--font-display);
  letter-spacing: -0.03em;
}

.header-brand h1 { font-size: 1.35rem; font-weight: 800; }

.tab-nav {
  display: flex;
  gap: 4px;
  padding: 4px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
}

.tab-btn {
  padding: 10px 18px;
  border: none;
  border-radius: 999px;
  background: transparent;
  color: var(--text-2);
  font-family: var(--font-body);
  font-size: 0.84rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: background var(--transition), color var(--transition), transform var(--transition);
}

.tab-btn:hover {
  background: var(--surface-2);
  color: var(--text);
}

.tab-btn.active {
  background: var(--surface-3);
  color: var(--text);
  box-shadow: inset 0 0 0 1px var(--border-strong);
}

.tab-icon { width: 17px; height: 17px; }

.app-main {
  max-width: 1280px;
  width: 100%;
  margin: 0 auto;
  padding: 32px 28px 40px;
}

.tab-content { display: none; }
.tab-content.active { display: block; }

.toolbar,
.table-container,
.form-card,
.modal-content {
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px 12px;
  padding: 12px;
  border-radius: var(--radius);
  margin-bottom: 16px;
}

.toolbar-block { flex: 1; min-width: 0; }

.search-wrapper { position: relative; flex: 1 1 220px; min-width: 200px; }

.search-icon {
  position: absolute;
  left: 15px;
  top: 50%;
  transform: translateY(-50%);
  width: 18px;
  height: 18px;
  color: var(--text-3);
  pointer-events: none;
}

.search-input,
.form-group input,
.form-group select,
.form-group textarea,
.chip-select {
  width: 100%;
  padding: 11px 13px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 0.88rem;
  transition: border-color var(--transition), box-shadow var(--transition), background var(--transition);
}

.search-input {
  padding-left: 42px;
  min-height: 44px;
  width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.search-input::placeholder,
.form-group input::placeholder,
.form-group textarea::placeholder {
  color: var(--text-3);
}

.search-input:focus,
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus,
.chip-select:focus {
  outline: none;
  border-color: rgba(116, 214, 192, 0.42);
  box-shadow: 0 0 0 3px rgba(116, 214, 192, 0.1);
}

.filter-chips {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  min-width: 0;
}

.filter-field {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  white-space: nowrap;
}

.filter-field .chip-select {
  width: auto;
  min-width: 0;
  max-width: 170px;
  min-height: 44px;
  font-size: 0.84rem;
  font-weight: 600;
  text-transform: none;
  letter-spacing: normal;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
}

.filter-field span { color: var(--text-3); flex: none; }

/* Single consistent chevron for every select — replaces native arrows
   that rendered at different insets per OS/browser */
.chip-select,
.form-group select {
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%237d8a9b' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 14px 14px;
  padding-right: 34px !important;
}

.chip-select::-ms-expand,
.form-group select::-ms-expand { display: none; }

.chip-btn-clear {
  min-height: 44px;
  padding: 0 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text-2);
  font-family: var(--font-body);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  transition: background var(--transition), border-color var(--transition), color var(--transition);
}

.chip-btn-clear:hover {
  background: var(--danger-soft);
  border-color: rgba(242, 139, 130, 0.4);
  color: #ffd2ce;
}

.table-section { min-height: 200px; margin-top: 10px; }

.table-section h2 {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1.08rem;
  font-weight: 700;
  margin-bottom: 12px;
}

.count-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 34px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.76rem;
  font-weight: 700;
}

.table-container {
  overflow-x: hidden;
  border-radius: var(--radius);
}

table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  font-size: 0.86rem;
}

#mistakes-table .col-date { width: 7%; }
#mistakes-table .col-category { width: 8%; }
#mistakes-table .col-subtopic { width: 8%; }
#mistakes-table .col-question { width: 7%; }
#mistakes-table .col-solution { width: 7%; }
#mistakes-table .col-type { width: 11%; }
#mistakes-table .col-why { width: 22%; }
#mistakes-table .col-avoid { width: 23%; }
#mistakes-table .col-actions { width: 7%; }

thead {
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}

th, td {
  padding: 12px 10px;
  text-align: left;
  border-bottom: 1px solid rgba(130, 149, 178, 0.12);
  vertical-align: top;
}

th:first-child, td:first-child { padding-left: 16px; }
th:last-child, td:last-child { padding-right: 16px; }

th {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 700;
  color: var(--text-3);
  white-space: nowrap;
}

tbody tr { transition: background var(--transition); }

tbody tr:hover { background: var(--surface-2); }

td:nth-child(1) {
  white-space: nowrap;
  font-size: 0.75rem;
  color: var(--text-3);
}

td:nth-child(2) {
  font-weight: 700;
  color: var(--text);
}

td:nth-child(3) {
  color: var(--text-2);
}

td:nth-child(4),
td:nth-child(5) {
  text-align: center;
}

td:nth-child(7),
td:nth-child(8) {
  color: var(--text-2);
  line-height: 1.55;
  overflow-wrap: anywhere;
  word-break: break-word;
}

td:nth-child(9) {
  white-space: nowrap;
}

.card-thumb {
  width: 48px;
  height: 36px;
  border-radius: var(--radius-xs);
  object-fit: cover;
  border: 1px solid var(--border);
  cursor: pointer;
  transition: transform var(--transition), border-color var(--transition);
}

.card-thumb:hover {
  transform: translateY(-1px);
  border-color: rgba(110, 231, 200, 0.45);
}

.no-image {
  color: var(--text-3);
  font-size: 0.8rem;
  font-style: italic;
}

.badge {
  display: inline-flex;
  align-items: center;
  margin-top: 2px;
  padding: 4px 9px;
  border-radius: 999px;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  white-space: nowrap;
}

.badge-conceptual { background: var(--warn-soft); color: var(--warn); }
.badge-new-info-detail { background: var(--accent-soft); color: var(--accent); }
.badge-silly-careless { background: var(--danger-soft); color: var(--danger); }
.badge-calculation { background: var(--info-soft); color: var(--info); }
.badge-time-pressure { background: rgba(167, 139, 250, 0.14); color: #c4b5fd; }
.badge-misread-question { background: rgba(251, 146, 60, 0.14); color: #fdba74; }
.badge-memory-formula { background: var(--success-soft); color: var(--success); }

.action-btns { display: flex; gap: 4px; justify-content: flex-end; }

.card-action-btn {
  width: 26px;
  height: 26px;
  padding: 0;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-2);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition), border-color var(--transition), color var(--transition);
}

#mistakes-table th,
#mistakes-table td {
  overflow: hidden;
}

#mistakes-table .card-action-btn svg {
  width: 12px;
  height: 12px;
}

.card-action-btn.edit-btn:hover {
  background: var(--accent-soft);
  border-color: rgba(110, 231, 200, 0.35);
  color: var(--accent);
}

.card-action-btn.delete-btn:hover {
  background: var(--danger-soft);
  border-color: rgba(242, 139, 130, 0.35);
  color: #ffc4be;
}

.card-action-btn.archive-btn:hover {
  background: var(--warn-soft);
  border-color: rgba(242, 200, 121, 0.35);
  color: var(--warn);
}

.card-action-btn.unarchive-btn:hover {
  background: var(--accent-soft);
  border-color: rgba(110, 231, 200, 0.35);
  color: var(--accent);
}

.archive-folder {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  margin-bottom: 8px;
}

.archive-folder-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  cursor: pointer;
  transition: background var(--transition);
  user-select: none;
}

.archive-folder-header:hover {
  background: var(--surface-2);
}

.archive-folder-info {
  display: flex;
  align-items: center;
  gap: 10px;
}

.folder-icon {
  width: 20px;
  height: 20px;
  color: var(--warn);
  flex-shrink: 0;
}

.folder-icon-sm {
  width: 16px;
  height: 16px;
  color: var(--warn);
  flex-shrink: 0;
}

.archive-folder-name {
  font-weight: 700;
  font-size: 0.9rem;
}

.archive-folder-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.folder-chevron {
  width: 16px;
  height: 16px;
  color: var(--text-3);
  transition: transform var(--transition);
}

.archive-folder-content {
  border-top: 1px solid var(--border);
}

.archive-folder-content.hidden { display: none; }

.archive-folder-content .table-container {
  border: none;
  border-radius: 0;
}

.archive-folder-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  font-size: 0.86rem;
}

.archive-folder-table .col-date { width: 7%; }
.archive-folder-table .col-subtopic { width: 12%; }
.archive-folder-table .col-question { width: 6%; }
.archive-folder-table .col-solution { width: 6%; }
.archive-folder-table .col-type { width: 11%; }
.archive-folder-table .col-why { width: 24%; }
.archive-folder-table .col-avoid { width: 26%; }
.archive-folder-table .col-actions { width: 8%; }

.archive-folder-table thead {
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}

.archive-folder-table th,
.archive-folder-table td {
  padding: 12px 10px;
  text-align: left;
  border-bottom: 1px solid rgba(130, 149, 178, 0.12);
  vertical-align: top;
  overflow: hidden;
}

.archive-folder-table th {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 700;
  color: var(--text-3);
  white-space: nowrap;
}

.archive-folder-table td {
  color: var(--text-2);
  line-height: 1.55;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.archive-folder-table td:nth-child(1) {
  white-space: nowrap;
  font-size: 0.75rem;
  color: var(--text-3);
}

.archive-folder-table td:last-child {
  white-space: nowrap;
}

.btn-sm {
  padding: 6px 12px;
  font-size: 0.76rem;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border: none;
  cursor: pointer;
  font-family: var(--font-body);
  font-weight: 600;
  transition: background var(--transition);
}

.btn-restore {
  background: var(--accent-soft);
  color: var(--accent);
}
.btn-restore:hover { background: rgba(116, 214, 192, 0.22); }

.btn-archive-topic {
  background: var(--warn-soft);
  color: var(--warn);
}
.btn-archive-topic:hover { background: rgba(242, 200, 121, 0.22); }

.chip-btn-archive {
  min-height: 44px;
  padding: 0 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-2);
  font-family: var(--font-body);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  flex-shrink: 0;
  transition: background var(--transition), border-color var(--transition), color var(--transition);
}

.chip-btn-archive:hover {
  background: var(--warn-soft);
  border-color: rgba(242, 200, 121, 0.35);
  color: var(--warn);
}

.archive-topic-modal-content {
  width: 480px;
  max-width: 92vw;
  max-height: 75vh;
  overflow-y: auto;
}

.archive-topic-modal-content h2 {
  font-size: 1.2rem;
  font-weight: 800;
  margin-bottom: 4px;
}

.modal-desc {
  color: var(--text-3);
  font-size: 0.86rem;
  margin-bottom: 16px;
}

.archive-topic-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.archive-topic-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
}

.archive-topic-item-info {
  display: flex;
  align-items: center;
  gap: 8px;
}

.archive-topic-item-name {
  font-weight: 600;
  font-size: 0.88rem;
}

.empty-state {
  text-align: center;
  padding: 64px 22px;
  color: var(--text-3);
  font-size: 0.92rem;
}

.empty-state.hidden { display: none !important; }

.empty-icon {
  display: block;
  width: 48px;
  height: 48px;
  margin: 0 auto 14px;
  color: var(--text-3);
}

.empty-sub {
  display: inline-block;
  margin-top: 8px;
  font-size: 0.82rem;
}

.form-card {
  border-radius: var(--radius);
  padding: 22px;
}

.form-title {
  font-size: 1.15rem;
  font-weight: 800;
  margin-bottom: 18px;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 16px;
}

.form-row-images { grid-template-columns: 1fr 1fr; }

.form-group { display: flex; flex-direction: column; }

.form-group label {
  font-weight: 600;
  margin-bottom: 8px;
  font-size: 0.84rem;
  color: var(--text-2);
}

.label-hint {
  font-weight: 400;
  color: var(--text-3);
  font-size: 0.74rem;
}

.form-group textarea {
  min-height: 110px;
  resize: vertical;
}

.paste-zone {
  position: relative;
  min-height: 160px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-md);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition), transform var(--transition);
  background: var(--bg);
  outline: none;
}

.paste-zone:hover,
.paste-zone:focus,
.paste-zone.active {
  border-color: rgba(110, 231, 200, 0.42);
  background: #0f141b;
}

.paste-hint {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  color: var(--text-3);
  font-size: 0.84rem;
  text-align: center;
  padding: 14px;
}

.paste-zone:focus .paste-hint,
.paste-zone.active .paste-hint { color: var(--text-2); }

.paste-zone img {
  max-width: 100%;
  max-height: 200px;
  object-fit: contain;
  border-radius: var(--radius-xs);
}

.btn-clear {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: rgba(242, 139, 130, 0.92);
  color: #fff;
  border: none;
  font-size: 0.76rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn {
  padding: 11px 22px;
  border: none;
  border-radius: 12px;
  font-family: var(--font-body);
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition), color var(--transition), transform var(--transition);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.btn:hover { transform: translateY(-1px); }

.btn-primary {
  background: var(--accent);
  color: #071012;
}

.btn-primary:hover { background: #8be1ce; }

.btn-ghost {
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-2);
  border: 1px solid var(--border);
}

.btn-ghost:hover { background: rgba(255, 255, 255, 0.08); }

.btn-danger {
  background: #d96d66;
  color: #fff;
}

.btn-danger:hover { background: #eb7f78; }

.btn-large {
  width: 100%;
  min-height: 52px;
  font-size: 0.95rem;
  margin-top: 6px;
}

.form-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-top: 20px;
  flex-wrap: wrap;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal.hidden { display: none; }

.modal-overlay {
  position: absolute;
  inset: 0;
  background: rgba(4, 6, 9, 0.76);
  backdrop-filter: blur(6px);
}

.modal-content {
  position: relative;
  border-radius: var(--radius);
  padding: 24px;
  max-width: 90vw;
  max-height: 90vh;
  overflow: auto;
  z-index: 1;
}

.modal-close-btn {
  position: absolute;
  top: 12px;
  right: 14px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-2);
  font-size: 0.9rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-image-content {
  padding: 12px;
  background: transparent;
  border: none;
  box-shadow: none;
}

.modal-image-content img {
  max-width: 90vw;
  max-height: 85vh;
  border-radius: var(--radius-md);
}

.edit-modal-content { width: 760px; max-width: 95vw; }

.edit-modal-content h2 {
  font-size: 1.3rem;
  font-weight: 800;
  margin-bottom: 20px;
}

.delete-modal-content {
  width: 400px;
  max-width: 90vw;
  text-align: center;
}

.delete-icon {
  display: block;
  width: 56px;
  height: 56px;
  margin: 0 auto 16px;
  color: var(--danger);
}

.delete-modal-content h2 {
  color: var(--text);
  font-weight: 800;
  margin-bottom: 8px;
}

.delete-modal-content p {
  color: var(--text-3);
  margin-bottom: 20px;
  font-size: 0.9rem;
}

#toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  padding: 12px 18px;
  border-radius: 14px;
  font-family: var(--font-body);
  font-size: 0.86rem;
  font-weight: 600;
  pointer-events: auto;
  border: 1px solid var(--border);
  max-width: 360px;
  box-shadow: var(--shadow);
}

.toast-success { background: #123126; color: #c9f6de; border-color: #2a7f63; }
.toast-error { background: #3a1718; color: #ffd2ce; border-color: #a94a44; }
.toast-info { background: var(--surface-2); color: var(--text); border-color: rgba(110, 231, 200, 0.3); }

.hidden { display: none !important; }

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
.paste-zone:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: rgba(255, 255, 255, 0.03); }
::-webkit-scrollbar-thumb { background: rgba(148, 168, 192, 0.24); border-radius: 999px; }
::-webkit-scrollbar-thumb:hover { background: rgba(148, 168, 192, 0.38); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; }
}

@media (max-width: 980px) {
  .header-inner { flex-direction: column; }

  .toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .search-wrapper { flex: 1 1 auto; }

  .filter-chips { flex-wrap: wrap; }
  .filter-field .chip-select { max-width: none; flex: 1; }
}

@media (max-width: 800px) {
  .header-inner { padding: 16px 18px; }
  .app-main { padding: 22px 14px 32px; }
  .toolbar,
  .form-card { padding: 18px; }

  table, thead, tbody, th, td, tr { display: block; }
  thead { display: none; }
  tbody { display: grid; gap: 12px; padding: 12px; }
  tbody tr {
    background: rgba(255, 255, 255, 0.025);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 14px;
  }
  tbody tr:hover { background: rgba(255, 255, 255, 0.025); }
  td {
    width: 100% !important;
    max-width: none !important;
    min-width: 0 !important;
    padding: 10px 0;
    border-bottom: 1px solid rgba(130, 149, 178, 0.12);
    white-space: normal;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 14px;
  }
  td:last-child { border-bottom: none; padding-bottom: 0; }
  td::before {
    content: attr(data-label);
    color: var(--text-3);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-size: 0.7rem;
    flex: 0 0 112px;
  }
  td > * { flex: 1; min-width: 0; }
  td.note-cell { display: block; }
  td.note-cell::before { display: block; margin-bottom: 4px; }
}

/* Footer — GitHub + clone workflow (inside mistakes-tab only) */
.app-footer {
  margin-top: auto;
  border-top: 1px solid var(--border);
  background: var(--surface);
}

#mistakes-tab .app-footer {
  margin-top: 24px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.footer-inner {
  max-width: 1280px;
  margin: 0 auto;
  padding: 16px 28px;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  font-size: 0.84rem;
  color: var(--text-2);
}

.footer-left {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.footer-tagline {
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
}

.footer-github-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-weight: 600;
  font-size: 0.82rem;
  text-decoration: none;
  transition: background var(--transition), border-color var(--transition), color var(--transition);
}

.footer-github-link:hover {
  background: var(--surface-3);
  border-color: var(--border-strong);
  color: var(--accent);
}

.footer-clone {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 260px;
  max-width: 520px;
  padding: 6px 6px 6px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg);
  transition: border-color var(--transition), box-shadow var(--transition);
}

.footer-clone:hover {
  border-color: var(--border-strong);
}

.footer-clone:focus-within {
  border-color: rgba(116, 214, 192, 0.42);
  box-shadow: 0 0 0 3px rgba(116, 214, 192, 0.1);
}

.clone-prompt {
  flex-shrink: 0;
  color: var(--accent);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.78rem;
  font-weight: 700;
  user-select: none;
}

#clone-cmd {
  flex: 1;
  min-width: 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.78rem;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  user-select: all;
}

.copy-btn {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-2);
  font-family: var(--font-body);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition), color var(--transition), transform var(--transition);
}

.copy-btn:hover {
  background: var(--accent-soft);
  border-color: rgba(116, 214, 192, 0.35);
  color: var(--accent);
}

.copy-btn:focus-visible {
  outline: none;
  border-color: rgba(116, 214, 192, 0.55);
  box-shadow: 0 0 0 3px rgba(116, 214, 192, 0.18);
}

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

.copy-btn.copied {
  background: var(--accent);
  border-color: var(--accent);
  color: #071012;
}

.footer-hint {
  font-size: 0.78rem;
  color: var(--text-3);
  white-space: nowrap;
}

.footer-hint code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.74rem;
  padding: 2px 6px;
  border-radius: 6px;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text-2);
}

/* Demo mode: in-flow banner (injected by demo-mode.js) — never overlaps footer */
.demo-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px 10px 14px;
  margin-bottom: 16px;
  border-radius: var(--radius-sm);
  background: var(--warn-soft);
  border: 1px solid rgba(242, 200, 121, 0.32);
  color: var(--text-2);
  font-size: 0.82rem;
  line-height: 1.45;
}

.demo-banner svg { flex-shrink: 0; color: var(--warn); }

.demo-banner strong { color: var(--warn); font-weight: 700; }

.demo-banner-dismiss {
  margin-left: auto;
  flex-shrink: 0;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-3);
  font-size: 0.75rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition), color var(--transition);
}

.demo-banner-dismiss:hover { background: rgba(242, 200, 121, 0.16); color: var(--warn); }

@media (max-width: 760px) {
  .footer-inner { padding: 14px 16px; gap: 12px; }
  .footer-clone { flex-basis: 100%; max-width: none; min-width: 0; }
  .footer-hint { white-space: normal; }
}

@media (max-width: 600px) {
  .header-brand h1 { font-size: 1.2rem; }
  .tab-nav { width: 100%; }
  .tab-btn { flex: 1; justify-content: center; padding: 10px 12px; }
  .form-row,
  .form-row-images { grid-template-columns: 1fr; }
  .paste-zone { min-height: 126px; }
  .modal-content { max-width: calc(100% - 16px); max-height: calc(100% - 16px); }
  .edit-modal-content { width: calc(100% - 16px); }
  td { flex-direction: column; align-items: flex-start; gap: 4px; }
  td::before { flex: 0 0 auto; }
}

/* Insights: recurring study patterns and portable local data */
.insights-heading {
  display: grid;
  grid-template-columns: minmax(230px, 0.85fr) minmax(0, 1.4fr);
  align-items: center;
  gap: 28px;
  padding: 26px;
  margin-bottom: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: linear-gradient(115deg, #121a20 0%, var(--surface) 62%);
}

.insights-kicker,
.analytics-overline {
  color: var(--accent);
  font-size: 0.66rem;
  font-weight: 800;
  letter-spacing: 0.12em;
}

.insights-intro h2 {
  margin-top: 5px;
  font: 800 1.65rem/1.2 var(--font-display);
  letter-spacing: -0.04em;
}

.insights-intro p {
  margin-top: 8px;
  color: var(--text-2);
  font-size: 0.86rem;
}

.insights-summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.insight-metric {
  min-width: 0;
  padding: 13px 14px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: rgba(7, 11, 15, 0.35);
}

.insight-metric-label {
  display: block;
  color: var(--text-3);
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
}

.insight-metric-value {
  display: block;
  overflow: hidden;
  margin-top: 6px;
  color: var(--text);
  font: 700 1rem/1.35 var(--font-display);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.analytics-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 16px;
}

.analytics-card,
.data-care-card {
  min-width: 0;
  padding: 20px 22px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.analytics-card-heading {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding-bottom: 15px;
  border-bottom: 1px solid var(--border);
}

.analytics-card-heading h3,
.data-care-copy h3 {
  margin-top: 3px;
  font: 700 1.05rem/1.35 var(--font-display);
  letter-spacing: -0.02em;
}

.distribution-list {
  display: grid;
  gap: 15px;
  padding-top: 17px;
}

.distribution-row { min-width: 0; }

.distribution-label {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 7px;
  color: var(--text-2);
  font-size: 0.8rem;
}

.distribution-label span {
  min-width: 0;
  overflow-wrap: anywhere;
}

.distribution-value {
  flex: none;
  color: var(--text-3);
  font: 600 0.72rem/1.4 ui-monospace, SFMono-Regular, Menlo, monospace;
}

.distribution-track {
  height: 7px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--surface-3);
}

.distribution-fill {
  display: block;
  height: 100%;
  min-width: 2px;
  border-radius: inherit;
  background: var(--accent);
  transition: width 240ms ease;
}

.analytics-card-categories .distribution-fill { background: var(--info); }
.analytics-subtopics-card .distribution-fill { background: var(--warn); }

.distribution-empty {
  padding: 18px 0 4px;
  color: var(--text-3);
  font-size: 0.84rem;
}

.data-care-card {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 28px;
  margin-top: 16px;
  background: linear-gradient(110deg, var(--surface) 0%, #151d22 100%);
}

.data-care-copy { max-width: 650px; }

.data-care-copy p {
  margin-top: 7px;
  color: var(--text-2);
  font-size: 0.82rem;
}

.data-care-copy code {
  padding: 2px 5px;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: var(--bg);
  color: var(--text);
  font: 0.76rem ui-monospace, SFMono-Regular, Menlo, monospace;
}

.data-care-actions {
  display: flex;
  flex: none;
  flex-direction: column;
  gap: 8px;
  min-width: 176px;
}

.data-care-actions .btn { justify-content: center; }

.backup-status:empty { display: none; }
.backup-status { color: var(--accent) !important; overflow-wrap: anywhere; }

.restore-backup-icon { color: var(--warn); }
.restore-backup-modal-content p { overflow-wrap: anywhere; }

@media (max-width: 900px) {
  .insights-heading { grid-template-columns: 1fr; gap: 20px; }
  .data-care-card { align-items: flex-start; flex-direction: column; gap: 18px; }
  .data-care-actions { flex-direction: row; flex-wrap: wrap; }
}

@media (max-width: 600px) {
  .insights-heading,
  .analytics-card,
  .data-care-card { padding: 18px; }
  .insights-summary { grid-template-columns: 1fr; }
  .analytics-grid { grid-template-columns: 1fr; }
  .data-care-actions { width: 100%; flex-direction: column; }
  .tab-btn { gap: 5px; padding: 9px 5px; font-size: 0.73rem; }
  .tab-icon { width: 15px; height: 15px; }
}

@media (prefers-reduced-motion: reduce) {
  .distribution-fill { transition: none; }
}
