:root {
  --ink: #182026;
  --muted: #65717b;
  --paper: #fbf8f1;
  --panel: #ffffff;
  --line: #d8dedb;
  --teal: #16847f;
  --teal-dark: #0e5f5b;
  --coral: #e85d4f;
  --amber: #f2b842;
  --green: #2f8f5b;
  --shadow: 0 18px 50px rgba(24, 32, 38, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  background:
    linear-gradient(135deg, rgba(22, 132, 127, 0.12), transparent 34%),
    linear-gradient(315deg, rgba(232, 93, 79, 0.12), transparent 31%),
    var(--paper);
}

button,
input {
  font: inherit;
}

button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: #fff;
  cursor: pointer;
  transition:
    transform 160ms ease,
    border-color 160ms ease,
    background 160ms ease,
    color 160ms ease;
}

button:hover {
  transform: translateY(-1px);
  border-color: var(--teal);
}

button:focus-visible,
input:focus-visible {
  outline: 3px solid rgba(22, 132, 127, 0.22);
  outline-offset: 2px;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 24px;
  width: min(1120px, calc(100% - 32px));
  margin: 0 auto;
  padding: 32px 0;
}

.practice,
.controls {
  min-width: 0;
}

.brand-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 18px;
}

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

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

h1 {
  margin-bottom: 0;
  font-size: clamp(2.2rem, 7vw, 5.2rem);
  line-height: 0.92;
}

h2 {
  margin-bottom: 12px;
  font-size: 1rem;
}

.score-pill {
  display: grid;
  place-items: center;
  width: 82px;
  height: 82px;
  border: 2px solid var(--ink);
  border-radius: 50%;
  background: var(--amber);
  box-shadow: 6px 6px 0 var(--ink);
}

.score-pill span {
  font-size: 1.7rem;
  font-weight: 900;
  line-height: 1;
}

.score-pill small,
.stats small {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
}

.challenge-panel,
.controls,
.control-section,
.stats {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.88);
  box-shadow: var(--shadow);
}

.challenge-panel {
  position: relative;
  overflow: hidden;
  padding: clamp(18px, 4vw, 34px);
}

.challenge-panel::before {
  position: absolute;
  inset: auto 24px 20px auto;
  width: 160px;
  height: 160px;
  border: 2px solid rgba(24, 32, 38, 0.12);
  background:
    linear-gradient(var(--line) 1px, transparent 1px),
    linear-gradient(90deg, var(--line) 1px, transparent 1px);
  background-size: 40px 40px;
  content: "";
  transform: rotate(-7deg);
}

.timer-row,
.timer-copy,
.section-title,
.quick-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.timer-row {
  position: relative;
  z-index: 1;
}

.timer-row strong {
  font-size: 1.1rem;
}

.mode-badge,
.square-badge {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 0 12px;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 900;
}

.mode-badge {
  color: #fff;
  background: var(--teal-dark);
}

.square-badge {
  color: var(--ink);
  background: var(--amber);
}

.timer-track {
  position: relative;
  z-index: 1;
  height: 12px;
  margin: 18px 0 30px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #eef2ef;
}

.timer-track span {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--green), var(--amber), var(--coral));
  transform-origin: left center;
}

.problem {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: clamp(12px, 3vw, 28px);
  min-height: 190px;
  text-align: center;
}

.problem span:not(.operator) {
  display: grid;
  place-items: center;
  width: 100%;
  min-width: 0;
  min-height: clamp(110px, 19vw, 180px);
  border: 2px solid var(--ink);
  border-radius: 8px;
  font-size: clamp(4.4rem, 15vw, 9.5rem);
  font-weight: 950;
  line-height: 1;
  background: #fff;
  box-shadow: 10px 10px 0 rgba(24, 32, 38, 0.18);
}

.operator {
  color: var(--coral);
  font-size: clamp(2.4rem, 8vw, 5rem);
  font-weight: 950;
}

