:root {
  color-scheme: light;
  --bg: #f3f5f8;
  --bg-subtle: #edf1f5;
  --surface: #ffffff;
  --surface-raised: #ffffff;
  --muted-surface: #eef2f6;
  --surface-hover: #e8edf3;
  --text: #172033;
  --muted: #5f6b7d;
  --subtle: #7a8596;
  --border: #d7dee8;
  --border-strong: #bac5d3;
  --accent: #3557d5;
  --accent-strong: #2947b8;
  --accent-hover: #2947b8;
  --accent-soft: #e8edff;
  --accent-contrast: #ffffff;
  --success: #16724a;
  --success-soft: #e7f5ed;
  --warning: #8a5a00;
  --warning-soft: #fff3d6;
  --danger: #b42318;
  --danger-soft: #fdebea;
  --type-question: #7554c9;
  --type-code: #0f7b64;
  --type-steps: #b85f0f;
  --type-checklist: #b93675;
  --focus: #4c6fff;
  --shadow-xs: 0 1px 2px rgb(23 32 51 / 0.05);
  --shadow-sm: 0 8px 24px rgb(23 32 51 / 0.07);
  --shadow: 0 18px 48px rgb(23 32 51 / 0.10);
  --shadow-lg: 0 30px 80px rgb(23 32 51 / 0.14);
  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-xl: 26px;
  --content-width: 1180px;
  --topbar-height: 68px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f141c;
  --bg-subtle: #131a24;
  --surface: #181f2a;
  --surface-raised: #1d2633;
  --muted-surface: #222c3a;
  --surface-hover: #2a3545;
  --text: #f2f5f9;
  --muted: #b4bfce;
  --subtle: #929fb1;
  --border: #303b4b;
  --border-strong: #46546a;
  --accent: #8ca3ff;
  --accent-strong: #a9b9ff;
  --accent-hover: #a9b9ff;
  --accent-soft: #27345f;
  --accent-contrast: #0d1737;
  --success: #6ed5a4;
  --success-soft: #18392b;
  --warning: #f2c267;
  --warning-soft: #403214;
  --danger: #ff948c;
  --danger-soft: #472126;
  --type-question: #b49aff;
  --type-code: #65d4b4;
  --type-steps: #f2a35f;
  --type-checklist: #f18abd;
  --focus: #9db0ff;
  --shadow-xs: 0 1px 2px rgb(0 0 0 / 0.22);
  --shadow-sm: 0 10px 28px rgb(0 0 0 / 0.24);
  --shadow: 0 20px 52px rgb(0 0 0 / 0.30);
  --shadow-lg: 0 34px 96px rgb(0 0 0 / 0.42);
}

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

html {
  min-width: 320px;
  background: var(--bg);
  scroll-behavior: smooth;
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  background: var(--bg);
  font-size: 16px;
  line-height: 1.5;
  transition: color 180ms ease, background-color 180ms ease;
}

body,
button,
input,
select,
textarea {
  font: inherit;
}

button,
select {
  cursor: pointer;
}

button,
input,
select,
textarea {
  -webkit-tap-highlight-color: transparent;
}

button:disabled,
input:disabled,
select:disabled {
  cursor: not-allowed;
  opacity: 0.58;
}

a,
button,
input,
select,
textarea,
.study-card {
  outline: none;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
.study-card:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--focus) 58%, transparent);
  outline-offset: 3px;
}

::selection {
  color: var(--accent-contrast);
  background: var(--accent);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: var(--topbar-height);
  padding: 10px clamp(16px, 4vw, 48px);
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  box-shadow: var(--shadow-xs);
  backdrop-filter: blur(16px) saturate(125%);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  position: relative;
  display: grid;
  flex: 0 0 auto;
  place-items: center;
  width: 42px;
  height: 42px;
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  color: var(--accent-contrast);
  background: var(--accent);
  box-shadow: var(--shadow-xs);
  font-size: 1.2rem;
  font-weight: 850;
  letter-spacing: -0.04em;
}

