:root {
  --bg: #f7f6f3;
  --card: #ffffff;
  --text: #2f3437;
  --muted: #787774;
  --line: #e9e9e7;
  --soft: #f1f1ef;
  --primary: #2f3437;
  --green: #0f7b6c;
  --red: #d44c47;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--text);
  background: var(--bg);
}

.app {
  width: min(1340px, calc(100% - 24px));
  height: 100vh;
  max-height: 768px;
  margin: 0 auto;
  padding: 12px 0;
  display: grid;
  grid-template-columns: 336px minmax(0, 1fr);
  gap: 12px;
  overflow: hidden;
}

.sidebar {
  display: grid;
  grid-template-rows: auto auto auto auto;
  gap: 10px;
  min-height: 0;
  overflow-y: auto;
  padding-right: 4px;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
}

.hero {
  padding: 14px 12px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 4px; font-size: 28px; line-height: 1.1; }
h2 { margin-bottom: 10px; font-size: 16px; }

label.disabled {
  opacity: .45;
}

label.disabled select {
  cursor: not-allowed;
  background: var(--soft);
  color: var(--muted);
}

.settings {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.settings h2,
.settings .button-row {
  grid-column: 1 / -1;
}

label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

select {
  width: 100%;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 9px;
  font-size: 14px;
  color: var(--text);
  background: #fff;
}

button {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 15px;
  font-weight: 650;
  color: var(--text);
  background: var(--soft);
  cursor: pointer;
  user-select: none;
  touch-action: manipulation;
}

button:hover:not(:disabled) { background: #e7e7e4; }
button:disabled { opacity: .45; cursor: not-allowed; }
.primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.primary:hover:not(:disabled) { background: #111; }

.button-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.start-button {
  width: 100%;
  background: #0f7b6c;
  border-color: #0f7b6c;
  color: #fff;
}

.start-button:hover:not(:disabled) {
  background: #0a675a;
}

.reset-button {
  width: 100%;
  background: #d44c47;
  border-color: #d44c47;
  color: #fff;
}

.reset-button:hover:not(:disabled) {
  background: #b93b37;
}

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

.status-grid div {
  padding: 8px;
  border-radius: 8px;
  background: var(--soft);
  display: grid;
  align-content: center;
  min-height: 64px;
}

.status-grid span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 3px;
}

.status-grid strong {
  display: block;
  color: var(--text);
  font-size: 18px;
}

.encouragement {
  margin: 9px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.question-nav-wrap {
  margin-bottom: 10px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfbfa;
}

.mini-title {
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
  margin-bottom: 6px;
}

.question-nav {
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  gap: 4px;
  max-height: 96px;
  overflow: auto;
}

.question-dot {
  min-width: 0;
  height: 22px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
  font-size: 11px;
  font-weight: 650;
  cursor: default;
}

.question-dot.current {
  border-color: var(--text);
  box-shadow: inset 0 0 0 1px var(--text);
}

.question-dot.correct {
  background: #e7f4ef;
  border-color: #b6dfd2;
  color: #0f6b5f;
}

.question-dot.wrong {
  background: #fbebea;
  border-color: #efc0bd;
  color: #a43631;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.section-head h2 { margin-bottom: 0; }
.section-head button { padding: 5px 9px; font-size: 13px; }

.mistakes {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 8px;
}

.mistake-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  align-content: start;
  gap: 6px;
  max-height: 140px;
  overflow: auto;
}

.mistake-list li {
  padding: 7px 9px;
  border-radius: 7px;
  background: #fbebea;
  color: #8f2c28;
  font-size: 13px;
  line-height: 1.35;
}

.mistake-list .empty { background: #edf6f3; color: #0f6b5f; }

.practice {
  min-height: 0;
  display: grid;
  grid-template-rows: minmax(190px, 1fr) auto 272px;
  gap: 10px;
}

.question-box {
  display: grid;
  place-items: center;
  align-content: center;
  padding: 18px;
  border-radius: 10px;
  text-align: center;
  background: #fff;
  border: 1px solid var(--line);
}

.prompt {
  color: var(--muted);
  margin-bottom: 6px;
  font-size: 15px;
}

.question {
  font-size: clamp(58px, 7vw, 96px);
  font-weight: 760;
  letter-spacing: 1px;
}

.answer-panel {
  display: grid;
  gap: 5px;
}

.answer-display {
  min-height: 54px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--text);
  font-size: clamp(28px, 3.8vw, 44px);
  font-weight: 760;
}

.answer-display.placeholder {
  color: #b7b7b4;
  font-size: 22px;
  font-weight: 600;
}

.feedback {
  min-height: 26px;
  text-align: center;
  font-size: 18px;
  font-weight: 700;
  white-space: pre-line;
}

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

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

.keypad button {
  min-height: 48px;
  font-size: 24px;
  background: #fff;
}

.keypad button[data-action] {
  font-size: 18px;
}

.keypad .remainder-key {
  font-size: 20px;
  letter-spacing: 1px;
}

.keypad .submit-key {
  background: var(--soft);
  color: var(--text);
  border-color: var(--line);
}

@media (max-width: 980px) {
  .app {
    height: auto;
    max-height: none;
    grid-template-columns: 1fr;
    overflow: visible;
  }

  .practice {
    grid-template-rows: auto auto auto auto;
  }
}
