@import url("https://fonts.googleapis.com/css2?family=Chivo:wght@400;600;800&family=IBM+Plex+Mono:wght@400;500&display=swap");

:root {
  --paper: #060c16;
  --ink: #e9f3ff;
  --text-soft: #9ab0ca;
  --accent: #00d8ff;
  --accent-soft: #10263b;
  --brand: #4dffb8;
  --brand-soft: #163945;
  --warning: #f59e0b;
  --danger: #ef4444;
  --panel-bg: rgba(9, 19, 34, 0.86);
  --panel-border: rgba(0, 216, 255, 0.25);
  --surface: #101d30;
  --surface-elevated: #162741;
  --surface-soft: #1d3553;
  --radius: 18px;
  --shadow: 0 14px 30px rgba(0, 0, 0, 0.5);
  
  /* Safe area support for iOS notch/dynamic island */
  --safe-area-top: env(safe-area-inset-top, 0px);
  --safe-area-bottom: env(safe-area-inset-bottom, 0px);
  --safe-area-left: env(safe-area-inset-left, 0px);
  --safe-area-right: env(safe-area-inset-right, 0px);
}

@supports (top: constant(safe-area-inset-top)) {
  :root {
    --safe-area-top: constant(safe-area-inset-top);
    --safe-area-bottom: constant(safe-area-inset-bottom);
    --safe-area-left: constant(safe-area-inset-left);
    --safe-area-right: constant(safe-area-inset-right);
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: "Chivo", "Segoe UI", sans-serif;
  color: var(--ink);
  background-color: transparent;
  overflow-x: hidden;
  scrollbar-width: none; /* Firefox */
}

html::-webkit-scrollbar,
body::-webkit-scrollbar {
  display: none; /* Chrome, Safari, Edge */
}

html {
  background-color: #09111f;
  background-image:
    radial-gradient(circle at 12% 10%, rgba(0, 216, 255, 0.14), transparent 40%),
    radial-gradient(circle at 88% 90%, rgba(77, 255, 184, 0.12), transparent 42%);
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  background-color: #09111f;
  background-image:
    radial-gradient(circle at 12% 10%, rgba(0, 216, 255, 0.14), transparent 40%),
    radial-gradient(circle at 88% 90%, rgba(77, 255, 184, 0.12), transparent 42%);
  user-select: none;
  -webkit-user-select: none;
  position: relative;
  isolation: isolate;
}

#app {
  min-height: 100vh;
  min-height: 100dvh;
}

#challengeField,
#answerField,
#submissionHistory,
#submissionHistory * {
  user-select: text;
  -webkit-user-select: text;
}

body[data-theme="light"] {
  --paper: #eaf4ff;
  --ink: #10243d;
  --text-soft: #4a6281;
  --accent: #068fc2;
  --accent-soft: #d8ecfb;
  --brand: #1aa8ff;
  --brand-soft: #c4ebff;
  --panel-bg: rgba(255, 255, 255, 0.94);
  --panel-border: rgba(16, 96, 146, 0.28);
  --surface: #f4faff;
  --surface-elevated: #ffffff;
  --surface-soft: #e2f2ff;
  --shadow: 0 12px 22px rgba(18, 59, 92, 0.16);
  background-color: #e8f4ff;
  background-image:
    radial-gradient(circle at 15% 12%, rgba(26, 168, 255, 0.18), transparent 38%),
    radial-gradient(circle at 86% 82%, rgba(77, 255, 184, 0.14), transparent 38%);
}

html[data-theme="light"] {
  background-color: #e8f4ff;
  background-image:
    radial-gradient(circle at 15% 12%, rgba(26, 168, 255, 0.18), transparent 38%),
    radial-gradient(circle at 86% 82%, rgba(77, 255, 184, 0.14), transparent 38%);
}

body[data-theme="light"] .panel {
  border-width: 2px;
  border-color: rgba(16, 96, 146, 0.36);
}

#app {
  max-width: 1100px;
  margin: 0 auto;
  padding:
    max(30px, calc(var(--safe-area-top) + 12px))
    calc(18px + var(--safe-area-right))
    calc(36px + var(--safe-area-bottom))
    calc(18px + var(--safe-area-left));
}

.shell {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: 16px;
  animation: rise 420ms ease-out;
}

.panel {
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(6px);
  padding: 18px;
}

.hero-controls {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: stretch;
}

.hero-controls .mode-toggle {
  min-width: 124px;
  background: var(--surface);
  border-color: color-mix(in srgb, var(--accent) 46%, var(--panel-border) 54%);
  border-width: 1px;
  color: var(--ink);
  box-shadow: none;
}

.hero-controls .mode-toggle .mode-divider {
  color: color-mix(in srgb, var(--ink) 48%, transparent);
}

body[data-theme="light"] .hero-controls .mode-toggle {
  background: var(--surface);
  border-color: rgba(12, 130, 180, 0.52);
  border-width: 2px;
  color: var(--ink);
  font-weight: 700;
  box-shadow: 0 0 0 1px rgba(12, 130, 180, 0.2);
}

