/* ============================================================
   DESIGN TOKENS
   ============================================================ */
:root[data-theme="light"] {
  --bg: #fafaf7;
  --bg-elev: #ffffff;
  --bg-card: #f4f3ed;
  --bg-hover: #ececec;
  --ink: #18181b;
  --ink-strong: #000000;
  --ink-dim: #71717a;
  --ink-mute: #a1a1aa;
  --line: #e4e4e0;
  --line-strong: #d4d4d0;
  --accent: #2563eb;
  --accent-bg: #dbeafe;
  --correct: #16a34a;
  --correct-bg: #dcfce7;
  --wrong: #dc2626;
  --wrong-bg: #fee2e2;
  --shadow: 0 1px 2px 0 rgb(0 0 0 / 0.04);
}
:root[data-theme="dark"] {
  --bg: #0a0a0a;
  --bg-elev: #111113;
  --bg-card: #161618;
  --bg-hover: #1f1f23;
  --ink: #e4e4e7;
  --ink-strong: #fafafa;
  --ink-dim: #a1a1aa;
  --ink-mute: #71717a;
  --line: #27272a;
  --line-strong: #3f3f46;
  --accent: #60a5fa;
  --accent-bg: #1e3a8a33;
  --correct: #4ade80;
  --correct-bg: #14532d33;
  --wrong: #f87171;
  --wrong-bg: #7f1d1d33;
  --shadow: 0 1px 2px 0 rgb(0 0 0 / 0.5);
}

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

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Inter', 'Pretendard', system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

::selection {
  background: var(--accent);
  color: var(--bg-elev);
}

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

.hidden {
  display: none !important;
}

/* ============================================================
   HEADER
   ============================================================ */
header {
  border-bottom: 1px solid var(--line);
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  background: var(--bg);
  flex-wrap: nowrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--ink);
  text-transform: uppercase;
  white-space: nowrap;
  overflow: hidden;
}

.brand .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  flex-shrink: 0;
}

