:root {
  color-scheme: light;
  --ink: #10213f;
  --muted: #64718c;
  --blue: #2767ff;
  --blue-dark: #1853e6;
  --blue-soft: #eaf1ff;
  --line: #cbd7ea;
  --surface: #ffffff;
  --page: #f5f8ff;
  --green: #0f9f68;
  --green-soft: #e9f9f2;
  --red: #cf3f53;
  --red-soft: #fff0f2;
  --amber: #9a6500;
  --amber-soft: #fff5d9;
  --shadow: 0 24px 70px rgba(47, 72, 121, 0.11);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--page);
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at 88% 4%, rgba(39, 103, 255, 0.09), transparent 30rem),
    linear-gradient(140deg, #fbfdff 0%, var(--page) 56%, #eef4ff 100%);
}

button,
input,
select {
  font: inherit;
}

button,
select {
  cursor: pointer;
}

button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 3px solid rgba(39, 103, 255, 0.3);
  outline-offset: 3px;
}

.page-shell {
  width: min(1540px, 100%);
  margin: 0 auto;
  padding: clamp(1.5rem, 3.6vw, 3.5rem);
}

.page-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 2rem;
}

.heading-copy {
  max-width: 72rem;
}

.eyebrow {
  margin: 0 0 0.8rem;
  color: var(--blue);
  font-size: 0.95rem;
  font-weight: 850;
  letter-spacing: 0.16em;
}

h1,
h2,
h3,
p {
  text-wrap: pretty;
}

h1 {
  margin: 0;
  font-size: clamp(2.7rem, 6vw, 6.2rem);
  line-height: 0.96;
  letter-spacing: -0.06em;
  font-weight: 850;
}

.subheading {
  margin: 1.25rem 0 0;
  color: var(--muted);
  font-size: clamp(1rem, 1.55vw, 1.45rem);
  line-height: 1.5;
}

.header-actions {
  display: flex;
  gap: 0.75rem;
  flex: 0 0 auto;
  padding-bottom: 0.35rem;
}

.button {
  min-height: 3.15rem;
  border-radius: 0.9rem;
  border: 1px solid transparent;
  padding: 0.8rem 1.25rem;
  font-weight: 780;
  color: var(--ink);
  background: transparent;
  transition: transform 150ms ease, background 150ms ease, border-color 150ms ease, box-shadow 150ms ease;
}

.button:hover {
  transform: translateY(-1px);
}

.button:active {
  transform: translateY(0);
}

.button-secondary {
  border-color: var(--line);
  background: rgba(255, 255, 255, 0.78);
}

.button-secondary:hover,
.button-ghost:hover {
  border-color: #aebed8;
  background: #fff;
}

.button-ghost {
  border-color: transparent;
  color: #384969;
}

.button-primary {
  color: #fff;
  background: var(--blue);
  box-shadow: 0 10px 24px rgba(39, 103, 255, 0.2);
}

.button-primary:hover {
  background: var(--blue-dark);
  box-shadow: 0 12px 28px rgba(39, 103, 255, 0.27);
}

.button-success {
  color: #fff;
  background: var(--green);
  box-shadow: 0 10px 24px rgba(15, 159, 104, 0.2);
}

.control-bar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1.5rem;
  margin: clamp(2rem, 4vw, 3.8rem) 0 1.25rem;
}

.select-wrap {
  display: grid;
  gap: 0.55rem;
  color: var(--muted);
  font-size: 0.95rem;
  font-weight: 750;
}

