:root {
  --ink: #1d2923;
  --muted: #5c6961;
  --paper: #fffef9;
  --canvas: #edf1ec;
  --line: #cbd4cc;
  --green: #24543c;
  --green-light: #e1eee5;
  --blue: #315e78;
  --blue-light: #e4eef4;
  --amber: #8a5a12;
  --amber-light: #f8ecd5;
  --red: #a33b35;
  --red-light: #f7e4e1;
  --shadow: 0 14px 34px rgba(31, 48, 38, 0.1);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  min-width: 320px;
  margin: 0;
  background: var(--canvas);
  color: var(--ink);
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.55;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
summary:focus-visible,
a:focus-visible {
  outline: 3px solid #e0a52b;
  outline-offset: 3px;
}

.skip-link {
  position: fixed;
  left: 1rem;
  top: -5rem;
  z-index: 50;
  padding: 0.65rem 0.9rem;
  background: var(--ink);
  color: white;
}

.skip-link:focus {
  top: 1rem;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  min-height: 4.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  border-bottom: 1px solid var(--line);
  padding: 0.65rem max(1rem, calc((100vw - 1180px) / 2));
  background: rgba(255, 254, 249, 0.96);
  backdrop-filter: blur(12px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.7rem;
  color: var(--ink);
  text-decoration: none;
}

.brand-mark {
  width: 2.6rem;
  height: 2.6rem;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--green);
  color: white;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.35rem;
  font-weight: 700;
}

.brand strong,
.brand small {
  display: block;
  line-height: 1.1;
}

.brand small {
  margin-top: 0.15rem;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
}

.header-status {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  color: var(--muted);
  font-size: 0.9rem;
}

main {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 3rem 0 5rem;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1,
h2,
h3 {
  letter-spacing: 0;
}

h1 {
  max-width: 16ch;
  margin-bottom: 1rem;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(2.5rem, 6vw, 5.2rem);
  line-height: 0.98;
}

h2 {
  margin-bottom: 0.75rem;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1.8rem, 3.5vw, 3rem);
  line-height: 1.05;
}

.eyebrow {
  margin-bottom: 0.45rem;
  color: var(--red);
  font-size: 0.76rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.onboarding {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(320px, 0.72fr);
  gap: 3rem;
  align-items: start;
}

.onboarding-intro {
  padding-top: 1.5rem;
}

.onboarding-intro > p:not(.eyebrow) {
  max-width: 62ch;
  color: var(--muted);
  font-size: 1.12rem;
}

.method-list {
  max-width: 680px;
  display: grid;
  gap: 0.75rem;
  margin: 2rem 0 0;
  padding-left: 2.4rem;
}

.method-list li {
  border-left: 4px solid var(--green);
  padding: 0.7rem 1rem;
  background: rgba(255, 254, 249, 0.65);
}

.profile-form,
.deck-toolbar,
.study-panel,
.session-summary,
.concept-list,
.learning-note,
.student-guide,
.data-settings {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper);
  box-shadow: var(--shadow);
}

.research-details {
  padding: 0;
}

.research-details > summary {
  position: relative;
  display: grid;
  gap: 0.35rem;
  cursor: pointer;
  padding: clamp(1.1rem, 3vw, 2rem);
  padding-right: clamp(3.8rem, 8vw, 5.5rem);
  list-style: none;
}

.research-details > summary::-webkit-details-marker {
  display: none;
}

.research-details > summary::after {
  content: "+";
  position: absolute;
  right: clamp(1.1rem, 3vw, 2rem);
  top: 50%;
  width: 2.5rem;
  height: 2.5rem;
  display: grid;
  place-items: center;
  border: 1px solid var(--green);
  border-radius: 50%;
  color: var(--green);
  font-size: 1.7rem;
  font-weight: 500;
  line-height: 1;
  transform: translateY(-50%);
}

.research-details[open] > summary::after {
  content: "−";
}

.research-details > summary .eyebrow {
  margin-bottom: 0;
}

.research-details > summary > strong {
  color: var(--ink);
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1.8rem, 3.5vw, 2.8rem);
  line-height: 1.05;
}

