:root {
  --bg: #161311;
  --bg-soft: #1d1a18;
  --bg-raised: #2a2623;
  --bg-raised-2: #342f2c;
  --bg-sunken: #100e0c;
  --surface: rgba(34, 31, 29, 0.72);
  --surface-strong: rgba(44, 40, 37, 0.9);
  --surface-glass: rgba(34, 31, 29, 0.7);
  --text: #efe5df;
  --muted: #dac0ad;
  --dim: #a78f7f;
  --accent: #ffbc62;
  --accent-2: #d48a1f;
  --success: #89d39c;
  --danger: #ff8a80;
  --warning: #ffbd8d;
  --shadow: 0 24px 48px rgba(10, 9, 8, 0.45);
  --shadow-soft: 0 16px 32px rgba(10, 9, 8, 0.26);
  --radius-sm: 16px;
  --radius: 22px;
  --radius-lg: 30px;
  --radius-xl: 36px;
  --radius-pill: 999px;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: "Manrope", sans-serif;
  background:
    radial-gradient(circle at top right, rgba(255, 188, 98, 0.10), transparent 28%),
    radial-gradient(circle at bottom left, rgba(255, 188, 98, 0.06), transparent 30%),
    linear-gradient(180deg, #181412 0%, #14110f 100%);
  color: var(--text);
  overflow-x: hidden;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  background:
    radial-gradient(circle at top center, rgba(255, 188, 98, 0.04), transparent 26%),
    radial-gradient(circle at 20% 80%, rgba(255, 188, 98, 0.03), transparent 24%);
  pointer-events: none;
  z-index: 0;
}

body > * { position: relative; z-index: 1; }

a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
input, select, textarea {
  width: 100%;
  background: rgba(15, 13, 12, 0.85);
  color: var(--text);
  border: 0;
  border-radius: 18px;
  padding: 14px 16px;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.03);
  transition: background-color 160ms ease, box-shadow 160ms ease, transform 160ms ease;
}
input::placeholder, textarea::placeholder { color: rgba(218, 192, 173, 0.58); }
input:focus, select:focus, textarea:focus {
  outline: none;
  background: rgba(25, 22, 20, 0.96);
  box-shadow: 0 0 0 1px rgba(255, 188, 98, 0.22), 0 0 0 4px rgba(255, 188, 98, 0.08);
}
textarea { min-height: 120px; resize: vertical; }

.study-shell { min-height: 100vh; }
.boot-card,
.auth-card,
.section-surface,
.surface,
.panel,
.quick-create,
.subject-card,
.history-card,
.recommendation-card,
.plan-card,
.stat-tile,
.folder-card,
.test-card,
.empty-state,
.filter-rail,
.leaderboard-panel,
.sidebar-profile,
.modal-shell {
  background: linear-gradient(180deg, rgba(53, 48, 44, 0.72), rgba(33, 29, 26, 0.86));
  backdrop-filter: blur(22px);
  box-shadow: var(--shadow);
}

.boot-card,
.auth-card {
  width: min(560px, calc(100vw - 32px));
  margin: 13vh auto 0;
  border-radius: var(--radius-xl);
  padding: 30px;
}

.auth-card h1,
.study-hero h1,
.plan-hero h1,
.hero-deck h1,
.panel-title,
.stat-number,
.folder-card h3,
.test-card h3,
.modal-head h3 {
  letter-spacing: -0.04em;
}

.kicker,
.folder-kicker {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--accent);
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.muted { color: var(--muted); }
.dim { color: var(--dim); }
.linkish,
.ghost-text {
  color: var(--accent);
  background: transparent;
  padding: 0;
  border: 0;
  cursor: pointer;
}

.primary,
.secondary,
.ghost,
.nav-link,
.segment,
.rating-input,
.chip,
.mini-pill,
.plan-pill,
.study-badge {
  border-radius: var(--radius-pill);
  transition: transform 160ms ease, background-color 160ms ease, box-shadow 160ms ease, color 160ms ease;
}

.primary,
.secondary,
.ghost,
.segment,
.rating-input {
  padding: 12px 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-align: center;
}

.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #1c1407;
  font-weight: 800;
}

.primary:hover,
.primary:focus-visible { transform: translateY(-1px); }
.secondary {
  background: rgba(58, 52, 47, 0.92);
  color: var(--text);
}
.secondary:hover,
.secondary:focus-visible,
.ghost:hover,
.ghost:focus-visible,
.segment:hover,
.segment:focus-visible,
.rating-input:hover,
.rating-input:focus-visible,
.nav-link:hover,
.nav-link:focus-visible,
.chip:hover,
.chip:focus-visible { transform: translateY(-1px); }
.ghost {
  background: rgba(37, 33, 30, 0.78);
  color: var(--muted);
}

.nav-link {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  color: var(--muted);
  background: transparent;
  text-align: left;
}
.nav-link.active {
  background: rgba(58, 52, 47, 0.88);
  color: var(--accent);
  font-weight: 800;
}
.nav-emoji { width: 24px; text-align: center; }

.study-app {
  display: grid;
  grid-template-columns: 286px minmax(0, 1fr);
  min-height: 100vh;
}

.study-sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 22px 18px 20px;
  background: linear-gradient(180deg, rgba(31, 28, 25, 0.92), rgba(22, 19, 17, 0.94));
  backdrop-filter: blur(26px);
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.study-brand {
  padding: 6px 10px 18px;
}
.study-brand h1 {
  margin: 0;
  font-size: 1.12rem;
  font-weight: 800;
}
.study-brand p {
  margin: 6px 0 0;
  color: var(--dim);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.18em;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sidebar-profile {
  margin-top: auto;
  padding: 18px;
  border-radius: var(--radius-lg);
}
.sidebar-profile .profile-kicker,
.profile-kicker,
.topbar-kicker,
.search-group-title,
.section-head .kicker,
.filter-label {
  color: var(--dim);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.16em;
}
.sidebar-profile .profile-name,
.profile-name {
  margin-top: 8px;
  font-weight: 800;
  font-size: 1.02rem;
}
.sidebar-profile .profile-meta,
.profile-meta {
  margin-top: 8px;
  color: var(--muted);
  line-height: 1.55;
  font-size: 0.92rem;
}
.sidebar-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 14px;
}

.auth-code {
  width: 100%;
  padding: 18px 20px;
  border-radius: 24px;
  background: linear-gradient(135deg, rgba(255, 188, 98, 0.18), rgba(255, 188, 98, 0.06));
  color: var(--accent);
  font-size: 1.25rem;
  font-weight: 900;
  letter-spacing: 0.18em;
  text-align: center;
  margin: 18px 0 14px;
  border: 0;
  box-shadow: inset 0 0 0 1px rgba(255, 188, 98, 0.10);
}

