/* 밈 바이럴력 측정기 — 모바일 우선, 다크 기본 */

/*
 * 오늘의 초성(민트) · 조회수 공장(코랄)과 같은 디자인 언어를 쓴다.
 * 계기판 재질, 모노 수치, 토큰 규율은 그대로 두고 강조색만 이 게임의 것으로 바꾼다.
 * 여기는 '밈'이 주제라서 마젠타다.
 */
:root {
  --point: #ff4d9d;
  --gold: #ffc453;
  --bg: #0e1113;
  --surface: #171b1e;
  --surface-2: #1f2427;
  --line: #2b3134;
  --text: #f2f5f4;
  --text-dim: #9aa4a7;

  /* 결과가 나오면 app.js가 티어 색으로 덮어쓴다 */
  --tier: var(--point);

  --font-num: 'JetBrains Mono', 'Pretendard Variable', Pretendard, ui-monospace, monospace;

  --t-xl: 34px;
  --t-lg: 20px;
  --t-md: 15px;
  --t-sm: 13px;
  --t-xs: 11px;

  --r-lg: 18px;
  --r-md: 12px;
  --r-sm: 10px;
}

* {
  box-sizing: border-box;
}

/* display:flex 가 걸린 요소는 hidden 속성만으로 숨겨지지 않는다 (명시도에서 밀림) */
[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  /* CDN이 정의하는 패밀리명은 'Pretendard Variable'. 로컬 설치본(Pretendard)은 그다음. */
  font-family: 'Pretendard Variable', Pretendard, -apple-system, BlinkMacSystemFont,
    'Apple SD Gothic Neo', 'Malgun Gothic', system-ui, sans-serif;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;

  /* 한글은 기본값이면 글자 단위로 잘린다. keep-all이 어절 단위로 끊게 만든다. */
  word-break: keep-all;
  overflow-wrap: break-word;
}

/* 배경 글로우 — 티어 색이 바뀌면 화면 전체 공기도 같이 바뀐다 */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(60% 45% at 50% 30%, color-mix(in srgb, var(--tier) 16%, transparent), transparent 70%);
  opacity: 0;
  transition: opacity 0.6s ease;
  z-index: 0;
}
body.lit::before {
  opacity: 1;
}

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

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

#fx {
  position: fixed;
  inset: 0;
  z-index: 50;
  pointer-events: none; /* 파티클이 버튼 클릭을 먹으면 안 된다 */
}

.wrap {
  position: relative;
  z-index: 1;
  max-width: 480px;
  margin: 0 auto;
  padding: 20px 18px calc(28px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-height: 100dvh;
}

/* ── 시리즈 헤더 ───────────────────────────── */
.series {
  display: flex;
  align-items: center;
  gap: 9px;
}
.series .bar {
  width: 3px;
  height: 16px;
  border-radius: 2px;
  background: var(--point);
}
.series .name {
  font-size: var(--t-sm);
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text-dim);
}
.mute {
  margin-left: auto;
  background: none;
  border: 0;
  color: var(--text-dim);
  font-size: 15px;
  cursor: pointer;
  padding: 4px 6px;
  line-height: 1;
}

/* ── 공통 패널 재질 ───────────────────────────
   상단에 백라이트가 걸린 얇은 하이라이트 — 계기판의 질감 */
.panel,
.scanner,
.result {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 22px 18px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05), 0 1px 2px rgba(0, 0, 0, 0.35);
}

/* ── 입력 ─────────────────────────────────── */
.title {
  margin: 0 0 8px;
  font-size: 27px;
  font-weight: 800;
  line-height: 1.32;
  letter-spacing: -0.02em;
}
.lead {
  margin: 0 0 18px;
  font-size: var(--t-md);
  line-height: 1.6;
  color: var(--text-dim);
}

.form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
#word {
  width: 100%;
  padding: 15px 16px;
  font: inherit;
  font-size: 19px;
  font-weight: 700;
  text-align: center;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
#word::placeholder {
  font-weight: 500;
  color: #5b6467;
}
#word:focus {
  outline: none;
  border-color: var(--point);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--point) 22%, transparent);
}

.go {
  padding: 15px;
  font: inherit;
  font-size: 16px;
  font-weight: 800;
  color: #12060c;
  background: var(--point);
  border: 0;
  border-radius: var(--r-md);
  cursor: pointer;
  transition: transform 0.12s ease, filter 0.2s ease;
}
.go:hover {
  filter: brightness(1.08);
}
.go:active {
  transform: scale(0.98);
}
.go[disabled] {
  opacity: 0.5;
  cursor: default;
}