.answer-form {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 150px;
  gap: 12px;
  margin-top: 22px;
}

.answer-form input {
  min-width: 0;
  height: 58px;
  border: 2px solid var(--ink);
  border-radius: 8px;
  padding: 0 16px;
  font-size: 1.5rem;
  font-weight: 900;
  background: #fff;
}

.answer-form button,
.table-grid button.active,
#hardTablesButton.active {
  border-color: var(--teal-dark);
  color: #fff;
  background: var(--teal-dark);
}

.feedback {
  position: relative;
  z-index: 1;
  min-height: 24px;
  margin: 16px 0 0;
  color: var(--muted);
  font-weight: 700;
}

.feedback.correct {
  color: var(--green);
}

.feedback.missed {
  color: var(--coral);
}

.controls {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 14px;
}

.control-section,
.stats {
  padding: 16px;
  box-shadow: none;
}

.section-title h2 {
  margin-bottom: 0;
}

.section-title button,
.quick-actions button {
  padding: 0 14px;
  font-weight: 800;
}

.table-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin-top: 14px;
}

.table-grid button {
  width: 100%;
  aspect-ratio: 1;
  min-height: 0;
  font-weight: 950;
}

.table-grid button.priority {
  border-color: rgba(232, 93, 79, 0.72);
  background: #fff7ed;
}

.table-grid button.priority.active {
  border-color: var(--coral);
  background: var(--coral);
}

.quick-actions {
  margin-top: 12px;
}

.quick-actions button {
  flex: 1;
}

.duration-control {
  display: grid;
  grid-template-columns: 48px 1fr 48px;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}

.duration-control span {
  display: grid;
  place-items: center;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  font-size: 1.25rem;
}

.toggle-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 32px;
  color: var(--ink);
  font-weight: 800;
}

.toggle-row + .toggle-row {
  margin-top: 8px;
}

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

.memory-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 800;
}

.memory-row strong {
  color: var(--ink);
}

.memory-row button {
  min-height: 34px;
  padding: 0 12px;
  font-size: 0.85rem;
  font-weight: 800;
}

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

.stats div {
  display: grid;
  gap: 4px;
  min-height: 74px;
  place-items: center;
  border-radius: 8px;
  background: #f5f7f4;
}

.stats span {
  font-size: 1.5rem;
  font-weight: 950;
}

.square-mode .problem span:not(.operator) {
  animation: square-pop 560ms cubic-bezier(0.18, 0.89, 0.32, 1.28);
  background: #fff3bf;
  box-shadow: 10px 10px 0 rgba(242, 184, 66, 0.55);
}

.answer-flash {
  animation: answer-flash 360ms ease;
}

@keyframes square-pop {
  0% {
    transform: scale(0.9) rotate(-2deg);
  }
  55% {
    transform: scale(1.05) rotate(1deg);
  }
  100% {
    transform: scale(1) rotate(0);
  }
}

@keyframes answer-flash {
  0% {
    transform: translateY(0);
  }
  35% {
    transform: translateY(-4px);
  }
  100% {
    transform: translateY(0);
  }
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

@media (max-width: 860px) {
  .app-shell {
    grid-template-columns: 1fr;
    padding: 18px 0;
  }

  .problem {
    grid-template-columns: minmax(0, 1fr) 34px minmax(0, 1fr);
    min-height: 140px;
    gap: 8px;
  }

  .problem span:not(.operator) {
    min-height: 94px;
    font-size: clamp(3.4rem, 18vw, 4.8rem);
    box-shadow: 6px 6px 0 rgba(24, 32, 38, 0.18);
  }

  .operator {
    font-size: 3rem;
  }

  .table-grid {
    grid-template-columns: repeat(6, minmax(42px, 1fr));
  }
}

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

  .brand-row {
    align-items: flex-start;
  }

  .score-pill {
    width: 66px;
    height: 66px;
    box-shadow: 4px 4px 0 var(--ink);
  }

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

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

}