.auth-code:hover,
.auth-code:focus-visible {
  transform: translateY(-1px);
  background: linear-gradient(135deg, rgba(255, 188, 98, 0.22), rgba(255, 188, 98, 0.09));
  box-shadow: 0 0 0 1px rgba(255, 188, 98, 0.16), 0 0 0 4px rgba(255, 188, 98, 0.08);
}

.auth-help {
  color: var(--muted);
  line-height: 1.65;
  font-size: 0.96rem;
}

.auth-status {
  margin-top: 12px;
  color: var(--dim);
  font-size: 0.85rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.study-main {
  min-width: 0;
  padding: 22px 28px 44px;
}

.study-topbar {
  position: sticky;
  top: 18px;
  z-index: 24;
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(320px, 560px) auto;
  gap: 18px;
  align-items: center;
  margin-bottom: 22px;
  padding: 18px 20px;
  border-radius: var(--radius-xl);
  background: rgba(40, 36, 33, 0.74);
  backdrop-filter: blur(28px);
  box-shadow: var(--shadow);
}

.topbar-copy h2 {
  margin: 4px 0 0;
  font-size: 1.7rem;
  font-weight: 800;
}
.topbar-copy p {
  margin: 6px 0 0;
  color: var(--muted);
  line-height: 1.45;
}

.topbar-search-shell {
  position: relative;
  min-width: 0;
}
.search-shell-label { display: block; }
.search-shell-label input {
  padding: 16px 18px;
  border-radius: 24px;
  background: rgba(18, 16, 14, 0.9);
}
.search-status {
  margin-top: 8px;
  color: var(--dim);
  font-size: 0.8rem;
  letter-spacing: 0.06em;
}
.search-overlay {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 14px);
  z-index: 40;
  padding: 18px;
  border-radius: 28px;
  background: rgba(31, 28, 25, 0.96);
  backdrop-filter: blur(26px);
  box-shadow: var(--shadow);
  display: grid;
  gap: 14px;
}
.search-overlay-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}
.search-group { display: grid; gap: 10px; }
.search-group-list { display: grid; gap: 10px; }
.search-row {
  width: 100%;
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: center;
  text-align: left;
  padding: 14px 16px;
  border-radius: 20px;
  background: rgba(18, 16, 14, 0.88);
  color: var(--text);
}
.search-row-title { font-weight: 800; }
.search-row-meta { color: var(--muted); font-size: 0.9rem; margin-top: 5px; }
.search-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(16, 14, 12, 0.08);
  backdrop-filter: blur(2px);
  z-index: 20;
}

.topbar-actions {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
}

.topic-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.study-badge,
.mini-pill,
.plan-pill,
.topic-pill,
.chip,
.meta-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  background: rgba(58, 52, 47, 0.9);
  color: var(--muted);
  font-size: 0.9rem;
}

.hero-deck,
.study-hero,
.plan-hero {
  position: relative;
  overflow: hidden;
  border-radius: 36px;
  padding: 34px;
  background:
    linear-gradient(160deg, rgba(54, 49, 45, 0.95), rgba(28, 25, 23, 0.92)),
    radial-gradient(circle at top right, rgba(255, 188, 98, 0.16), transparent 30%);
  box-shadow: var(--shadow);
}
.hero-deck::after,
.study-hero::after,
.plan-hero::after {
  content: "";
  position: absolute;
  inset: auto -84px -84px auto;
  width: 240px;
  height: 240px;
  border-radius: 50%;
  background: rgba(255, 188, 98, 0.08);
  filter: blur(2px);
}
.hero-deck {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 22px;
  align-items: center;
}
.hero-copy { position: relative; z-index: 1; }
.hero-copy h1,
.study-hero h1,
.plan-hero h1 {
  margin: 10px 0 0;
  font-size: clamp(2rem, 3vw, 3.6rem);
  line-height: 1.02;
}
.hero-copy p,
.study-hero p,
.plan-hero p {
  margin: 14px 0 0;
  color: var(--muted);
  line-height: 1.7;
  max-width: 72ch;
}
.hero-actions {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  gap: 12px;
  justify-content: flex-end;
  align-items: stretch;
  min-width: 240px;
}
.hero-actions .primary,
.hero-actions .secondary { justify-content: center; }

.section-surface,
.surface,
.quick-create,
.panel,
.empty-state,
.stat-tile,
.history-card,
.recommendation-card,
.plan-card,
.subject-card,
.folder-card,
.test-card,
.filter-rail,
.leaderboard-panel {
  border-radius: 28px;
  padding: 22px;
  background: rgba(45, 41, 38, 0.78);
  box-shadow: var(--shadow-soft);
}
.section-surface-spacious { padding: 24px; }

.section-head,
.workspace-head,
.modal-head,
.folder-card-head,
.test-card-top,
.card-footer,
.card-legend,
.folder-footer,
.modal-stretch,
.modal-actions,
.toolbar-row,
.card-actions,
.inline-actions,
.plan-actions,
.leaderboard-row {
  display: flex;
  gap: 12px;
  align-items: center;
}
.section-head,
.workspace-head,
.modal-head,
.folder-card-head,
.test-card-top,
.folder-footer,
.modal-stretch,
.leaderboard-row {
  justify-content: space-between;
}
.section-head h3,
.workspace-head h3,
.panel-title,
.modal-head h3,
.folder-card h3,
.test-card h3,
.recommendation-card h3,
.plan-card h3,
.subject-card h3,
.stat-tile .stat-number {
  margin: 0;
}
.panel-title { font-size: 1.18rem; font-weight: 800; }

