:root {
  --bg: #0b0e14;
  --bg-soft: #11151f;
  --card: #161b28;
  --card-hover: #1c2233;
  --line: #232b3d;
  --text: #e8ecf4;
  --text-dim: #97a0b5;
  --text-faint: #5d6678;
  --accent: #7c5cff;
  --accent2: #2dd4bf;
  --danger: #f4536e;
  --ok: #34d399;
  --warn: #fbbf24;
  --radius: 16px;
  --shadow: 0 10px 40px rgba(0, 0, 0, 0.45);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { color-scheme: dark; }

body {
  font-family: "Pretendard", -apple-system, BlinkMacSystemFont, "Segoe UI", "Malgun Gothic", sans-serif;
  background:
    radial-gradient(1000px 500px at 80% -10%, rgba(124, 92, 255, 0.14), transparent 60%),
    radial-gradient(800px 400px at 10% 110%, rgba(45, 212, 191, 0.10), transparent 60%),
    var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  line-height: 1.6;
}

/* ---------- topbar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px clamp(16px, 4vw, 40px);
  border-bottom: 1px solid var(--line);
  background: rgba(11, 14, 20, 0.8);
  backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 10;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text);
  font-size: 18px;
  font-weight: 800;
  letter-spacing: -0.02em;
  font-family: inherit;
}

.logo-emoji { font-size: 24px; }

.topbar-tag {
  font-size: 12px;
  color: var(--text-dim);
  border: 1px solid var(--line);
  padding: 4px 12px;
  border-radius: 999px;
  background: var(--bg-soft);
}

/* ---------- layout ---------- */
main#app {
  flex: 1;
  width: 100%;
  max-width: 1060px;
  margin: 0 auto;
  padding: clamp(20px, 4vw, 44px) clamp(16px, 4vw, 40px) 60px;
}

.footer {
  border-top: 1px solid var(--line);
  padding: 20px clamp(16px, 4vw, 40px);
  font-size: 12.5px;
  color: var(--text-dim);
  text-align: center;
}

.footer-dim { opacity: 0.55; margin-top: 4px; }

/* ---------- hero ---------- */
.hero { text-align: center; padding: clamp(8px, 3vw, 28px) 0 clamp(24px, 4vw, 40px); }

.hero h1 {
  font-size: clamp(30px, 5.5vw, 52px);
  font-weight: 900;
  letter-spacing: -0.03em;
  line-height: 1.2;
}

