:root {
  color-scheme: light;
  --bg: #f6f7f4;
  --ink: #17211f;
  --muted: #61706d;
  --panel: #ffffff;
  --line: #d9e0dc;
  --primary: #0f766e;
  --primary-dark: #0b514c;
  --accent: #c2410c;
  --good: #15803d;
  --bad: #b91c1c;
  --focus: #f59e0b;
  --shadow: 0 18px 38px rgba(23, 33, 31, 0.12);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100%;
  margin: 0;
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button,
input {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

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

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 10px 2px 14px;
}

.eyebrow {
  margin: 0 0 2px;
  color: var(--primary);
  font-size: 0.76rem;
  font-weight: 800;
  text-transform: uppercase;
}

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

h1 {
  margin-bottom: 0;
  font-size: clamp(1.45rem, 7vw, 2.6rem);
  line-height: 1;
}

h2 {
  margin-bottom: 6px;
  font-size: 1.28rem;
}

h3 {
  margin-bottom: 14px;
  font-size: 1.22rem;
  line-height: 1.28;
}

.status-pill {
  flex: 0 0 auto;
  min-width: 74px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #ecfdf5;
  color: var(--primary-dark);
  font-size: 0.82rem;
  font-weight: 800;
  text-align: center;
}

.mode-tabs {
  position: sticky;
  top: 0;
  z-index: 4;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin: 0 -2px 14px;
  padding: 6px 2px;
  background: rgba(246, 247, 244, 0.92);
  backdrop-filter: blur(10px);
}

.tab,
.quick-actions button,
.answer-form button,
.streak-actions button,
.test-card button {
  min-height: 44px;
  border-radius: 8px;
  background: #e7ece9;
  color: var(--ink);
  font-weight: 800;
}

.tab.is-active,
.answer-form button,
.streak-actions button:first-child,
.test-card button {
  background: var(--primary);
  color: #fff;
}

.mode-panel {
  display: none;
}

.mode-panel.is-active {
  display: block;
}

.panel-head,
.quiz-surface,
.test-card,
.score-row > div {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 16px;
  margin-bottom: 12px;
}

.panel-head p {
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.42;
}

.icon-button {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: #f1f5f3;
  color: var(--primary-dark);
  font-size: 1.3rem;
  font-weight: 900;
}

.toolbar {
  display: grid;
  gap: 10px;
  margin-bottom: 12px;
}

.search-box {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 800;
}

input {
  width: 100%;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 13px;
  background: #fff;
  color: var(--ink);
}

input:focus,
button:focus-visible {
  outline: 3px solid rgba(245, 158, 11, 0.45);
  outline-offset: 2px;
}

.quick-actions {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.selection-stage {
  margin-bottom: 12px;
}

.start-row {
  position: sticky;
  bottom: max(10px, env(safe-area-inset-bottom));
  z-index: 3;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.95);
  box-shadow: var(--shadow);
}

.start-row span {
  color: var(--muted);
  font-weight: 800;
}

.start-row button,
.secondary-action {
  min-height: 44px;
  border-radius: 8px;
  padding: 0 14px;
  background: var(--primary);
  color: #fff;
  font-weight: 800;
}

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

.element-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(76px, 1fr));
  gap: 8px;
  max-height: 340px;
  margin-bottom: 12px;
  padding: 2px;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

.element-chip {
  position: relative;
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-height: 84px;
  padding: 7px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  text-align: left;
}

.element-chip.is-selected {
  border-color: var(--primary);
  background: #dff7f2;
}

.element-chip .number {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
}

.element-chip .symbol {
  align-self: center;
  font-size: 1.35rem;
  line-height: 1;
}

.element-chip .name {
  overflow: hidden;
  color: var(--muted);
  font-size: 0.72rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.quiz-surface {
  padding: 16px;
}

.quiz-meta,
.score-row {
  display: grid;
  gap: 8px;
}

.quiz-meta {
  grid-template-columns: repeat(2, 1fr);
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 800;
}

.quiz-meta span:last-child {
  text-align: right;
}

.answer-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.answer-form button {
  min-width: 94px;
  padding: 0 14px;
}

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

.choice-button {
  min-height: 58px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fff;
  color: var(--ink);
  font-weight: 900;
  line-height: 1.2;
  text-align: center;
}

.choice-button:hover {
  border-color: var(--primary);
  background: #eefbf8;
}

.choice-button:disabled {
  cursor: not-allowed;
  opacity: 0.7;
}

.choice-button.is-correct {
  border-color: var(--good);
  background: #dcfce7;
  color: var(--good);
}

.choice-button.is-wrong {
  border-color: var(--bad);
  background: #fee2e2;
  color: var(--bad);
}

.feedback {
  min-height: 26px;
  margin: 12px 0 0;
  color: var(--muted);
  font-weight: 800;
  line-height: 1.35;
}

.feedback.good {
  color: var(--good);
}

.feedback.bad {
  color: var(--bad);
}

.score-row {
  grid-template-columns: repeat(3, 1fr);
  margin-bottom: 12px;
}

.score-row > div {
  padding: 12px;
}

.score-row span {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.score-row strong {
  display: block;
  margin-top: 3px;
  font-size: 1.45rem;
}

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

.streak-actions button:last-child {
  background: #e7ece9;
  color: var(--ink);
}

.secondary-action {
  width: 100%;
  margin-top: 10px;
  background: #e7ece9;
  color: var(--ink);
}

.test-list {
  display: grid;
  gap: 10px;
  margin-bottom: 12px;
}

.test-card {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 14px;
}

.test-card h3 {
  margin-bottom: 4px;
  font-size: 1rem;
}

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

.test-card.is-locked {
  opacity: 0.58;
}

.test-card button {
  min-width: 86px;
  padding: 0 12px;
}

.test-card button:disabled,
.answer-form button:disabled,
input:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

@media (min-width: 760px) {
  .toolbar {
    grid-template-columns: 1fr auto;
    align-items: end;
  }

  .quick-actions {
    width: 280px;
  }

  .element-grid {
    grid-template-columns: repeat(auto-fill, minmax(88px, 1fr));
    max-height: 420px;
  }

  .mode-tabs {
    max-width: 540px;
  }
}

@media (max-width: 420px) {
  .answer-form {
    grid-template-columns: 1fr;
  }

  .answer-form button {
    width: 100%;
  }

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

  .panel-head,
  .quiz-surface {
    padding: 14px;
  }

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

  .test-card button {
    width: 100%;
  }

  .start-row {
    grid-template-columns: 1fr;
  }

  .start-row button {
    width: 100%;
  }
}