.content-grid,
.workspace-layout,
.summary-grid,
.plan-grid,
.subject-grid,
.history-grid,
.test-grid,
.form-grid,
.modal-meta-grid {
  display: grid;
  gap: 14px;
}
.chip-row,
.chip-stack {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  min-width: 0;
}
.content-grid { grid-template-columns: minmax(0, 1.35fr) minmax(320px, 0.8fr); }
.summary-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.plan-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.subject-grid { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.history-grid { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.test-grid { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.form-grid,
.modal-meta-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid .full,
.modal-meta-grid .full { grid-column: 1 / -1; }

.stat-tile {
  display: grid;
  gap: 8px;
  min-height: 140px;
}
.stat-number {
  font-size: clamp(1.8rem, 4vw, 2.8rem);
  font-weight: 800;
}
.stat-label {
  color: var(--muted);
  font-size: 0.92rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
}
.metric-trend,
.history-meta,
.subject-card p,
.plan-card p,
.recommendation-card p,
.panel p,
.small-note,
.empty-state p,
.workspace-head p,
.filter-group p,
.modal-head p {
  color: var(--muted);
  line-height: 1.65;
}

.folder-card,
.test-card {
  display: grid;
  gap: 14px;
  cursor: pointer;
  background:
    linear-gradient(180deg, rgba(58, 52, 47, 0.86), rgba(29, 25, 22, 0.92)),
    rgba(42, 38, 35, 0.78);
}
.folder-card:hover,
.test-card:hover,
.subject-card:hover,
.history-card:hover,
.plan-card:hover,
.recommendation-card:hover {
  transform: translateY(-2px);
}
.folder-card h3,
.test-card h3,
.plan-card h3,
.subject-card h3,
.recommendation-card h3 { font-size: 1.08rem; }
.folder-icon {
  min-width: 56px;
  height: 56px;
  border-radius: 18px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, rgba(255, 188, 98, 0.18), rgba(255, 188, 98, 0.06));
  color: var(--accent);
  font-weight: 800;
  letter-spacing: 0.08em;
}
.folder-stats { display: flex; gap: 10px; flex-wrap: wrap; }
.folder-footer { justify-content: space-between; margin-top: 4px; }

.workspace-layout { grid-template-columns: 290px minmax(0, 1fr); align-items: start; }
.workspace-layout-stats { grid-template-columns: minmax(0, 1.2fr) 0.8fr; }
.workspace-layout-profile { grid-template-columns: minmax(0, 1fr) minmax(320px, 0.8fr); }
.workspace-main,
.leaderboard-panel,
.filter-rail { position: relative; }
.filter-rail {
  position: sticky;
  top: 132px;
  display: grid;
  gap: 16px;
}
.filter-rail-head { display: grid; gap: 6px; }
.filter-group { display: grid; gap: 10px; }
.filter-label { margin-bottom: 0; }
.segmented { display: grid; gap: 8px; }
.segment {
  width: 100%;
  background: transparent;
  color: var(--muted);
  position: relative;
  z-index: 1;
}
.segment.selected,
.chip.selected,
.chip-strong,
.nav-link.active,
.rating-input:hover,
.rating-input:focus-visible {
  background: linear-gradient(135deg, rgba(255, 188, 98, 0.2), rgba(255, 188, 98, 0.08));
  color: var(--accent);
}
.select-shell { width: 100%; }
.filter-actions { display: flex; gap: 10px; flex-wrap: wrap; }

.chip,
.topic-pill,
.meta-pill,
.plan-pill,
.mini-pill,
.study-badge {
  border: 0;
  background: rgba(64, 58, 54, 0.92);
  color: var(--muted);
  padding: 8px 14px;
  max-width: 100%;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chip { cursor: pointer; }
.chip-empty { color: rgba(218, 192, 173, 0.52); }
.chip-strong { color: var(--accent); }
.topic-pill { color: var(--muted); }

.test-card-top { align-items: flex-start; }
.test-card-kicker,
.test-card .muted,
.card-legend,
.card-legend .muted { color: var(--dim); font-size: 0.88rem; }
.test-card p { color: var(--muted); line-height: 1.6; margin: 0; }
.card-footer,
.card-actions,
.inline-actions,
.plan-actions {
  justify-content: flex-start;
  flex-wrap: wrap;
}
.card-legend {
  justify-content: space-between;
  margin-top: 2px;
}
.ghost-text { font-weight: 700; }

.rating-badge,
.rating-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: var(--radius-pill);
  background: rgba(20, 18, 16, 0.8);
  color: var(--muted);
}
.rating-pill.compact,
.rating-badge.compact {
  padding: 7px 10px;
}
.rating-pill.vertical,
.rating-badge.vertical {
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  min-width: 58px;
}
.rating-stars { display: inline-flex; gap: 2px; color: rgba(218, 192, 173, 0.46); }
.rating-star.filled { color: var(--accent); }
.rating-value,
.rating-values { color: var(--text); font-weight: 800; }
.rating-count { color: var(--dim); font-size: 0.84rem; }
.rating-inputs { display: flex; gap: 8px; flex-wrap: wrap; }
.rating-input {
  min-width: 42px;
  background: rgba(18, 16, 14, 0.88);
  color: var(--muted);
}
.modal-rating { display: grid; gap: 8px; }
.rating-summary { display: flex; justify-content: flex-start; }

.empty-state {
  display: grid;
  gap: 14px;
  background: rgba(34, 31, 29, 0.72);
}
.empty-state-strong {
  padding: 28px;
  background: linear-gradient(180deg, rgba(52, 47, 43, 0.88), rgba(29, 25, 22, 0.92));
}
.empty-state h3 { margin: 0; font-size: 1.08rem; }

.loading-line {
  width: 100%;
  height: 10px;
  border-radius: var(--radius-pill);
  background: linear-gradient(90deg, rgba(255,255,255,0.04), rgba(255,188,98,0.20), rgba(255,255,255,0.04));
  background-size: 200% 100%;
  animation: shimmer 1.8s linear infinite;
}

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  max-width: 380px;
  padding: 14px 18px;
  border-radius: 18px;
  background: rgba(44, 40, 37, 0.94);
  color: var(--text);
  box-shadow: var(--shadow);
  z-index: 100;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(16, 14, 12, 0.44);
  backdrop-filter: blur(10px);
}
.modal-shell {
  width: min(920px, 100%);
  max-height: min(86vh, 920px);
  overflow: auto;
  display: grid;
  gap: 18px;
  border-radius: 32px;
  padding: 24px;
  background: linear-gradient(180deg, rgba(54, 49, 45, 0.96), rgba(27, 24, 22, 0.98));
  box-shadow: 0 30px 60px rgba(8, 7, 6, 0.5);
  transform-origin: top center;
}

.modal-shell.is-opening {
  animation: modalIn 180ms ease;
}

.modal-shell.is-closing {
  animation: modalOut 180ms ease forwards;
}
.modal-wide { width: min(1040px, 100%); }
.modal-head p { max-width: 70ch; }
.modal-meta-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}
.meta-block {
  padding: 16px 18px;
  border-radius: 22px;
  background: rgba(17, 15, 14, 0.84);
}
.meta-label { display: block; color: var(--dim); margin-bottom: 8px; font-size: 0.76rem; letter-spacing: 0.14em; text-transform: uppercase; }
.modal-stretch { align-items: flex-start; }
.modal-actions { flex-wrap: wrap; justify-content: flex-start; }

.search-group .rating-badge { margin-left: auto; }

.search-row-create {
  background: linear-gradient(180deg, rgba(54, 49, 45, 0.84), rgba(25, 22, 20, 0.9));
  box-shadow: inset 0 0 0 1px rgba(255, 188, 98, 0.14);
}

.search-row-action {
  color: var(--accent);
  font-size: 1.3rem;
  line-height: 1;
}