body[data-theme="light"] .hero-controls .mode-toggle .mode-divider {
  color: color-mix(in srgb, var(--ink) 62%, transparent);
}

.hero {
  grid-column: span 12;
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: clamp(14px, 3vw, 28px);
  background: linear-gradient(130deg, #0a2d56 0%, #1178a5 55%, #0ea27f 100%);
  border-color: rgba(0, 216, 255, 0.45);
  box-shadow:
    0 14px 28px rgba(0, 0, 0, 0.4),
    0 0 0 1px rgba(0, 216, 255, 0.24),
    0 0 30px rgba(0, 216, 255, 0.22);
}

body[data-theme="light"] .hero {
  background: linear-gradient(130deg, #caedff 0%, #a8ddff 54%, #cbffe9 100%);
  border-color: rgba(12, 130, 180, 0.44);
  box-shadow:
    0 10px 22px rgba(20, 54, 82, 0.16),
    0 0 0 1px rgba(12, 130, 180, 0.24);
}

.hero-copy {
  flex: 1 1 auto;
  min-width: 0;
}

.hero-logo {
  flex: 0 0 auto;
  width: clamp(64px, 10vw, 116px);
  max-width: 24%;
  height: auto;
  object-fit: contain;
  filter: drop-shadow(0 10px 14px rgba(0, 0, 0, 0.28));
}

.hero-logo-light {
  display: none;
}



.eyebrow {
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 0.78rem;
  color: #95f8ff;
}

.hero h1 {
  margin: 8px 0 4px;
  font-size: clamp(2rem, 3.4vw, 3rem);
  letter-spacing: 0.01em;
}

.subtitle {
  margin: 0;
  max-width: 760px;
  font-size: 1.02rem;
  line-height: 1.45;
}

.challenge {
  grid-column: span 12;
}

.answer {
  grid-column: span 12;
}

.feedback {
  grid-column: span 12;
}

h2 {
  margin: 0 0 12px;
  font-size: 1.1rem;
}

.challenge-title-short {
  display: none;
}

.tile-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.tile-head h2 {
  margin: 0;
}

.tile-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.notation-inline {
  display: flex;
  align-items: center;
  gap: 8px;
}

.notation-inline label {
  font-size: 0.84rem;
  color: var(--text-soft);
  margin: 0;
}

.mode-toggle {
  min-width: 124px;
  border-radius: 12px;
  border: 1px solid color-mix(in srgb, var(--accent) 46%, var(--panel-border) 54%);
  padding: 7px 9px;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.84rem;
  background: var(--surface);
  color: var(--ink);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
}

.mode-toggle .mode-divider {
  color: color-mix(in srgb, var(--ink) 48%, transparent);
}

body[data-theme="light"] .mode-toggle .mode-divider {
  color: color-mix(in srgb, var(--ink) 62%, transparent);
}

.mode-toggle.mode-aqa-active .mode-aqa,
.mode-toggle.mode-ocr-active .mode-ocr {
  color: var(--ink);
}

.mode-toggle.mode-aqa-active .mode-ocr,
.mode-toggle.mode-ocr-active .mode-aqa {
  color: color-mix(in srgb, var(--ink) 40%, transparent);
}

body[data-theme="light"] .mode-toggle.mode-aqa-active .mode-ocr,
body[data-theme="light"] .mode-toggle.mode-ocr-active .mode-aqa,
.mode-toggle.theme-dark-active .theme-light,
.mode-toggle.theme-light-active .theme-dark {
  color: color-mix(in srgb, var(--text-soft) 72%, transparent);
}

.mode-toggle.theme-dark-active .theme-dark,
.mode-toggle.theme-light-active .theme-light {
  color: var(--ink);
}

body[data-theme="light"] .eyebrow {
  color: #0e6f93;
}

.copyright {
  grid-column: 1 / -1;
  justify-self: center;
  margin: 0;
  text-align: center;
  color: var(--ink);
  font-size: 0.92rem;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.more-link {
  grid-column: 1 / -1;
  justify-self: center;
  margin: -8px 0 0;
  text-align: center;
  color: var(--ink);
  font-size: 0.9rem;
  white-space: nowrap;
}

.more-link a {
  color: var(--ink);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.more-link a:hover {
  color: var(--accent);
}

#notationHelp {
  margin-top: 0;
}

.control-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

label {
  font-size: 0.92rem;
  font-weight: 600;
}

select {
  border-radius: 12px;
  border: 1px solid color-mix(in srgb, var(--panel-border) 84%, transparent);
  padding: 9px 10px;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.9rem;
  background: var(--surface);
  color: var(--ink);
}

.worksheet-title-input {
  border-radius: 12px;
  border: 1px solid color-mix(in srgb, var(--panel-border) 84%, transparent);
  padding: 9px 10px;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.9rem;
  background: var(--surface);
  color: var(--ink);
}

.notation-help {
  margin: 10px 0 14px;
  font-size: 0.88rem;
  color: var(--text-soft);
  line-height: 1.35;
}

math-field {
  width: 100%;
  border-radius: 12px;
  border: 1px solid color-mix(in srgb, var(--panel-border) 92%, transparent);
  background: var(--surface);
  color: var(--ink);
  --caret-color: var(--brand);
  --selection-background-color: color-mix(in srgb, var(--brand) 34%, transparent);
}

body[data-theme="light"] math-field {
  border-width: 2px;
  border-color: rgba(16, 96, 146, 0.38);
}

#challengeField {
  --adaptive-scale: 1;
  min-height: 88px;
  padding: 12px;
  font-size: calc(1.45rem * var(--adaptive-scale));
  text-align: center;
  background: color-mix(in srgb, var(--surface) 88%, black 12%);
  border-color: color-mix(in srgb, var(--panel-border) 76%, transparent);
}

body[data-theme="light"] #challengeField {
  border-color: rgba(16, 96, 146, 0.38);
}

#challengeField::part(content) {
  display: block;
  width: fit-content;
  margin-inline: auto;
  text-align: center;
  transform: translateY(1px);
}

