:root {
  --blue: #4f9dff;
  --mint: #00e5c8;
  --orange: #ff9144;
  --green: #4ade80;
  --red: #ff4f7b;
  --yellow: #ffcc44;
  --purple: #b388ff;
  --bg: #08090a;
  --s1: #0f1011;
  --s2: #16171a;
  --s3: #1c1d21;
  --border: #23252a;
  --border2: #2a2c33;
  --text: #f7f8f8;
  --dim: #6b7084;
  --dim2: #9499ab;
  --theme: var(--blue);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-pill: 999px;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --font-stat: clamp(1.5rem, 5vw, 2rem);
  --font-stat-lg: clamp(2.25rem, 8vw, 3rem);
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --active-scale: 0.97;
  --nav-blur: 12px;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  overflow-x: hidden;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Pretendard', -apple-system, sans-serif;
  min-height: 100vh;
  min-height: 100dvh;
  padding-bottom: calc(68px + env(safe-area-inset-bottom, 0px));
  overflow-x: hidden;
  width: 100%;
  max-width: 100vw;
}

body.app-ready {
  padding-top: env(safe-area-inset-top, 0px);
}

.mono { font-family: 'DM Mono', monospace; }

/* ── nav ── */
.nav {
  background: color-mix(in srgb, var(--s1) 88%, transparent);
  backdrop-filter: blur(var(--nav-blur));
  -webkit-backdrop-filter: blur(var(--nav-blur));
  border-bottom: 1px solid var(--border);
  padding: var(--space-3) var(--space-4);
  display: flex;
  align-items: center;
  gap: 10px;
  position: sticky;
  top: 0;
  z-index: 200;
  min-height: 48px;
}
@media (min-width: 768px) {
  .nav { min-height: 52px; padding: 14px var(--space-5); }
}
.nav-logo {
  font-size: .95rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.02em;
}
.nav-logo em { font-style: normal; color: var(--theme); font-weight: 700; }
.nav-sub { font-size: .68rem; color: var(--dim2); margin-left: auto; font-family: 'DM Mono', monospace; }

/* ── container ── */
.container {
  max-width: 680px;
  width: 100%;
  margin: 0 auto;
  padding: 20px 16px;
  overflow-x: hidden;
}

/* ── space tabs ── */
.space-tabs { display: flex; gap: var(--space-2); margin-bottom: var(--space-4); }
.space-tab {
  flex: 1;
  min-height: 44px;
  padding: 10px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border2);
  background: var(--s1);
  color: var(--dim2);
  font-size: .82rem;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
  transition: transform .12s var(--ease-out), border-color .15s, color .15s, background .15s;
}
.space-tab:active { transform: scale(var(--active-scale)); }
.space-tab.active {
  border-color: color-mix(in srgb, var(--theme) 55%, var(--border2));
  color: var(--theme);
  background: color-mix(in srgb, var(--theme) 10%, var(--s1));
}

/* ── cards ── */
.card {
  background: var(--s1);
  border: 1px solid var(--border2);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  margin-bottom: var(--space-3);
}
.card-title {
  font-size: .78rem;
  font-weight: 600;
  margin-bottom: var(--space-2);
  color: var(--dim2);
  letter-spacing: 0.02em;
  text-transform: none;
}