.leaderboard-panel {
  display: grid;
  gap: 12px;
  align-self: start;
}
.leaderboard-row {
  display: grid;
  grid-template-columns: 60px minmax(0, 1fr) 80px 80px;
  gap: 12px;
  padding: 14px 16px;
  border-radius: 20px;
  background: rgba(18, 16, 14, 0.88);
}
.leaderboard-row.self {
  background: linear-gradient(135deg, rgba(255, 188, 98, 0.14), rgba(18, 16, 14, 0.9));
}
.leaderboard-rank,
.leaderboard-points,
.leaderboard-meta {
  font-weight: 800;
  color: var(--text);
}
.leaderboard-name { justify-self: start; text-align: left; padding: 0; }

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
  background: var(--dim);
  box-shadow: 0 0 0 4px rgba(255, 255, 255, 0.02);
}
.status-dot.good { background: var(--success); }
.status-dot.bad { background: var(--danger); }

.workspace-head { margin-bottom: 12px; }
.workspace-head-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }

.section-surface .section-head + .summary-grid,
.section-surface .section-head + .test-grid,
.section-surface .section-head + .empty-state,
.section-surface .section-head + .leaderboard-row { margin-top: 8px; }

.history-card,
.recommendation-card,
.plan-card,
.subject-card {
  display: grid;
  gap: 12px;
}
.history-card h3,
.subject-card h3,
.plan-card h3,
.recommendation-card h3 { font-size: 1.06rem; margin: 0; }

.topic-score { color: var(--accent); font-weight: 800; }
.weak-topic {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 0;
}
.weak-topic + .weak-topic { border-top: 0; }

.plan-card { align-content: start; }
.plan-phase { min-height: 100%; }
.plan-card { position: relative; }
.plan-delete-action {
  position: absolute;
  top: 16px;
  right: 16px;
  z-index: 2;
}
.danger-text {
  color: #ffb0b0;
  border-color: rgba(217, 93, 93, 0.28);
}
.danger-text:hover {
  color: #fff0f0;
  background: rgba(118, 42, 42, 0.18);
}

.card-actions { margin-top: 4px; }
.section-surface .panel-title + .muted,
.section-surface .folder-kicker + .panel-title { margin-top: 8px; }

.form-field {
  display: grid;
  gap: 8px;
  color: var(--muted);
}
.form-field span { font-size: 0.82rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--dim); }

.quick-create,
.panel,
.surface,
.section-surface {
  background: rgba(45, 41, 38, 0.8);
}

.study-hero .summary-grid,
.plan-hero .summary-grid { margin-top: 22px; }

.subject-folder-grid {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
}

.empty-grid {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
}

.folder-card,
.test-card,
.subject-card,
.history-card,
.plan-card,
.recommendation-card,
.stat-tile,
.panel,
.surface,
.section-surface,
.quick-create,
.empty-state {
  border: 0;
}

.subject-card {
  background: linear-gradient(180deg, rgba(56, 52, 49, 0.8), rgba(29, 26, 23, 0.94));
}

.history-card .card-actions,
.plan-card .card-actions,
.subject-card .card-actions { margin-top: auto; }

/* Existing shared utility classes from the prior study shell */
.history-card .history-score { color: var(--accent); font-weight: 800; }
.history-card .status-dot,
.subject-card .status-dot,
.plan-card .status-dot { flex-shrink: 0; }

.muted strong,
.small-note strong { color: var(--text); }

.hidden { display: none !important; }

/* v3 Library-first overrides */
.study-main > section,
.study-main > .content-grid,
.study-main > .workspace-layout,
.study-main > .section-surface,
.study-main > .surface {
  margin-bottom: 28px;
}

.study-topbar {
  top: 12px;
  z-index: 32;
  grid-template-columns: minmax(140px, 220px) minmax(360px, 640px) auto;
  padding: 16px 18px;
  margin-bottom: 28px;
  background: rgba(33, 29, 26, 0.78);
  overflow: visible;
}

.study-topbar-minimal {
  grid-template-columns: 1fr minmax(360px, 620px) auto;
  padding: 0;
  background: transparent;
  box-shadow: none;
  backdrop-filter: none;
}

.topbar-copy h2 {
  font-size: 1.25rem;
  margin: 4px 0 0;
}

.topbar-copy-empty {
  min-height: 1px;
}

.topbar-search-shell {
  justify-self: center;
  width: 100%;
  max-width: 560px;
  z-index: 1;
}

.search-shell-label input {
  height: 50px;
  padding: 14px 18px;
  text-align: left;
  box-shadow: 0 18px 40px rgba(8, 7, 6, 0.24), inset 0 0 0 1px rgba(255, 255, 255, 0.03);
}

.search-status {
  min-height: 18px;
  margin-top: 6px;
  display: none;
}

.topbar-actions {
  position: relative;
  min-width: 58px;
  z-index: 65;
}

.profile-trigger {
  width: 48px;
  height: 48px;
  border-radius: 999px;
  background: linear-gradient(135deg, rgba(255, 188, 98, 0.24), rgba(255, 188, 98, 0.08));
  color: var(--accent);
  font-weight: 800;
  display: grid;
  place-items: center;
  box-shadow: inset 0 0 0 1px rgba(255, 188, 98, 0.14);
}

.profile-flyout {
  position: absolute;
  top: calc(100% + 12px);
  right: 0;
  width: min(320px, calc(100vw - 32px));
  padding: 18px;
  border-radius: 24px;
  background: rgba(30, 27, 24, 0.96);
  backdrop-filter: blur(28px);
  box-shadow: var(--shadow);
  display: grid;
  gap: 14px;
  z-index: 70;
}

.profile-flyout-head {
  display: grid;
  gap: 6px;
}

.profile-flyout-stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.profile-flyout-stats > div {
  border-radius: 18px;
  padding: 12px 14px;
  background: rgba(17, 15, 14, 0.84);
  display: grid;
  gap: 4px;
}