.grad {
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.hero p {
  margin-top: 14px;
  color: var(--text-dim);
  font-size: clamp(14px, 2vw, 17px);
  max-width: 560px;
  margin-left: auto;
  margin-right: auto;
}

/* ---------- tier banner ---------- */
.tier-banner {
  margin: 26px auto 0;
  max-width: 640px;
  display: flex;
  align-items: center;
  gap: 18px;
  background: linear-gradient(135deg, rgba(124, 92, 255, 0.12), rgba(45, 212, 191, 0.08));
  border: 1px solid rgba(124, 92, 255, 0.35);
  border-radius: var(--radius);
  padding: 16px 22px;
  text-align: left;
}

.tier-letter {
  font-size: 44px;
  font-weight: 900;
  line-height: 1;
  background: linear-gradient(180deg, var(--accent2), var(--accent));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  min-width: 64px;
  text-align: center;
}

.tier-info b { font-size: 16px; }
.tier-info div { font-size: 13.5px; color: var(--text-dim); }

.tier-progress {
  margin: 22px auto 0;
  font-size: 13px;
  color: var(--text-dim);
}

.tier-progress .dots { letter-spacing: 3px; }

/* ---------- cards ---------- */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px;
  cursor: pointer;
  text-align: left;
  color: var(--text);
  font-family: inherit;
  transition: transform 0.15s ease, border-color 0.15s ease, background 0.15s ease;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.card:hover {
  transform: translateY(-3px);
  border-color: rgba(124, 92, 255, 0.55);
  background: var(--card-hover);
}

.card-top { display: flex; align-items: center; gap: 12px; }
.card-emoji { font-size: 30px; }
.card-name { font-size: 17px; font-weight: 800; letter-spacing: -0.02em; }
.card-desc { font-size: 13.5px; color: var(--text-dim); flex: 1; }

.card-best {
  margin-top: 6px;
  font-size: 13px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-top: 1px dashed var(--line);
  padding-top: 10px;
  color: var(--text-dim);
}

.card-best b { color: var(--accent2); font-size: 15px; }
.card-best .none { color: var(--text-faint, #5d6678); }

/* ---------- test page ---------- */
.test-head {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 18px;
}

.test-head .back {
  background: var(--card);
  border: 1px solid var(--line);
  color: var(--text-dim);
  border-radius: 10px;
  padding: 8px 14px;
  cursor: pointer;
  font-family: inherit;
  font-size: 14px;
}

.test-head .back:hover { color: var(--text); border-color: var(--accent); }

.test-head h2 { font-size: 22px; font-weight: 800; letter-spacing: -0.02em; }
.test-head .test-sub { font-size: 13px; color: var(--text-dim); }

.stage {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  min-height: 460px;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: center;
  overflow: hidden;
  position: relative;
  box-shadow: var(--shadow);
}

.stage-center {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 30px;
  text-align: center;
}

.stage-fill {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  padding: 30px;
  text-align: center;
}

.big { font-size: clamp(30px, 6vw, 48px); font-weight: 900; letter-spacing: -0.02em; }
.sub { font-size: 15px; color: var(--text-dim); }

.howto {
  font-size: 14.5px;
  color: var(--text-dim);
  max-width: 460px;
  line-height: 1.7;
}

.howto b { color: var(--text); }

/* reaction states */
.reaction.wait { background: linear-gradient(135deg, #2b1220, #3d1524); }
.reaction.go { background: linear-gradient(135deg, #0c3b2e, #11543f); }
.reaction.early { background: linear-gradient(135deg, #3a2a08, #4a350a); }
.reaction.between { background: var(--bg-soft); }

/* ---------- buttons ---------- */
.btn {
  font-family: inherit;
  font-size: 15.5px;
  font-weight: 700;
  padding: 13px 30px;
  border-radius: 12px;
  border: none;
  cursor: pointer;
  transition: transform 0.12s ease, filter 0.12s ease;
}

.btn:hover { transform: translateY(-1px); filter: brightness(1.1); }
.btn:active { transform: translateY(0); }

.btn-primary {
  background: linear-gradient(90deg, var(--accent), #9d7bff);
  color: #fff;
  box-shadow: 0 6px 24px rgba(124, 92, 255, 0.35);
}

.btn-ghost {
  background: var(--bg-soft);
  border: 1px solid var(--line);
  color: var(--text);
}

.btn-ghost:hover { border-color: var(--accent); }

.btn-row { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }

/* ---------- grid games ---------- */
.game-status {
  display: flex;
  justify-content: center;
  gap: 26px;
  padding: 18px 20px 0;
  font-size: 15px;
  color: var(--text-dim);
}

.game-status b { color: var(--text); font-size: 17px; }

.tile-grid {
  display: grid;
  gap: 10px;
  margin: auto;
  padding: 26px;
  touch-action: manipulation;
}

.tile {
  width: var(--tile, 86px);
  height: var(--tile, 86px);
  border-radius: 12px;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  cursor: pointer;
  transition: background 0.1s ease, transform 0.1s ease;
}

.tile:hover { border-color: rgba(124, 92, 255, 0.4); }

.tile.lit {
  background: linear-gradient(135deg, var(--accent), #9d7bff);
  border-color: transparent;
  transform: scale(1.05);
  box-shadow: 0 0 20px rgba(124, 92, 255, 0.5);
}

.tile.good {
  background: linear-gradient(135deg, #0e9f7f, var(--ok));
  border-color: transparent;
}

.tile.bad {
  background: linear-gradient(135deg, #b91c3b, var(--danger));
  border-color: transparent;
  animation: shake 0.3s ease;
}

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

/* ---------- number memory ---------- */
.number-display {
  font-size: clamp(44px, 9vw, 76px);
  font-weight: 900;
  letter-spacing: 0.12em;
  font-variant-numeric: tabular-nums;
}

.time-bar {
  width: min(340px, 70%);
  height: 6px;
  border-radius: 3px;
  background: var(--line);
  overflow: hidden;
}

.time-bar > div {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  transform-origin: left;
  animation: shrink linear forwards;
}

@keyframes shrink { from { transform: scaleX(1); } to { transform: scaleX(0); } }

.number-input {
  font-family: inherit;
  font-size: 30px;
  font-weight: 800;
  text-align: center;
  letter-spacing: 0.12em;
  background: var(--bg-soft);
  border: 2px solid var(--line);
  border-radius: 12px;
  color: var(--text);
  padding: 14px 18px;
  width: min(360px, 80%);
  outline: none;
  font-variant-numeric: tabular-nums;
}

.number-input:focus { border-color: var(--accent); }

/* ---------- aim ---------- */
.aim-area {
  flex: 1;
  position: relative;
  cursor: crosshair;
  min-height: 400px;
}

.aim-target {
  position: absolute;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #b49bff, var(--accent) 60%);
  box-shadow: 0 0 18px rgba(124, 92, 255, 0.6);
  border: 3px solid rgba(255, 255, 255, 0.75);
  cursor: pointer;
  animation: pop 0.14s ease;
  touch-action: manipulation;
}

@keyframes pop { from { transform: scale(0.4); } to { transform: scale(1); } }

/* ---------- typing ---------- */
.typing-wrap {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 34px clamp(20px, 5vw, 50px);
  flex: 1;
  justify-content: center;
}

.typing-target {
  font-size: clamp(18px, 3vw, 24px);
  font-weight: 600;
  line-height: 1.8;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 18px 22px;
  letter-spacing: 0.01em;
  word-break: keep-all;
}

.typing-target .ok { color: var(--ok); }
.typing-target .err { color: var(--danger); text-decoration: underline; }
.typing-target .cur { border-left: 2px solid var(--accent); animation: blink 1s step-end infinite; }

@keyframes blink { 50% { border-color: transparent; } }

.typing-input {
  font-family: inherit;
  font-size: clamp(17px, 2.6vw, 21px);
  background: var(--bg-soft);
  border: 2px solid var(--line);
  border-radius: 12px;
  color: var(--text);
  padding: 15px 20px;
  outline: none;
  width: 100%;
}

.typing-input:focus { border-color: var(--accent); }

.typing-meta {
  display: flex;
  justify-content: space-between;
  font-size: 14px;
  color: var(--text-dim);
}

/* ---------- result ---------- */
.result {
  text-align: center;
  padding: clamp(24px, 5vw, 50px) 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.result-emoji { font-size: 52px; }

.result-score {
  font-size: clamp(48px, 9vw, 76px);
  font-weight: 900;
  letter-spacing: -0.03em;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.result-score small { font-size: 0.38em; font-weight: 700; color: var(--text-dim); margin-left: 6px; }

.result-top {
  font-size: 19px;
  font-weight: 800;
}

.result-top .grad { font-size: 24px; }

.result-note { font-size: 14px; color: var(--text-dim); }

.new-best {
  display: inline-block;
  background: rgba(52, 211, 153, 0.12);
  border: 1px solid rgba(52, 211, 153, 0.4);
  color: var(--ok);
  font-size: 13px;
  font-weight: 700;
  padding: 5px 14px;
  border-radius: 999px;
}

.pct-bar {
  width: min(440px, 85%);
  height: 12px;
  background: linear-gradient(90deg, #313a52, #232b3d);
  border-radius: 6px;
  position: relative;
  margin-top: 6px;
}

.pct-bar .fill {
  position: absolute;
  inset: 0 auto 0 0;
  border-radius: 6px;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  transition: width 0.8s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.pct-bar .marker {
  position: absolute;
  top: -7px;
  width: 4px;
  height: 26px;
  border-radius: 2px;
  background: #fff;
  box-shadow: 0 0 10px rgba(255, 255, 255, 0.6);
  transform: translateX(-50%);
  transition: left 0.8s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.pct-labels {
  width: min(440px, 85%);
  display: flex;
  justify-content: space-between;
  font-size: 11.5px;
  color: var(--text-faint, #5d6678);
}

/* ---------- toast ---------- */
#toast {
  position: fixed;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: #1e2536;
  border: 1px solid var(--accent);
  color: var(--text);
  padding: 12px 24px;
  border-radius: 12px;
  font-size: 14.5px;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
  z-index: 100;
  box-shadow: var(--shadow);
}

#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- responsive ---------- */
@media (max-width: 560px) {
  .topbar-tag { display: none; }
  .stage { min-height: 420px; }
  .tile { --tile: 64px; }
  .tier-banner { flex-direction: column; text-align: center; gap: 8px; }
  .tier-info { text-align: center; }
}