/* ── buttons ── */
.btn {
  width: 100%;
  min-height: 48px;
  padding: 14px;
  border: none;
  border-radius: var(--radius-md);
  font-size: .92rem;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  transition: transform .12s var(--ease-out), opacity .15s, box-shadow .15s;
}
.btn-primary {
  background: var(--theme);
  color: #fff;
  box-shadow: 0 1px 0 color-mix(in srgb, var(--theme) 40%, #000), inset 0 1px 0 color-mix(in srgb, #fff 12%, transparent);
}
.btn-primary:hover { opacity: .94; }
.btn-primary:active:not(:disabled) { transform: scale(var(--active-scale)); }
.btn-primary:disabled { opacity: .45; cursor: not-allowed; transform: none; box-shadow: none; }
.btn-ghost {
  background: var(--s2);
  border: 1px solid var(--border2);
  color: var(--dim2);
  font-size: .78rem;
  padding: 12px;
}
.btn-ghost:active { transform: scale(var(--active-scale)); }
.btn-link {
  display: block;
  text-align: center;
  text-decoration: none;
  margin-top: var(--space-2);
}

/* ── tab bar ── */
.tab-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  min-height: 56px;
  background: color-mix(in srgb, var(--s1) 92%, transparent);
  backdrop-filter: blur(var(--nav-blur));
  -webkit-backdrop-filter: blur(var(--nav-blur));
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  z-index: 300;
  padding: 6px var(--space-2) calc(6px + env(safe-area-inset-bottom, 0px));
}
.tab-item {
  flex: 1;
  min-width: 0;
  min-height: 44px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  text-decoration: none;
  color: var(--dim);
  font-size: .58rem;
  font-weight: 500;
  position: relative;
  border-radius: var(--radius-pill);
  transition: color .15s var(--ease-out), transform .12s var(--ease-out);
}
.tab-item:active { transform: scale(var(--active-scale)); }
.tab-label {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 0 2px;
}
.tab-item.active {
  color: var(--theme);
  font-weight: 600;
}
.tab-item.active::before {
  content: '';
  position: absolute;
  inset: 2px 4px;
  background: color-mix(in srgb, var(--theme) 12%, transparent);
  border-radius: var(--radius-pill);
  z-index: -1;
}
.tab-icon { font-size: 1.15rem; line-height: 1; }
.tab-dot { display: none; }

/* ── stats (legacy 3-col) ── */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-2);
  margin-bottom: var(--space-4);
}
.stat-card {
  background: var(--s1);
  border: 1px solid var(--border2);
  border-radius: var(--radius-md);
  padding: var(--space-3);
  text-align: center;
}
.stat-val { font-size: var(--font-stat); font-weight: 700; font-family: 'DM Mono', monospace; line-height: 1.1; }
.stat-lbl { font-size: .62rem; color: var(--dim2); margin-top: var(--space-1); }
@media (max-width: 380px) {
  .stat-val { font-size: 1.25rem; }
  .stat-lbl { font-size: .56rem; }
  .stat-card { padding: 10px 6px; }
}

/* ── bento (home dashboard) ── */
.bento {
  display: grid;
  grid-template-columns: 1.25fr 1fr;
  grid-template-rows: auto auto;
  gap: var(--space-2);
  margin-bottom: var(--space-4);
}
.bento-tile {
  background: var(--s1);
  border: 1px solid var(--border2);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  min-height: 0;
}
.bento-hero {
  grid-column: 1;
  grid-row: 1 / 3;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: var(--space-5) var(--space-4);
  border-color: color-mix(in srgb, var(--red) 25%, var(--border2));
  background: linear-gradient(160deg, var(--s1) 0%, color-mix(in srgb, var(--red) 6%, var(--s2)) 100%);
}
.bento-streak {
  grid-column: 2;
  grid-row: 1;
  border-color: color-mix(in srgb, var(--yellow) 30%, var(--border2));
  background: linear-gradient(160deg, var(--s1) 0%, color-mix(in srgb, var(--yellow) 5%, var(--s2)) 100%);
}
.bento-mini-grid {
  grid-column: 2;
  grid-row: 2;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-2);
}
.bento-mini {
  padding: var(--space-3) var(--space-2);
  text-align: center;
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 72px;
}
.bento-val {
  font-family: 'DM Mono', monospace;
  font-weight: 700;
  line-height: 1.1;
  font-size: var(--font-stat);
}
.bento-val--lg { font-size: var(--font-stat-lg); }
.bento-val--sm { font-size: clamp(1.1rem, 4vw, 1.35rem); }
.bento-lbl {
  font-size: .62rem;
  color: var(--dim2);
  margin-top: var(--space-1);
  letter-spacing: 0.01em;
}
.bento-lbl--hero { font-size: .72rem; color: var(--dim); margin-bottom: var(--space-1); }
.bento-tip {
  margin-bottom: var(--space-3);
  border-color: color-mix(in srgb, var(--theme) 20%, var(--border2));
}
.bento-tip-text {
  font-size: .82rem;
  color: var(--dim2);
  line-height: 1.65;
}
.streak-flame {
  font-size: 1.4rem;
  line-height: 1;
  margin-bottom: var(--space-1);
  animation: streak-pulse 2.4s ease-in-out infinite;
}
.streak-hint {
  font-size: .62rem;
  color: var(--dim);
  margin-top: var(--space-1);
  line-height: 1.4;
}
@keyframes streak-pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.08); opacity: .88; }
}
@media (max-width: 340px) {
  .bento { grid-template-columns: 1fr; grid-template-rows: auto; }
  .bento-hero, .bento-streak, .bento-mini-grid { grid-column: 1; grid-row: auto; }
  .bento-hero { min-height: 120px; }
}

