:root {
  color-scheme: light;
  font-family: "Segoe UI", Tahoma, sans-serif;
  --ink: #1e272e;
  --muted: #607077;
  --paper: #fffdf7;
  --line: #d8e2df;
  --teal: #1c7c73;
  --teal-dark: #145f59;
  --yellow: #ffd166;
  --coral: #ef6f6c;
  --blue: #4f7cac;
  --green: #2f9e44;
  --red: #d9480f;
  --bg: #f3f7f4;
}

* {
  box-sizing: border-box;
}

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

body {
  min-height: 100%;
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(90deg, rgba(28, 124, 115, 0.08) 1px, transparent 1px),
    linear-gradient(rgba(28, 124, 115, 0.06) 1px, transparent 1px),
    var(--bg);
  background-size: 28px 28px;
}

button,
select,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

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

.topbar,
.practice-header,
.control-panel,
.problem-head,
.work-area {
  display: flex;
  align-items: center;
}

.topbar,
.practice-header {
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.eyebrow {
  margin: 0 0 3px;
  color: var(--teal-dark);
  font-size: 0.82rem;
  font-weight: 700;
}

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

h1 {
  margin-bottom: 0;
  font-size: clamp(2rem, 9vw, 3.8rem);
  line-height: 1.05;
}

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

.hero-panel {
  display: grid;
  grid-template-columns: 82px 1fr;
  gap: 14px;
  align-items: center;
  padding: 16px;
  margin-bottom: 16px;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 247, 0.9);
}

.hero-panel p,
.install-help,
.mode-detail,
.score-card {
  color: var(--muted);
}

.app-mark {
  width: 82px;
  height: 82px;
}

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

.mode-card {
  min-height: 148px;
  padding: 16px;
  border: 2px solid #cfdcda;
  border-radius: 8px;
  background: var(--paper);
  color: var(--ink);
  text-align: left;
  box-shadow: 0 8px 0 rgba(28, 124, 115, 0.12);
}

.mode-card:nth-child(1) .mode-symbol { background: var(--yellow); }
.mode-card:nth-child(2) .mode-symbol { background: #a7d8de; }
.mode-card:nth-child(3) .mode-symbol { background: #ffb199; }
.mode-card:nth-child(4) .mode-symbol { background: #b8e986; }

.mode-symbol,
.mode-label,
.mode-detail {
  display: block;
}

.mode-symbol {
  width: 48px;
  height: 48px;
  margin-bottom: 12px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 2rem;
  font-weight: 800;
}

.mode-label {
  font-size: 1.35rem;
  font-weight: 800;
}

.mode-detail {
  margin-top: 4px;
  font-size: 0.92rem;
  line-height: 1.35;
}

.icon-button,
.text-button,
.primary-button,
.secondary-button,
.clear-button {
  min-height: 44px;
  border-radius: 8px;
  border: 0;
  font-weight: 800;
}

.icon-button {
  width: 48px;
  background: var(--teal);
  color: white;
  font-size: 1.3rem;
}

.text-button,
.secondary-button,
.clear-button {
  background: #e7efed;
  color: var(--teal-dark);
}

.text-button {
  padding: 0 16px;
}

.primary-button,
.secondary-button {
  padding: 0 14px;
}

.primary-button {
  background: var(--teal);
  color: white;
}

.control-panel {
  flex-wrap: wrap;
  gap: 10px;
  padding: 12px;
  margin-bottom: 12px;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 247, 0.92);
}

.field {
  display: grid;
  gap: 4px;
  min-width: 120px;
  font-weight: 800;
  color: var(--teal-dark);
}

select,
input {
  min-height: 44px;
  border: 2px solid #bfd0cd;
  border-radius: 8px;
  background: white;
  color: var(--ink);
}

select {
  padding: 0 12px;
}

.score-card {
  padding: 12px 14px;
  margin-bottom: 12px;
  border-left: 5px solid var(--blue);
  border-radius: 8px;
  background: white;
  font-weight: 800;
}

.worksheet {
  display: grid;
  gap: 14px;
}

.problem-card {
  padding: 14px;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
}

.problem-card.is-correct {
  border-color: rgba(47, 158, 68, 0.55);
}

.problem-card.is-wrong {
  border-color: rgba(217, 72, 15, 0.55);
}

.problem-head {
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
  font-weight: 900;
}

.clear-button {
  padding: 0 12px;
  font-size: 0.88rem;
}

.work-area {
  align-items: stretch;
  gap: 14px;
  margin-bottom: 12px;
}

.vertical-problem {
  min-width: 118px;
  padding: 12px 14px;
  border-radius: 8px;
  background: white;
  font-family: Consolas, "Courier New", monospace;
  font-size: 2rem;
  font-weight: 800;
  line-height: 1.08;
  text-align: right;
}

.problem-line {
  color: var(--muted);
}

.answer-field {
  flex: 1;
  display: grid;
  gap: 6px;
  font-weight: 800;
  color: var(--teal-dark);
}

.answer-field input {
  width: 100%;
  padding: 0 12px;
  font-size: 1.4rem;
  font-weight: 800;
}

.scratch-wrap {
  overflow: hidden;
  border: 2px solid #cbd8d5;
  border-radius: 8px;
  background:
    repeating-linear-gradient(0deg, rgba(79, 124, 172, 0.12) 0, rgba(79, 124, 172, 0.12) 1px, transparent 1px, transparent 26px),
    #fffefa;
}

.scratch-canvas {
  display: block;
  width: 100%;
  height: 170px;
  touch-action: none;
}

.result-text {
  min-height: 24px;
  margin: 8px 0 0;
  font-weight: 900;
}

.is-correct .result-text {
  color: var(--green);
}

.is-wrong .result-text {
  color: var(--red);
}

.install-help {
  margin: 16px 2px 0;
  font-size: 0.9rem;
  line-height: 1.45;
}

[hidden] {
  display: none !important;
}

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

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

  .hero-panel {
    grid-template-columns: 62px 1fr;
  }

  .app-mark {
    width: 62px;
    height: 62px;
  }

  .control-panel > * {
    flex: 1 1 100%;
  }

  .work-area {
    display: grid;
    grid-template-columns: 1fr;
  }

  .vertical-problem {
    width: 100%;
    font-size: 2.15rem;
  }

  .scratch-canvas {
    height: 190px;
  }
}

@media (min-width: 760px) {
  .worksheet {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