body[data-theme="light"] #challengeField,
body[data-theme="light"] #challengeField::part(content) {
  font-weight: 700;
}

#challengeField::part(container) {
  display: flex;
  justify-content: center;
  align-items: center;
}

#challengeField::part(virtual-keyboard-toggle),
#challengeField::part(menu-toggle) {
  display: none;
}

.submission-history {
  margin-top: 10px;
  display: grid;
  gap: 8px;
  overflow-anchor: none;
}

.submission-row {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  min-height: 42px;
  padding: 6px 8px;
  border-radius: 10px;
  border: 1px solid color-mix(in srgb, var(--panel-border) 74%, transparent);
  background: color-mix(in srgb, var(--surface) 78%, black 22%);
}

.equiv-symbol {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.05rem;
  line-height: 1;
  color: var(--text-soft);
}

.submission-item {
  --adaptive-scale: 1;
  min-height: 30px;
  padding: 0;
  font-size: calc(1.02rem * var(--adaptive-scale));
  color: var(--ink);
  border: 0;
  background: transparent;
}

.submission-gate-count {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  color: var(--text-soft);
  background: color-mix(in srgb, var(--panel-border) 50%, transparent);
  padding: 2px 6px;
  border-radius: 6px;
  white-space: nowrap;
  align-self: center;
}

.gate-label-short {
  display: none;
}

@media (max-width: 620px) {
  .gate-label-full { display: none; }
  .gate-label-short { display: inline; }
}

.submission-item::part(container) {
  display: flex;
  align-items: center;
  justify-content: center;
}

.submission-item::part(content) {
  display: block;
  width: fit-content;
  margin-inline: auto;
  text-align: center;
  transform: translateY(1px);
}

body[data-theme="light"] .submission-item,
body[data-theme="light"] .submission-item::part(content) {
  font-weight: 700;
}

.submission-item::part(menu-toggle),
.submission-item::part(virtual-keyboard-toggle),
.submission-item::part(keyboard-toggle) {
  display: none;
}

#answerField::part(menu-toggle) {
  display: none;
}

#hintField {
  min-height: 66px;
  padding: 8px;
}

body[data-theme="light"] #hintField,
body[data-theme="light"] #hintField::part(content) {
  font-weight: 700;
}

#answerField {
  --adaptive-scale: 1;
  min-height: 74px;
  margin-bottom: 10px;
  padding: 8px;
  font-size: calc(1.2rem * var(--adaptive-scale));
  --keyboard-zindex: 9999;
  --contains-highlight-background-color: transparent;
  --answer-border-unfocused: color-mix(in srgb, var(--panel-border) 82%, #ffffff 18%);
  --answer-border-focused: color-mix(in srgb, var(--brand) 68%, #ffffff 32%);
  --answer-glow-unfocused: color-mix(in srgb, var(--panel-border) 34%, transparent);
  --answer-glow-focused: color-mix(in srgb, var(--brand) 36%, transparent);
  background:
    linear-gradient(140deg, rgba(0, 216, 255, 0.2), rgba(77, 255, 184, 0.12), rgba(20, 55, 95, 0.12)),
    color-mix(in srgb, var(--brand) 14%, var(--surface-elevated) 86%);
  border-color: var(--answer-border-unfocused) !important;
  box-shadow: 0 0 0 1px var(--answer-glow-unfocused) !important;
  outline: none !important;
}

#answerField:focus-within,
#answerField:focus,
#answerField:focus-visible {
  border-color: var(--answer-border-focused) !important;
  box-shadow: 0 0 0 1px var(--answer-glow-focused) !important;
  outline: none !important;
}