/* ── filter chips (note) ── */
.filter-tabs { display: flex; gap: var(--space-2); margin-bottom: var(--space-3); flex-wrap: wrap; }
.filter-tab {
  min-height: 36px;
  padding: 6px 14px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border2);
  background: var(--s2);
  color: var(--dim2);
  font-size: .72rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: transform .12s var(--ease-out), background .15s, border-color .15s, color .15s;
}
.filter-tab:active { transform: scale(var(--active-scale)); }
.filter-tab.active {
  background: color-mix(in srgb, var(--theme) 14%, var(--s2));
  color: var(--theme);
  border-color: color-mix(in srgb, var(--theme) 45%, var(--border2));
}

/* ── problem card ── */
.problem-card {
  background: var(--s1);
  border: 1px solid var(--border2);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  margin-bottom: var(--space-3);
  position: relative;
  overflow: hidden;
  transition: border-color .15s var(--ease-out);
}
.problem-card::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 4px;
  border-radius: var(--radius-md) 0 0 var(--radius-md);
}
.problem-card.wrong::before { background: var(--red); }
.problem-card.correct::before { background: var(--green); }
.problem-card.wrong { border-color: color-mix(in srgb, var(--red) 18%, var(--border2)); }
.problem-card.correct { border-color: color-mix(in srgb, var(--green) 18%, var(--border2)); }
.problem-card.is-repeat {
  border-color: color-mix(in srgb, var(--orange) 35%, var(--border2));
  background: linear-gradient(135deg, var(--s1) 0%, color-mix(in srgb, var(--orange) 4%, var(--s2)) 100%);
}
.problem-card.is-repeat::before { background: var(--orange); width: 4px; }

.unit-chips {
  display: flex;
  gap: var(--space-2);
  margin-bottom: var(--space-3);
  flex-wrap: nowrap;
  overflow-x: auto;
  padding-bottom: var(--space-1);
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.unit-chips::-webkit-scrollbar { display: none; }
.unit-chip {
  flex-shrink: 0;
  min-height: 32px;
  padding: 5px 12px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border2);
  background: var(--s2);
  color: var(--dim2);
  font-size: .68rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  white-space: nowrap;
  transition: transform .12s var(--ease-out), background .15s, border-color .15s, color .15s;
}
.unit-chip:active { transform: scale(var(--active-scale)); }
.unit-chip.active {
  background: color-mix(in srgb, var(--purple) 12%, var(--s2));
  color: var(--purple);
  border-color: color-mix(in srgb, var(--purple) 40%, var(--border2));
}
.unit-chip-count {
  margin-left: 4px;
  opacity: .7;
  font-family: 'DM Mono', monospace;
  font-size: .62rem;
}

.problem-meta { font-size: .65rem; color: var(--dim); margin-left: auto; font-family: 'DM Mono', monospace; }
.problem-question { font-size: .78rem; line-height: 1.55; margin-bottom: var(--space-2); color: var(--text); }
.weakness-tag {
  display: inline-block;
  font-size: .65rem;
  color: var(--orange);
  margin-top: var(--space-1);
}
.problem-comment { font-size: .72rem; color: var(--dim2); margin-top: var(--space-2); line-height: 1.5; }

