:root {
  color-scheme: light;
  --bg: #ffffff;
  --fg: #1b1b1b;
  --muted: #8a8a8a;
  --line: #e4e4e4;
  --field: #fafafa;
  --accent: #1b1b1b;
  --accent-fg: #ffffff;
  --ok: #1f9d55;
  --ok-bg: rgba(31, 157, 85, .07);
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f0f11;
  --fg: #ededed;
  --muted: #8c8c92;
  --line: #2b2b30;
  --field: #161619;
  --accent: #ededed;
  --accent-fg: #101012;
  --ok: #4ade80;
  --ok-bg: rgba(74, 222, 128, .08);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--fg);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
               "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  padding: env(safe-area-inset-top) env(safe-area-inset-right)
           env(safe-area-inset-bottom) env(safe-area-inset-left);
}

#app { min-height: 100dvh; }

.screen {
  min-height: 100dvh;
  max-width: 520px;
  margin: 0 auto;
  padding: 40px 24px calc(32px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 0;
}

.eyebrow {
  margin: 0 0 10px;
  font-size: 12px;
  letter-spacing: .18em;
  text-transform: uppercase;
  color: var(--muted);
}

h1 {
  margin: 0 0 18px;
  font-size: 22px;
  line-height: 1.5;
  font-weight: 600;
  letter-spacing: .01em;
}

.test-label {
  margin: 0 0 12px;
  font-size: clamp(32px, 10vw, 44px);
  line-height: 1.15;
  font-weight: 700;
  letter-spacing: .07em;
  color: var(--fg);
}

.test-sub {
  margin: 0 0 30px;
  font-size: 16px;
  line-height: 1.6;
  color: var(--fg);
  opacity: .72;
}

.puzzle {
  margin: 0 0 30px;
  font-size: 15px;
  line-height: 1.95;
  color: var(--fg);
}

.fields { display: flex; flex-direction: column; gap: 12px; }

.field {
  display: flex;
  align-items: center;
  gap: 12px;
}

.field .num {
  flex: 0 0 22px;
  font-size: 13px;
  color: var(--muted);
  text-align: center;
  font-variant-numeric: tabular-nums;
}

input[type="text"] {
  flex: 1 1 auto;
  min-width: 0;
  height: 50px;
  padding: 0 14px;
  font-size: 16px;
  line-height: 50px;
  color: var(--fg);
  background: var(--field);
  border: 1px solid var(--line);
  border-radius: 12px;
  outline: none;
  transition: border-color .15s ease, background .15s ease, box-shadow .15s ease;
  -webkit-appearance: none;
  appearance: none;
}

input[type="text"]::placeholder { color: var(--muted); opacity: .55; }

input[type="text"]:focus {
  border-color: var(--fg);
  box-shadow: 0 0 0 3px rgba(127, 127, 127, .12);
}

input.ok {
  border-color: var(--ok);
  background: var(--ok-bg);
}

button.primary {
  width: 100%;
  height: 50px;
  margin-top: 22px;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: .08em;
  color: var(--accent-fg);
  background: var(--accent);
  border: 0;
  border-radius: 12px;
  cursor: pointer;
  transition: opacity .15s ease, transform .1s ease;
}

button.primary:disabled { opacity: .35; cursor: default; }
button.primary:active:not(:disabled) { transform: scale(.985); }

.msg {
  min-height: 22px;
  margin-top: 14px;
  font-size: 13px;
  line-height: 22px;
  color: var(--muted);
  text-align: center;
}

.msg.bad { color: #d64545; }

.hint {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: calc(38px + env(safe-area-inset-bottom));
  max-width: 480px;
  margin: 0 auto;
  padding: 13px 16px;
  font-size: 13px;
  line-height: 1.7;
  color: var(--fg);
  background: var(--field);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, .08);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity .35s ease, transform .35s ease;
  pointer-events: none;
  z-index: 20;
}

.hint.show { opacity: 1; transform: translateY(0); }

.success {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  z-index: 50;
  opacity: 0;
  transition: opacity .35s ease;
}

.success.show { opacity: 1; }

.success span {
  font-size: 17px;
  letter-spacing: .14em;
  color: var(--fg);
}

.reveal {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 26px;
  padding: 32px 24px;
  background: var(--bg);
  z-index: 45;
  opacity: 0;
  transition: opacity .3s ease;
}

.reveal.show { opacity: 1; }

.reveal-item { text-align: center; }

.reveal-short {
  margin: 0;
  font-size: 13px;
  letter-spacing: .1em;
  color: var(--muted);
}

.reveal-full {
  margin: 0;
  font-size: 26px;
  line-height: 1.4;
  letter-spacing: .04em;
  color: var(--fg);
}

.reveal-sub {
  margin: 10px 0 0;
  font-size: 14px;
  letter-spacing: .04em;
  color: var(--muted);
}

.shake { animation: shake .38s cubic-bezier(.36, .07, .19, .97) both; }

.reset {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(4px + env(safe-area-inset-bottom));
  padding: 10px 16px;
  font-family: inherit;
  font-size: 12px;
  letter-spacing: .06em;
  color: var(--muted);
  background: transparent;
  border: 0;
  opacity: .5;
  cursor: pointer;
  z-index: 30;
  transition: opacity .2s ease, color .2s ease;
}

.reset:active { opacity: .9; }
.reset.armed { opacity: 1; color: #d64545; }

button.ghost {
  margin-top: 26px;
  padding: 10px 0;
  font-family: inherit;
  font-size: 13px;
  color: var(--muted);
  background: transparent;
  border: 0;
  text-decoration: underline;
  text-underline-offset: 4px;
  cursor: pointer;
}

@keyframes shake {
  10%, 90% { transform: translateX(-2px); }
  20%, 80% { transform: translateX(3px); }
  30%, 50%, 70% { transform: translateX(-5px); }
  40%, 60% { transform: translateX(5px); }
}

@media (prefers-reduced-motion: reduce) {
  .shake { animation: none; }
  .hint, .success, input[type="text"] { transition: none; }
}

.stub {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.9;
}

@media (min-width: 600px) {
  .screen { padding-top: 64px; padding-bottom: 64px; }
}