#answerField.answer-field-focused {
  border-color: var(--answer-border-focused) !important;
  box-shadow: 0 0 0 1px var(--answer-glow-focused) !important;
  outline: none !important;
}

.touch-keypad {
  margin-top: 8px;
  margin-bottom: 8px;
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 8px;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
}

.touch-key {
  min-height: 42px;
  border-radius: 10px;
  border: 1px solid color-mix(in srgb, var(--panel-border) 74%, transparent);
  background:
    linear-gradient(145deg, rgba(0, 216, 255, 0.14), rgba(77, 255, 184, 0.1)),
    var(--surface-elevated);
  color: var(--ink);
  font: 600 0.9rem/1 "IBM Plex Mono", monospace;
}

.touch-key[data-touch-key="BACKSPACE"] {
  font-size: 1.2rem;
  line-height: 1;
}

.touch-key:active {
  transform: translateY(1px);
  background:
    linear-gradient(145deg, rgba(0, 216, 255, 0.22), rgba(77, 255, 184, 0.16)),
    var(--surface-elevated);
}

.touch-key--action {
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.04), rgba(255, 255, 255, 0.02)),
    var(--surface-elevated);
  opacity: 0.72;
}

.touch-key--action:active {
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.09), rgba(255, 255, 255, 0.05)),
    var(--surface-elevated);
  opacity: 1;
}

body[data-theme="light"] .touch-key {
  border-color: rgba(16, 96, 146, 0.32);
  background:
    linear-gradient(145deg, rgba(0, 160, 210, 0.22), rgba(40, 200, 140, 0.18)),
    var(--surface-elevated);
}

body[data-theme="light"] .touch-key:active {
  background:
    linear-gradient(145deg, rgba(0, 160, 210, 0.36), rgba(40, 200, 140, 0.30)),
    var(--surface-elevated);
}

body[data-theme="light"] .touch-key--action {
  background:
    linear-gradient(145deg, rgba(0, 0, 0, 0.07), rgba(0, 0, 0, 0.04)),
    var(--surface-elevated);
  opacity: 1;
}

body[data-theme="light"] .touch-key--action:active {
  background:
    linear-gradient(145deg, rgba(0, 0, 0, 0.13), rgba(0, 0, 0, 0.09)),
    var(--surface-elevated);
}

body[data-theme="light"] #answerField {
  --answer-border-unfocused: rgba(16, 96, 146, 0.38);
  --answer-glow-unfocused: rgba(16, 96, 146, 0.18);
}

body[data-theme="light"] #answerField:focus-within,
body[data-theme="light"] #answerField:focus,
body[data-theme="light"] #answerField:focus-visible {
  --answer-border-focused: color-mix(in srgb, var(--brand) 58%, #ffffff 42%);
  --answer-glow-focused: color-mix(in srgb, var(--brand) 28%, transparent);
}

body:not([data-theme="light"]) #answerField {
  background: color-mix(in srgb, var(--brand) 12%, var(--surface-elevated) 88%);
}

#answerField::part(container) {
  display: flex;
  align-items: center;
  justify-content: center;
}

#answerField::part(content) {
  display: block;
  width: fit-content;
  margin-inline: auto;
  text-align: center;
  transform: translateY(1px);
}

body[data-theme="light"] #answerField,
body[data-theme="light"] #answerField::part(content) {
  font-weight: 700;
}

#answerField::part(virtual-keyboard-toggle),
#answerField::part(keyboard-toggle) {
  display: none !important;
}

#answerField::part(virtual-keyboard-toggle):hover,
#answerField::part(keyboard-toggle):hover {
  color: var(--ink);
}

.ML__keyboard,
.ML__virtual-keyboard,
math-field::part(keyboard) {
  z-index: 9999;
}

.metrics {
  margin-top: 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.metrics span {
  font-family: "IBM Plex Mono", monospace;
  background: var(--surface-elevated);
  border: 1px solid rgba(236, 243, 251, 0.2);
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 0.82rem;
}

#minimalGateCount {
  color: #ecffff;
  background: color-mix(in srgb, var(--brand) 34%, var(--surface-elevated) 66%);
  border-color: color-mix(in srgb, var(--brand) 70%, #ffffff 30%);
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--brand) 30%, transparent);
}

body[data-theme="light"] #minimalGateCount {
  color: #10304d;
  background: color-mix(in srgb, var(--brand) 46%, var(--surface-elevated) 54%);
  border-color: rgba(12, 130, 180, 0.62);
  box-shadow: 0 0 0 1px rgba(12, 130, 180, 0.32);
  font-weight: 700;
}

.primary-btn,
.ghost-btn {
  border-radius: 12px;
  border: 1px solid transparent;
  padding: 10px 12px;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.88rem;
  cursor: pointer;
  transition: transform 120ms ease, box-shadow 120ms ease, background-color 120ms ease;
}

.primary-btn:hover,
.ghost-btn:hover {
  transform: translateY(-1px);
}

