:root {
  --bg: #f4efe7;
  --bg-2: #efe6d7;
  --panel: #fffaf4;
  --panel-2: #f8f0e3;
  --ink: #2a2521;
  --muted: #6f655b;
  --accent: #d45a2d;
  --accent-2: #1f7a6e;
  --danger: #c0392b;
  --success: #1f8f4e;
  --border: #e1d6c7;
  --shadow: 0 8px 30px rgba(36, 25, 17, 0.08);
  --radius: 18px;
  --radius-sm: 12px;
  --transition: 180ms ease;
  --text-size: 1rem;
}

[data-theme="dark"] {
  --bg: #171513;
  --bg-2: #221f1c;
  --panel: #1e1b18;
  --panel-2: #2a2521;
  --ink: #f2ede8;
  --muted: #b0a59a;
  --accent: #f0803b;
  --accent-2: #2dcbb6;
  --danger: #f56565;
  --success: #7ad890;
  --border: #3b352f;
  --shadow: 0 8px 30px rgba(10, 8, 7, 0.5);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Avenir Next", "Trebuchet MS", "Segoe UI", sans-serif;
  background: radial-gradient(circle at top left, var(--bg-2), var(--bg));
  color: var(--ink);
  min-height: 100vh;
  font-size: var(--text-size);
}

h1,
h2,
h3,
h4 {
  font-family: "Iowan Old Style", "Palatino Linotype", "Book Antiqua", serif;
  margin: 0;
}

p {
  margin: 0;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}

input,
select {
  width: 100%;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--ink);
}

input:focus,
select:focus {
  outline: 2px solid rgba(212, 90, 45, 0.4);
  outline-offset: 2px;
}

.app-shell {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding: 28px 20px;
  background: linear-gradient(180deg, #1c1a18, #2c2520);
  color: #f6f1ea;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.logo-img {
  width: 160px;
  max-width: 100%;
  height: auto;
}

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

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 14px;
  color: inherit;
  background: transparent;
  transition: var(--transition);
}

.nav-item.active,
.nav-item:hover {
  background: rgba(255, 255, 255, 0.12);
}

.nav-ico {
  width: 20px;
  text-align: center;
}

.sidebar-foot {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.resume-pill {
  background: rgba(255, 255, 255, 0.14);
  padding: 10px 12px;
  border-radius: 12px;
  font-size: 0.9rem;
  cursor: pointer;
}

.side-hint {
  font-size: 0.8rem;
  color: rgba(255, 255, 255, 0.6);
}

.main {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  display: grid;
  grid-template-columns: 1fr minmax(260px, 420px) 1fr;
  align-items: center;
  gap: 16px;
  padding: 18px 28px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  position: sticky;
  top: 0;
  z-index: 10;
}

.section-title {
  font-size: 1.4rem;
}

.section-subtitle {
  color: var(--muted);
  font-size: 0.9rem;
}

.search-wrap {
  position: relative;
}

.search-results {
  position: absolute;
  top: 48px;
  left: 0;
  right: 0;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  max-height: 320px;
  overflow-y: auto;
  z-index: 20;
}

.search-results .result-item {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}

.search-results .result-item:hover {
  background: var(--panel-2);
}

.topbar-right {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.ghost-btn {
  padding: 8px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  transition: var(--transition);
}

.ghost-btn:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow);
}

.primary-btn {
  padding: 12px 16px;
  border-radius: 14px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  box-shadow: var(--shadow);
}

.primary-btn:hover {
  filter: brightness(1.05);
}

.danger-btn {
  padding: 12px 16px;
  border-radius: 14px;
  background: var(--danger);
  color: #fff;
}

.card {
  background: var(--panel);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}

.card.hero {
  background: linear-gradient(135deg, var(--panel), var(--panel-2));
}

.card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.muted {
  color: var(--muted);
}

.badge {
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--panel-2);
  font-size: 0.8rem;
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 18px;
  margin-bottom: 18px;
}

.grid-4 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 18px;
}

.content {
  padding: 24px 28px 80px;
}

.section {
  display: none;
  animation: fadeIn 0.25s ease;
}

.section.active {
  display: block;
}

.section-head {
  margin-bottom: 16px;
}

.quick-actions {
  display: grid;
  gap: 12px;
}

