:root {
  --bg: #f4f7f9;
  --panel: #ffffff;
  --ink: #17202a;
  --muted: #657483;
  --line: #dce5ec;
  --accent: #117864;
  --accent-dark: #0b5345;
  --accent-soft: #d8f3ed;
  --warn: #b03a2e;
  --sun: #f4b942;
  --blue: #2e6f95;
  --shadow: 0 18px 45px rgba(23, 32, 42, 0.11);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Inter", Arial, sans-serif;
  background:
    radial-gradient(circle at top left, rgba(244, 185, 66, 0.2), transparent 34rem),
    linear-gradient(135deg, #f8fbfc 0%, var(--bg) 48%, #eef5f4 100%);
  color: var(--ink);
}

button,
input,
select {
  font: inherit;
}

.app-shell {
  width: min(1120px, calc(100% - 32px));
  margin: 0 auto;
  padding: 32px 0 48px;
}

.intro-panel,
.training-panel,
.result-panel,
.history-panel,
.setup-block {
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.intro-panel {
  display: grid;
  grid-template-columns: 1fr minmax(260px, 340px);
  gap: 28px;
  align-items: end;
  padding: 34px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent-dark);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

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

h1 {
  margin-bottom: 14px;
  font-size: clamp(2.4rem, 6vw, 5rem);
  line-height: 0.95;
}

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

.intro-text {
  max-width: 660px;
  margin-bottom: 0;
  color: var(--muted);
  font-size: 1.08rem;
  line-height: 1.6;
}

.student-box,
.round-options,
.answer-form {
  display: grid;
  gap: 8px;
}

label {
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 700;
}

input,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 13px 14px;
  outline: none;
}

input:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(17, 120, 100, 0.13);
}

.setup-grid {
  display: grid;
  grid-template-columns: 1.35fr 0.8fr;
  gap: 20px;
  margin-top: 20px;
}

.setup-block {
  padding: 24px;
}

.tables-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(60px, 1fr));
  gap: 10px;
}

.table-button {
  min-height: 58px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  font-weight: 800;
  transition: transform 0.16s ease, border-color 0.16s ease, background 0.16s ease;
}

.table-button:hover {
  transform: translateY(-2px);
  border-color: var(--accent);
}

.table-button.is-selected {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent-dark);
}

.operation-options,
.level-options {
  display: grid;
  gap: 8px;
  margin-bottom: 18px;
}

.operation-options {
  grid-template-columns: repeat(2, 1fr);
}

.level-options {
  grid-template-columns: repeat(3, 1fr);
}

.operation-options label,
.level-options label {
  cursor: pointer;
}

.operation-options input,
.level-options input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.operation-options span,
.level-options span {
  display: grid;
  min-height: 46px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
}

.operation-options input:checked + span {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-dark);
  font-weight: 800;
}

.level-options input:checked + span {
  border-color: var(--blue);
  background: #eaf4f8;
  color: #1f5978;
  font-weight: 800;
}

.round-options {
  margin-bottom: 18px;
}

.primary-button,
.secondary-button,
.ghost-button {
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 800;
}

.primary-button {
  width: 100%;
  background: var(--accent);
  color: white;
  padding: 14px 18px;
}

.primary-button:hover {
  background: var(--accent-dark);
}

.secondary-button {
  background: var(--sun);
  color: #3a2c04;
  padding: 14px 18px;
}

.ghost-button {
  background: transparent;
  color: var(--accent-dark);
  padding: 8px 10px;
}

.training-panel,
.result-panel,
.history-panel {
  margin-top: 20px;
  padding: 26px;
}

.training-topbar {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: start;
}

#questionText {
  margin: 0;
  font-size: clamp(2.1rem, 6vw, 4.4rem);
}

.score-card {
  min-width: 110px;
  border-radius: 8px;
  background: #17202a;
  color: #fff;
  padding: 14px;
  text-align: center;
}

.score-card span {
  display: block;
  color: #b9c6ce;
  font-size: 0.78rem;
  font-weight: 700;
}

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

.score-card.score-pop {
  animation: scorePop 0.46s ease both;
}

.progress-track {
  height: 12px;
  margin: 24px 0;
  overflow: hidden;
  border-radius: 999px;
  background: #e4ebef;
}

.progress-track div {
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), var(--sun));
  transition: width 0.25s ease;
}

.answer-row {
  display: grid;
  grid-template-columns: 1fr 190px;
  gap: 10px;
}

.feedback {
  min-height: 48px;
  margin-top: 16px;
  padding: 13px 14px;
  border-radius: 8px;
  background: #eef3f5;
  color: var(--muted);
  font-weight: 700;
  position: relative;
  overflow: hidden;
  transform-origin: center;
}

.feedback.is-correct {
  background: var(--accent-soft);
  color: var(--accent-dark);
  box-shadow: 0 0 0 1px rgba(17, 120, 100, 0.16) inset;
}

