:root {
  --bg-color: #0f172a;
  --card-bg: #1e293b;
  --accent: #38bdf8;
  --accent-hover: #0284c7;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --correct: #22c55e;
  --wrong: #ef4444;
  --border: #334155;
  --touch-highlight: rgba(56, 189, 248, 0.25);
  --focus-ring: #38bdf8;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

html {
  overflow-x: hidden;
}

body {
  background-color: var(--bg-color);
  color: var(--text-main);
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 100vh;
  width: 100%;
  padding: 16px;
  touch-action: manipulation;
  overflow-x: hidden;
}

@media (max-width: 340px) {
  body {
    padding: 10px 8px;
  }
  .card {
    padding: 16px 14px !important;
  }
  header h1 {
    font-size: 1.15rem !important;
  }
}

.container {
  width: 100%;
  max-width: 480px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

header {
  text-align: center;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

header h1 {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: -0.5px;
}

header p {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 4px;
}

/* 최상단 슬림 유튜브 배너 */
.yt-banner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 46px;
  padding: 6px 12px;
  border: 1px solid rgba(239, 68, 68, 0.4);
  border-radius: 12px;
  background: linear-gradient(135deg, rgba(239, 68, 68, 0.13), rgba(30, 41, 59, 0.85));
  color: var(--text-main);
  font-size: 0.78rem;
  font-weight: 700;
  line-height: 1.35;
  text-align: center;
  text-decoration: none;
}

.yt-banner:active {
  border-color: rgba(239, 68, 68, 0.75);
  background: linear-gradient(135deg, rgba(239, 68, 68, 0.22), rgba(30, 41, 59, 0.95));
}

.yt-banner .yt-play {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #ef4444;
  color: #fff;
  font-size: 0.58rem;
  padding-left: 1px;
}

.yt-banner .yt-arrow {
  color: #fca5a5;
}

/* Card */
.card {
  background-color: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 24px;
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.3);
}

/* Progress */
.progress-bar {
  height: 6px;
  background-color: var(--border);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 20px;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #38bdf8, #818cf8);
  width: 20%;
  transition: width 0.3s ease;
}

.question-meta {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 12px;
  font-weight: 600;
}

.question-meta span {
  min-width: 0;
  overflow-wrap: anywhere;
}

.question-text {
  font-size: 1.15rem;
  font-weight: 700;
  line-height: 1.5;
  margin-bottom: 24px;
  min-height: 56px;
  overflow-wrap: anywhere;
}

/* Options */
.options-grid {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.option-btn {
  background-color: #0f172a;
  border: 1.5px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  color: var(--text-main);
  font-size: 0.95rem;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
  transition: all 0.15s ease;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 52px;
  user-select: none;
  overflow-wrap: anywhere;
}

/* Hover and Active / Touch Feedback */
.option-btn:hover:not(:disabled) {
  border-color: var(--accent);
  background-color: #1e293b;
}

.option-btn:active:not(:disabled),
.option-btn.touch-active:not(:disabled) {
  background-color: var(--touch-highlight) !important;
  border-color: var(--accent) !important;
  transform: scale(0.98);
}

/* Accessible Focus States */
.option-btn:focus-visible,
.next-btn:focus-visible,
.share-btn:focus-visible,
.footer-link:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

.option-btn.correct {
  background-color: rgba(34, 197, 94, 0.2);
  border-color: var(--correct);
  color: #4ade80;
}

.option-btn.wrong {
  background-color: rgba(239, 68, 68, 0.2);
  border-color: var(--wrong);
  color: #f87171;
}

/* Explanation Box */
.explanation-box {
  margin-top: 16px;
  padding: 14px;
  background-color: #0f172a;
  border-left: 3px solid var(--accent);
  border-radius: 6px;
  font-size: 0.85rem;
  line-height: 1.5;
  display: none;
  overflow-wrap: anywhere;
}

.explanation-box.show {
  display: block;
  animation: fadeIn 0.3s ease;
}

/* Next Button */
.next-btn {
  width: 100%;
  margin-top: 20px;
  padding: 16px;
  background: linear-gradient(135deg, var(--accent), #6366f1);
  color: #ffffff;
  border: none;
  border-radius: 12px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  display: none;
  box-shadow: 0 4px 14px rgba(56, 189, 248, 0.3);
  min-height: 52px;
  line-height: 1.35;
  text-align: center;
  white-space: normal;
  overflow-wrap: anywhere;
  transition: all 0.15s ease;
}

.next-btn:active,
.next-btn.touch-active {
  transform: scale(0.98);
  filter: brightness(1.1);
}

.next-btn.show {
  display: block;
}

/* 결과 화면 보조 버튼: 주 동작(다음 미풀이)을 가리지 않게 낮춘 비중 */
.next-btn.btn-secondary {
  background: #1e293b;
  border: 1.5px solid var(--border);
  color: #cbd5e1;
  font-weight: 600;
  font-size: 0.92rem;
  box-shadow: none;
}

.next-btn.btn-secondary:hover {
  border-color: var(--accent);
  color: var(--text-main);
}

.next-btn.btn-secondary:active,
.next-btn.btn-secondary.touch-active {
  background: #273449;
  transform: scale(0.98);
  filter: none;
}

/* Result Screen */
.result-screen {
  display: none;
  text-align: center;
}

.result-screen.show {
  display: block;
  animation: fadeIn 0.4s ease;
}

.score-circle {
  width: 110px;
  height: 110px;
  border-radius: 55px;
  background: linear-gradient(135deg, rgba(56, 189, 248, 0.2), rgba(99, 102, 241, 0.2));
  border: 3px solid var(--accent);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  margin: 0 auto 20px;
}

.score-num {
  font-size: 2.2rem;
  font-weight: 800;
  color: var(--accent);
}

.score-total {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.rank-title {
  font-size: 1.3rem;
  font-weight: 700;
  margin-bottom: 8px;
}

.rank-desc {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 24px;
  line-height: 1.4;
}

.share-btn {
  width: 100%;
  padding: 14px;
  background-color: #334155;
  color: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  margin-bottom: 12px;
  min-height: 48px;
  transition: all 0.15s ease;
}

.share-btn:hover {
  background-color: #3e4f68;
}

.share-btn:active,
.share-btn.touch-active {
  background-color: #475569;
  transform: scale(0.98);
}

/* Revisit stats bar */
.stats-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
  margin-top: -4px;
}

.stats-bar[hidden] {
  display: none;
}

.stat-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 5px 11px;
  border-radius: 9999px;
  background-color: var(--card-bg);
  border: 1px solid var(--border);
  font-size: 0.71rem;
  color: #cbd5e1;
  white-space: nowrap;
}

.stat-pill strong {
  color: var(--accent);
  font-weight: 700;
}

/* Category deep links */
.cat-nav {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.cat-nav-label {
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--text-muted);
  letter-spacing: 0.02em;
}

.cat-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.cat-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 7px 12px;
  border-radius: 9999px;
  border: 1px solid var(--border);
  background-color: #0f172a;
  color: #cbd5e1;
  font-size: 0.76rem;
  font-weight: 600;
  text-decoration: none;
  min-height: 34px;
  transition: all 0.15s ease;
}

.cat-chip:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.cat-chip.active,
.cat-chip.active:hover {
  background-color: rgba(56, 189, 248, 0.18);
  border-color: var(--accent);
  color: var(--accent);
}

.cat-chip-count {
  font-size: 0.66rem;
  font-weight: 700;
  color: var(--text-muted);
  background-color: rgba(148, 163, 184, 0.15);
  border-radius: 9999px;
  padding: 1px 6px;
}

.cat-chip.active .cat-chip-count {
  color: var(--accent);
  background-color: rgba(56, 189, 248, 0.2);
}

.cat-chip-all {
  border-style: dashed;
}

/* Active category notice */
.filter-notice {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 10px;
  background-color: rgba(56, 189, 248, 0.08);
  border: 1px solid rgba(56, 189, 248, 0.35);
  font-size: 0.76rem;
  color: #cbd5e1;
}

.filter-notice[hidden] {
  display: none;
}

.filter-tag {
  font-weight: 700;
  color: var(--accent);
}

.filter-sub {
  color: var(--text-muted);
}

.filter-link {
  margin-left: auto;
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
}

@media (max-width: 420px) {
  .filter-link {
    margin-left: 0;
    flex-basis: 100%;
  }
}

.filter-link:hover {
  text-decoration: underline;
}

/* Result screen stats */
.result-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 18px;
  text-align: left;
}

