:root {
  --paper: #f7f4ec;
  --paper-ink: rgba(28, 33, 38, 0.07);
  --surface: #fffdf7;
  --surface-alt: #f1f6f4;
  --text: #1f252b;
  --muted: #667078;
  --line: rgba(31, 37, 43, 0.14);
  --teal: #087466;
  --teal-dark: #07564d;
  --teal-soft: #dff3ef;
  --yellow: #f7c948;
  --coral: #df614d;
  --coral-soft: #ffe3dc;
  --blue: #315f8f;
  --shadow: 0 14px 34px rgba(27, 39, 45, 0.12);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Avenir Next", "Segoe UI", sans-serif;
  color: var(--text);
  background-color: var(--paper);
  background-image:
    linear-gradient(var(--paper-ink) 1px, transparent 1px),
    linear-gradient(90deg, var(--paper-ink) 1px, transparent 1px);
  background-size: 28px 28px;
}

button,
input {
  font: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
}

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

.page-shell {
  width: min(1180px, 100%);
  margin: 0 auto;
  padding: 18px 16px 44px;
}

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

.eyebrow,
.panel-kicker,
.label {
  margin: 0 0 6px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0;
  font-size: 0.76rem;
  font-weight: 800;
}

h1 {
  margin-bottom: 0;
  font-size: 2.15rem;
  line-height: 1;
}

h2 {
  margin-bottom: 0;
  font-size: 1.1rem;
  line-height: 1.2;
}

h3 {
  font-size: 1rem;
}

.header-actions,
.tool-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.button {
  min-height: 48px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: 0 16px;
  cursor: pointer;
  font-weight: 800;
}

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

.button-primary:active {
  background: var(--teal-dark);
}

.button-secondary {
  background: var(--surface);
  border-color: var(--line);
  color: var(--text);
}

.button-ghost {
  background: transparent;
  border-color: var(--line);
  color: var(--muted);
}

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

.scoreboard {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  align-items: stretch;
  margin-bottom: 14px;
}

.score-card {
  min-height: 76px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  background: var(--surface);
  box-shadow: 0 8px 20px rgba(27, 39, 45, 0.08);
}

.score-card strong {
  display: block;
  font-size: 1.65rem;
  line-height: 1;
}

.progress-track {
  grid-column: 1 / -1;
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(31, 37, 43, 0.1);
}

.progress-bar {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--teal), var(--yellow), var(--coral));
  transition: width 220ms ease;
}

.game-layout {
  display: grid;
  grid-template-columns: minmax(310px, 0.78fr) minmax(0, 1.22fr);
  gap: 14px;
  align-items: start;
}

.play-panel,
.teacher-panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 253, 247, 0.94);
  box-shadow: var(--shadow);
}

.play-panel {
  padding: 14px;
}

.current-card-panel {
  position: sticky;
  top: 14px;
}

.section-title {
  margin-bottom: 12px;
}

.expression-card {
  min-height: 260px;
  display: grid;
  align-content: center;
  gap: 22px;
  border: 2px solid #1f252b;
  border-radius: var(--radius);
  padding: 18px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.78), rgba(255, 255, 255, 0.38)),
    repeating-linear-gradient(0deg, transparent 0, transparent 35px, rgba(8, 116, 102, 0.08) 36px),
    var(--surface-alt);
}

.card-meta {
  display: flex;
  gap: 10px;
  justify-content: space-between;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
  text-transform: uppercase;
}

.expression-text {
  margin: 0;
  overflow-wrap: anywhere;
  text-align: center;
  font-size: 3rem;
  font-weight: 900;
  line-height: 1.08;
}

.tool-row {
  margin-top: 12px;
}

.toggle {
  min-height: 48px;
  display: inline-flex;
  gap: 10px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0 12px;
  background: var(--surface);
  color: var(--text);
  font-weight: 800;
}

.toggle input {
  width: 20px;
  height: 20px;
  accent-color: var(--teal);
}

.feedback {
  min-height: 70px;
  margin-top: 12px;
  padding: 12px;
  border-left: 5px solid var(--blue);
  border-radius: var(--radius);
  background: #eef5fb;
  line-height: 1.45;
  color: #253647;
}

.feedback.success {
  border-left-color: var(--teal);
  background: var(--teal-soft);
}

.feedback.error {
  border-left-color: var(--coral);
  background: var(--coral-soft);
}

.results-grid,
.solutions-table,
.teacher-grid {
  display: grid;
  gap: 10px;
}

.results-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.result-card {
  min-height: 116px;
  display: grid;
  align-content: space-between;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  padding: 12px;
  text-align: left;
  box-shadow: 0 5px 14px rgba(27, 39, 45, 0.06);
  transition:
    transform 150ms ease,
    border-color 150ms ease,
    box-shadow 150ms ease,
    background 150ms ease;
}

.result-card:hover:not(:disabled),
.result-card:focus-visible:not(:disabled) {
  transform: translateY(-2px);
  border-color: rgba(8, 116, 102, 0.5);
  box-shadow: 0 10px 18px rgba(8, 116, 102, 0.12);
  outline: none;
}

.result-card:disabled {
  cursor: default;
}

.result-label {
  display: inline-flex;
  width: fit-content;
  min-width: 34px;
  min-height: 28px;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  background: #edf0f2;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 900;
}

.result-expression {
  font-size: 1.18rem;
  line-height: 1.16;
  overflow-wrap: anywhere;
}

.result-card.is-correct {
  border-color: rgba(8, 116, 102, 0.65);
  background: var(--teal-soft);
}

.result-card.is-wrong {
  border-color: rgba(223, 97, 77, 0.65);
  background: var(--coral-soft);
}

.result-card.is-solved {
  opacity: 0.42;
}

.teacher-panel {
  margin-top: 14px;
  padding: 16px;
}

.teacher-panel.hidden {
  display: none;
}

.teacher-grid {
  grid-template-columns: 300px minmax(0, 1fr);
}

.teacher-list {
  padding-left: 18px;
  line-height: 1.6;
}

.solutions-table {
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
}

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

.solution-row p {
  margin-bottom: 8px;
}

@media (max-width: 980px) {
  .app-header,
  .game-layout,
  .teacher-grid {
    grid-template-columns: 1fr;
  }

  .app-header {
    display: grid;
  }

  .current-card-panel {
    position: static;
  }

  .results-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 680px) {
  .page-shell {
    padding: 12px 10px 28px;
  }

  h1 {
    font-size: 1.55rem;
  }

  .header-actions,
  .tool-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .toggle {
    grid-column: 1 / -1;
  }

  .button,
  .toggle {
    width: 100%;
    justify-content: center;
  }

  .score-card {
    min-height: 64px;
    padding: 10px;
  }

  .score-card strong {
    font-size: 1.35rem;
  }

  .expression-card {
    min-height: 210px;
    gap: 16px;
  }

  .card-meta {
    font-size: 0.74rem;
  }

  .expression-text {
    font-size: 2.35rem;
  }

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

  .result-card {
    min-height: 104px;
    padding: 10px;
  }

  .result-expression {
    font-size: 1.04rem;
  }
}

@media (max-width: 360px) {
  .expression-text {
    font-size: 2.05rem;
  }

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