.brand-mark::after {
  content: "";
  position: absolute;
  right: 6px;
  bottom: 6px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--accent-contrast);
  opacity: 0.86;
}

.brand strong,
.brand small {
  display: block;
}

.brand strong {
  font-size: 0.98rem;
  letter-spacing: -0.015em;
}

.brand small {
  margin-top: 1px;
  color: var(--muted);
  font-size: 0.74rem;
}

.icon-button,
.theme-toggle {
  display: inline-grid;
  place-items: center;
  min-width: 42px;
  height: 42px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  background: var(--surface);
  box-shadow: var(--shadow-xs);
  transition: border-color 160ms ease, background-color 160ms ease, color 160ms ease, transform 160ms ease;
}

.icon-button:hover,
.theme-toggle:hover {
  border-color: var(--border-strong);
  background: var(--muted-surface);
}

.icon-button:active,
.theme-toggle:active {
  transform: translateY(1px);
}

.theme-toggle {
  grid-auto-flow: column;
  gap: 8px;
  width: auto;
  padding: 0 12px;
}

.theme-toggle-icons {
  position: relative;
  width: 18px;
  height: 18px;
}

.theme-toggle-icons svg {
  position: absolute;
  inset: 0;
  width: 18px;
  height: 18px;
  transition: opacity 160ms ease, transform 160ms ease;
}

.theme-icon-moon {
  opacity: 0;
  transform: rotate(-18deg) scale(0.72);
}

:root[data-theme="dark"] .theme-icon-sun {
  opacity: 0;
  transform: rotate(18deg) scale(0.72);
}

:root[data-theme="dark"] .theme-icon-moon {
  opacity: 1;
  transform: rotate(0) scale(1);
}

.theme-toggle-label {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 760;
}

.theme-toggle-label::before {
  content: "Light";
}

:root[data-theme="dark"] .theme-toggle-label::before {
  content: "Dark";
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(248px, 296px) minmax(0, 1fr);
  min-height: calc(100vh - var(--topbar-height));
}

.sidebar {
  padding: 24px;
  border-right: 1px solid var(--border);
  background: var(--surface);
}

.control-section {
  margin-bottom: 24px;
}

.control-section label,
.field-label {
  display: block;
  margin-bottom: 8px;
  color: var(--text);
  font-size: 0.82rem;
  font-weight: 760;
}

select,
input[type="search"],
input[type="url"] {
  width: 100%;
  min-height: 44px;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  background: var(--muted-surface);
  box-shadow: inset 0 1px 0 rgb(255 255 255 / 0.04);
  transition: border-color 160ms ease, background-color 160ms ease, box-shadow 160ms ease;
}

select:hover,
input[type="search"]:hover,
input[type="url"]:hover {
  border-color: var(--border-strong);
}

select:focus,
input[type="search"]:focus,
input[type="url"]:focus {
  border-color: var(--accent);
  background: var(--surface-raised);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 16%, transparent);
}

input::placeholder {
  color: var(--subtle);
  opacity: 1;
}

.helper-text {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.5;
}

.segmented-control {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--muted-surface);
}

.segmented-control button {
  min-height: 36px;
  padding: 7px 10px;
  border: 0;
  border-radius: 8px;
  color: var(--muted);
  background: transparent;
  font-size: 0.8rem;
  font-weight: 760;
  transition: color 160ms ease, background-color 160ms ease, box-shadow 160ms ease;
}

.segmented-control button:hover {
  color: var(--text);
}

.segmented-control button.is-active {
  color: var(--accent-strong);
  background: var(--surface-raised);
  box-shadow: var(--shadow-xs);
}

.progress-panel {
  padding: 17px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--muted-surface);
}

