@font-face {
  font-family: "Inter";
  src: url("/fonts/InterVariable.woff2") format("woff2");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

:root {
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --radius: 8px;
  --radius-sm: 6px;
  --bar-h: 56px;
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #ffffff;
  --fg: #0a0a0a;
  --muted: #6b6b6b;
  --faint: #a6a6a6;
  --line: #ebebeb;
  --line-strong: #d4d4d4;
  --surface: #f7f7f7;
  --hover: #f2f2f2;
  --press: #ebebeb;
  --selected: #ffffff;
  --selected-shadow: 0 0 0 1px rgb(0 0 0 / 0.08), 0 1px 2px rgb(0 0 0 / 0.06);
  --shadow: 0 0 0 1px rgb(0 0 0 / 0.06), 0 4px 8px -2px rgb(0 0 0 / 0.04), 0 12px 32px -4px rgb(0 0 0 / 0.1);
  --backdrop: rgb(0 0 0 / 0.24);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0a0a0a;
  --fg: #ededed;
  --muted: #8f8f8f;
  --faint: #575757;
  --line: #1f1f1f;
  --line-strong: #333333;
  --surface: #121212;
  --hover: #1a1a1a;
  --press: #222222;
  --selected: #262626;
  --selected-shadow: 0 0 0 1px rgb(255 255 255 / 0.06), 0 1px 2px rgb(0 0 0 / 0.4);
  --shadow: 0 0 0 1px rgb(255 255 255 / 0.08), 0 12px 32px -4px rgb(0 0 0 / 0.7);
  --backdrop: rgb(0 0 0 / 0.6);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--fg);
  font-family: "Inter", ui-sans-serif, system-ui, -apple-system, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  font-feature-settings: "cv11";
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

button,
input {
  font: inherit;
  color: inherit;
  letter-spacing: inherit;
}

button {
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

:focus-visible {
  outline: 2px solid var(--fg);
  outline-offset: 2px;
}

kbd {
  font: inherit;
  font-size: 11px;
  font-weight: 500;
  line-height: 1;
  padding: 3px 5px;
  border-radius: 4px;
  border: 1px solid currentColor;
  opacity: 0.55;
  margin-left: 4px;
}

.theme-switching *,
.theme-switching *::before,
.theme-switching *::after {
  transition: none !important;
}

.slot:empty {
  display: none;
}

[hidden] {
  display: none !important;
}

/* Header */

.bar {
  height: var(--bar-h);
  padding: 0 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  position: relative;
  z-index: 10;
}

.bar-left,
.bar-right {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.bar-left {
  gap: 20px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--fg);
  text-decoration: none;
  flex-shrink: 0;
}

.mark {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  background: var(--fg);
  color: var(--bg);
  display: grid;
  place-items: center;
  font-size: 15px;
  font-weight: 600;
  line-height: 1;
  padding-bottom: 1px;
}

.word {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.02em;
}

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

.seg {
  display: inline-flex;
  align-items: center;
  padding: 2px;
  gap: 2px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.seg-item {
  height: 26px;
  min-width: 28px;
  padding: 0 8px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  transition: background-color 120ms, color 120ms, transform 120ms var(--ease-out);
}

.seg-item.op {
  font-size: 15px;
  padding: 0;
  width: 28px;
}

.seg-item[aria-pressed="true"],
.seg-item[aria-checked="true"],
.seg-item[aria-selected="true"] {
  background: var(--selected);
  color: var(--fg);
  box-shadow: var(--selected-shadow);
}

.seg-item.op[aria-pressed="false"] {
  color: var(--faint);
}

.seg-item:active,
.btn:active,
.icon-btn:active,
.quiet-btn:active {
  transform: scale(0.97);
}

.quiet-btn {
  height: 32px;
  padding: 0 10px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background-color 120ms, color 120ms, transform 120ms var(--ease-out);
}

.quiet-btn[aria-expanded="true"] {
  color: var(--fg);
  background: var(--hover);
}

.quiet-btn svg {
  transition: transform 160ms var(--ease-out);
}

.quiet-btn[aria-expanded="true"] svg {
  transform: rotate(180deg);
}

.btn {
  height: 32px;
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--bg);
  font-size: 13px;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  white-space: nowrap;
  transition: background-color 120ms, border-color 120ms, transform 120ms var(--ease-out);
}

.btn-primary {
  background: var(--fg);
  border-color: var(--fg);
  color: var(--bg);
}

.btn-block {
  width: 100%;
  height: 36px;
}

.icon-btn {
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  color: var(--muted);
  display: grid;
  place-items: center;
  transition: background-color 120ms, color 120ms, transform 120ms var(--ease-out);
}

:root[data-theme="light"] .icon-sun,
:root[data-theme="dark"] .icon-moon {
  display: none;
}

.text-btn {
  border: 0;
  padding: 0;
  background: none;
  color: var(--fg);
  font-weight: 500;
  text-decoration: underline;
  text-decoration-color: var(--line-strong);
  text-underline-offset: 3px;
}

.account-btn {
  padding: 0 10px 0 4px;
  border-color: var(--line);
}

.avatar {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--fg);
  color: var(--bg);
  display: grid;
  place-items: center;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
}

@media (hover: hover) and (pointer: fine) {
  .seg-item:not([aria-pressed="true"], [aria-checked="true"], [aria-selected="true"]):hover,
  .quiet-btn:hover,
  .icon-btn:hover {
    color: var(--fg);
    background: var(--hover);
  }
  .btn:not(.btn-primary):hover {
    background: var(--hover);
  }
  .btn-primary:hover {
    opacity: 0.88;
  }
  .text-btn:hover {
    text-decoration-color: currentColor;
  }
  .menu-item:hover {
    background: var(--hover);
  }
}

/* Popovers */

.anchor {
  position: relative;
}

.popover {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  background: var(--bg);
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 14px;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: scale(0.97) translateY(-4px);
  transform-origin: top left;
  transition:
    opacity 120ms ease-out,
    transform 120ms ease-out,
    visibility 0s linear 120ms;
}

.popover.open {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: none;
  transition:
    opacity 180ms var(--ease-out),
    transform 180ms var(--ease-out),
    visibility 0s;
}

.ranges {
  width: max-content;
}

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

.range-label {
  font-size: 13px;
  font-weight: 500;
  width: 104px;
}

.range-inputs {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.range-inputs input {
  width: 52px;
  height: 30px;
  padding: 0 8px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--bg);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.range-inputs input:focus-visible {
  outline-offset: 0;
  outline-width: 1px;
  border-color: var(--fg);
}

.dash {
  color: var(--faint);
}

.range-op {
  width: 20px;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
}

.range-note {
  margin: 6px 0 14px 120px;
  font-size: 12px;
  color: var(--muted);
}

.range-foot {
  display: flex;
  justify-content: flex-end;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  font-size: 12px;
}

.menu {
  left: auto;
  right: 0;
  transform-origin: top right;
  padding: 6px;
  min-width: 200px;
}

.menu-head {
  margin: 0;
  padding: 6px 8px 0;
  font-size: 13px;
  color: var(--muted);
}

.menu-head strong {
  color: var(--fg);
  font-weight: 500;
}

.menu-sub {
  margin: 0;
  padding: 0 8px 8px;
  font-size: 12px;
  color: var(--faint);
  border-bottom: 1px solid var(--line);
}

.menu-item {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 7px 8px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  text-align: left;
  font-size: 13px;
}

/* Stage */

.stage {
  flex: 1;
  display: grid;
  place-items: center;
  padding: 24px 20px 12vh;
}

.screen {
  display: none;
  width: 100%;
  max-width: 560px;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

body[data-phase="idle"] .screen-idle,
body[data-phase="playing"] .screen-play,
body[data-phase="ended"] .screen-end {
  display: flex;
}

.problem {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: baseline;
  column-gap: 0.3em;
  font-size: clamp(30px, 7vw, 40px);
  font-weight: 450;
  letter-spacing: -0.02em;
  line-height: 1.2;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.problem-text {
  justify-self: end;
}

.eq {
  color: var(--faint);
  font-weight: 400;
}

.answer-field {
  justify-self: start;
  position: relative;
  min-width: calc(var(--answer-len, 3) * 1ch + 0.2em);
  padding-bottom: 3px;
  border-bottom: 1px solid var(--line-strong);
  text-align: left;
}

.answer-text::after {
  content: "";
  display: inline-block;
  width: 2px;
  height: 0.9em;
  margin-left: 0.04em;
  vertical-align: -0.1em;
}

.answer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  color: transparent;
  caret-color: transparent;
  font-size: 16px;
  opacity: 0;
}

.answer-field:focus-within {
  border-bottom-color: var(--fg);
}

.answer-field:focus-within .answer-text::after {
  background: var(--fg);
}

.problem-preview {
  color: var(--faint);
  margin: 24px 0 36px;
}

.problem-preview .eq {
  color: var(--line-strong);
}

.mode {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.01em;
}

.start-btn {
  height: 40px;
  padding: 0 18px;
  font-size: 14px;
}

.best-line {
  margin: 20px 0 0;
  font-size: 13px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.best-line strong {
  color: var(--fg);
  font-weight: 500;
}

/* Play */

.hud {
  width: 100%;
  display: flex;
  justify-content: space-between;
  margin-bottom: 72px;
}

.stat {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
}

.stat-right {
  align-items: flex-end;
}

.stat-label {
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--faint);
}

.stat-value {
  font-size: 22px;
  font-weight: 500;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
}

#time-left {
  color: var(--muted);
}

#time-left.urgent {
  color: var(--fg);
}

.race {
  width: 320px;
  max-width: 100%;
  margin-top: 64px;
}

.race-track {
  position: relative;
  height: 9px;
}

.race-track::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 4px;
  height: 1px;
  background: var(--line-strong);
}