.error {
  margin: 12px 0 0;
  font-size: var(--t-sm);
  line-height: 1.55;
  color: #ff8a8a;
}

/* 틀 안내 — 가장 큰 지렛대이므로 예시 칩보다 먼저, 강조색으로 */
.tip {
  margin: 14px 0 0;
  padding: 10px 12px;
  font-size: var(--t-sm);
  line-height: 1.55;
  color: var(--text-dim);
  background: var(--surface-2);
  border-left: 3px solid var(--point);
  border-radius: 0 var(--r-sm) var(--r-sm) 0;
}
.tip b {
  color: var(--text);
  font-weight: 800;
}
.tip-ex {
  font-size: var(--t-xs);
  opacity: 0.7;
}

.samples {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 12px;
}
.chip {
  padding: 7px 12px;
  font: inherit;
  font-size: var(--t-xs);
  font-weight: 700;
  color: var(--text-dim);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 999px;
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease;
}
.chip:hover {
  color: var(--point);
  border-color: var(--point);
}

/* ── 측정 중 ──────────────────────────────── */
.scanner {
  position: relative;
  overflow: hidden;
  text-align: center;
}
.tiles {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 7px;
  margin-bottom: 18px;
}
.tile {
  width: 46px;
  height: 54px;
  display: grid;
  place-items: center;
  font-size: 26px;
  font-weight: 800;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  opacity: 0.35;
  transform: translateY(6px);
  animation: tile-in 0.4s ease forwards;
}
/* 타일이 순서대로 켜진다 — 왼쪽부터 훑는 스캔 라인과 박자를 맞춘 딜레이 */
@keyframes tile-in {
  to {
    opacity: 1;
    transform: translateY(0);
    border-color: var(--point);
    box-shadow: 0 0 14px color-mix(in srgb, var(--point) 35%, transparent);
  }
}

/* 패널 위를 왼쪽에서 오른쪽으로 훑고 지나가는 빛 */
.scanline {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 90px;
  left: -90px;
  background: linear-gradient(
    90deg,
    transparent,
    color-mix(in srgb, var(--point) 22%, transparent),
    transparent
  );
  animation: sweep 1.1s linear infinite;
}
@keyframes sweep {
  to {
    left: 100%;
  }
}

.log {
  margin: 0;
  font-size: var(--t-sm);
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}

/* ── 결과 ─────────────────────────────────── */
.result {
  text-align: center;
  animation: pop-in 0.4s cubic-bezier(0.2, 1.1, 0.4, 1);
}
@keyframes pop-in {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.97);
  }
}

.result-word {
  margin: 0 0 14px;
  font-size: var(--t-md);
  font-weight: 700;
  color: var(--text-dim);
}
.result-word b {
  color: var(--text);
  font-weight: 800;
}

.gauge {
  position: relative;
  width: 200px;
  max-width: 62vw;
  margin: 0 auto 6px;
}
.gauge svg {
  width: 100%;
  display: block;
  transform: rotate(-90deg); /* 12시 방향에서 시작해야 게이지로 읽힌다 */
}
.gauge circle {
  fill: none;
  stroke-width: 12;
  stroke-linecap: round;
}
.gauge .track {
  stroke: var(--surface-2);
}
.gauge .fill {
  stroke: var(--tier);
  /* r=86 → 둘레 2πr ≈ 540.35. offset을 둘레→0으로 줄이면 채워진다 */
  stroke-dasharray: 540.35;
  stroke-dashoffset: 540.35;
  transition: stroke-dashoffset 1.15s cubic-bezier(0.2, 0.8, 0.2, 1), stroke 0.4s ease;
  filter: drop-shadow(0 0 8px color-mix(in srgb, var(--tier) 55%, transparent));
}
.gauge-center {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  align-items: baseline;
  grid-auto-flow: column;
  gap: 3px;
}
.score {
  font-family: var(--font-num);
  font-size: 56px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  line-height: 1;
}
.unit {
  font-size: var(--t-md);
  font-weight: 700;
  color: var(--text-dim);
}

.tier {
  margin: 10px 0 4px;
  font-size: 23px;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--tier);
  animation: tier-pop 0.5s cubic-bezier(0.2, 1.4, 0.4, 1) 0.35s both;
}
@keyframes tier-pop {
  from {
    opacity: 0;
    transform: scale(0.7);
  }
}
.tier-sub {
  margin: 0 0 20px;
  font-size: var(--t-md);
  color: var(--text-dim);
}