.progress-heading-row,
.progress-stats {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.progress-heading-row {
  align-items: baseline;
}

.progress-heading-row span {
  color: var(--accent-strong);
  font-variant-numeric: tabular-nums;
  font-weight: 800;
}

.progress-track {
  height: 8px;
  margin: 14px 0;
  overflow: hidden;
  border-radius: 999px;
  background: var(--border);
}

.progress-track span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  transition: width 240ms ease;
}

.progress-stats {
  color: var(--muted);
  font-size: 0.76rem;
}

.progress-stats strong {
  color: var(--text);
}

.text-button {
  margin-top: 14px;
  padding: 0;
  border: 0;
  color: var(--accent-strong);
  background: transparent;
  font-size: 0.8rem;
  font-weight: 760;
  text-underline-offset: 3px;
}

.text-button:hover {
  text-decoration: underline;
}

.content-area {
  width: min(100%, 1120px);
  margin: 0 auto;
  padding: clamp(28px, 4vw, 56px);
}

.deck-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 28px;
  margin-bottom: 30px;
}

.eyebrow {
  color: var(--accent-strong);
  font-size: 0.72rem;
  font-weight: 850;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.deck-header h1 {
  margin: 8px 0 10px;
  font-size: clamp(2rem, 5vw, 3.5rem);
  line-height: 1;
  letter-spacing: -0.048em;
}

.deck-header p {
  max-width: 680px;
  margin: 0;
  color: var(--muted);
  line-height: 1.65;
}

.deck-summary {
  display: grid;
  grid-template-columns: repeat(2, minmax(90px, 1fr));
  min-width: 252px;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  box-shadow: var(--shadow-xs);
}

.deck-summary span {
  padding: 13px;
  color: var(--muted);
  background: var(--surface);
  font-size: 0.73rem;
}

.deck-summary span:nth-child(odd) {
  border-right: 1px solid var(--border);
}

.deck-summary span:nth-child(-n + 2) {
  border-bottom: 1px solid var(--border);
}

.deck-summary strong {
  display: block;
  margin-bottom: 1px;
  color: var(--text);
  font-size: 1.02rem;
  font-variant-numeric: tabular-nums;
}

.study-card {
  position: relative;
  min-height: 470px;
  padding: clamp(26px, 5vw, 50px);
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  background: var(--surface-raised);
  box-shadow: var(--shadow);
}

.study-card::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 4px;
  background: var(--accent);
}

.card-type-question::before {
  background: var(--type-question);
}

.card-type-code::before {
  background: var(--type-code);
}

.card-type-steps::before {
  background: var(--type-steps);
}

.card-type-checklist::before {
  background: var(--type-checklist);
}

.card-topline,
.card-heading,
.overview-card-topline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.card-type-label,
.difficulty,
.status-pill {
  display: inline-flex;
  width: fit-content;
  align-items: center;
  border-radius: 999px;
  font-size: 0.71rem;
  font-weight: 820;
}

.card-type-label {
  color: var(--accent-strong);
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

.card-position {
  color: var(--muted);
  font-size: 0.78rem;
  font-variant-numeric: tabular-nums;
}

.card-heading {
  align-items: flex-start;
  margin-top: 34px;
}

.difficulty {
  padding: 5px 9px;
  border: 1px solid var(--border);
  color: var(--muted);
  background: var(--muted-surface);
  text-transform: capitalize;
}

.card-heading h2 {
  max-width: 760px;
  margin: 12px 0 0;
  font-size: clamp(1.75rem, 4vw, 2.9rem);
  line-height: 1.08;
  letter-spacing: -0.037em;
}

.status-pill {
  padding: 6px 10px;
  border: 1px solid transparent;
  color: var(--muted);
  background: var(--muted-surface);
  white-space: nowrap;
}

.status-mastered .status-pill {
  border-color: color-mix(in srgb, var(--success) 30%, transparent);
  color: var(--success);
  background: var(--success-soft);
}

.status-review .status-pill {
  border-color: color-mix(in srgb, var(--warning) 32%, transparent);
  color: var(--warning);
  background: var(--warning-soft);
}

.card-prompt {
  max-width: 780px;
  margin: 28px 0;
  color: var(--muted);
  font-size: clamp(1.04rem, 2vw, 1.23rem);
  line-height: 1.7;
}

.reveal-button {
  min-height: 44px;
  padding: 10px 15px;
  border: 1px solid color-mix(in srgb, var(--accent) 65%, var(--border));
  border-radius: var(--radius-sm);
  color: var(--accent-strong);
  background: var(--accent-soft);
  font-weight: 800;
  transition: border-color 160ms ease, background-color 160ms ease, transform 160ms ease;
}

.reveal-button:hover {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent-soft) 76%, var(--surface));
}