.result-stat {
  display: flex;
  flex-direction: column;
  gap: 3px;
  background-color: #0f172a;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
}

.result-stat .k {
  font-size: 0.68rem;
  color: var(--text-muted);
  font-weight: 600;
}

.result-stat .v {
  font-size: 0.9rem;
  font-weight: 700;
  color: #e2e8f0;
}

.completion-banner {
  padding: 11px 14px;
  margin-bottom: 14px;
  border-radius: 10px;
  background-color: rgba(34, 197, 94, 0.14);
  border: 1px solid rgba(34, 197, 94, 0.45);
  color: #86efac;
  font-size: 0.8rem;
  font-weight: 600;
  line-height: 1.45;
}

.completion-banner[hidden] {
  display: none;
}

/* Cross promo Section */
.cross-promo {
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
  text-align: left;
}

.cross-promo h3 {
  font-size: 0.95rem;
  font-weight: 700;
  color: #e2e8f0;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.web-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background-color: #0f172a;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  margin-bottom: 8px;
  text-decoration: none;
  color: inherit;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

.web-card:hover {
  border-color: var(--accent);
  background-color: #131f36;
}

.web-card:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

.web-card:active {
  transform: scale(0.99);
}

.web-card-body {
  min-width: 0;
}

.web-card-body h4 {
  font-size: 0.88rem;
  color: #f1f5f9;
}

.web-card-body p {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 2px;
  line-height: 1.35;
}

.web-card-go {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--accent);
  white-space: nowrap;
}