.page-thumb {
  width: 100%;
  max-height: 160px;
  object-fit: contain;
  border-radius: var(--radius-sm);
  margin-bottom: var(--space-2);
  border: 1px solid var(--border2);
  background: var(--s2);
}

/* ── report ── */
.report-summary {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-2);
  margin-bottom: var(--space-4);
}
.report-stat {
  background: var(--s1);
  border: 1px solid var(--border2);
  border-radius: var(--radius-md);
  padding: var(--space-3);
  text-align: center;
}
.report-stat-val {
  font-family: 'DM Mono', monospace;
  font-size: clamp(1.2rem, 4vw, 1.5rem);
  font-weight: 700;
  line-height: 1.1;
}
.report-stat-lbl { font-size: .6rem; color: var(--dim2); margin-top: var(--space-1); }

.card--repeat {
  border-color: color-mix(in srgb, var(--orange) 35%, var(--border2)) !important;
  background: linear-gradient(160deg, var(--s1) 0%, color-mix(in srgb, var(--orange) 5%, var(--s2)) 100%);
}
.repeat-item {
  padding: var(--space-3) var(--space-4);
  border: 1px solid color-mix(in srgb, var(--orange) 25%, var(--border2));
  border-radius: var(--radius-sm);
  background: var(--s2);
  margin-top: var(--space-2);
}
.repeat-item:first-child { margin-top: 0; }
.repeat-item-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-2);
  font-size: .8rem;
}
.repeat-item-hint { font-size: .68rem; color: var(--dim2); margin-top: var(--space-1); line-height: 1.45; }

.chart-wrap {
  position: relative;
  height: 220px;
  margin-top: var(--space-1);
}
.chart-empty {
  text-align: center;
  padding: var(--space-6) var(--space-4);
  color: var(--dim2);
  font-size: .78rem;
}

.unit-row {
  padding: var(--space-3) var(--space-4);
  margin-bottom: var(--space-2);
}
.unit-row-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-2);
  font-size: .8rem;
}
.unit-row-score {
  font-family: 'DM Mono', monospace;
  color: var(--red);
  flex-shrink: 0;
}
.unit-pattern { font-size: .68rem; color: var(--orange); margin-top: var(--space-1); }
.progress-track {
  height: 4px;
  background: var(--border2);
  border-radius: var(--radius-pill);
  margin-top: var(--space-2);
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--red), color-mix(in srgb, var(--orange) 60%, var(--red)));
  border-radius: var(--radius-pill);
  transition: width .4s var(--ease-out);
}
.unit-report { font-size: .7rem; color: var(--dim2); margin-top: var(--space-2); line-height: 1.55; }

.repeat-badge {
  display: inline-block;
  font-size: .65rem;
  color: var(--orange);
  background: color-mix(in srgb, var(--orange) 10%, var(--s2));
  border: 1px solid color-mix(in srgb, var(--orange) 45%, var(--border2));
  border-radius: var(--radius-pill);
  padding: 2px 10px;
  margin-top: var(--space-1);
  font-weight: 600;
}