.reveal-button:active {
  transform: translateY(1px);
}

.card-answer,
.card-note {
  max-width: 820px;
  margin-top: 22px;
  padding: 18px 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--muted-surface);
  line-height: 1.72;
}

.card-note {
  border-left: 4px solid var(--accent);
}

.tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 30px;
}

.tag-row span {
  padding: 5px 9px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted);
  background: color-mix(in srgb, var(--surface) 70%, transparent);
  font-size: 0.71rem;
}

.code-block {
  max-width: 100%;
  margin: 22px 0;
  padding: 20px;
  overflow-x: auto;
  border: 1px solid #2d3b4f;
  border-radius: var(--radius-md);
  color: #eef4ff;
  background: #101722;
  box-shadow: inset 0 1px 0 rgb(255 255 255 / 0.04);
  font-size: 0.92rem;
  line-height: 1.65;
  tab-size: 2;
}

.steps-list,
.checklist {
  max-width: 820px;
  margin: 20px 0 0;
  padding: 0;
}

.steps-list {
  padding-left: 24px;
}

.steps-list li {
  padding: 7px 0 7px 8px;
  line-height: 1.58;
}

.checklist {
  list-style: none;
}

.checklist li {
  display: flex;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  line-height: 1.55;
}

.checklist li span {
  color: var(--success);
  font-weight: 900;
}

.question-options {
  display: grid;
  gap: 10px;
  max-width: 820px;
}

.question-options button {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 54px;
  padding: 11px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  background: var(--muted-surface);
  text-align: left;
  transition: border-color 160ms ease, background-color 160ms ease, transform 160ms ease;
}

.question-options button:hover {
  border-color: var(--border-strong);
  background: var(--surface-hover);
}

.question-options button:active {
  transform: translateY(1px);
}

.question-options button span {
  display: grid;
  flex: 0 0 auto;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  color: var(--accent-strong);
  background: var(--accent-soft);
  font-weight: 820;
}

.question-options button.is-correct {
  border-color: var(--success);
  background: var(--success-soft);
}

.question-options button.is-incorrect {
  border-color: var(--danger);
  background: var(--danger-soft);
}

.answer-feedback {
  max-width: 820px;
  margin-top: 16px;
  padding: 14px 16px;
  border: 1px solid transparent;
  border-radius: 12px;
  line-height: 1.58;
}

.answer-feedback.is-correct {
  border-color: color-mix(in srgb, var(--success) 30%, transparent);
  color: var(--success);
  background: var(--success-soft);
}

.answer-feedback.is-incorrect {
  border-color: color-mix(in srgb, var(--danger) 30%, transparent);
  color: var(--danger);
  background: var(--danger-soft);
}

.card-actions {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 14px;
  margin-top: 22px;
}

.learning-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
}

.primary-button,
.secondary-button {
  min-height: 44px;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  font-weight: 780;
  transition: border-color 160ms ease, background-color 160ms ease, color 160ms ease, box-shadow 160ms ease, transform 160ms ease;
}