.feedback.is-wrong {
  background: #fdecea;
  color: var(--warn);
  box-shadow: 0 0 0 1px rgba(176, 58, 46, 0.16) inset;
}

.feedback.is-correct::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(100deg, transparent 0%, rgba(255, 255, 255, 0.72) 45%, transparent 70%);
  transform: translateX(-115%);
}

.feedback-correct-pop {
  animation: correctPop 0.52s cubic-bezier(0.2, 0.9, 0.25, 1.2) both;
}

.feedback-correct-pop::after {
  animation: successShine 0.52s ease both;
}

.feedback-wrong-shake {
  animation: wrongShake 0.42s ease both;
}

.question-correct {
  animation: questionCorrect 0.48s ease both;
}

.question-wrong {
  animation: questionWrong 0.38s ease both;
}

.answer-error {
  animation: inputWrong 0.42s ease both;
}

@keyframes correctPop {
  0% {
    transform: scale(0.98);
  }

  55% {
    transform: scale(1.025);
  }

  100% {
    transform: scale(1);
  }
}

@keyframes successShine {
  0% {
    transform: translateX(-115%);
  }

  100% {
    transform: translateX(115%);
  }
}

@keyframes wrongShake {
  0%,
  100% {
    transform: translateX(0);
  }

  20% {
    transform: translateX(-8px);
  }

  40% {
    transform: translateX(7px);
  }

  60% {
    transform: translateX(-5px);
  }

  80% {
    transform: translateX(3px);
  }
}

@keyframes questionCorrect {
  0% {
    color: var(--ink);
    transform: scale(1);
  }

  45% {
    color: var(--accent-dark);
    transform: scale(1.035);
  }

  100% {
    color: var(--ink);
    transform: scale(1);
  }
}

@keyframes questionWrong {
  0%,
  100% {
    color: var(--ink);
    transform: translateX(0);
  }

  30% {
    color: var(--warn);
    transform: translateX(-5px);
  }

  60% {
    color: var(--warn);
    transform: translateX(4px);
  }
}

@keyframes inputWrong {
  0%,
  100% {
    border-color: var(--line);
    box-shadow: none;
  }

  45% {
    border-color: var(--warn);
    box-shadow: 0 0 0 4px rgba(176, 58, 46, 0.13);
  }
}

@keyframes scorePop {
  0% {
    transform: scale(1);
  }

  45% {
    transform: scale(1.08);
    background: var(--accent-dark);
  }

  100% {
    transform: scale(1);
  }
}

@media (prefers-reduced-motion: reduce) {
  .score-card.score-pop,
  .feedback-correct-pop,
  .feedback-correct-pop::after,
  .feedback-wrong-shake,
  .question-correct,
  .question-wrong,
  .answer-error {
    animation: none;
  }
}

.result-panel {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 20px;
  align-items: start;
}

.result-actions {
  display: grid;
  gap: 10px;
  min-width: 210px;
}

.review-list {
  grid-column: 1 / -1;
  display: grid;
  gap: 8px;
}

.report-panel {
  grid-column: 1 / -1;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fbfc;
  padding: 18px;
}

.report-heading {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: start;
}

.report-heading h3 {
  margin: 0;
  font-size: 1.12rem;
}

.report-heading strong {
  display: grid;
  min-width: 76px;
  min-height: 54px;
  place-items: center;
  border-radius: 8px;
  background: var(--accent-dark);
  color: #fff;
  font-size: 1.3rem;
}

.report-recommendation {
  margin: 14px 0;
  color: var(--ink);
  font-weight: 700;
  line-height: 1.5;
}

.report-list {
  display: grid;
  gap: 8px;
}

.report-item {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  border-radius: 8px;
  background: #fff;
  padding: 11px 12px;
}

.review-item,
.history-item {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 12px 14px;
}

.review-item strong,
.history-item strong {
  color: var(--accent-dark);
}

.history-heading {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
}

.history-heading h2 {
  margin-bottom: 0;
}

.history-list {
  display: grid;
  gap: 8px;
  margin-top: 16px;
}

.empty-state {
  margin: 0;
  color: var(--muted);
}

.is-hidden {
  display: none;
}

@media (max-width: 820px) {
  .intro-panel,
  .setup-grid,
  .result-panel {
    grid-template-columns: 1fr;
  }

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

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

  .training-topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .score-card {
    width: 100%;
  }
}

@media (max-width: 520px) {
  .app-shell {
    width: min(100% - 20px, 1120px);
    padding-top: 10px;
  }

  .intro-panel,
  .setup-block,
  .training-panel,
  .result-panel,
  .history-panel {
    padding: 18px;
  }

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

  .level-options {
    grid-template-columns: 1fr;
  }

  .operation-options {
    grid-template-columns: 1fr;
  }
}
