:root {
  color-scheme: light;
  --paper: #f7f5ef;
  --paper-strong: #fffdf7;
  --ink: #172321;
  --muted: #66736f;
  --line: #d8d1c2;
  --green: #214f4b;
  --green-2: #2f6f68;
  --gold: #e2b84b;
  --blue: #375f8a;
  --red: #ba5f4b;
  --shadow: 0 20px 50px rgba(35, 43, 39, 0.14);
  --radius: 8px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background:
    linear-gradient(135deg, rgba(226, 184, 75, 0.08), transparent 34%),
    linear-gradient(315deg, rgba(55, 95, 138, 0.08), transparent 38%),
    var(--paper);
  color: var(--ink);
}

button,
textarea,
input {
  font: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
}

.app-shell {
  width: min(1180px, 100%);
  margin: 0 auto;
  padding: max(18px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  display: grid;
  width: 48px;
  height: 48px;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 8px;
  background: var(--green);
  color: var(--paper-strong);
  font-weight: 800;
  letter-spacing: 0;
}

h1,
h2,
p {
  margin: 0;
}

.brand h1 {
  font-size: 1.2rem;
  line-height: 1.1;
}

.brand p {
  max-width: 48ch;
  overflow: hidden;
  color: var(--muted);
  font-size: 0.88rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.header-actions,
.dialog-actions,
.panel-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 16px;
}

.summary-grid {
  display: grid;
  grid-column: 1 / -1;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.metric,
.side-panel,
.study-area {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 253, 247, 0.78);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.64) inset;
}

.metric {
  display: flex;
  min-height: 72px;
  flex-direction: column;
  justify-content: center;
  padding: 12px;
}

.metric-value {
  font-size: 1.35rem;
  font-weight: 800;
  line-height: 1;
}

.metric-label {
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
}

.study-area {
  min-width: 0;
  padding: 14px;
}

.mode-row,
.panel-header,
.card-topline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.mode-row {
  margin-bottom: 12px;
}

.segmented-control {
  display: grid;
  grid-template-columns: repeat(2, minmax(84px, 1fr));
  gap: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ece6d8;
  padding: 4px;
}

.segment,
.primary-button,
.quiet-button,
.icon-button,
.grade-button,
.file-picker {
  min-height: 42px;
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  transition: transform 120ms ease, background 120ms ease, border-color 120ms ease;
}

.segment {
  background: transparent;
  color: var(--muted);
  font-weight: 700;
}

.segment.active {
  background: var(--paper-strong);
  color: var(--green);
  box-shadow: 0 1px 5px rgba(35, 43, 39, 0.12);
}

.primary-button {
  background: var(--green);
  color: var(--paper-strong);
  font-weight: 800;
  padding: 0 16px;
}

.primary-button:hover,
.primary-button:focus-visible,
.segment:hover,
.quiet-button:hover,
.icon-button:hover,
.grade-button:hover,
.file-picker:hover {
  transform: translateY(-1px);
}

.quiet-button,
.icon-button,
.file-picker {
  border-color: var(--line);
  background: var(--paper-strong);
  color: var(--ink);
  font-weight: 700;
  padding: 0 14px;
}

.icon-button {
  width: 42px;
  padding: 0;
}

.wide {
  width: 100%;
}

.flashcard {
  display: block;
  width: 100%;
  min-height: 430px;
  border: 1px solid #c9beaa;
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255, 253, 247, 0.96), rgba(255, 250, 236, 0.96)),
    var(--paper-strong);
  box-shadow: var(--shadow);
  color: inherit;
  padding: 18px;
  text-align: left;
}

.card-topline {
  min-height: 24px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
  text-transform: uppercase;
}

.card-face {
  display: flex;
  min-height: 338px;
  flex-direction: column;
  justify-content: center;
  padding: 20px 4px 8px;
}

.card-face.question h2 {
  font-size: clamp(1.75rem, 6vw, 3.8rem);
  line-height: 1.04;
}

.card-face.answer {
  justify-content: flex-start;
}

.markdown {
  overflow-wrap: anywhere;
}

