:root {
  --bg: #f6f7f4;
  --surface: #ffffff;
  --surface-2: #eef2ea;
  --ink: #18211c;
  --muted: #667063;
  --line: #dce3d8;
  --accent: #1f6f4a;
  --accent-2: #8b5f2b;
  --danger: #a64038;
  --shadow: 0 18px 45px rgba(20, 32, 24, 0.1);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-user-select: none;
  user-select: none;
}

button,
input,
select {
  font: inherit;
}

input {
  -webkit-user-select: text;
  user-select: text;
}

button {
  cursor: pointer;
}

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

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding: 22px;
  background: #122018;
  color: #f7faf4;
}

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

.brand-logo {
  display: block;
  width: 46px;
  height: 46px;
  object-fit: cover;
  border-radius: var(--radius);
}

.brand h1 {
  margin: 0;
  font-size: 20px;
  line-height: 1.1;
}

.brand h1 em {
  font-family: Georgia, "Times New Roman", serif;
  font-style: italic;
  font-weight: 700;
}

.brand p {
  margin: 4px 0 0;
  color: #b9c8bb;
  font-size: 13px;
}

.brand .version {
  margin-top: 2px;
  color: #8fa393;
  font-size: 12px;
}

.brand-credit {
  font-weight: 800;
}

.type-nav {
  display: grid;
  gap: 8px;
}

.type-button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  padding: 12px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: var(--radius);
  background: transparent;
  color: #f7faf4;
  text-align: left;
}

.type-button.active {
  background: #f7faf4;
  color: #122018;
}

.type-button small {
  color: currentColor;
  opacity: 0.7;
}

.filter-group > span,
.search-box span,
.words-head span,
.progress-box > span {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.credits {
  margin-top: auto;
  color: #b9c8bb;
  font-size: 12px;
  line-height: 1.4;
}

.credits a {
  color: #f7faf4;
  font-weight: 800;
}

.workspace {
  min-width: 0;
  padding: 22px;
}

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

.session-title {
  display: grid;
  gap: 3px;
}

.session-title span {
  color: var(--muted);
  font-size: 13px;
}

.session-title strong {
  font-size: 24px;
}

.progress-strip {
  display: grid;
  grid-template-columns: repeat(3, 96px);
  gap: 8px;
}

.progress-strip div {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  text-align: center;
}

.progress-strip span {
  display: block;
  font-weight: 800;
}

.progress-strip small {
  color: var(--muted);
}

.study-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 18px;
  align-items: start;
}

.study-panel,
.filter-panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.study-panel {
  min-height: calc(100vh - 112px);
  overflow: hidden;
}

.filter-panel {
  display: grid;
  gap: 20px;
  padding: 18px;
  position: sticky;
  top: 22px;
}

.mode-bar {
  display: flex;
  gap: 4px;
  padding: 10px;
  border-bottom: 1px solid var(--line);
  background: #fbfcfa;
}

.mode-btn {
  min-height: 36px;
  padding: 0 12px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

.mode-btn.active {
  border-color: var(--line);
  background: var(--surface);
  color: var(--ink);
}

.card-view {
  padding: 24px;
}

.card-meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  color: var(--accent-2);
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(22px, 2.5vw, 34px);
  font-weight: 700;
}

.flashcard,
.prompt-card,
.exam-card {
  display: grid;
  align-content: center;
  min-height: 300px;
  padding: 24px;
  border: 1px solid #d9cfbd;
  border-radius: var(--radius);
  background:
    linear-gradient(180deg, rgba(255,255,255,0.92), rgba(255,255,255,0.98)),
    repeating-linear-gradient(0deg, #f4efe4, #f4efe4 28px, #eee5d5 29px);
}

.flashcard p {
  min-height: 22px;
  margin: 0 0 8px;
  color: var(--accent-2);
  font-weight: 800;
}

.flashcard h2,
.prompt-card h2,
.exam-card h2 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(32px, 4.4vw, 58px);
  line-height: 1.12;
  font-weight: 700;
}

.answer {
  margin-top: 28px;
  padding-top: 24px;
  border-top: 1px solid #dacbb2;
  color: #243027;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(28px, 4vw, 50px);
  line-height: 1.45;
}

.answer em {
  font-style: italic;
  font-weight: 400;
}

.card-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 16px;
}

.primary-btn,
.strong-btn,
.soft-btn,
.icon-btn,
.text-btn {
  min-height: 42px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  padding: 0 14px;
  background: var(--surface);
  color: var(--ink);
  font-weight: 800;
}