.primary-btn {
  background: linear-gradient(110deg, #00d8ff, #1aa8ff 54%, #4dffb8 100%);
  color: #042031;
  font-weight: 700;
  box-shadow: 0 8px 18px rgba(0, 216, 255, 0.32);
}

body:not([data-theme="light"]) .primary-btn {
  background: linear-gradient(110deg, #00d8ff, #1aa8ff 54%, #4dffb8 100%);
}

body[data-theme="light"] .primary-btn {
  background: linear-gradient(110deg, #00c8ef, #1698e6 52%, #3fe7a5 100%);
  box-shadow: 0 8px 16px rgba(0, 170, 225, 0.26);
}

body[data-theme="light"] .primary-btn,
body[data-theme="light"] .ghost-btn {
  font-weight: 600;
  color: #0f2e49;
}

#checkBtn {
  background: color-mix(in srgb, var(--brand) 58%, #ffffff 42%);
  color: #032434;
  box-shadow: 0 8px 18px color-mix(in srgb, var(--brand) 34%, transparent);
}

body[data-theme="light"] #checkBtn {
  background: color-mix(in srgb, var(--brand) 58%, #ffffff 42%);
  color: #0f2e49;
  box-shadow: 0 8px 16px color-mix(in srgb, var(--brand) 28%, transparent);
}

body[data-theme="light"] .ghost-btn {
  border-color: rgba(16, 96, 146, 0.32);
  background: var(--surface);
}

body[data-theme="light"] .mode-toggle {
  font-weight: 700;
  border-width: 2px;
  border-color: rgba(12, 130, 180, 0.52);
  box-shadow: 0 0 0 1px rgba(12, 130, 180, 0.2);
}

body[data-theme="light"] #newChallengeBtn {
  color: #0f2f45;
  background: #d8eeff;
  border-color: rgba(12, 130, 180, 0.52);
  box-shadow: 0 0 0 1px rgba(12, 130, 180, 0.2);
}

.ghost-btn {
  background:
    linear-gradient(130deg, rgba(0, 216, 255, 0.12), rgba(77, 255, 184, 0.08), rgba(39, 110, 170, 0.12)),
    var(--surface-elevated);
  border-color: color-mix(in srgb, var(--panel-border) 80%, transparent);
  color: var(--ink);
}

body:not([data-theme="light"]) .ghost-btn {
  background: var(--surface-elevated);
}

#newChallengeBtn {
  background: color-mix(in srgb, var(--surface-elevated) 78%, #0f3f70 22%);
  border-color: rgba(0, 216, 255, 0.42);
  box-shadow: 0 0 0 1px rgba(0, 216, 255, 0.2);
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.input-help-modal {
  position: fixed;
  inset: 0;
  z-index: 12000;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(1, 10, 20, 0.68);
  backdrop-filter: blur(4px);
}

.input-help-dialog {
  position: relative;
  width: min(720px, 100%);
  max-height: min(82vh, 760px);
  overflow: auto;
  border-radius: 16px;
  border: 1px solid color-mix(in srgb, var(--panel-border) 88%, transparent);
  background: var(--surface-elevated);
  color: var(--ink);
  box-shadow: 0 18px 36px rgba(0, 0, 0, 0.48);
  padding: 18px 18px 14px;
}

.input-help-close {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 32px;
  height: 32px;
  border-radius: 999px;
  border: 1px solid color-mix(in srgb, var(--panel-border) 84%, transparent);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  font: 700 0.9rem/1 "IBM Plex Mono", monospace;
}

.input-help-content {
  font-size: 0.93rem;
  line-height: 1.45;
}

.input-help-content h4 {
  margin: 14px 0 6px;
}

.worksheet-dialog {
  width: min(640px, 100%);
}

.worksheet-dialog .control-row + .control-row {
  margin-top: 12px;
}

.worksheet-modal-copy p {
  margin: 0 0 18px;
}

.worksheet-feature-list {
  margin: 0 0 16px;
  padding-left: 18px;
  display: grid;
  gap: 6px;
}

.worksheet-actions {
  margin-top: 16px;
}

.worksheet-status {
  margin: 0;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.84rem;
}

.worksheet-status:empty {
  display: none;
}

.worksheet-dialog .worksheet-status:not(:empty) {
  margin-top: 14px;
}

.worksheet-render-root {
  position: fixed;
  top: 0;
  left: -10000px;
  width: 794px;
  pointer-events: none;
  z-index: -1;
}

.worksheet-render-root.is-capturing {
  left: -10000px;
  z-index: -1;
}

.worksheet-doc {
  display: grid;
  gap: 24px;
}

.worksheet-page {
  --worksheet-font-size: 17px;
  width: 794px;
  height: 1123px;
  padding: 44px;
  background: #ffffff;
  color: #000000;
  font-family: "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  overflow: hidden;
}

.worksheet-frame {
  height: 100%;
  display: flex;
  flex-direction: column;
  border: 2px solid #000000;
  border-radius: 18px;
  padding: 28px 30px 24px;
  background: #ffffff;
}

.worksheet-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 22px;
  border-bottom: 1px solid #000000;
  padding-bottom: 14px;
}

.worksheet-heading h1 {
  margin: 0;
  font-size: 1.9rem;
  color: #000000;
}

.worksheet-heading p {
  margin: 8px 0 0;
  font-size: 1rem;
  color: #000000;
}

.worksheet-meta {
  display: grid;
  gap: 8px;
  justify-items: end;
  font: 700 0.88rem/1.25 "IBM Plex Mono", monospace;
  color: #000000;
  white-space: nowrap;
}

.worksheet-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 14px 18px;
  align-content: start;
  font-size: var(--worksheet-font-size);
}

.worksheet-item {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 10px;
  align-items: flex-start;
  break-inside: avoid;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid #000000;
  background: #ffffff;
}

.worksheet-item-number {
  font: 700 0.96em/1.3 "IBM Plex Mono", monospace;
  color: #000000;
}

.worksheet-item-content {
  font-family: "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  line-height: 1.35;
  color: #000000;
  word-break: normal;
  white-space: nowrap;
  overflow: hidden;
}

.worksheet-expression {
  display: inline-block;
}

.worksheet-item-gates {
  justify-self: end;
  align-self: start;
  white-space: nowrap;
  font: 700 0.82em/1.25 "IBM Plex Mono", monospace;
  color: #000000;
}

.worksheet-group,
.worksheet-overbar {
  display: inline-block;
  vertical-align: baseline;
}

.worksheet-overbar {
  line-height: 1.15;
}

.worksheet-overbar-content {
  display: inline-block;
  border-top: 1.5px solid currentColor;
  padding: 0.16em 0.06em 0;
  line-height: inherit;
  vertical-align: baseline;
}

.worksheet-footer {
  margin-top: auto;
  padding-top: 16px;
  border-top: 1px solid #000000;
  font: 700 0.84rem/1.2 "IBM Plex Mono", monospace;
  color: #000000;
  text-align: center;
}

.worksheet-footer span {
  display: block;
}

.input-help-table {
  width: 100%;
  border-collapse: collapse;
  margin: 0 0 10px;
  font-size: 0.9rem;
}

.input-help-table th,
.input-help-table td {
  border: 1px solid color-mix(in srgb, var(--panel-border) 80%, transparent);
  padding: 8px 10px;
  text-align: left;
  vertical-align: top;
}

.input-help-table th {
  background: color-mix(in srgb, var(--surface) 78%, transparent);
  font-weight: 700;
}

.input-help-content code {
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.88em;
}

.key-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.4em;
  padding: 1px 7px;
  border-radius: 7px;
  border: 1px solid color-mix(in srgb, var(--panel-border) 72%, transparent);
  background: color-mix(in srgb, var(--surface) 68%, #ffffff 32%);
  color: var(--ink);
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.86em;
  font-weight: 700;
  line-height: 1.25;
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.2);
}