.primary-button {
  border: 1px solid var(--accent);
  color: var(--accent-contrast);
  background: var(--accent);
  box-shadow: 0 7px 18px color-mix(in srgb, var(--accent) 22%, transparent);
}

.primary-button:hover {
  border-color: var(--accent-hover);
  background: var(--accent-hover);
}

.secondary-button {
  border: 1px solid var(--border);
  color: var(--text);
  background: var(--surface);
  box-shadow: var(--shadow-xs);
}

.secondary-button:hover {
  border-color: var(--border-strong);
  background: var(--muted-surface);
}

.primary-button:active,
.secondary-button:active {
  transform: translateY(1px);
  box-shadow: none;
}

.primary-button.is-selected {
  border-color: var(--success);
  color: var(--success);
  background: var(--success-soft);
  box-shadow: none;
}

.secondary-button.is-selected {
  border-color: var(--warning);
  color: var(--warning);
  background: var(--warning-soft);
}

.keyboard-hint {
  margin: 12px 0 0;
  color: var(--muted);
  text-align: center;
  font-size: 0.75rem;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 16px;
}

.overview-card {
  display: flex;
  flex-direction: column;
  min-height: 240px;
  padding: 19px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text);
  background: var(--surface);
  text-align: left;
  box-shadow: var(--shadow-sm);
  transition: transform 180ms ease, border-color 180ms ease, background-color 180ms ease, box-shadow 180ms ease;
}

.overview-card:hover {
  transform: translateY(-3px);
  border-color: color-mix(in srgb, var(--accent) 56%, var(--border));
  background: var(--surface-raised);
  box-shadow: var(--shadow);
}

.overview-card-topline {
  color: var(--muted);
  font-size: 0.71rem;
  text-transform: uppercase;
}

.overview-card strong {
  margin-top: 30px;
  font-size: 1.18rem;
  line-height: 1.28;
}

.overview-card p {
  flex: 1;
  color: var(--muted);
  line-height: 1.55;
}

.overview-card .status-pill {
  align-self: flex-start;
}

.empty-state,
.error-panel {
  padding: 56px 24px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-xl);
  background: var(--surface);
  text-align: center;
}

.empty-state h2,
.error-panel h1 {
  margin-top: 0;
}

.empty-state p,
.error-panel p {
  color: var(--muted);
}

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

  .sidebar {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

  .control-section {
    margin: 0;
  }

  .progress-panel {
    grid-column: 1 / -1;
  }

  .deck-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .deck-summary {
    width: 100%;
  }
}

@media (max-width: 680px) {
  :root {
    --topbar-height: 64px;
  }

  .topbar {
    gap: 12px;
    padding-inline: 14px;
  }

  .brand small {
    display: none;
  }

  .theme-toggle {
    width: 42px;
    padding: 0;
  }

  .theme-toggle-label {
    display: none;
  }

  .sidebar {
    grid-template-columns: 1fr;
    padding: 16px;
  }

  .progress-panel {
    grid-column: auto;
  }

  .content-area {
    padding: 24px 14px 40px;
  }

  .study-card {
    min-height: 430px;
    padding: 24px 20px;
    border-radius: 20px;
  }

  .card-heading {
    align-items: flex-start;
    flex-direction: column;
    margin-top: 26px;
  }

  .card-actions {
    grid-template-columns: 1fr 1fr;
  }

  .learning-actions {
    grid-column: 1 / -1;
    grid-row: 1;
  }

  .learning-actions button {
    flex: 1;
  }

  #previous-card {
    grid-column: 1;
  }

  #next-card {
    grid-column: 2;
  }

  .keyboard-hint {
    display: none;
  }
}

@media (max-width: 420px) {
  .brand > span:last-child {
    display: none;
  }

  .brand-mark {
    width: 40px;
    height: 40px;
  }

  .card-actions {
    gap: 10px;
  }

  .primary-button,
  .secondary-button {
    padding-inline: 12px;
  }
}