.brand-sub {
  color: var(--ink-mute);
  font-weight: 400;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-meta {
  display: flex;
  align-items: center;
  gap: 16px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  color: var(--ink-dim);
  letter-spacing: 0.05em;
  flex-shrink: 0;
}

.stat {
  display: flex;
  align-items: baseline;
  gap: 6px;
  white-space: nowrap;
}

.stat-label {
  color: var(--ink-mute);
  text-transform: uppercase;
  font-size: 10px;
}

.stat-value {
  color: var(--ink);
  font-weight: 700;
}

.stat-divider {
  color: var(--ink-mute);
  opacity: 0.4;
}

.theme-toggle {
  display: flex;
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 2px;
  flex-shrink: 0;
}

.theme-toggle button {
  background: transparent;
  border: none;
  color: var(--ink-mute);
  padding: 6px 8px;
  cursor: pointer;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  min-width: 28px;
  min-height: 28px;
}

.theme-toggle button:hover {
  color: var(--ink);
}

.theme-toggle button.active {
  background: var(--bg-elev);
  color: var(--ink-strong);
  box-shadow: var(--shadow);
}

.theme-toggle svg {
  width: 14px;
  height: 14px;
}

/* ============================================================
   LAYOUT
   ============================================================ */
main {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 32px 24px;
  max-width: 760px;
  width: 100%;
  margin: 0 auto;
  gap: 24px;
}

/* ============================================================
   QUIZ
   ============================================================ */
.quiz {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 36px;
  text-align: center;
  padding: 32px 16px;
  min-height: 360px;
}

.source-block {
  width: 100%;
}

.source-label {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  color: var(--ink-mute);
  letter-spacing: 0.15em;
  text-transform: uppercase;
  margin-bottom: 12px;
}

.source-word {
  font-family: 'JetBrains Mono', monospace;
  font-size: clamp(32px, 7vw, 64px);
  font-weight: 500;
  color: var(--ink-strong);
  letter-spacing: -0.02em;
  line-height: 1.1;
  word-break: break-word;
  overflow-wrap: anywhere;
}

.choices {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  width: 100%;
  max-width: 480px;
}

.choice-btn {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 20px 12px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  transition: all 0.15s;
  font-family: inherit;
  color: var(--ink);
  box-shadow: var(--shadow);
  min-height: 72px;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.choice-btn:hover:not(:disabled) {
  border-color: var(--accent);
  background: var(--bg-hover);
}

.choice-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.choice-btn:active:not(:disabled) {
  transform: scale(0.98);
}

.choice-btn:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.choice-btn.correct {
  background: var(--correct-bg);
  border-color: var(--correct);
  color: var(--correct);
  opacity: 1;
}

.choice-btn.wrong {
  background: var(--wrong-bg);
  border-color: var(--wrong);
  color: var(--wrong);
  opacity: 1;
}

.choice-key {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  font-weight: 700;
  color: var(--ink-mute);
  background: var(--bg-card);
  padding: 2px 6px;
  border-radius: 3px;
  letter-spacing: 0.1em;
}

.choice-btn.correct .choice-key,
.choice-btn.wrong .choice-key {
  background: transparent;
  color: inherit;
  opacity: 0.7;
}

.choice-text {
  font-size: clamp(18px, 4vw, 22px);
  font-weight: 500;
  letter-spacing: -0.01em;
  word-break: keep-all;
}

/* ============================================================
   RESULT BANNER
   ============================================================ */
.result {
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 13px;
  color: var(--ink-mute);
  letter-spacing: 0.05em;
  flex-wrap: wrap;
  padding: 0 8px;
  text-align: center;
}

.result.show-correct {
  color: var(--correct);
}

.result.show-wrong {
  color: var(--wrong);
}

.result .label {
  text-transform: uppercase;
  font-weight: 700;
}

.result .next-hint {
  color: var(--ink-mute);
  font-size: 11px;
}

.result .correct-answer {
  font-weight: 500;
  color: var(--ink);
}

/* ============================================================
   AD SLOT
   ============================================================ */
.ad-container {
  width: 100%;
  display: flex;
  justify-content: center;
  margin: 0 auto;
}

.ad-slot {
  width: 100%;
  max-width: 728px;
  min-height: 90px;
  background: var(--bg-card);
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.ad-slot:has(.adsbygoogle[data-adsbygoogle-status]) .ad-placeholder {
  display: none;
}

.ad-placeholder {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  color: var(--ink-mute);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  text-align: center;
  padding: 16px;
  line-height: 1.6;
}

.ad-placeholder .ad-tag {
  display: block;
  margin-top: 4px;
  font-size: 10px;
  opacity: 0.6;
}

.adsbygoogle {
  display: block;
  width: 100%;
}

/* ============================================================
   FOOTER
   ============================================================ */
footer {
  border-top: 1px solid var(--line);
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  color: var(--ink-mute);
  letter-spacing: 0.05em;
  flex-wrap: wrap;
}

.keys {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
}

.key {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.kbd {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  font-weight: 700;
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 3px;
  padding: 2px 6px;
  color: var(--ink);
  min-width: 18px;
  text-align: center;
}

.footer-version {
  white-space: nowrap;
}

/* ============================================================
   BLOCKED / LOADING
   ============================================================ */
.blocked,
.loading {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 48px 24px;
  gap: 16px;
}

.blocked-title {
  font-family: 'JetBrains Mono', monospace;
  font-size: 14px;
  font-weight: 700;
  color: var(--ink);
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.blocked-msg {
  color: var(--ink-dim);
  max-width: 400px;
  font-size: 14px;
}

.loading-text {
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  color: var(--ink-mute);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  display: flex;
  align-items: center;
  gap: 10px;
}

.loading-text::before {
  content: '';
  width: 8px;
  height: 8px;
  background: var(--accent);
  border-radius: 50%;
  animation: pulse 1.2s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 0.3; }
  50%      { opacity: 1; }
}

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 768px) {
  header { padding: 12px 18px; }
  .brand-sub { display: none; }
  .header-meta { gap: 12px; }
  main { padding: 24px 18px; gap: 20px; }
  .quiz { padding: 24px 8px; gap: 32px; min-height: 320px; }
  footer { padding: 10px 18px; }
}

@media (max-width: 480px) {
  header { padding: 10px 14px; gap: 8px; }
  .brand { font-size: 11px; gap: 8px; }
  .header-meta { gap: 8px; font-size: 10px; }
  .stat-label { display: none; }
  .stat { gap: 0; }
  main { padding: 16px 14px; gap: 16px; }
  .quiz { padding: 20px 4px; gap: 28px; min-height: 280px; }
  .source-label { margin-bottom: 8px; }
  .choices { grid-template-columns: 1fr; gap: 10px; }
  .choice-btn {
    padding: 18px 16px;
    flex-direction: row;
    justify-content: center;
    gap: 12px;
    min-height: 56px;
  }
  .ad-slot { min-height: 70px; }
  .keys { display: none; }
  footer { padding: 10px 14px; justify-content: center; }
}

@media (max-height: 500px) and (orientation: landscape) {
  .quiz { gap: 20px; min-height: 200px; padding: 16px 8px; }
  .source-word { font-size: clamp(28px, 5vw, 48px); }
  main { gap: 14px; }
}

@media (min-width: 1280px) {
  main { max-width: 880px; }
  .quiz { padding: 56px 24px; }
}