.profile-flyout-stats span {
  color: var(--dim);
  font-size: 0.72rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.profile-flyout-actions {
  display: grid;
  gap: 10px;
}

.profile-flyout-footer {
  display: flex;
  justify-content: flex-end;
}

.icon-link {
  width: 38px;
  height: 38px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  background: rgba(58, 52, 47, 0.92);
  color: var(--accent);
}

.search-overlay {
  z-index: 64;
  overflow: hidden;
}

.search-backdrop {
  z-index: 28;
}

.hero-deck,
.study-hero,
.plan-hero,
.section-surface,
.surface,
.panel,
.empty-state,
.filter-rail,
.leaderboard-panel {
  margin-top: 0;
}

.subject-folder-grid {
  gap: 18px;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
}

.folder-card {
  position: relative;
  padding-top: 28px;
  gap: 12px;
  min-height: 220px;
  overflow: hidden;
}

.folder-card-ribbon {
  position: absolute;
  top: 0;
  left: 0;
  width: 96px;
  height: 12px;
  border-bottom-right-radius: 16px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
}

.folder-card-head {
  justify-content: flex-start;
  align-items: center;
  gap: 14px;
}

.folder-copy {
  display: grid;
  gap: 4px;
}

.folder-meta {
  color: var(--dim);
  font-size: 0.88rem;
}

.folder-card p {
  margin: 0;
  color: var(--muted);
  line-height: 1.65;
}

.folder-icon-dashed {
  background: rgba(29, 25, 22, 0.38);
  box-shadow: inset 0 0 0 1px rgba(255, 188, 98, 0.22);
  border: 1.5px dashed rgba(255, 188, 98, 0.24);
}

.folder-card-create {
  border: 1.5px dashed rgba(163, 140, 124, 0.34);
  background: rgba(41, 37, 34, 0.38);
}

.compact-chips {
  gap: 10px;
}

.hero-actions {
  min-width: 220px;
}

.workspace-layout {
  grid-template-columns: minmax(0, 280px) minmax(0, 1fr);
  gap: 24px;
}

.filter-rail {
  top: 118px;
  gap: 14px;
}

.filter-rail.collapsed .filter-rail-body {
  display: none;
}

.filter-rail-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.tag-search-shell input {
  height: 46px;
}

.chip-stack-vertical {
  grid-template-columns: 1fr;
}

.chip-removable {
  justify-content: space-between;
  gap: 12px;
  width: fit-content;
}

.segmented-inline {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.workspace-head {
  margin-bottom: 18px;
  align-items: flex-end;
}

.workspace-head-actions {
  align-items: center;
}

.back-button {
  white-space: nowrap;
}

.compact-select {
  width: auto;
  min-width: 150px;
  padding-right: 36px;
}

.compact-test-grid {
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
}

.test-card {
  gap: 10px;
  padding: 18px;
  min-height: 170px;
  align-content: start;
  position: relative;
}

.test-card-copy {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.test-card h3 {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  overflow: hidden;
  line-height: 1.28;
  min-height: calc(1.28em * 3);
}

.test-card-meta {
  color: var(--dim);
  font-size: 0.82rem;
  line-height: 1.4;
}

.test-card-footer {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  margin-top: auto;
}

.test-card-completion-text {
  color: var(--dim);
  font-size: 0.84rem;
  line-height: 1.45;
}

.test-card .rating-pill {
  flex-shrink: 0;
}

.test-complete-badge {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 28px;
  height: 28px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  background: rgba(45, 104, 63, 0.92);
  color: #eaffed;
  font-weight: 800;
  box-shadow: 0 10px 22px rgba(0, 0, 0, 0.24);
}

.test-card.completed {
  box-shadow: var(--shadow-soft), inset 0 0 0 1px rgba(137, 211, 156, 0.14);
}

.modal-head,
.modal-actions,
.modal-stretch {
  flex-wrap: wrap;
}

.section-head {
  gap: 14px;
}

.leaderboard-panel,
.section-surface,
.surface,
.panel {
  padding: 24px;
}

@keyframes shimmer {
  from { background-position: 200% 0; }
  to { background-position: -200% 0; }
}

@media (max-width: 1180px) {
  .study-app { grid-template-columns: 1fr; }
  .study-sidebar { position: static; height: auto; }
  .study-topbar { grid-template-columns: 1fr; }
  .hero-deck { grid-template-columns: 1fr; }
  .content-grid,
  .workspace-layout,
  .workspace-layout-stats,
  .workspace-layout-profile,
  .summary-grid,
  .plan-grid,
  .modal-meta-grid {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 860px) {
  .study-main { padding: 18px 16px 32px; }
  .study-sidebar { padding: 18px 14px; }
  .study-topbar,
  .hero-deck,
  .content-grid,
  .workspace-layout,
  .workspace-layout-stats,
  .workspace-layout-profile,
  .summary-grid,
  .plan-grid,
  .modal-meta-grid,
  .subject-folder-grid,
  .empty-grid {
    grid-template-columns: 1fr;
  }
  .filter-rail {
    position: static;
  }
  .profile-flyout {
    right: 0;
    left: auto;
  }
  .topbar-actions,
  .hero-actions,
  .card-actions,
  .inline-actions,
  .toolbar-row,
  .workspace-head,
  .folder-card-head,
  .test-card-top,
  .section-head,
  .modal-head,
  .modal-stretch,
  .leaderboard-row {
    flex-direction: column;
    align-items: flex-start;
  }
  .leaderboard-row {
    grid-template-columns: 48px 1fr;
  }
  .leaderboard-points,
  .leaderboard-meta { justify-self: start; }
}

@media (max-width: 640px) {
  .boot-card,
  .auth-card,
  .section-surface,
  .surface,
  .panel,
  .quick-create,
  .subject-card,
  .history-card,
  .recommendation-card,
  .plan-card,
  .stat-tile,
  .folder-card,
  .test-card,
  .empty-state,
  .filter-rail,
  .leaderboard-panel,
  .sidebar-profile,
  .modal-shell {
    border-radius: 24px;
    padding: 18px;
  }
  .study-topbar {
    padding: 16px;
  }
  .profile-flyout {
    width: min(100vw - 32px, 320px);
  }
  .study-brand h1,
  .topbar-copy h2,
  .study-hero h1,
  .plan-hero h1,
  .hero-deck h1 {
    font-size: 1.8rem;
  }
  .summary-grid { grid-template-columns: 1fr; }
}

/* v4 Subject + Stats + Plans refinements */
.hero-deck-compact,
.hero-deck-subject {
  padding: 28px 30px;
}

.hero-actions-minimal {
  min-width: 0;
  align-items: flex-end;
}

.subject-shell {
  display: grid;
  gap: 12px;
}

.back-button-hero {
  width: fit-content;
  padding: 10px 14px;
  color: var(--dim);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.workspace-head-subject {
  margin-bottom: 18px;
}

.workspace-head-subject .workspace-head-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.filter-rail {
  gap: 0;
  overflow: hidden;
}

.filter-rail-toggle {
  width: 100%;
  padding: 0;
  background: transparent;
  color: inherit;
}

.filter-chevron {
  color: var(--accent);
  font-size: 1.1rem;
}

.filter-rail-body {
  display: grid;
  gap: 14px;
  margin-top: 16px;
}

.tag-search-shell {
  display: block;
  position: relative;
}

.tag-search-shell input {
  background: rgba(18, 16, 14, 0.92);
  border-bottom-left-radius: 16px;
  border-bottom-right-radius: 16px;
}

.suggestion-list {
  display: grid;
  gap: 4px;
  margin-top: 4px;
  padding: 8px;
  max-height: 220px;
  overflow: auto;
  border-radius: 0 0 18px 18px;
  background: rgba(17, 15, 14, 0.94);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.03);
}

.suggestion-row {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 14px;
  background: rgba(22, 19, 17, 0.86);
  color: var(--text);
  text-align: left;
}

.suggestion-row-main {
  min-width: 0;
  display: grid;
  gap: 3px;
}

.suggestion-row-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.suggestion-row-hint,
.suggestion-row-enter,
.suggestion-empty {
  color: var(--dim);
  font-size: 0.74rem;
}

.chip-stack-vertical {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.compact-test-grid {
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 16px;
}

.test-card {
  min-height: 0;
  padding: 18px;
  align-content: start;
  overflow: hidden;
}

.test-card h3 {
  -webkit-line-clamp: 4;
  font-size: 1rem;
  line-height: 1.28;
  min-height: calc(1.28em * 4);
}

.test-card-kind {
  color: var(--accent);
  font-size: 0.84rem;
  font-weight: 700;
  text-transform: lowercase;
}

.test-card-top {
  align-items: flex-start;
  gap: 12px;
}

.test-card-create {
  border: 1.5px dashed rgba(255, 188, 98, 0.24);
  background: linear-gradient(180deg, rgba(44, 39, 36, 0.76), rgba(25, 22, 20, 0.88));
  place-items: start;
}

.test-card-create-icon {
  width: 52px;
  height: 52px;
  border-radius: 18px;
  display: grid;
  place-items: center;
  background: rgba(255, 188, 98, 0.1);
  color: var(--accent);
  font-size: 1.4rem;
  font-weight: 700;
}

.modal-shell-test {
  width: min(960px, 100%);
}

.modal-meta-grid-compact {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.modal-detail-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 280px;
  gap: 18px;
}

.modal-detail-main,
.modal-detail-side,
.modal-rich-copy {
  display: grid;
  gap: 16px;
}

.modal-rich-copy p {
  margin: 0;
  color: var(--muted);
  line-height: 1.7;
}

.meta-block-rating {
  gap: 12px;
  align-content: start;
}

.compact-rating-block {
  padding: 14px 16px;
}

.completed-callout {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-radius: 18px;
  background: rgba(21, 30, 22, 0.92);
  color: var(--success);
}

.completed-callout-top {
  justify-self: end;
  margin-left: auto;
}

.modal-actions-spread {
  justify-content: space-between;
}

.modal-actions-balanced,
.modal-actions-create {
  justify-content: center;
  align-items: center;
}

.author-link {
  padding: 0;
}

.form-grid-immersive {
  gap: 16px;
}

.switch-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
}

.switch-field {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 18px;
  border-radius: 22px;
  background: rgba(18, 16, 14, 0.84);
}

.switch-field > span:first-child {
  color: var(--text);
  font-size: 0.95rem;
  line-height: 1.45;
}

.switch-shell {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.switch-shell input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.switch-ui {
  width: 52px;
  height: 30px;
  border-radius: 999px;
  background: rgba(110, 97, 89, 0.48);
  position: relative;
  transition: background 0.2s ease;
}

.switch-ui::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #f7efe4;
  transition: transform 0.2s ease;
}

.switch-shell input:checked + .switch-ui {
  background: linear-gradient(135deg, rgba(255, 188, 98, 0.68), rgba(255, 155, 85, 0.68));
}

.switch-shell input:checked + .switch-ui::after {
  transform: translateX(22px);
}

.segment-choice {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 48px;
  padding: 10px 14px;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  z-index: 1;
}

.segment-choice input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.segmented-two,
.segmented-three,
.segmented-four {
  display: grid;
  gap: 0;
}

.segmented-inline {
  position: relative;
  padding: 4px;
  border-radius: 999px;
  background: rgba(16, 14, 12, 0.92);
  box-shadow: inset 0 2px 14px rgba(0, 0, 0, 0.34), inset 0 0 0 1px rgba(255, 255, 255, 0.03);
}

.segmented-inline::before {
  content: "";
  position: absolute;
  top: 4px;
  left: calc(4px + ((100% - 8px) / var(--segments, 1)) * var(--active-index, 0));
  width: calc((100% - 8px) / var(--segments, 1));
  height: calc(100% - 8px);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  box-shadow: inset 0 0 0 1px rgba(255, 188, 98, 0.28), 0 10px 24px rgba(0, 0, 0, 0.24);
  transition: left 180ms ease;
  pointer-events: none;
}

.segment-choice.selected,
.segment.selected {
  background: transparent;
  color: var(--accent);
}

.segmented-two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.segmented-three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.segmented-four { grid-template-columns: repeat(4, minmax(0, 1fr)); }

.form-field-slider input[type="range"] {
  width: 100%;
}

.field-row-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.slider-readout {
  color: var(--accent);
  font-weight: 700;
}

.compact-inline-switch {
  margin-bottom: 10px;
}

.compact-rated-state {
  padding: 14px 16px;
  border-radius: 20px;
  background: rgba(18, 16, 14, 0.84);
}

.empty-inline-copy {
  grid-column: 1 / -1;
  color: var(--dim);
  font-size: 0.92rem;
}

.stats-kpi-grid,
.stats-subject-grid {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-bottom: 28px;
}

.stats-workspace {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) 360px;
  gap: 24px;
  align-items: start;
}

.stats-workspace > .section-surface:last-child {
  grid-column: 1 / 2;
}

.leaderboard-panel-rich {
  grid-column: 2 / 3;
  grid-row: 1 / span 2;
}

.stats-trend-list,
.leaderboard-stack,
.activity-list {
  display: grid;
  gap: 12px;
}

.trend-row,
.activity-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-radius: 20px;
  background: rgba(18, 16, 14, 0.84);
}

.trend-copy {
  display: grid;
  gap: 4px;
}

.trend-copy strong {
  font-size: 0.98rem;
}

.trend-metrics {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.mini-pill-strong {
  color: var(--accent);
  background: rgba(255, 188, 98, 0.12);
}

.stats-subsection {
  display: grid;
  gap: 12px;
  margin-top: 20px;
  padding-top: 20px;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}

.plans-workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 0.86fr);
  gap: 24px;
  align-items: start;
}

.plan-builder,
.plans-column {
  align-self: start;
}

.plan-grid-single {
  grid-template-columns: 1fr;
}

.plan-card-compact {
  min-height: 0;
}

.plans-workspace-wide {
  grid-template-columns: 1fr;
}

.plan-card-create {
  border: 1.5px dashed rgba(255, 188, 98, 0.24);
  background: rgba(41, 37, 34, 0.5);
}

.history-list-scroll {
  max-height: 540px;
  overflow: auto;
  display: grid;
  gap: 12px;
}

.history-card-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 14px;
}