.research-details > summary .research-intro {
  display: block;
}

.toggle-label {
  margin-top: 0.35rem;
  color: var(--blue);
  font-size: 0.82rem;
  font-weight: 850;
}

.research-details[open] .toggle-label {
  font-size: 0;
}

.research-details[open] .toggle-label::after {
  content: "Close research and bibliography";
  font-size: 0.82rem;
}

.profile-form {
  display: grid;
  gap: 1rem;
  padding: 1.5rem;
}

.privacy-note {
  border-left: 3px solid var(--blue);
  padding-left: 0.8rem;
  color: var(--muted);
  font-size: 0.92rem;
}

label {
  display: grid;
  gap: 0.35rem;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 800;
}

input,
select {
  width: 100%;
  min-height: 2.8rem;
  border: 1px solid #aebbb1;
  border-radius: 6px;
  padding: 0.6rem 0.7rem;
  background: white;
  color: var(--ink);
}

.primary-button,
.secondary-button,
.danger-button,
.rating-button {
  min-height: 2.8rem;
  border-radius: 6px;
  padding: 0.65rem 1rem;
  font-weight: 850;
}

.primary-button {
  border: 1px solid var(--green);
  background: var(--green);
  color: white;
}

.secondary-button {
  border: 1px solid var(--green);
  background: white;
  color: var(--green);
}

.text-button {
  border: 0;
  padding: 0.35rem;
  background: transparent;
  color: var(--blue);
  font-weight: 800;
  text-decoration: underline;
  text-underline-offset: 0.18rem;
}

.workspace {
  display: grid;
  gap: 1.25rem;
}

.deck-toolbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(360px, 0.72fr);
  gap: 2rem;
  align-items: end;
  padding: 1.4rem;
}

.deck-toolbar h1 {
  max-width: none;
  margin-bottom: 0.35rem;
  font-size: clamp(2rem, 4vw, 3.3rem);
}

.deck-toolbar p:last-child,
#deck-description {
  margin-bottom: 0;
  color: var(--muted);
}

.goal-card {
  margin-top: 1rem;
  border-left: 4px solid var(--green);
  border-radius: 6px;
  padding: 0.8rem 1rem;
  background: var(--green-light);
}

.goal-card p {
  margin: 0;
}

.deck-toolbar .goal-label {
  color: var(--green);
  font-size: 0.76rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.deck-controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.file-control input {
  padding: 0.45rem;
  font-size: 0.82rem;
}

.dashboard {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--paper);
}

.metric {
  min-width: 0;
  padding: 1.1rem;
  border-right: 1px solid var(--line);
}

.metric:last-child {
  border-right: 0;
}

.metric span,
.metric small,
.metric strong {
  display: block;
}

.metric span {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 850;
  text-transform: uppercase;
}

.metric strong {
  margin: 0.25rem 0;
  color: var(--green);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 2.25rem;
  line-height: 1;
}

.metric small {
  overflow-wrap: anywhere;
  color: var(--muted);
}

.study-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.7rem;
}

.receipt-button {
  margin-left: auto;
  border-color: var(--blue);
  color: var(--blue);
}

.study-panel,
.session-summary,
.concept-list,
.learning-note {
  padding: clamp(1.1rem, 3vw, 2rem);
}

.study-topline {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: start;
}

.study-topline h2 {
  margin-bottom: 0;
  font-size: clamp(1.65rem, 3vw, 2.4rem);
}

.study-prompt {
  margin: 0.45rem 0 0;
  color: var(--blue);
  font-weight: 800;
}

.progress-track {
  height: 0.55rem;
  margin-top: 1.2rem;
  overflow: hidden;
  border-radius: 4px;
  background: #dde3de;
}