.action-card {
  padding: 14px;
  border-radius: 14px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  text-align: left;
  display: grid;
  gap: 6px;
  transition: var(--transition);
}

.action-card:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow);
}

.mini-progress {
  margin-top: 16px;
}

.bar {
  height: 8px;
  background: var(--bg-2);
  border-radius: 999px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
}

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

.kpi {
  font-size: 1.4rem;
  font-weight: 600;
}

.tabs {
  display: inline-flex;
  background: var(--panel-2);
  padding: 6px;
  border-radius: 16px;
  gap: 6px;
  margin-bottom: 18px;
}

.tab {
  padding: 8px 12px;
  border-radius: 12px;
}

.tab.active {
  background: var(--panel);
  box-shadow: var(--shadow);
}

.tab-panel {
  display: none;
  margin-bottom: 18px;
}

.tab-panel.active {
  display: block;
}

#study.session-active .tabs,
#study.session-active .tab-panel {
  display: none;
}

#study.session-active #study-session {
  display: block;
}

#errors-study-session {
  display: none;
}

#errors.session-active .tabs,
#errors.session-active .tab-panel {
  display: none;
}

#errors.session-active #errors-study-session {
  display: flex;
}

#exam.session-active #exam-config {
  display: none;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

.field-block {
  display: grid;
  gap: 8px;
}

.field-label {
  font-size: 0.9rem;
  color: var(--muted);
}

.toggle-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.toggle-pill {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

.toggle-pill input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.toggle-pill span {
  display: inline-flex;
  align-items: center;
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  transition: var(--transition);
}

.toggle-pill input:checked + span {
  background: rgba(212, 90, 45, 0.18);
  border-color: var(--accent);
  color: var(--ink);
  box-shadow: var(--shadow);
}

.checkbox-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 8px;
}

.checkbox-item {
  position: relative;
  display: inline-flex;
  align-items: center;
  cursor: pointer;
}

.checkbox-item input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.checkbox-item span {
  display: inline-flex;
  align-items: center;
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  transition: var(--transition);
}

.checkbox-item input:checked + span {
  background: rgba(31, 122, 110, 0.18);
  border-color: var(--accent-2);
  color: var(--ink);
  box-shadow: var(--shadow);
}

.inline-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 12px;
}

.session {
  margin-top: 20px;
}

.question-card {
  display: grid;
  gap: 12px;
  width: min(860px, 100%);
}

.question-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.question-text {
  font-size: 1.1rem;
  line-height: 1.4;
  white-space: pre-wrap;
}

.question-text,
.image-wrap,
.video-wrap,
.answer-grid {
  width: 100%;
}

.session-progress {
  display: grid;
  gap: 6px;
}

.codeish {
  font-family: "SFMono-Regular", "Consolas", "Liberation Mono", monospace;
  background: rgba(31, 122, 110, 0.12);
  padding: 8px 10px;
  border-radius: 12px;
  display: inline-block;
}

.answer-grid {
  display: grid;
  gap: 10px;
}

.answer-card {
  border: 1px solid var(--border);
  background: var(--panel-2);
  padding: 12px;
  border-radius: 14px;
  display: grid;
  grid-template-columns: 36px 1fr;
  gap: 10px;
  align-items: start;
  cursor: pointer;
  transition: var(--transition);
  text-align: left;
}

.answer-card.selected {
  border-color: var(--accent);
  box-shadow: var(--shadow);
}

.answer-card.correct {
  border-color: var(--success);
  background: rgba(31, 143, 78, 0.12);
}

.answer-card.wrong {
  border-color: var(--danger);
  background: rgba(192, 57, 43, 0.12);
}

.answer-letter {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--panel);
  border: 1px solid var(--border);
  display: grid;
  place-items: center;
  font-weight: 700;
}

.answer-text {
  white-space: pre-wrap;
  text-align: left;
}

.answer-text.codeish {
  display: block;
}

.sticky-actions {
  position: sticky;
  bottom: 12px;
  display: flex;
  gap: 10px;
  justify-content: space-between;
  background: rgba(255, 255, 255, 0.8);
  backdrop-filter: blur(6px);
  padding: 12px;
  border-radius: 16px;
  border: 1px solid var(--border);
  margin-top: 16px;
}