.overbar-symbol {
  text-decoration: overline;
  text-decoration-thickness: 2px;
}

.input-help-current {
  margin-top: 2px;
}

@media (max-width: 620px) {
  .input-help-table {
    font-size: 0.84rem;
  }

  .input-help-table th,
  .input-help-table td {
    padding: 7px 8px;
  }
}

body.modal-open {
  overflow: hidden;
}

#feedbackSummary {
  margin-top: 10px;
  font-weight: 400;
}

.feedback-details {
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
  margin-top: 12px;
}

.feedback-details div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px dashed color-mix(in srgb, var(--panel-border) 72%, transparent);
  padding-bottom: 4px;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.84rem;
}

.feedback-details strong {
  font-weight: 600;
}

.hint-area {
  margin-top: 14px;
  padding: 12px;
  border-radius: 12px;
  background:
    linear-gradient(135deg, rgba(0, 216, 255, 0.25), rgba(22, 39, 65, 0.52), rgba(77, 255, 184, 0.2)),
    var(--accent-soft);
  border: 1px solid color-mix(in srgb, var(--accent) 56%, black 44%);
}

body:not([data-theme="light"]) .hint-area {
  background: color-mix(in srgb, var(--accent) 20%, var(--surface) 80%);
}

body[data-theme="light"] .hint-area {
  border-width: 2px;
  border-color: rgba(12, 130, 180, 0.58);
  background: color-mix(in srgb, var(--accent) 18%, var(--surface) 82%);
}

.hint-area p {
  margin: 0 0 8px;
}

body[data-theme="light"] .hint-area p,
body[data-theme="light"] .hint-text {
  font-weight: 700;
}

.hint-area .hint-text {
  font-family: "IBM Plex Mono", monospace;
  margin-top: 14px;
}

