:root {
  --bg: #0D0F14;
  --text: #F3F1EA;
  --accent: #FFC83D;

  /* Tints of the three colors above. Text tints stay at or above 4.5:1 on --bg. */
  --muted: rgba(243, 241, 234, 0.68);
  --dim: rgba(243, 241, 234, 0.5);
  --line: rgba(243, 241, 234, 0.16);
  --wash: rgba(243, 241, 234, 0.05);
  --accent-wash: rgba(255, 200, 61, 0.1);
  --accent-line: rgba(255, 200, 61, 0.4);
  --focus-frame: rgba(255, 200, 61, 0.5);

  --font: system-ui, -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", "Segoe UI", Roboto, sans-serif;
  --font-num: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);

  color-scheme: dark;
}

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

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

h1,
h2,
p {
  margin: 0;
}

button {
  font: inherit;
  color: inherit;
}

[hidden] {
  display: none !important;
}

:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
}

[tabindex="-1"]:focus {
  outline: none;
}

/* Layout: the number sits in the exact middle row in every state. */

.stage {
  position: relative;
  width: 100%;
  max-width: 440px;
  min-height: 100vh;
  min-height: min(100dvh, 880px);
  display: grid;
  grid-template-rows: 1fr auto 1fr;
  padding:
    max(24px, env(safe-area-inset-top))
    max(20px, env(safe-area-inset-right))
    max(24px, env(safe-area-inset-bottom))
    max(20px, env(safe-area-inset-left));
  text-align: center;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

.top {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  padding-bottom: clamp(20px, 4.5vh, 44px);
}

.bottom {
  display: flex;
  flex-direction: column;
  padding-top: clamp(14px, 2.6vh, 26px);
}

.only-idle,
.only-running,
.only-result,
.only-void {
  display: none;
}

[data-state="idle"] .only-idle,
[data-state="running"] .only-running,
[data-state="result"] .only-result,
[data-state="void"] .only-void {
  display: flex;
}

.intro,
.top .only-result,
.top .only-void {
  flex-direction: column;
  align-items: center;
}

.stack {
  flex: 1;
  flex-direction: column;
  gap: 28px;
}

/* Buttons stay in the same thumb spot in every state. */
.stack > .actions {
  margin-top: auto;
}

/* Top row */

.challenge {
  margin-bottom: 22px;
  padding: 9px 16px;
  border: 1px solid var(--accent-line);
  border-radius: 999px;
  background: var(--accent-wash);
  font-size: 15px;
  font-weight: 600;
  line-height: 1.4;
}

.challenge strong {
  color: var(--accent);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.title {
  font-size: clamp(26px, 7vw, 32px);
  font-weight: 800;
  line-height: 1.2;
  letter-spacing: -0.03em;
}

.lede {
  margin-top: 8px;
  color: var(--muted);
  font-size: 16px;
}

.rank {
  color: var(--accent);
  font-size: clamp(26px, 7.4vw, 34px);
  font-weight: 800;
  line-height: 1.2;
  letter-spacing: -0.03em;
  word-break: keep-all;
}

.void-title {
  font-size: clamp(22px, 6vw, 26px);
  font-weight: 800;
  line-height: 1.3;
  letter-spacing: -0.02em;
  word-break: keep-all;
}

/* The number */

.readout {
  position: relative;
  justify-self: center;
  font-family: var(--font-num);
  font-size: 26vw;
  font-size: clamp(64px, min(26vw, 30vh), 184px);
  font-weight: 700;
  line-height: 1;
  white-space: nowrap;
}

.value {
  display: inline-block;
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
  letter-spacing: -0.04em;
}

.unit {
  position: absolute;
  left: 100%;
  bottom: 0.1em;
  margin-left: 0.06em;
  color: var(--muted);
  font-family: var(--font);
  font-size: 0.22em;
  font-weight: 700;
}

[data-state="idle"] .value,
[data-state="void"] .value {
  color: var(--dim);
}

[data-state="running"] .unit,
[data-state="void"] .unit {
  visibility: hidden;
}

/* Bottom row */

.best {
  color: var(--muted);
  font-size: 15px;
}

.best b {
  color: var(--text);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.best .dot {
  margin: 0 6px;
  color: var(--dim);
}

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

.actions-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.keys {
  display: none;
  color: var(--dim);
  font-size: 14px;
}

@media (hover: hover) and (pointer: fine) {
  .keys {
    display: block;
  }
}

.hint {
  color: var(--muted);
  font-size: 15px;
}

.error {
  color: var(--muted);
  font-size: 18px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.verdict {
  margin-top: 22px;
  padding: 14px 18px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--wash);
}

.verdict[data-outcome="win"] {
  border-color: var(--accent-line);
  background: var(--accent-wash);
}

.verdict-title {
  font-size: 20px;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.verdict[data-outcome="win"] .verdict-title {
  color: var(--accent);
}

.verdict-detail {
  margin-top: 2px;
  color: var(--muted);
  font-size: 15px;
  font-variant-numeric: tabular-nums;
  word-break: keep-all;
}

.void-detail {
  color: var(--muted);
  font-size: 15px;
  word-break: keep-all;
}

/* Buttons */

.btn {
  -webkit-appearance: none;
  appearance: none;
  min-height: 56px;
  padding: 0 20px;
  border: 1px solid transparent;
  border-radius: 16px;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.01em;
  cursor: pointer;
  touch-action: manipulation;
}

.btn-wide {
  width: 100%;
}

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

.btn-ghost {
  border-color: var(--line);
  background: transparent;
  color: var(--text);
}

@media (hover: hover) {
  .btn-primary:hover {
    filter: brightness(1.08);
  }

  .btn-ghost:hover {
    background: var(--wash);
  }
}

.btn-primary:active {
  filter: brightness(0.92);
}

.btn-ghost:active {
  background: var(--line);
}

/* While running the whole screen is the stop button. */

.stop-area {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: none;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
  touch-action: manipulation;
}

[data-state="running"] .stop-area {
  display: block;
}

.stop-area:focus {
  outline: none;
}

.stop-area:focus-visible {
  box-shadow: inset 0 0 0 3px var(--focus-frame);
}

/* Feedback */

.toast {
  position: absolute;
  left: 50%;
  bottom: calc(max(24px, env(safe-area-inset-bottom)) + 72px);
  z-index: 20;
  padding: 10px 18px;
  border-radius: 999px;
  background: var(--text);
  color: var(--bg);
  font-size: 15px;
  font-weight: 700;
  white-space: nowrap;
  pointer-events: none;
  transform: translateX(-50%);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
}

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

.copy-buffer {
  position: fixed;
  top: 0;
  left: 0;
  width: 1px;
  height: 1px;
  font-size: 16px;
  opacity: 0;
  pointer-events: none;
}

/* Motion: only when the number is masked and when the result lands. */

@keyframes veil {
  from {
    opacity: 0.15;
    filter: blur(14px);
    transform: scale(1.08);
  }
  to {
    opacity: 1;
    filter: blur(0);
    transform: none;
  }
}

@keyframes land {
  from {
    opacity: 0;
    filter: blur(8px);
    transform: translateY(0.1em) scale(0.92);
  }
  to {
    opacity: 1;
    filter: blur(0);
    transform: none;
  }
}

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

[data-masked] .value {
  animation: veil 480ms var(--ease-out) both;
}

[data-state="result"] .value,
[data-state="void"] .value {
  animation: land 600ms var(--ease-out) both;
}

[data-state="result"] .top .only-result,
[data-state="void"] .top .only-void {
  animation: rise 520ms var(--ease-out) 140ms both;
}

[data-state="result"] .result-info,
[data-state="void"] .void-detail {
  animation: rise 520ms var(--ease-out) 220ms both;
}

[data-state="result"] .actions-row,
[data-state="void"] .only-void .actions {
  animation: rise 520ms var(--ease-out) 300ms both;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}