.primary-btn {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

.strong-btn {
  background: #e3f2e8;
  border-color: #b9dbc7;
  color: #185334;
}

.soft-btn {
  background: #f7efe4;
  border-color: #e2cfb3;
  color: #6c461d;
}

.icon-btn {
  width: 44px;
  padding: 0;
  font-size: 28px;
  line-height: 1;
}

.text-btn {
  min-height: 34px;
  padding: 0;
  border: 0;
  color: var(--danger);
  background: transparent;
}

.search-box input,
.filter-group select,
.exam-card input {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0 12px;
  background: #fbfcfa;
  color: var(--ink);
}

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

.chip {
  min-height: 34px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fbfcfa;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.chip.active {
  border-color: var(--accent);
  background: #e9f3ed;
  color: var(--accent);
}

.exam-card span {
  color: var(--accent-2);
  font-weight: 800;
}

.direction-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 12px 0 22px;
}

.direction-btn {
  min-height: 34px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fbfcfa;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.direction-btn.active {
  border-color: var(--accent);
  background: #e9f3ed;
  color: var(--accent);
}

.prompt-card input {
  margin-top: 24px;
  font-size: 20px;
}

.exam-card input {
  margin-top: 18px;
  font-size: 20px;
}

.exam-choices {
  display: grid;
  gap: 10px;
  margin-top: 18px;
}

.exam-choice {
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fbfcfa;
  color: var(--ink);
  padding: 10px 12px;
  text-align: left;
  font-size: 16px;
  line-height: 1.35;
}

.exam-choice.correct {
  border-color: #7bb991;
  background: #e3f2e8;
  color: #185334;
}

.exam-choice.wrong {
  border-color: #d79a92;
  background: #fae8e6;
  color: var(--danger);
}

#examResult {
  min-height: 28px;
  margin: 16px 0 0;
  color: var(--muted);
  font-weight: 700;
}

.words-view,
.tutorial-view,
.exam-view,
.progress-box {
  display: grid;
  gap: 10px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.words-view,
.tutorial-view,
.exam-view {
  padding: 24px;
  border-top: 0;
}

.tutorial-content {
  max-width: 780px;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fbfcfa;
}

.tutorial-content h2 {
  margin: 0 0 14px;
  font-size: 28px;
}

.tutorial-content p {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 17px;
  line-height: 1.65;
}

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

.words-head h2 {
  margin: 0;
  font-size: 24px;
}

.words-head span {
  color: var(--muted);
  margin: 0;
}

.latin-word-list {
  display: grid;
  gap: 16px;
  max-height: calc(100vh - 220px);
  margin: 0;
  padding: 0;
  overflow: auto;
}

.word-section {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 8px;
}

.word-section h3 {
  grid-column: 1 / -1;
  margin: 8px 0 2px;
  color: var(--accent-2);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 23px;
}

.latin-word-list button {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fbfcfa;
  color: var(--ink);
  text-align: left;
  padding: 8px 10px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 15px;
}

.category-progress {
  display: grid;
  gap: 10px;
}

.progress-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 5px 10px;
  align-items: center;
}

.progress-row strong,
.progress-row span,
.progress-row small {
  font-size: 12px;
}

.progress-row span,
.progress-row small {
  color: var(--muted);
  text-align: right;
}

.progress-row meter {
  grid-column: 1 / -1;
  width: 100%;
  height: 8px;
}

.exam-box {
  display: grid;
  gap: 8px;
}

.exam-start {
  display: flex;
  align-items: center;
  width: 100%;
  min-height: 44px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: var(--radius);
  background: transparent;
  color: #f7faf4;
  font-weight: 400;
  text-align: left;
  padding: 0 12px;
}

.exam-start.total {
  background: #f7faf4;
  border-color: #f7faf4;
  color: #122018;
  font-weight: 400;
}

.feedback-link {
  margin: 0;
  color: #b9c8bb;
  font-size: 13px;
  line-height: 1.5;
}

.feedback-link a {
  color: #f7faf4;
  font-weight: 800;
}

.hidden {
  display: none !important;
}

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

  .sidebar {
    position: static;
  }

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

  .filter-panel {
    position: static;
  }

  .study-panel {
    min-height: auto;
  }
}

@media (max-width: 620px) {
  body {
    background: var(--surface);
  }

  .workspace,
  .sidebar {
    padding: 12px;
  }

  .sidebar {
    gap: 14px;
  }

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

  .brand h1 {
    font-size: 18px;
  }

  .type-nav {
    gap: 6px;
  }

  .topbar,
  .card-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .progress-strip {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    width: 100%;
  }

  .session-title strong {
    font-size: 20px;
  }

  .type-nav {
    grid-template-columns: 1fr;
  }

  .flashcard,
  .prompt-card,
  .exam-card {
    min-height: 230px;
    padding: 18px;
  }

  .flashcard h2,
  .prompt-card h2,
  .exam-card h2 {
    font-size: clamp(28px, 10vw, 42px);
  }

  .answer {
    font-size: clamp(26px, 9vw, 38px);
  }

  .card-view,
  .words-view,
  .tutorial-view,
  .exam-view {
    padding: 14px;
  }

  .mode-bar {
    overflow-x: auto;
  }

  .mode-btn {
    flex: 0 0 auto;
  }
}