.progress-track span {
  width: 0;
  height: 100%;
  display: block;
  background: var(--green);
  transition: width 180ms ease;
}

.progress-copy {
  margin: 0.4rem 0 1rem;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 750;
}

.flashcard {
  min-height: 340px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  border: 1px solid #aebbb1;
  border-top: 6px solid var(--green);
  border-radius: var(--radius);
  padding: clamp(1.3rem, 5vw, 3.5rem);
  background: white;
}

.card-context {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.6rem;
  margin-bottom: 1.5rem;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 850;
  text-transform: uppercase;
}

.flashcard h3 {
  max-width: 32ch;
  margin: 0 auto;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1.65rem, 4vw, 2.8rem);
  line-height: 1.15;
  text-align: center;
}

.card-hint {
  margin: 1.2rem auto 0;
  color: var(--muted);
  font-style: italic;
  text-align: center;
}

.answer {
  max-width: 760px;
  margin: 2rem auto 0;
  border-top: 1px solid var(--line);
  padding-top: 1.5rem;
  font-size: 1.06rem;
}

.answer-label {
  margin-bottom: 0.35rem;
  color: var(--red);
  font-size: 0.76rem;
  font-weight: 900;
  text-transform: uppercase;
}

.recall-controls {
  display: flex;
  justify-content: center;
  padding-top: 1rem;
}

.reveal-button {
  min-width: min(100%, 260px);
}

.rating-controls {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.7rem;
  border: 0;
  margin: 0;
  padding: 1rem 0 0;
}

.rating-controls legend {
  width: 100%;
  margin-bottom: 0.5rem;
  color: var(--muted);
  font-weight: 850;
  text-align: center;
}

.rating-button {
  display: grid;
  gap: 0.1rem;
  border: 1px solid;
  background: white;
  text-align: left;
}

.rating-button span {
  font-size: 0.78rem;
  font-weight: 600;
}

.rating-button.unknown {
  border-color: var(--red);
  color: var(--red);
}

.rating-button.review {
  border-color: var(--amber);
  color: var(--amber);
}

.rating-button.known {
  border-color: var(--green);
  color: var(--green);
}

.summary-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  max-width: 640px;
  margin: 1.5rem 0;
  border: 1px solid var(--line);
}

.summary-stats p {
  margin: 0;
  padding: 1rem;
  border-right: 1px solid var(--line);
}

.summary-stats p:last-child {
  border-right: 0;
}

.summary-stats strong,
.summary-stats span {
  display: block;
}

.summary-stats strong {
  font-size: 1.7rem;
}

.summary-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.7rem;
}

.summary-stats span {
  color: var(--muted);
  font-size: 0.78rem;
}

.concept-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 0.75rem;
  margin-top: 1.2rem;
}

.concept-item {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 1rem;
  background: white;
}

.concept-item h3 {
  margin-bottom: 0.4rem;
  font-size: 1rem;
}

.concept-item p {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 0.88rem;
}

.learning-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0;
  margin: 0 clamp(1.1rem, 3vw, 2rem);
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.research-intro {
  max-width: 78ch;
  color: var(--muted);
  font-size: 1.04rem;
}

.learning-grid article {
  padding: 1.4rem;
  border-right: 1px solid var(--line);
}

.learning-grid article:first-child {
  padding-left: 0;
}

.learning-grid article:last-child {
  border-right: 0;
  padding-right: 0;
}

.learning-grid h3 {
  margin: 0 0 0.8rem;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.45rem;
  line-height: 1.15;
}

.learning-grid p {
  color: var(--muted);
}

.learning-grid strong,
.spaced-repetition strong {
  color: var(--ink);
}

.principle-number {
  margin-bottom: 0.35rem;
  color: var(--red) !important;
  font-size: 0.76rem;
  font-weight: 900;
}

.learning-note sup a {
  color: var(--blue);
  font-weight: 900;
  text-decoration: none;
}