.hint-expression {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin: 0 1px;
  padding: 2px 6px;
  border-radius: 8px;
  border: 1px solid color-mix(in srgb, var(--brand) 56%, transparent);
  background: color-mix(in srgb, var(--brand) 20%, var(--surface-elevated) 80%);
  color: color-mix(in srgb, var(--ink) 90%, #ffffff 10%);
  font-weight: 600;
  line-height: 1.2;
  vertical-align: middle;
}

body[data-theme="light"] .hint-expression {
  border-color: rgba(12, 130, 180, 0.52);
  background: color-mix(in srgb, var(--brand) 26%, #ffffff 74%);
  color: #0e2f4a;
}

.hidden {
  display: none;
}

@media (max-width: 760px) {
  .tile-actions {
    width: auto;
    justify-content: flex-end;
    flex-wrap: nowrap;
  }

  .tile-actions .ghost-btn {
    flex: 0 0 auto;
  }
}

@media (pointer: fine) {
  .touch-keypad {
    display: none !important;
  }
}

@media (pointer: coarse), (any-pointer: coarse) {
  #inputHelpBtn {
    display: none !important;
  }
}

@media (max-width: 760px) {
  .challenge .tile-head h2 {
    min-height: 38px;
    display: flex;
    align-items: center;
    line-height: 1;
  }

  .challenge-title-full {
    display: none;
  }

  .challenge-title-short {
    display: inline;
  }

  #worksheetBtn {
    display: none;
  }

  .touch-key {
    min-height: 38px;
    font-size: 0.85rem;
  }
}