/* Portal Footer */
.portal-footer {
  text-align: center;
  padding: 16px 0 24px;
  border-top: 1px solid var(--border);
  font-size: 0.75rem;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* 쿠팡 파트너스 다이나믹 배너: 680px 위젯을 화면 폭에 맞춤 (가로 오버플로 0) */
.affiliate-section {
  margin: 0;
}

.affiliate-section[hidden] {
  display: none;
}

.coupang-wrap {
  max-width: 100%;
  overflow: hidden;
  background: #ffffff;
  border-radius: 12px;
  border: 1px solid var(--border);
}

.coupang-slot {
  transform-origin: top left;
}

.affiliate-note {
  font-size: 0.69rem;
  color: var(--text-muted);
  line-height: 1.45;
  margin-top: 6px;
  text-align: left;
  word-break: keep-all;
  overflow-wrap: anywhere;
}

/* 한국어 어절 중간 줄바꿈 방지 (좁은 화면에서는 overflow-wrap이 받아 줌) */
.question-text,
.option-btn,
.explanation-box,
.rank-desc,
.completion-banner,
.web-card-body p,
.portal-footer p {
  word-break: keep-all;
  overflow-wrap: anywhere;
}

.footer-links {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px 16px;
}

.footer-link {
  color: var(--accent);
  text-decoration: none;
  transition: color 0.15s ease;
}

.footer-link:hover {
  text-decoration: underline;
  color: #7dd3fc;
}

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background-color: #1e293b;
  border: 1px solid var(--accent);
  color: #fff;
  padding: 10px 18px;
  border-radius: 20px;
  font-size: 0.8rem;
  box-shadow: 0 4px 14px rgba(0,0,0,0.6);
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none;
  z-index: 999;
  max-width: 90%;
  text-align: center;
  overflow-wrap: anywhere;
}

.toast.show {
  opacity: 1;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}