.select-wrap select,
.field select {
  appearance: none;
  min-width: 18rem;
  border: 1px solid var(--line);
  border-radius: 0.85rem;
  padding: 0.82rem 2.8rem 0.82rem 1rem;
  color: var(--ink);
  background-color: #fff;
  background-image:
    linear-gradient(45deg, transparent 50%, #445575 50%),
    linear-gradient(135deg, #445575 50%, transparent 50%);
  background-position:
    calc(100% - 1.18rem) 50%,
    calc(100% - 0.86rem) 50%;
  background-size: 0.34rem 0.34rem, 0.34rem 0.34rem;
  background-repeat: no-repeat;
  font-size: 1.05rem;
}

.scoreboard {
  display: flex;
  align-items: flex-end;
  gap: 1.75rem;
}

.scoreboard > div {
  display: grid;
  gap: 0.15rem;
  min-width: 4.5rem;
}

.scoreboard span {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.scoreboard strong {
  font-size: 1.25rem;
}

.question-number {
  margin: 0 0 0.05rem;
  color: var(--muted);
  font-size: 1.05rem;
  font-weight: 720;
}

.practice-card {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: clamp(1.4rem, 2.5vw, 2.2rem);
  padding: clamp(1.5rem, 4vw, 3.8rem);
  background: rgba(255, 255, 255, 0.96);
  box-shadow: var(--shadow);
}

.practice-card::before {
  position: absolute;
  inset: 0 0 auto;
  height: 0.28rem;
  content: "";
  background: linear-gradient(90deg, var(--blue), #55a4ff 50%, #7b63ff);
}

.question-topline {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
}

.question-kicker {
  margin: 0 0 0.45rem;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.09em;
}

.question-topline h2 {
  margin: 0;
  font-size: clamp(1.7rem, 3.3vw, 3.2rem);
  line-height: 1.08;
  letter-spacing: -0.035em;
}

.level-badge {
  flex: 0 0 auto;
  border-radius: 999px;
  padding: 0.5rem 0.85rem;
  color: var(--amber);
  background: var(--amber-soft);
  font-size: 0.9rem;
  font-weight: 800;
}

.level-badge[data-level="Standard"] {
  color: #1c5fbe;
  background: #e8f2ff;
}

.level-badge[data-level="Challenge"] {
  color: #6940b8;
  background: #f1ebff;
}

.level-badge[data-level="Custom"] {
  color: #2c6270;
  background: #e8f6f8;
}

.formula-workspace {
  display: grid;
  grid-template-columns: minmax(18rem, 0.9fr) minmax(22rem, 1.25fr);
  align-items: stretch;
  gap: clamp(1.5rem, 4vw, 4.25rem);
  margin: clamp(2rem, 4vw, 3.7rem) 0;
}

.building-blocks {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(0.75rem, 2vw, 1.4rem);
  min-height: 10rem;
  border: 1px solid #d9e4f4;
  border-radius: 1.4rem;
  padding: 1.5rem;
  background:
    linear-gradient(#edf3ff 1px, transparent 1px),
    linear-gradient(90deg, #edf3ff 1px, transparent 1px),
    #f9fbff;
  background-size: 1.5rem 1.5rem;
}

.ion-card {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 5.3rem;
  min-height: 5.3rem;
  border: 2px solid #a9bee2;
  border-radius: 1rem;
  padding: 0.75rem;
  color: var(--ink);
  background: #fff;
  box-shadow: 0 8px 18px rgba(44, 71, 120, 0.09);
}

.ion-card .symbol {
  font-size: clamp(1.65rem, 3vw, 2.5rem);
  font-weight: 820;
  line-height: 1;
}

.ion-card .charge {
  position: absolute;
  top: 0.42rem;
  right: 0.5rem;
  color: var(--blue);
  font-size: 0.78rem;
  font-weight: 850;
}

.ion-card small {
  position: absolute;
  top: calc(100% + 0.45rem);
  width: max-content;
  max-width: 7.5rem;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
  text-align: center;
}

.join-symbol {
  color: #8191ae;
  font-size: 2rem;
  font-weight: 700;
}

.custom-clue {
  color: var(--ink);
  font-size: clamp(1.35rem, 3vw, 2.4rem);
  font-weight: 760;
  text-align: center;
}

.custom-clue sub,
.custom-clue sup,
.formula-preview sub,
.formula-preview sup {
  font-size: 0.62em;
}

.answer-area {
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.answer-area > label {
  margin-bottom: 0.6rem;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.answer-row {
  display: grid;
  grid-template-columns: minmax(12rem, 1fr) minmax(8rem, 0.7fr);
  gap: 0.85rem;
}

.formula-input-wrap {
  display: flex;
  min-height: 5rem;
  border: 2px solid #b9c8df;
  border-radius: 1rem;
  background: #fff;
  transition: border-color 150ms ease, box-shadow 150ms ease;
}

.formula-input-wrap:focus-within {
  border-color: var(--blue);
  box-shadow: 0 0 0 5px rgba(39, 103, 255, 0.1);
}

.formula-input-wrap input {
  min-width: 0;
  width: 100%;
  border: 0;
  outline: 0;
  border-radius: inherit;
  padding: 0.75rem 1.1rem;
  color: var(--ink);
  background: transparent;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: clamp(1.45rem, 2.7vw, 2.15rem);
  font-weight: 760;
}

.formula-input-wrap input::placeholder {
  color: #a2aec2;
  font-family: inherit;
  font-size: 0.72em;
  font-weight: 600;
}

.formula-input-wrap.is-correct {
  border-color: var(--green);
  box-shadow: 0 0 0 5px rgba(15, 159, 104, 0.1);
}

.formula-input-wrap.is-wrong {
  border-color: var(--red);
  animation: shake 260ms ease-in-out;
}

.formula-preview {
  display: grid;
  place-items: center;
  align-content: center;
  min-height: 5rem;
  border: 1px solid #d7e2f1;
  border-radius: 1rem;
  padding: 0.55rem 0.85rem;
  background: #f7faff;
}

.formula-preview span {
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

.formula-preview strong {
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1.65rem, 3vw, 2.45rem);
  font-weight: 700;
}

.entry-help {
  margin: 0.7rem 0 0;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.5;
}

.feedback {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  min-height: 4.2rem;
  border: 1px solid #d5e0ef;
  border-radius: 1rem;
  padding: 0.85rem 1rem;
  background: #f7faff;
}

.feedback p {
  margin: 0;
  color: #53627e;
  font-size: 1rem;
  line-height: 1.45;
}

.feedback-icon {
  display: grid;
  flex: 0 0 auto;
  place-items: center;
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  color: #fff;
  background: #8493ad;
  font-family: Georgia, serif;
  font-size: 1rem;
  font-weight: 800;
}

.feedback-success {
  border-color: #bfe9d8;
  background: var(--green-soft);
}

.feedback-success p {
  color: #096845;
}

.feedback-success .feedback-icon {
  background: var(--green);
}

.feedback-error {
  border-color: #f1c4cb;
  background: var(--red-soft);
}

.feedback-error p {
  color: #9f293c;
}

.feedback-error .feedback-icon {
  background: var(--red);
}

.feedback-hint {
  border-color: #f0dca5;
  background: var(--amber-soft);
}

.feedback-hint p {
  color: #79510a;
}

.feedback-hint .feedback-icon {
  background: #b77a0a;
}

.card-actions,
.left-actions,
.right-actions,
.modal-actions {
  display: flex;
  align-items: center;
  gap: 0.7rem;
}

.card-actions {
  justify-content: space-between;
  margin-top: 1.4rem;
}

.keyboard-note {
  margin: 1rem 0 0;
  color: #8190aa;
  font-size: 0.82rem;
  text-align: center;
}

kbd {
  border: 1px solid #c4d0e0;
  border-bottom-width: 2px;
  border-radius: 0.35rem;
  padding: 0.08rem 0.38rem;
  color: #4b5c78;
  background: #fff;
  font-family: inherit;
  font-size: 0.78rem;
}

.is-hidden {
  display: none !important;
}

.modal {
  width: 100%;
  max-width: none;
  height: 100%;
  max-height: none;
  border: 0;
  padding: 1rem;
  background: transparent;
}

.modal[open] {
  display: grid;
  place-items: center;
}

.modal::backdrop {
  background: rgba(9, 22, 48, 0.55);
  backdrop-filter: blur(8px);
}

.modal-panel {
  width: min(55rem, calc(100vw - 2rem));
  max-height: calc(100vh - 2rem);
  overflow: auto;
  border: 1px solid #d4deed;
  border-radius: 1.6rem;
  padding: clamp(1.25rem, 3vw, 2rem);
  background: #fff;
  box-shadow: 0 32px 90px rgba(8, 25, 58, 0.28);
}

.reference-panel {
  width: min(64rem, calc(100vw - 2rem));
}

.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.6rem;
}

.modal-header h2 {
  margin: 0;
  font-size: clamp(1.75rem, 4vw, 2.6rem);
  letter-spacing: -0.04em;
}

.icon-button {
  display: grid;
  flex: 0 0 auto;
  place-items: center;
  width: 2.7rem;
  height: 2.7rem;
  border: 1px solid var(--line);
  border-radius: 50%;
  color: #4c5c78;
  background: #fff;
  font-size: 1.55rem;
  line-height: 1;
}

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

.guide-section {
  border: 1px solid #d9e3f2;
  border-radius: 1.15rem;
  padding: 1.15rem;
  background: #f9fbff;
}

.guide-section-wide {
  grid-column: 1 / -1;
}

.guide-section h3 {
  margin: 0 0 0.9rem;
  font-size: 1.05rem;
}

.guide-section p {
  margin: 0.85rem 0 0;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.5;
}

.charge-row {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 0.4rem;
}

.charge-row span {
  display: grid;
  place-items: center;
  border: 1px solid #cbd9ee;
  border-radius: 0.7rem;
  padding: 0.55rem 0.35rem;
  color: var(--ink);
  background: #fff;
}

.charge-row small {
  color: var(--blue);
  font-weight: 800;
}

.reference-table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

th,
td {
  border-bottom: 1px solid #dfe7f2;
  padding: 0.55rem;
  text-align: left;
  white-space: nowrap;
}

th {
  color: #53627e;
}

td {
  color: var(--ink);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1rem;
  font-weight: 700;
}

.prefixes {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0.45rem;
}

.prefixes span {
  display: flex;
  justify-content: space-between;
  gap: 0.4rem;
  border: 1px solid #d4e0f1;
  border-radius: 0.65rem;
  padding: 0.55rem 0.65rem;
  color: var(--blue);
  background: #fff;
  font-size: 0.82rem;
  font-weight: 750;
}

.prefixes b {
  color: var(--ink);
}

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

.field {
  display: grid;
  gap: 0.45rem;
}

.field-wide {
  grid-column: 1 / -1;
}

.field > span {
  color: #53627e;
  font-size: 0.87rem;
  font-weight: 780;
}

.field input,
.field select {
  width: 100%;
  min-width: 0;
  min-height: 3.2rem;
  border: 1px solid #c5d2e5;
  border-radius: 0.8rem;
  padding: 0.75rem 0.9rem;
  color: var(--ink);
  background-color: #fff;
}

.form-note {
  margin: 1rem 0 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.modal-actions {
  justify-content: flex-end;
  margin-top: 1.4rem;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  30% { transform: translateX(-5px); }
  65% { transform: translateX(5px); }
}

@media (max-width: 900px) {
  .page-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .header-actions {
    width: 100%;
  }

  .header-actions .button {
    flex: 1;
  }

  .formula-workspace {
    grid-template-columns: 1fr;
  }

  .building-blocks {
    min-height: 9rem;
  }
}

@media (max-width: 680px) {
  .page-shell {
    padding: 1rem;
  }

  h1 {
    font-size: clamp(2.55rem, 14vw, 4.5rem);
  }

  .header-actions {
    flex-direction: column;
  }

  .control-bar {
    align-items: stretch;
    flex-direction: column;
    margin-top: 2rem;
  }

  .select-wrap select {
    width: 100%;
    min-width: 0;
  }

  .scoreboard {
    justify-content: space-between;
    gap: 0.75rem;
  }

  .scoreboard > div {
    min-width: 0;
  }

  .practice-card {
    padding: 1.25rem;
    border-radius: 1.3rem;
  }

  .formula-workspace {
    gap: 1.4rem;
    margin: 1.6rem 0;
  }

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

  .formula-preview {
    min-height: 4.2rem;
  }

  .card-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .left-actions,
  .right-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .right-actions .button:only-child {
    grid-column: 1 / -1;
  }

  .keyboard-note {
    display: none;
  }

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

  .field-wide,
  .guide-section-wide {
    grid-column: auto;
  }

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

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

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