/* ── 확산 시뮬레이션 ──────────────────────────
   점수 밑에 붙는 '증거' 구역. 계기판 안의 작은 관측창처럼 보이게 한 단 낮춘다. */
.viral {
  margin: 0 0 20px;
  padding: 14px 12px 10px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
}

.r-line {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 7px;
  margin: 0 0 4px;
  font-size: var(--t-sm);
}
.r-label {
  color: var(--text-dim);
  font-weight: 700;
}
.r-val {
  font-family: var(--font-num);
  font-variant-numeric: tabular-nums;
  font-size: 22px;
  font-weight: 800;
  color: var(--tier);
}
.r-verdict {
  font-size: var(--t-xs);
  font-weight: 700;
  color: var(--text-dim);
}

#spread {
  display: block;
  width: 100%;
  height: 180px;
}

.reach {
  margin: 0;
  font-size: var(--t-sm);
  color: var(--text-dim);
}
.reach b {
  color: var(--text);
  font-weight: 800;
}
/* 진지한 예측으로 읽히면 안 되는 값이라, 농담이라는 표시를 눈에 띄게 둔다 */
.reach .joke {
  font-size: var(--t-xs);
  opacity: 0.6;
}

/* 지표 막대 — 위에서부터 차례로 차오른다 */
.metrics {
  list-style: none;
  margin: 0 0 18px;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 9px;
  text-align: left;
}
.metrics li {
  display: grid;
  grid-template-columns: 82px 1fr 34px;
  align-items: center;
  gap: 9px;
  font-size: var(--t-sm);
  color: var(--text-dim);
}
.metrics .bar {
  height: 7px;
  background: var(--surface-2);
  border-radius: 999px;
  overflow: hidden;
}
.metrics .bar i {
  display: block;
  height: 100%;
  width: 0;
  /* 0점이어도 심지는 남긴다 — 빈 막대는 '측정 실패'처럼 읽힌다 */
  min-width: 7px;
  border-radius: 999px;
  background: linear-gradient(90deg, color-mix(in srgb, var(--tier) 55%, transparent), var(--tier));
  transition: width 0.75s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.metrics .val {
  font-family: var(--font-num);
  font-variant-numeric: tabular-nums;
  text-align: right;
  color: var(--text);
}

.notes {
  list-style: none;
  margin: 0 0 16px;
  padding: 14px;
  background: var(--bg);
  border-radius: var(--r-md);
  text-align: left;
}
.notes li {
  font-size: var(--t-sm);
  line-height: 1.65;
  color: var(--text-dim);
}
.notes li + li {
  margin-top: 6px;
}

.rx {
  margin: 0 0 18px;
  padding: 12px 14px;
  font-size: var(--t-sm);
  font-weight: 700;
  line-height: 1.6;
  color: var(--text);
  text-align: left;
  border-left: 3px solid var(--tier);
  background: var(--surface-2);
  border-radius: 0 var(--r-sm) var(--r-sm) 0;
}

.actions {
  display: flex;
  gap: 8px;
}
.secondary {
  flex: 1;
  padding: 13px;
  font: inherit;
  font-size: var(--t-md);
  font-weight: 700;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  cursor: pointer;
  transition: border-color 0.15s ease;
}
.secondary:hover {
  border-color: var(--tier);
}

.foot {
  margin-top: auto;
  padding-top: 18px;
  text-align: center;
  font-size: var(--t-xs);
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--text-dim);
  opacity: 0.75;
}

/* ── 흔들림 ───────────────────────────────── */
@keyframes shake {
  10%, 90% { transform: translateX(-1px); }
  20%, 80% { transform: translateX(2px); }
  30%, 50%, 70% { transform: translateX(-3px); }
  40%, 60% { transform: translateX(3px); }
}
@keyframes shake-hard {
  10%, 90% { transform: translate(-3px, 1px) rotate(-0.4deg); }
  20%, 80% { transform: translate(5px, -2px) rotate(0.5deg); }
  30%, 50%, 70% { transform: translate(-7px, 2px) rotate(-0.7deg); }
  40%, 60% { transform: translate(7px, -1px) rotate(0.7deg); }
}
.shake {
  animation: shake 0.4s ease;
}
.shake-hard {
  animation: shake-hard 0.55s ease;
}

/*
 * 움직임을 줄여 달라고 설정한 사람에게는 전부 끈다.
 * 화면이 흔들리면 어지럼증·편두통을 겪는 사람이 실제로 있다.
 */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