.vk-debug-toggle {
  position: fixed;
  left: max(10px, var(--safe-area-left, 0px));
  bottom: max(10px, var(--safe-area-bottom, 0px));
  z-index: 10020;
  border: 1px solid color-mix(in srgb, var(--accent) 55%, #000 45%);
  border-radius: 999px;
  padding: 6px 10px;
  background: color-mix(in srgb, var(--surface-elevated) 82%, #000 18%);
  color: var(--ink);
  font: 600 12px/1 "IBM Plex Mono", monospace;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.35);
}

.vk-debug-toggle.is-active {
  border-color: color-mix(in srgb, var(--brand) 64%, #000 36%);
  background: color-mix(in srgb, var(--brand) 28%, var(--surface-elevated) 72%);
}

.vk-debug-panel {
  position: fixed;
  left: max(10px, var(--safe-area-left, 0px));
  right: max(10px, var(--safe-area-right, 0px));
  top: calc(max(10px, var(--safe-area-top, 0px)) + 6px);
  z-index: 10030;
  border: 1px solid color-mix(in srgb, var(--accent) 48%, #000 52%);
  border-radius: 12px;
  background: rgba(4, 12, 22, 0.96);
  color: #d8efff;
  box-shadow: 0 16px 28px rgba(0, 0, 0, 0.5);
  max-height: min(56vh, 420px);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

.vk-debug-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  border-bottom: 1px solid rgba(154, 176, 202, 0.34);
  font: 600 12px/1 "IBM Plex Mono", monospace;
}

.vk-debug-version {
  margin-left: 6px;
  color: #8fd8ff;
  font-weight: 500;
}

.vk-debug-actions {
  display: inline-flex;
  gap: 6px;
}

.vk-debug-actions button {
  border: 1px solid rgba(154, 176, 202, 0.5);
  border-radius: 7px;
  padding: 4px 6px;
  background: rgba(16, 29, 48, 0.95);
  color: #d8efff;
  font: 500 11px/1 "IBM Plex Mono", monospace;
}

.vk-debug-log {
  margin: 0;
  padding: 8px 10px 10px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  font: 11px/1.35 "IBM Plex Mono", monospace;
}

.tone-neutral,
.tone-info,
.tone-good,
.tone-warn,
.tone-error,
.tone-success {
  margin: 0;
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 0.94rem;
}

.tone-neutral {
  background: var(--surface);
  border: 1px solid color-mix(in srgb, var(--panel-border) 76%, transparent);
}

.tone-info {
  background:
    linear-gradient(132deg, rgba(0, 216, 255, 0.24), rgba(22, 39, 65, 0.42), rgba(77, 255, 184, 0.14)),
    color-mix(in srgb, var(--brand) 18%, var(--surface) 82%);
  border: 1px solid color-mix(in srgb, var(--accent) 58%, rgba(220, 252, 255, 0.24));
}

/* Fullscreen PWA support - respects notch/safe areas */
@media (display-mode: fullscreen) {
  html {
    width: 100vw;
    height: 100vh;
  }
  
  body {
    width: 100vw;
    height: 100vh;
    overflow: hidden;
  }
  
  .shell {
    height: 100vh;
    overflow-y: auto;
    padding-left: max(12px, calc(var(--safe-area-left, 0px) + 0px));
    padding-right: max(12px, calc(var(--safe-area-right, 0px) + 0px));
    padding-top: max(30px, calc(var(--safe-area-top, 0px) + 12px));
    padding-bottom: max(24px, calc(var(--safe-area-bottom, 0px) + 0px));
  }
  
  /* Virtual keyboard in fullscreen extends to edge, respecting safe areas */
    .ML__keyboard,
    .ML__keyboard-container,
    .ML__virtual-keyboard,
    math-field::part(keyboard) {
      padding-bottom: 0px !important;
      margin-bottom: 0px !important;
    }
    
    /* MathLive CSS variables for proper keyboard positioning */
    .ML__keyboard {
      --keyboard-padding-bottom: 0px !important;
      --_padding-bottom: 0px !important;
      --keyboard-padding-top: 5px !important;
      --_padding-top: 5px !important;
    }
    
    /* Target keyboard backdrop and plate specifically */
    .MLK__backdrop {
      padding-bottom: 0px !important;
      margin-bottom: 0px !important;
    }
    
    .MLK__plate {
      padding-bottom: 0px !important;
      margin-bottom: 0px !important;
  }
}

/* Handle standalone PWA mode (alternative mode on iOS) */
@media (display-mode: standalone) {
  .ML__keyboard,
  .ML__keyboard-container,
  .ML__virtual-keyboard,
  math-field::part(keyboard) {
    padding-bottom: 0px !important;
    margin-bottom: 0px !important;
  }
  
  .ML__keyboard {
    --keyboard-padding-bottom: 0px !important;
    --_padding-bottom: 0px !important;
    --keyboard-padding-top: 5px !important;
    --_padding-top: 5px !important;
  }
  
  .MLK__backdrop {
    padding-bottom: 0px !important;
    margin-bottom: 0px !important;
  }
  
  .MLK__plate {
    padding-bottom: 0px !important;
    margin-bottom: 0px !important;
  }
}
body:not([data-theme="light"]) .tone-info {
  background: color-mix(in srgb, var(--brand) 18%, var(--surface) 82%);
}

.tone-good {
  background: linear-gradient(130deg, rgba(77, 255, 184, 0.24), rgba(77, 255, 184, 0.14));
  border: 1px solid rgba(77, 255, 184, 0.48);
}

body:not([data-theme="light"]) .tone-good {
  background: rgba(77, 255, 184, 0.2);
}

.tone-success {
  background: rgba(42, 170, 90, 0.2);
  border: 1px solid rgba(72, 214, 131, 0.46);
}

.tone-warn {
  background: linear-gradient(130deg, rgba(245, 158, 11, 0.24), rgba(0, 216, 255, 0.12));
  border: 1px solid rgba(245, 158, 11, 0.45);
}

body:not([data-theme="light"]) .tone-warn {
  background: rgba(245, 158, 11, 0.2);
}

.tone-error {
  background: linear-gradient(130deg, rgba(239, 68, 68, 0.24), rgba(0, 216, 255, 0.12));
  border: 1px solid rgba(248, 113, 113, 0.48);
}

body:not([data-theme="light"]) .tone-error {
  background: rgba(239, 68, 68, 0.2);
}

body[data-theme="light"] .tone-neutral {
  border-width: 2px;
  border-color: rgba(16, 96, 146, 0.34);
}

body[data-theme="light"] .tone-info {
  border-width: 2px;
  border-color: rgba(12, 130, 180, 0.58);
  background: color-mix(in srgb, var(--brand) 26%, var(--surface) 74%);
}

body[data-theme="light"] .tone-good {
  border-width: 2px;
  border-color: rgba(18, 124, 111, 0.6);
  background: rgba(36, 182, 165, 0.22);
}

body[data-theme="light"] .tone-success {
  border-width: 2px;
  border-color: rgba(39, 141, 79, 0.6);
  background: rgba(42, 170, 90, 0.22);
}

body[data-theme="light"] .tone-warn {
  border-width: 2px;
  border-color: rgba(171, 118, 18, 0.64);
  background: rgba(245, 158, 11, 0.22);
}

body[data-theme="light"] .tone-error {
  border-width: 2px;
  border-color: rgba(174, 52, 52, 0.62);
  background: rgba(239, 68, 68, 0.22);
}

@media (max-width: 960px) {
  .challenge,
  .answer,
  .feedback {
    grid-column: span 12;
  }

  .tile-head {
    flex-wrap: wrap;
    align-items: flex-start;
  }

  .notation-inline {
    width: auto;
  }

  .notation-inline .mode-toggle {
    min-width: 124px;
    flex: 0 0 auto;
  }
}

@media (max-width: 620px) {
  #app {
    padding:
      max(30px, calc(var(--safe-area-top, 0px) + 12px))
      calc(12px + var(--safe-area-right, 0px))
      calc(24px + var(--safe-area-bottom, 0px))
      calc(12px + var(--safe-area-left, 0px));
  }

  .panel {
    padding: 14px;
  }

  #challengeField {
    min-height: 76px;
    font-size: 1.22rem;
  }

  #answerField {
    font-size: 1.08rem;
  }

  .hero {
    align-items: flex-start;
  }

  .hero-logo {
    width: clamp(56px, 16vw, 88px);
    max-width: 26%;
  }
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