[data-theme="dark"] .sticky-actions {
  background: rgba(30, 27, 24, 0.8);
}

.action-group {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.feedback {
  padding: 10px 12px;
  border-radius: 12px;
  font-weight: 600;
}

.feedback.correct {
  background: rgba(31, 143, 78, 0.2);
  color: var(--success);
}

.feedback.wrong {
  background: rgba(192, 57, 43, 0.2);
  color: var(--danger);
}

.image-wrap {
  display: grid;
  gap: 8px;
}

.image-wrap img {
  max-width: 100%;
  border-radius: 14px;
  border: 1px solid var(--border);
  display: block;
}

.video-wrap {
  display: grid;
  gap: 8px;
}

.video-wrap video {
  width: 100%;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: #0f0f0f;
  display: block;
}

.video-wrap a {
  font-size: 0.9rem;
  color: var(--accent-2);
  text-decoration: none;
}

.list {
  display: grid;
  gap: 10px;
}

.list-item {
  padding: 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  display: grid;
  gap: 6px;
}

button.list-item {
  text-align: left;
  width: 100%;
}

.list-item strong {
  font-weight: 600;
}

.list-item.result-wrong {
  border-color: rgba(192, 57, 43, 0.5);
  background: rgba(192, 57, 43, 0.08);
}

.list-item.result-empty {
  border-color: rgba(111, 101, 91, 0.5);
  background: rgba(111, 101, 91, 0.08);
}

.result-line {
  font-size: 0.95rem;
}

.virtual-list {
  position: relative;
  height: 520px;
  overflow-y: auto;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.virtual-spacer {
  width: 100%;
}

.virtual-items {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
}

.virtual-row {
  position: absolute;
  left: 0;
  right: 0;
  height: 64px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  display: grid;
  grid-template-columns: 60px 1fr 160px;
  gap: 12px;
  background: var(--panel);
  cursor: pointer;
}

.virtual-row.row-correct {
  background: rgba(31, 143, 78, 0.12);
}

.virtual-row.row-wrong {
  background: rgba(192, 57, 43, 0.12);
}

.virtual-row:hover {
  background: var(--panel-2);
}

.virtual-row.row-correct:hover {
  background: rgba(31, 143, 78, 0.2);
}

.virtual-row.row-wrong:hover {
  background: rgba(192, 57, 43, 0.2);
}

#study-session,
#errors-study-session {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 60vh;
  gap: 16px;
}

.row-tags {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.chart {
  display: grid;
  gap: 10px;
}

.chart-bar {
  display: flex;
  align-items: center;
  gap: 10px;
}

.chart-bar span {
  width: 70px;
  font-size: 0.85rem;
}

.chart-bar .bar {
  flex: 1;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(22, 18, 16, 0.6);
  display: grid;
  place-items: center;
  z-index: 30;
}

.modal-card {
  background: var(--panel);
  border-radius: var(--radius);
  padding: 20px;
  width: min(800px, 92vw);
  max-height: 86vh;
  overflow: auto;
  box-shadow: var(--shadow);
}

.modal-card.wide {
  width: min(980px, 92vw);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.modal-body img {
  max-width: 100%;
  border-radius: 14px;
}

.modal.hidden,
.hidden {
  display: none;
}

.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--panel);
  border: 1px solid var(--border);
  padding: 12px 16px;
  border-radius: 12px;
  box-shadow: var(--shadow);
}

.file-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.file-btn input {
  display: none;
}

.divider {
  height: 1px;
  background: var(--border);
  margin: 16px 0;
}

.bottom-nav {
  display: none;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 1000px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    display: none;
  }

  .topbar {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .topbar-right {
    justify-content: flex-start;
    flex-wrap: wrap;
  }

  .content {
    padding: 18px 16px 100px;
  }

  .bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--panel);
    border-top: 1px solid var(--border);
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    padding: 8px;
    z-index: 20;
  }

  .bottom-nav .nav-item {
    padding: 10px 6px;
    border-radius: 10px;
    font-size: 0.85rem;
  }

  .sticky-actions {
    position: static;
  }
}

@media (max-width: 700px) {
  .virtual-row {
    grid-template-columns: 50px 1fr;
    grid-template-rows: auto auto;
    height: 80px;
  }

  .virtual-row .row-tags {
    grid-column: 1 / -1;
  }
}
