:root {
  --bg: #f6f7f4;
  --surface: #ffffff;
  --surface-2: #eef3f1;
  --text: #17201c;
  --muted: #66736e;
  --line: #d8dfdc;
  --primary: #0f766e;
  --primary-ink: #ffffff;
  --blue: #2563eb;
  --amber: #b45309;
  --red: #dc2626;
  --green: #15803d;
  --shadow: 0 18px 45px rgba(23, 32, 28, 0.08);
}

* {
  box-sizing: border-box;
}

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

button,
input {
  font: inherit;
}

button {
  border: 0;
}

svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

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

.topbar {
  min-height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px clamp(14px, 3vw, 32px);
  background: rgba(255, 255, 255, 0.92);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
  backdrop-filter: blur(14px);
}

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

.brand-mark {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  color: var(--primary-ink);
  background: linear-gradient(135deg, var(--primary), var(--blue));
  border-radius: 8px;
  font-weight: 800;
}

h1 {
  margin: 0;
  font-size: 20px;
  line-height: 1.2;
}

.brand p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.top-actions {
  display: flex;
  gap: 8px;
}

.icon-button,
.text-button,
.secondary-button,
.nav-button,
.primary-button,
.mode-grid button,
.segmented button,
.option-button {
  cursor: pointer;
}

.icon-button {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  color: var(--text);
  background: var(--surface-2);
  border-radius: 8px;
}

.workspace {
  width: min(1440px, 100%);
  margin: 0 auto;
  flex: 1;
  display: grid;
  grid-template-columns: minmax(280px, 340px) minmax(0, 1fr);
  gap: 18px;
  padding: 18px clamp(12px, 3vw, 32px) 24px;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

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

.stats-panel,
.filter-panel,
.sheet-panel {
  padding: 12px;
}

.scoreline {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.scoreline > div {
  min-width: 0;
}

.metric-label {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 4px;
}

.scoreline strong {
  font-size: 22px;
  line-height: 1.1;
}

.progress-track {
  height: 8px;
  background: var(--surface-2);
  border-radius: 999px;
  margin-top: 12px;
  overflow: hidden;
}

.progress-track div {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--blue));
  transition: width 160ms ease;
}

.progress-actions {
  display: flex;
  margin-top: 12px;
}

.secondary-button {
  width: 100%;
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: var(--primary);
  background: #e7f3ef;
  border: 1px solid #b9d8d2;
  border-radius: 8px;
  font-weight: 700;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  padding: 4px;
  background: var(--surface-2);
  border-radius: 8px;
}

.segmented button {
  min-height: 34px;
  color: var(--muted);
  background: transparent;
  border-radius: 6px;
  font-size: 13px;
}

.segmented button.active {
  color: var(--text);
  background: var(--surface);
  box-shadow: 0 1px 4px rgba(23, 32, 28, 0.1);
}

.mode-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 10px;
}

.mode-grid button {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  color: var(--muted);
  background: var(--surface-2);
  border-radius: 8px;
}

.mode-grid button.active {
  color: var(--primary-ink);
  background: var(--primary);
}

.panel-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 700;
  margin-bottom: 10px;
}

.text-button {
  color: var(--primary);
  background: transparent;
  padding: 6px 8px;
  border-radius: 6px;
}

.text-button:hover {
  background: var(--surface-2);
}

.question-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 6px;
  max-height: calc(100vh - 340px);
  overflow: auto;
  padding-right: 2px;
}

.question-grid button {
  aspect-ratio: 1;
  min-width: 0;
  color: var(--muted);
  background: var(--surface-2);
  border: 1px solid transparent;
  border-radius: 6px;
  font-size: 12px;
}

.question-grid button.current {
  border-color: var(--primary);
  color: var(--primary);
  background: #e7f5f2;
}

.question-grid button.correct {
  color: var(--green);
  background: #e8f7ed;
}

.question-grid button.wrong {
  color: var(--red);
  background: #feecec;
}

.practice {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.search-row {
  display: none;
  align-items: center;
  gap: 10px;
  min-height: 46px;
  padding: 0 14px;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.search-row.open {
  display: flex;
}

.search-row input {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: none;
  background: transparent;
  color: var(--text);
}

.question-surface {
  min-height: 460px;
  display: flex;
  flex-direction: column;
  padding: clamp(16px, 3vw, 28px);
}

.question-meta,
.answer-bar,
.bottom-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.question-meta {
  margin-bottom: 18px;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 10px;
  color: var(--primary);
  background: #e7f5f2;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
}

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

.question-text {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: inherit;
  font-size: 18px;
  line-height: 1.75;
}

.options {
  display: grid;
  gap: 10px;
  margin: 24px 0;
}

.option-button {
  width: 100%;
  min-height: 52px;
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  color: var(--text);
  background: #f9faf8;
  border: 1px solid var(--line);
  border-radius: 8px;
  text-align: left;
}

.option-key {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  color: var(--muted);
  background: var(--surface-2);
  border-radius: 999px;
  font-weight: 800;
}

.option-text {
  min-width: 0;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.5;
}

.option-button.selected {
  border-color: var(--blue);
  background: #eef4ff;
}

.option-button.selected .option-key {
  color: #fff;
  background: var(--blue);
}

.option-button.correct {
  border-color: #86efac;
  background: #ecfdf3;
}

.option-button.correct .option-key {
  color: #fff;
  background: var(--green);
}

.option-button.incorrect {
  border-color: #fecaca;
  background: #fff1f1;
}

.option-button.incorrect .option-key {
  color: #fff;
  background: var(--red);
}

.answer-bar {
  min-height: 44px;
  margin-top: auto;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.answer-state {
  font-weight: 800;
  margin-right: 8px;
}

.answer-state.pass {
  color: var(--green);
}

.answer-state.fail {
  color: var(--red);
}

.bottom-nav {
  background: rgba(246, 247, 244, 0.88);
  position: sticky;
  bottom: 0;
  padding-top: 4px;
  backdrop-filter: blur(12px);
}

.nav-button,
.primary-button {
  min-height: 46px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-radius: 8px;
  padding: 0 16px;
  white-space: nowrap;
}

.nav-button {
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
}

.primary-button {
  min-width: 160px;
  color: var(--primary-ink);
  background: var(--primary);
}

.primary-button:disabled,
.nav-button:disabled,
.option-button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

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

  .sidebar {
    order: 2;
  }

  .practice {
    order: 1;
  }

  .question-grid {
    grid-template-columns: repeat(10, 1fr);
    max-height: none;
  }
}

@media (max-width: 560px) {
  .topbar {
    min-height: 64px;
  }

  .brand-mark {
    width: 38px;
    height: 38px;
    font-size: 13px;
  }

  h1 {
    font-size: 18px;
  }

  .brand p {
    max-width: 190px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .workspace {
    padding: 12px;
  }

  .question-surface {
    min-height: 420px;
  }

  .question-text {
    font-size: 16px;
  }

  .bottom-nav {
    display: grid;
    grid-template-columns: 1fr 1.2fr 1fr;
  }

  .nav-button,
  .primary-button {
    min-width: 0;
    padding: 0 10px;
    font-size: 14px;
  }

  .question-grid {
    grid-template-columns: repeat(8, 1fr);
  }
}