.race-rail {
  position: absolute;
  inset: 0;
  transform: translateX(calc(var(--p, 0) * 100%));
  transition: transform 160ms var(--ease-out);
}

.dot {
  position: absolute;
  top: 0;
  left: -4.5px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
}

.dot-ghost {
  border: 1px solid var(--muted);
  background: var(--bg);
}

.dot-you {
  background: var(--fg);
}

.play-hint {
  margin: 40px 0 0;
  font-size: 12px;
  color: var(--faint);
}

.play-hint kbd {
  margin: 0 2px 0 0;
}

@media (hover: none) {
  .play-hint {
    display: none;
  }
}

.race-label {
  margin: 14px 0 0;
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  min-height: 18px;
}

.race.empty .race-track {
  display: none;
}

/* End */

body[data-phase="ended"] .screen-end > * {
  animation: rise 220ms var(--ease-out) both;
}

body[data-phase="ended"] .screen-end > :nth-child(2) {
  animation-delay: 30ms;
}

body[data-phase="ended"] .screen-end > :nth-child(3) {
  animation-delay: 60ms;
}

body[data-phase="ended"] .screen-end > :nth-child(n + 4) {
  animation-delay: 90ms;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
}

.end-label {
  margin: 0;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--faint);
}

.end-score {
  margin: 4px 0 0;
  font-size: 112px;
  font-weight: 500;
  letter-spacing: -0.05em;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.end-verdict {
  margin: 20px 0 0;
  font-size: 14px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  display: flex;
  align-items: center;
  gap: 8px;
}

.pill {
  display: inline-flex;
  align-items: center;
  height: 22px;
  padding: 0 8px;
  border-radius: 999px;
  background: var(--fg);
  color: var(--bg);
  font-size: 12px;
  font-weight: 600;
}

.end-stats {
  margin: 4px 0 0;
  font-size: 13px;
  color: var(--faint);
  font-variant-numeric: tabular-nums;
}

.end-actions {
  display: flex;
  gap: 8px;
  margin-top: 36px;
}

.end-actions .btn {
  height: 36px;
}

.end-hint {
  margin: 20px 0 0;
  font-size: 12px;
  color: var(--muted);
}

/* Dialog */

.dialog {
  width: min(360px, calc(100vw - 32px));
  padding: 0;
  border: 0;
  border-radius: 12px;
  background: var(--bg);
  color: var(--fg);
  box-shadow: var(--shadow);
  opacity: 1;
  transform: none;
  transition:
    opacity 180ms var(--ease-out),
    transform 180ms var(--ease-out),
    overlay 180ms allow-discrete,
    display 180ms allow-discrete;
}

.dialog:not([open]) {
  opacity: 0;
  transform: scale(0.98);
  transition-duration: 120ms;
}

@starting-style {
  .dialog[open] {
    opacity: 0;
    transform: scale(0.97);
  }
}

.dialog::backdrop {
  background: var(--backdrop);
  transition:
    opacity 180ms var(--ease-out),
    overlay 180ms allow-discrete,
    display 180ms allow-discrete;
}

.dialog:not([open])::backdrop {
  opacity: 0;
}

@starting-style {
  .dialog[open]::backdrop {
    opacity: 0;
  }
}

.dialog form {
  padding: 24px;
}

.dialog-title {
  margin: 0 0 16px;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.seg-wide {
  display: flex;
  margin-bottom: 20px;
}

.seg-wide .seg-item {
  flex: 1;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
}

.field input {
  height: 36px;
  padding: 0 10px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--bg);
  font-size: 14px;
  font-weight: 400;
  color: var(--fg);
}

.field input:focus-visible {
  outline: 1px solid var(--fg);
  outline-offset: 0;
  border-color: var(--fg);
}

.form-error {
  margin: -4px 0 12px;
  min-height: 18px;
  font-size: 12px;
  color: var(--fg);
  font-weight: 500;
}

.form-error:empty {
  min-height: 0;
  margin: 0;
}

.dialog-note {
  margin: 14px 0 0;
  font-size: 12px;
  line-height: 1.5;
  color: var(--faint);
}

/* Small screens */

@media (max-width: 760px) {
  .bar {
    height: auto;
    padding: 12px 16px;
    flex-wrap: wrap;
    row-gap: 12px;
  }
  .bar-left {
    display: contents;
  }
  .brand {
    order: 1;
  }
  .bar-right {
    order: 2;
  }
  .controls {
    order: 3;
    width: 100%;
    flex-wrap: wrap;
  }
  .ranges {
    position: fixed;
    top: auto;
    left: 16px;
    right: 16px;
    width: auto;
  }
  .range-row {
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
  }
  .range-note {
    margin-left: 0;
  }
  .hud {
    margin-bottom: 48px;
  }
  .end-score {
    font-size: 88px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 1ms !important;
    animation-delay: 0ms !important;
    transition-duration: 1ms !important;
  }
}