.research-caution {
  border-left: 3px solid var(--amber);
  padding-left: 0.7rem;
  font-size: 0.9rem;
}

.spaced-repetition {
  margin: 1.5rem clamp(1.1rem, 3vw, 2rem) 0;
  border-left: 5px solid var(--blue);
  padding: 1.2rem 1.4rem;
  background: var(--blue-light);
}

.spaced-repetition h3 {
  margin: 0 0 0.65rem;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1.6rem, 3vw, 2.3rem);
}

.spaced-repetition p:last-child {
  margin-bottom: 0;
}

.bibliography {
  margin-top: 1.5rem;
  border-top: 1px solid var(--line);
  padding: clamp(1.1rem, 3vw, 2rem);
}

.bibliography h2 {
  font-size: clamp(1.8rem, 3.5vw, 2.8rem);
}

.bibliography ol {
  display: grid;
  gap: 0.8rem;
  margin: 1.2rem 0 0;
  padding-left: 1.4rem;
}

.bibliography li {
  padding-left: 0.35rem;
  color: var(--muted);
}

.bibliography a {
  color: var(--blue);
  text-underline-offset: 0.14rem;
}

.bibliography li:target {
  border-left: 4px solid var(--amber);
  padding-left: 0.7rem;
  background: #fff8e8;
}

.student-guide,
.data-settings {
  padding: 1rem 1.2rem;
}

.student-guide summary,
.data-settings summary {
  cursor: pointer;
  color: var(--blue);
  font-weight: 850;
}

.guide-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem 1.5rem;
  margin-top: 1rem;
}

.guide-grid p {
  margin: 0;
  color: var(--muted);
}

.guide-grid strong {
  color: var(--ink);
}

.guide-privacy {
  margin: 1rem 0 0;
  border-left: 3px solid var(--blue);
  padding-left: 0.8rem;
  color: var(--muted);
}

.data-settings p {
  max-width: 70ch;
  margin: 1rem 0;
  color: var(--muted);
}

.data-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.7rem;
  margin: 1rem 0;
}

.backup-upload {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

#load-backup {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

.danger-button {
  border: 1px solid var(--red);
  background: white;
  color: var(--red);
}

.error-message {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  z-index: 30;
  max-width: 420px;
  border: 1px solid var(--red);
  border-radius: 6px;
  padding: 0.8rem 1rem;
  background: var(--red-light);
  color: #6e211d;
  box-shadow: var(--shadow);
}

.error-message[data-tone="success"] {
  border-color: var(--green);
  background: var(--green-light);
  color: var(--green);
}

[hidden] {
  display: none !important;
}

@media (max-width: 850px) {
  .onboarding,
  .deck-toolbar {
    grid-template-columns: 1fr;
  }

  .dashboard {
    grid-template-columns: repeat(2, 1fr);
  }

  .metric:nth-child(2) {
    border-right: 0;
  }

  .metric:nth-child(-n+2) {
    border-bottom: 1px solid var(--line);
  }

  .learning-grid {
    grid-template-columns: 1fr;
  }

  .learning-grid article,
  .learning-grid article:first-child,
  .learning-grid article:last-child {
    border-right: 0;
    border-bottom: 1px solid var(--line);
    padding: 1.2rem 0;
  }

  .learning-grid article:last-child {
    border-bottom: 0;
  }

  .guide-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 580px) {
  main {
    width: min(100% - 20px, 1180px);
    padding-top: 1.5rem;
  }

  .header-status > span {
    display: none;
  }

  .deck-controls,
  .rating-controls {
    grid-template-columns: 1fr;
  }

  .study-actions {
    display: grid;
  }

  .study-actions button {
    width: 100%;
  }

  .receipt-button {
    margin-left: 0;
  }

  .flashcard {
    min-height: 300px;
  }

  .summary-stats {
    grid-template-columns: 1fr;
  }

  .summary-stats p {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .summary-stats p:last-child {
    border-bottom: 0;
  }
}