.history-card-main {
  display: grid;
  gap: 8px;
  min-width: 0;
}

.icon-action {
  width: 40px;
  height: 40px;
  border-radius: 999px;
  display: inline-grid;
  place-items: center;
  background: rgba(58, 52, 47, 0.92);
  color: var(--text);
}

.icon-action.danger,
.danger-fill {
  background: rgba(118, 42, 42, 0.92);
  color: #ffe7e7;
}

.danger-fill {
  background: linear-gradient(135deg, #d95d5d, #a73838);
  color: #fff;
}

.subtle-link {
  color: var(--muted);
  align-self: center;
}

.author-pill {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  max-width: 100%;
  padding: 6px 10px 6px 6px;
  border-radius: 999px;
  background: rgba(18, 16, 14, 0.84);
  color: var(--text);
  overflow: hidden;
}

.author-pill-avatar {
  width: 28px;
  height: 28px;
  border-radius: 999px;
  display: inline-grid;
  place-items: center;
  background: rgba(255, 188, 98, 0.18);
  color: var(--accent);
  font-size: 0.74rem;
  font-weight: 800;
  flex-shrink: 0;
}

.author-pill-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rating-star-input {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.rating-star-button {
  width: 34px;
  height: 34px;
  border-radius: 999px;
  display: inline-grid;
  place-items: center;
  background: rgba(18, 16, 14, 0.88);
  color: rgba(255, 255, 255, 0.26);
  font-size: 1.05rem;
}

.rating-star-button.is-active,
.rating-star-button:hover {
  color: var(--accent);
}

.chip-small {
  padding: 5px 9px;
  font-size: 0.78rem;
  line-height: 1.1;
  max-width: 220px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chip-row-tight {
  gap: 8px;
}

.chip-row-tight .chip {
  max-width: 100%;
  min-width: 0;
}

.modal-loading-state {
  display: grid;
  gap: 12px;
  padding: 24px 4px 8px;
}

.metric-trend,
.history-meta,
.subject-card p,
.plan-card p,
.recommendation-card p,
.panel p,
.small-note,
.empty-state p,
.workspace-head p,
.filter-group p,
.modal-head p,
.stat-tile .metric-trend {
  overflow-wrap: anywhere;
}

@keyframes modalIn {
  from { opacity: 0; transform: translateY(10px) scale(0.985); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes modalOut {
  from { opacity: 1; transform: translateY(0) scale(1); }
  to { opacity: 0; transform: translateY(10px) scale(0.985); }
}

.plan-phase {
  gap: 14px;
}

@media (max-width: 1180px) {
  .stats-workspace,
  .plans-workspace,
  .modal-detail-grid,
  .modal-meta-grid-compact,
  .stats-kpi-grid,
  .stats-subject-grid {
    grid-template-columns: 1fr 1fr;
  }
  .leaderboard-panel-rich {
    grid-column: auto;
    grid-row: auto;
  }
}

@media (max-width: 860px) {
  .stats-workspace,
  .plans-workspace,
  .modal-detail-grid,
  .modal-meta-grid-compact,
  .stats-kpi-grid,
  .stats-subject-grid {
    grid-template-columns: 1fr;
  }
  .trend-row,
  .activity-row,
  .field-row-between {
    flex-direction: column;
    align-items: flex-start;
  }
  .workspace-head-subject .workspace-head-actions {
    align-items: flex-start;
  }
}

/* v6 polish overrides */
.study-topbar-minimal {
  align-items: start;
}

.study-topbar-minimal .topbar-search-shell {
  max-width: 620px;
}

.study-topbar-minimal .search-shell-label input {
  border-radius: 999px;
}

.search-hint {
  color: var(--dim);
  font-size: 0.9rem;
  line-height: 1.5;
}

.tag-search-shell {
  display: grid;
  gap: 0;
}

.tag-search-shell.is-open input {
  border-bottom-left-radius: 12px;
  border-bottom-right-radius: 12px;
}

.tag-search-shell .suggestion-list {
  margin-top: -6px;
  padding-top: 14px;
  border-top-left-radius: 0;
  border-top-right-radius: 0;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.03), 0 16px 28px rgba(8, 7, 6, 0.18);
}

.tag-search-shell .suggestion-list-empty {
  min-height: 54px;
  align-items: center;
}

.compact-test-grid .test-card {
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 16px;
  min-height: 220px;
  padding: 18px 18px 16px;
}

.compact-test-grid .test-card .test-card-copy {
  min-width: 0;
  display: grid;
  gap: 8px;
}

.compact-test-grid .test-card h3 {
  margin: 0;
  font-size: 0.98rem;
  line-height: 1.2;
  min-height: calc(1.2em * 5);
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 5;
  overflow: hidden;
  overflow-wrap: anywhere;
}

.compact-test-grid .test-card-kind {
  font-size: 0.8rem;
  font-weight: 800;
}

.compact-test-grid .test-card-meta {
  color: var(--dim);
  font-size: 0.84rem;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
  overflow-wrap: anywhere;
}

.compact-test-grid .test-card-footer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: 12px;
}

.compact-test-grid .test-card-completion-text {
  color: var(--dim);
  font-size: 0.82rem;
  line-height: 1.35;
}

.test-card-rating {
  display: grid;
  justify-items: end;
  gap: 4px;
  min-width: 52px;
}

.test-card-rating-stars {
  display: inline-flex;
  gap: 1px;
  color: rgba(218, 192, 173, 0.34);
  font-size: 0.72rem;
  letter-spacing: -0.08em;
}

.test-card-rating-stars .rating-star.filled,
.test-card-rating-stars .rating-star.half {
  color: var(--accent);
}

.test-card-rating-count {
  color: var(--dim);
  font-size: 0.76rem;
  font-weight: 700;
}

.compact-test-grid .test-card .rating-pill {
  display: none;
}

.completed-callout-top {
  padding: 8px 12px;
  border-radius: 999px;
  font-size: 0.82rem;
}

.compact-rating-block {
  padding: 12px 14px;
}

.compact-rating-block .rating-pill {
  padding: 7px 10px;
  gap: 6px;
}

.compact-rating-block .rating-stars {
  font-size: 0.8rem;
}

.modal-actions-split {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
}

.modal-actions-main,
.modal-actions-side {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.author-pill {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr);
  align-items: center;
  justify-items: start;
  width: min(100%, 320px);
}

.user-rating-compact {
  display: inline-flex;
  align-items: center;
}

.user-rating-compact .rating-stars {
  font-size: 0.92rem;
}

.history-card-row .card-actions {
  align-items: center;
}

.summary-grid .stat-tile .metric-trend,
.summary-grid .stat-tile .stat-label {
  overflow-wrap: anywhere;
}

@media (max-width: 1120px) {
  .compact-test-grid .test-card h3 {
    -webkit-line-clamp: 4;
    min-height: calc(1.2em * 4);
  }
}

.search-row-create-subject {
  border-style: dashed;
}

.plan-card-generating {
  position: relative;
  overflow: hidden;
}

.plan-card-loader {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.plan-timeline {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 16px;
}

.plan-timeline-pill {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  padding: 7px 12px;
  border-radius: 999px;
  border: 1px solid rgba(210, 170, 120, 0.22);
  background: rgba(255, 248, 238, 0.03);
  font-size: 0.78rem;
  color: var(--text);
}

.plan-timeline-pill[data-open-plan-phase] {
  cursor: pointer;
}

.plan-timeline-compact .plan-timeline-pill {
  min-width: 38px;
  padding: 6px 10px;
}

.plan-timeline-check {
  position: absolute;
  right: -4px;
  top: -4px;
  width: 16px;
  height: 16px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #4ca86b;
  color: #fff;
  font-size: 0.68rem;
  box-shadow: 0 6px 14px rgba(76, 168, 107, 0.32);
}

.plan-timeline-status {
  position: absolute;
  right: -4px;
  top: -4px;
  width: 16px;
  height: 16px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.58rem;
  color: #fff;
  box-shadow: 0 6px 14px rgba(8, 7, 6, 0.26);
}

.plan-timeline-status.ready {
  background: #4ca86b;
  animation: phasePulse 1.8s ease-in-out infinite;
}

.plan-timeline-status.preparing {
  background: rgba(196, 155, 97, 0.9);
  color: #1a1410;
}

.plan-timeline-status.failed {
  background: #9c4539;
}

.plan-phase-grid {
  margin-top: 18px;
}

.plan-phase-card {
  display: grid;
  gap: 12px;
  padding: 18px;
  border-radius: 24px;
  background: rgba(26, 19, 14, 0.72);
  border: 1px solid rgba(210, 170, 120, 0.14);
}

.plan-phase-card[data-open-plan-phase] {
  cursor: pointer;
}

.plan-phase-card.completed {
  box-shadow: inset 0 0 0 1px rgba(137, 211, 156, 0.16);
}

.plan-phase-card-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 14px;
}

.phase-check-badge {
  width: 26px;
  height: 26px;
  flex-shrink: 0;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #4ca86b;
  color: #fff;
  box-shadow: 0 8px 18px rgba(76, 168, 107, 0.28);
}

.phase-status-badge {
  width: 26px;
  height: 26px;
  flex-shrink: 0;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 18px rgba(8, 7, 6, 0.22);
}

.phase-status-badge.ready {
  background: #4ca86b;
  color: #fff;
  animation: phasePulse 1.8s ease-in-out infinite;
}

.phase-status-badge.preparing {
  background: rgba(214, 177, 111, 0.95);
  color: #1a1410;
}

.phase-status-badge.failed {
  background: #9c4539;
  color: #fff;
}

.phase-status-line.ready {
  color: #8bd0a0;
}

.phase-status-line.preparing {
  color: #e2c08c;
}

.phase-status-line.failed {
  color: #d27b72;
}

.phase-status-inline {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.modal-shell-phase {
  width: min(860px, 100%);
}

.plan-draft-preview {
  display: grid;
  gap: 18px;
  position: relative;
}

.plan-draft-hero,
.plan-draft-strategy,
.plan-revision-box {
  padding: 18px;
  border-radius: 22px;
  background: rgba(26, 19, 14, 0.68);
  border: 1px solid rgba(210, 170, 120, 0.14);
}

.plan-draft-hero {
  display: grid;
  gap: 14px;
}

.plan-draft-phase-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
  position: relative;
  z-index: 1;
}

.plan-draft-actions {
  position: sticky;
  bottom: 0;
  z-index: 12;
  isolation: isolate;
  justify-content: flex-start;
  padding: 12px 0 4px;
  background: linear-gradient(180deg, rgba(27, 24, 22, 0), rgba(27, 24, 22, 0.92) 30%, rgba(27, 24, 22, 0.98));
}

.icon-secondary {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.modal-loading-state-plan {
  min-height: 220px;
  align-content: center;
}

.plan-detail-loader {
  margin-top: 18px;
}

.avatar-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  font-weight: 800;
  letter-spacing: 0.04em;
  color: #fff7ef;
}

.avatar-sm {
  width: 34px;
  height: 34px;
  font-size: 0.8rem;
}

.avatar-md {
  width: 44px;
  height: 44px;
  font-size: 0.95rem;
}

.avatar-lg {
  width: 60px;
  height: 60px;
  font-size: 1.08rem;
}

.avatar-sun { background: linear-gradient(135deg, #d58d3f, #f1c572); }
.avatar-ember { background: linear-gradient(135deg, #a94732, #d26c56); }
.avatar-ocean { background: linear-gradient(135deg, #2d5e8b, #4f98c0); }
.avatar-forest { background: linear-gradient(135deg, #355f3c, #5f9b69); }
.avatar-night { background: linear-gradient(135deg, #2a304f, #5f6b9d); }
.avatar-iris { background: linear-gradient(135deg, #6b4f8d, #b087d6); }

.profile-flyout-head {
  grid-template-columns: auto minmax(0, 1fr);
}

.profile-edit-preview {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 14px;
  align-items: center;
  padding: 8px 0 4px;
}

.profile-edit-preview strong,
.profile-edit-preview .muted {
  overflow-wrap: anywhere;
}

.avatar-picker-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: 12px;
  margin-top: 10px;
}

.avatar-choice {
  display: grid;
  justify-items: center;
  gap: 8px;
  padding: 12px;
  border-radius: 18px;
  border: 1px solid rgba(210, 170, 120, 0.14);
  background: rgba(255, 248, 238, 0.03);
  cursor: pointer;
}

.avatar-choice input {
  display: none;
}

.avatar-choice.selected {
  border-color: rgba(229, 188, 126, 0.42);
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.18);
}

@media (max-width: 920px) {
  .plan-phase-card-head {
    grid-template-columns: minmax(0, 1fr);
  }

  .plan-draft-phase-grid {
    grid-template-columns: 1fr;
  }
}

@keyframes phasePulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(76, 168, 107, 0.22), 0 8px 18px rgba(76, 168, 107, 0.28); }
  50% { box-shadow: 0 0 0 6px rgba(76, 168, 107, 0.05), 0 8px 18px rgba(76, 168, 107, 0.34); }
}