.problem-top { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; }
.problem-num {
  font-size: .68rem;
  font-family: 'DM Mono', monospace;
  color: var(--dim2);
  background: var(--s2);
  border: 1px solid var(--border2);
  border-radius: 4px;
  padding: 2px 8px;
}
.problem-result { font-size: .85rem; font-weight: 700; }
.problem-result.wrong { color: var(--red); }
.problem-result.correct { color: var(--green); }
.problem-unit {
  font-size: .65rem;
  background: color-mix(in srgb, var(--purple) 12%, var(--s2));
  color: var(--purple);
  border: 1px solid color-mix(in srgb, var(--purple) 30%, var(--border2));
  border-radius: var(--radius-pill);
  padding: 2px 10px;
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.type-tag {
  font-size: .62rem;
  border-radius: 4px;
  padding: 2px 8px;
  font-family: 'DM Mono', monospace;
}
.type-tag.algebra { background: #0e1a28; color: var(--blue); border: 1px solid #1a3050; }
.type-tag.geometry { background: #0e2018; color: var(--mint); border: 1px solid #1a4030; }
.type-tag.mixed { background: #1a1228; color: var(--purple); border: 1px solid #2a1a48; }

.answer-row { display: flex; gap: 8px; margin: 8px 0; flex-wrap: wrap; }
.answer-chip {
  font-size: .68rem;
  border-radius: 6px;
  padding: 4px 10px;
  font-family: 'DM Mono', monospace;
}
.answer-chip.student { background: #1a1010; border: 1px solid var(--red); color: var(--red); }
.answer-chip.correct-ans { background: #0e2010; border: 1px solid var(--green); color: var(--green); }

.toggle-row { display: flex; gap: 6px; margin-top: 8px; }
.toggle-btn {
  padding: 5px 14px;
  border-radius: 20px;
  border: 1px solid var(--border2);
  background: var(--s2);
  font-size: .78rem;
  cursor: pointer;
  color: var(--dim2);
  font-family: inherit;
  transition: transform .12s var(--ease-out);
}
.toggle-btn:active { transform: scale(var(--active-scale)); }
.toggle-btn.wrong-active { background: #2a0a10; border-color: var(--red); color: var(--red); font-weight: 600; }
.toggle-btn.correct-active { background: #0a2010; border-color: var(--green); color: var(--green); font-weight: 600; }

.repeat-card {
  border-color: #4a3018 !important;
  background: linear-gradient(135deg, var(--s1) 0%, #1a1208 100%);
}

.ai-solution {
  font-size: .7rem;
  color: var(--dim2);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px;
  margin-top: 8px;
  line-height: 1.5;
  white-space: pre-wrap;
}
.ai-solution-label {
  font-size: .62rem;
  color: var(--theme);
  font-weight: 600;
  margin-bottom: 4px;
  display: block;
}

.thumb-zoom { cursor: zoom-in; }
.thumb-zoom:active { opacity: .85; }

.lightbox-overlay {
  position: fixed;
  inset: 0;
  z-index: 950;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, .88);
  padding: 16px;
}
.lightbox-overlay.show { display: flex; }
.lightbox-img {
  max-width: 100%;
  max-height: 92vh;
  object-fit: contain;
  border-radius: 8px;
}

img, canvas, video { max-width: 100%; height: auto; }
.answer-chip, .ai-solution, .problem-card { overflow-wrap: anywhere; word-break: break-word; }
.lightbox-close {
  position: fixed;
  top: calc(16px + env(safe-area-inset-top, 0px));
  right: calc(16px + env(safe-area-inset-right, 0px));
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--border2);
  background: var(--s1);
  color: var(--text);
  font-size: 1.1rem;
  cursor: pointer;
  z-index: 951;
}

.card-actions { display: flex; justify-content: flex-end; margin-top: 10px; }
.btn-delete {
  padding: 5px 12px;
  border-radius: 20px;
  border: 1px solid #4a1a1a;
  background: #150a0a;
  color: var(--red);
  font-size: .68rem;
  cursor: pointer;
  font-family: inherit;
}

/* ── misc ── */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--dim2);
  font-size: .85rem;
  line-height: 1.6;
}
.error-box {
  background: #150a0a;
  border: 1px solid #4a1a1a;
  border-radius: 10px;
  padding: 14px;
  font-size: .78rem;
  color: var(--red);
  margin-bottom: 12px;
}
.loading-box {
  text-align: center;
  padding: 28px;
  background: var(--s1);
  border: 1px solid var(--border2);
  border-radius: 12px;
  margin-bottom: 12px;
}
.spin {
  width: 32px; height: 32px;
  border: 3px solid var(--border2);
  border-top-color: var(--theme);
  border-radius: 50%;
  animation: spin .8s linear infinite;
  margin: 0 auto 12px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── add page ── */
.add-steps {
  display: flex;
  align-items: center;
  gap: 0;
  margin-bottom: var(--space-4);
  padding: var(--space-3);
  background: var(--s1);
  border: 1px solid var(--border2);
  border-radius: var(--radius-md);
}
.add-step {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  opacity: .45;
  transition: opacity .2s var(--ease-out);
}
.add-step.active { opacity: 1; }
.add-step.done { opacity: .75; }
.add-step-num {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1px solid var(--border2);
  background: var(--s2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .72rem;
  font-weight: 700;
  font-family: 'DM Mono', monospace;
  color: var(--dim2);
}
.add-step.active .add-step-num {
  border-color: color-mix(in srgb, var(--theme) 50%, var(--border2));
  background: color-mix(in srgb, var(--theme) 14%, var(--s2));
  color: var(--theme);
}
.add-step.done .add-step-num {
  border-color: color-mix(in srgb, var(--green) 45%, var(--border2));
  background: color-mix(in srgb, var(--green) 12%, var(--s2));
  color: var(--green);
}
.add-step-lbl { font-size: .62rem; color: var(--dim2); font-weight: 600; }
.add-step.active .add-step-lbl { color: var(--text); }
.add-step-connector {
  flex: 0 0 20px;
  height: 1px;
  background: var(--border2);
  margin-bottom: 18px;
}
.add-step-connector.done { background: color-mix(in srgb, var(--green) 40%, var(--border2)); }

.mode-tabs { display: flex; gap: var(--space-2); margin-bottom: var(--space-3); flex-wrap: wrap; }
.mode-tab {
  min-height: 36px;
  padding: 6px 14px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border2);
  background: var(--s2);
  color: var(--dim2);
  font-size: .72rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: transform .12s var(--ease-out), background .15s, border-color .15s, color .15s;
}
.mode-tab:active { transform: scale(var(--active-scale)); }
.mode-tab.active {
  background: color-mix(in srgb, var(--theme) 14%, var(--s2));
  color: var(--theme);
  border-color: color-mix(in srgb, var(--theme) 45%, var(--border2));
}

.upload-zone {
  border: 1px dashed color-mix(in srgb, var(--theme) 25%, var(--border2));
  border-radius: var(--radius-lg);
  background: color-mix(in srgb, var(--s1) 92%, transparent);
  padding: var(--space-6) var(--space-5);
  text-align: center;
  cursor: default;
  position: relative;
  margin-bottom: var(--space-3);
  transition: border-color .15s;
}
.upload-zone:hover { border-color: color-mix(in srgb, var(--theme) 45%, var(--border2)); }
.upload-zone-icon { font-size: 2rem; margin-bottom: var(--space-2); line-height: 1; }
.upload-zone-title { font-weight: 600; margin-bottom: 4px; font-size: .9rem; }
.upload-zone-sub { font-size: .72rem; color: var(--dim2); margin-bottom: var(--space-1); }
.upload-actions { display: flex; gap: var(--space-2); margin-top: var(--space-3); justify-content: center; }
.upload-actions .btn { width: auto; flex: 1; max-width: 200px; padding: 12px 10px; font-size: .82rem; }
.paste-hint { font-size: .68rem; color: var(--dim2); margin-top: var(--space-3); }
.paste-hint kbd {
  font-family: 'DM Mono', monospace;
  font-size: .62rem;
  padding: 2px 5px;
  border-radius: 4px;
  border: 1px solid var(--border2);
  background: var(--s2);
}

.preview-wrap {
  display: none;
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 1px solid var(--border2);
  margin-bottom: var(--space-3);
}
.preview-wrap img {
  width: 100%;
  max-height: 320px;
  object-fit: contain;
  display: block;
  background: var(--s2);
}
.preview-meta {
  padding: var(--space-2) var(--space-3);
  font-size: .68rem;
  color: var(--dim2);
  display: flex;
  justify-content: space-between;
  background: var(--s1);
}
.preview-actions { display: none; margin-bottom: var(--space-2); }
.preview-actions .btn-cancel {
  color: var(--red);
  border-color: color-mix(in srgb, var(--red) 30%, var(--border2));
}
.add-analyze-btn { display: none; margin-bottom: var(--space-3); }
.add-result-area { display: none; }
.problem-crop {
  width: 100%;
  max-height: 140px;
  object-fit: contain;
  border-radius: var(--radius-sm);
  margin-bottom: var(--space-2);
  border: 1px solid var(--border2);
  background: var(--s2);
}

/* ── settings (my) ── */
.settings-page { padding-bottom: var(--space-4); }
.settings-header {
  font-size: .68rem;
  font-weight: 600;
  color: var(--dim);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: var(--space-4) var(--space-4) var(--space-2);
}
.settings-group {
  background: var(--s1);
  border: 1px solid var(--border2);
  border-radius: var(--radius-md);
  overflow: hidden;
  margin-bottom: var(--space-4);
}
.settings-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  min-height: 48px;
  border: none;
  border-bottom: 1px solid var(--border2);
  background: transparent;
  width: 100%;
  text-align: left;
  font-family: inherit;
  font-size: .82rem;
  color: var(--text);
  cursor: pointer;
  transition: background .12s;
}
.settings-row:last-child { border-bottom: none; }
.settings-row:active { background: var(--s2); transform: scale(var(--active-scale)); }
.settings-row.static { cursor: default; }
.settings-row.static:active { transform: none; background: transparent; }
.settings-icon { font-size: 1.1rem; width: 28px; text-align: center; flex-shrink: 0; }
.settings-body { flex: 1; min-width: 0; }
.settings-label { font-weight: 500; display: block; }
.settings-detail { font-size: .68rem; color: var(--dim2); margin-top: 2px; line-height: 1.4; }
.settings-value {
  font-family: 'DM Mono', monospace;
  font-size: .85rem;
  font-weight: 600;
  color: var(--theme);
  flex-shrink: 0;
}
.settings-chevron { color: var(--dim); font-size: .75rem; flex-shrink: 0; }
.settings-row.danger .settings-label { color: var(--red); }
.settings-footnote {
  font-size: .65rem;
  color: var(--dim);
  padding: 0 var(--space-4) var(--space-3);
  line-height: 1.5;
}

/* ── toast ── */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(76px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%) translateY(12px);
  background: var(--s3);
  border: 1px solid var(--border2);
  color: var(--text);
  padding: 10px 16px;
  border-radius: var(--radius-pill);
  font-size: .78rem;
  font-weight: 600;
  z-index: 800;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s var(--ease-out), transform .2s var(--ease-out);
  max-width: min(90vw, 360px);
  text-align: center;
  box-shadow: 0 8px 32px rgba(0, 0, 0, .35);
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
.toast.error {
  border-color: color-mix(in srgb, var(--red) 40%, var(--border2));
  color: var(--red);
}

/* ── login ── */
#loginScreen {
  position: fixed;
  inset: 0;
  z-index: 900;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  padding:
    env(safe-area-inset-top, 0px)
    env(safe-area-inset-right, 0px)
    env(safe-area-inset-bottom, 0px)
    env(safe-area-inset-left, 0px);
}
#loginScreen::before {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(var(--border) 1px, transparent 1px),
    linear-gradient(90deg, var(--border) 1px, transparent 1px);
  background-size: 40px 40px;
  opacity: .18;
}
.login-inner { position: relative; z-index: 1; text-align: center; padding: 0 var(--space-6); width: 100%; max-width: 340px; }
.login-mark {
  width: 56px;
  height: 56px;
  margin: 0 auto var(--space-4);
  border-radius: var(--radius-lg);
  background: color-mix(in srgb, var(--theme) 18%, var(--s2));
  border: 1px solid color-mix(in srgb, var(--theme) 35%, var(--border2));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.6rem;
  box-shadow: 0 0 40px color-mix(in srgb, var(--theme) 15%, transparent);
}
.login-title { font-size: 1.35rem; font-weight: 700; color: var(--text); margin-bottom: 6px; letter-spacing: -0.03em; }
.login-title span { color: var(--theme); }
.login-sub { font-size: .72rem; color: var(--dim2); margin-bottom: var(--space-6); }
.login-box { display: flex; flex-direction: column; gap: 10px; }
.login-input {
  width: 100%;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--border2);
  background: var(--s1);
  color: var(--text);
  font-size: 16px;
  outline: none;
}
.login-input:focus { border-color: var(--theme); }
.login-btn { width: 100%; margin-top: 4px; }
.login-error { font-size: .72rem; color: var(--red); min-height: 1.2em; }