.markdown h2,
.markdown h3 {
  margin: 0 0 14px;
  line-height: 1.12;
}

.markdown h2 {
  font-size: 1.6rem;
}

.markdown h3 {
  font-size: 1.15rem;
}

.markdown p,
.markdown li {
  color: #26332f;
  line-height: 1.58;
}

.markdown p + p,
.markdown pre,
.markdown ul,
.markdown ol {
  margin-top: 12px;
}

.markdown ul,
.markdown ol {
  padding-left: 1.35rem;
}

.markdown code {
  border-radius: 5px;
  background: #ebe4d5;
  padding: 0.1rem 0.25rem;
}

.markdown pre {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #1d2524;
  color: #f5efe1;
  padding: 12px;
}

.markdown pre code {
  background: transparent;
  padding: 0;
}

.answer-actions,
.grade-grid {
  margin-top: 12px;
}

.grade-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.grade-button {
  display: flex;
  min-width: 0;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  border-color: var(--line);
  background: var(--paper-strong);
  color: var(--ink);
  padding: 8px 4px;
}

.grade-button span {
  font-weight: 800;
}

.grade-button small {
  color: var(--muted);
  font-size: 0.72rem;
}

.grade-button.again {
  border-color: rgba(186, 95, 75, 0.48);
}

.grade-button.hard {
  border-color: rgba(226, 184, 75, 0.62);
}

.grade-button.good {
  border-color: rgba(47, 111, 104, 0.45);
}

.grade-button.easy {
  border-color: rgba(55, 95, 138, 0.44);
}

.side-panel {
  min-width: 0;
  padding: 14px;
}

.panel-header h2 {
  font-size: 1rem;
}

.panel-header span {
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
}

.queue-list {
  display: grid;
  max-height: 436px;
  margin: 12px 0;
  padding: 0;
  gap: 8px;
  overflow: auto;
  list-style: none;
}

.queue-list li {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper-strong);
}

.queue-list button {
  width: 100%;
  border: 0;
  background: transparent;
  color: inherit;
  cursor: pointer;
  padding: 10px;
  text-align: left;
}

.queue-title {
  display: -webkit-box;
  overflow: hidden;
  font-weight: 750;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.queue-meta {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-size: 0.78rem;
}

.hidden {
  display: none !important;
}

.empty-state {
  display: grid;
  min-height: 338px;
  place-content: center;
  text-align: center;
}

.empty-state h2 {
  font-size: 1.8rem;
}

.empty-state p {
  margin-top: 8px;
  color: var(--muted);
}

.import-dialog {
  width: min(720px, calc(100% - 24px));
  border: 0;
  border-radius: 8px;
  background: transparent;
  padding: 0;
}

.import-dialog::backdrop {
  background: rgba(23, 35, 33, 0.52);
}

.dialog-card {
  display: grid;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  padding: 14px;
}

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

.dialog-header h2 {
  font-size: 1.15rem;
}

.file-picker {
  display: grid;
  place-items: center;
}

.file-picker input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

textarea {
  min-height: 320px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper-strong);
  color: var(--ink);
  line-height: 1.5;
  padding: 12px;
}

.import-preview {
  color: var(--muted);
  font-weight: 700;
}

:focus-visible {
  outline: 3px solid rgba(226, 184, 75, 0.68);
  outline-offset: 2px;
}

@media (max-width: 860px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .side-panel {
    order: 3;
  }
}

@media (max-width: 620px) {
  .app-shell {
    padding-right: 12px;
    padding-left: 12px;
  }

  .app-header {
    display: grid;
    grid-template-columns: 1fr;
    align-items: stretch;
  }

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

  .header-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: stretch;
    width: 100%;
  }

  .header-actions button {
    min-height: 38px;
    width: 100%;
  }

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

  .mode-row {
    align-items: stretch;
    flex-direction: column;
  }

  .flashcard {
    min-height: 390px;
    padding: 14px;
  }

  .card-face {
    min-height: 304px;
    padding-top: 16px;
  }

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

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition: none !important;
  }
}
