/* 대비는 모두 WCAG AA(4.5:1) 이상으로 맞춤. --faint는 카드(--surface) 위에서만 쓴다. */
:root {
  color-scheme: light;
  --bg: #f5f7f7;
  --surface: #ffffff;
  --text: #14201f;
  --muted: #56636b;
  --faint: #6b767d;
  --border: #dfe5e6;
  --border-strong: #c5cfd1;
  --primary: #0f766e;
  --on-primary: #ffffff;
  --primary-soft: #e3f4f1;
  --guide-bg: #fff6dc;
  --guide-border: #ecd18a;
  --guide-ink: #8a5a00;
  --final: #15803d;
  --final-soft: #e5f6ea;
  --danger: #c62828;
  --ring: #0f766e;
  --shadow: 0 1px 2px rgb(16 24 32 / 0.04);
  --radius: 14px;
  --ease: cubic-bezier(0.2, 0, 0, 1);
  /* 펼칠 때는 감속(도착), 접을 때는 가속(떠남). 접기가 더 빠르다. */
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-in: cubic-bezier(0.4, 0, 1, 1);
  --dur-enter: 320ms;
  --dur-exit: 220ms;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #0f1214;
    --surface: #181c1f;
    --text: #e8eeee;
    --muted: #a3b0b6;
    --faint: #8e9aa0;
    --border: #2a3135;
    --border-strong: #3a4348;
    --primary: #2dd4bf;
    --on-primary: #062b28;
    --primary-soft: #11302c;
    --guide-bg: #2a2410;
    --guide-border: #5e4e1d;
    --guide-ink: #f0c868;
    --final: #4ade80;
    --final-soft: #12291a;
    --danger: #ff8a80;
    --ring: #2dd4bf;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Pretendard", -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", sans-serif;
  font-size: 16px;
  line-height: 1.6;
  word-break: keep-all;
  overflow-wrap: anywhere;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }

:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; border-radius: 8px; }

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

.icon { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon.sm { width: 15px; height: 15px; }

/* ---------------------------------------------------------------- 레이아웃 */

.topbar, main, .footer {
  max-width: 760px;
  margin: 0 auto;
  padding-left: 16px;
  padding-right: 16px;
}

.topbar { display: flex; align-items: center; gap: 10px; padding-top: 24px; padding-bottom: 16px; }
.brand { display: inline-flex; align-items: center; gap: 8px; font-weight: 700; font-size: 18px; letter-spacing: -0.01em; }
.brand .icon { color: var(--primary); width: 22px; height: 22px; }
.header-btn { margin-left: auto; }

main { display: flex; flex-direction: column; gap: 12px; padding-bottom: 40px; }

.footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  color: var(--muted);
  font-size: 14px;
  padding-bottom: 40px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}
.card.narrow { max-width: 420px; width: 100%; margin: 40px auto; display: flex; flex-direction: column; gap: 14px; }

h1 { font-size: 22px; margin: 8px 0 8px; line-height: 1.4; letter-spacing: -0.015em; }
h2 { font-size: 17px; margin: 8px 0 4px; line-height: 1.45; letter-spacing: -0.01em; }
h3 { display: flex; align-items: center; gap: 6px; font-size: 15px; margin: 0 0 10px; }

.muted { color: var(--muted); margin: 0; }
.center { text-align: center; padding: 20px 0 8px; }
.error { color: var(--danger); margin: 0; font-size: 14px; }
.prewrap { white-space: pre-wrap; margin: 0 0 8px; }
.meta { color: var(--faint); font-size: 13px; }
.meta-row { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; color: var(--faint); font-size: 13px; }

/* ---------------------------------------------------------------- 폼 */

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.field-label { font-weight: 600; font-size: 14px; }
.field-hint { color: var(--muted); font-size: 13px; }

input, textarea {
  width: 100%;
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  padding: 10px 12px;
  resize: vertical;
  transition: border-color 150ms var(--ease), box-shadow 150ms var(--ease);
}
input:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }

/* ---------------------------------------------------------------- 버튼 */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 40px;
  font: inherit;
  font-weight: 600;
  font-size: 14px;
  padding: 8px 14px;
  border-radius: 10px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 150ms var(--ease), border-color 150ms var(--ease), opacity 150ms var(--ease);
}
.btn:hover { background: var(--bg); }
.btn:disabled { opacity: 0.6; cursor: progress; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); }
.btn.small { min-height: 34px; padding: 4px 10px; font-size: 13px; }

.text-btn {
  min-height: 32px;
  padding: 4px 8px;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  background: none;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: background-color 150ms var(--ease), color 150ms var(--ease);
}
.text-btn:hover { background: var(--bg); color: var(--text); }
.text-btn.danger { color: var(--danger); }
.comment-actions { display: inline-flex; gap: 2px; margin-left: auto; }
.edit-form { margin: 4px 0 8px; }
.edit-form .field { margin-bottom: 10px; }

.link-btn { background: none; border: none; color: var(--muted); font: inherit; cursor: pointer; padding: 8px 0; text-decoration: underline; text-underline-offset: 3px; }

.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; margin-top: 10px; }

/* ---------------------------------------------------------------- 배지 / 탭 */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  font-weight: 600;
  line-height: 1;
  padding: 5px 9px;
  border-radius: 999px;
  background: var(--bg);
  color: var(--muted);
  white-space: nowrap;
}
.badge.open { background: var(--primary-soft); color: var(--primary); }
.badge.final { background: var(--final-soft); color: var(--final); }
.badge.guide { background: var(--guide-bg); color: var(--guide-ink); }
.badge.admin { background: var(--text); color: var(--surface); }

.list-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.tabs { display: flex; gap: 2px; flex-wrap: wrap; padding: 3px; background: var(--border); border-radius: 11px; }
.tab {
  min-height: 36px;
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  border: none;
  background: none;
  color: var(--muted);
  padding: 6px 12px;
  border-radius: 8px;
  cursor: pointer;
  transition: background-color 150ms var(--ease), color 150ms var(--ease);
}
.tab:hover { color: var(--text); }
.tab.small { min-height: 32px; font-size: 13px; padding: 4px 10px; }
.tab.active { background: var(--surface); color: var(--text); font-weight: 700; box-shadow: var(--shadow); }

/* ---------------------------------------------------------------- 목록 */

.topic-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.topic-card { position: relative; scroll-margin-top: 16px; transition: border-color 150ms var(--ease); }
.topic-card:not(.open):hover, .topic-card.open { border-color: var(--primary); }
.topic-toggle {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  padding: 0;
  font: inherit;
  color: inherit;
  text-align: left;
  background: none;
  border: none;
  cursor: pointer;
}
.topic-toggle .icon {
  margin-top: 3px;
  color: var(--muted);
  transition: transform var(--dur-exit) var(--ease-in);
}
.topic-card.open .topic-toggle .icon { transform: rotate(180deg); transition: transform var(--dur-enter) var(--ease-out); }
.topic-card:not(.open):hover .topic-toggle .icon { color: var(--primary); }
/* 접힌 카드는 어디를 눌러도 펼쳐진다 */
.topic-card:not(.open) .topic-toggle::after { content: ""; position: absolute; inset: 0; border-radius: var(--radius); }
.topic-toggle:focus-visible { outline: none; }
.topic-card:not(.open) .topic-toggle:focus-visible::after { outline: 2px solid var(--ring); outline-offset: 2px; }
.topic-card.open .topic-toggle:focus-visible { outline: 2px solid var(--ring); outline-offset: 4px; border-radius: 6px; }

/* 펼침/접힘: grid 행을 0fr ↔ 1fr로 바꿔 실제 내용 높이까지 부드럽게 늘리고, 내용은 살짝 떠오르며 나타난다 */
.fold {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows var(--dur-exit) var(--ease-in);
}
.fold-inner {
  min-height: 0;
  overflow: hidden;
  padding: 4px;          /* 포커스 링이 잘리지 않을 여유 */
  margin: -4px;
  opacity: 0;
  transform: translateY(-6px);
  transition: opacity var(--dur-exit) var(--ease-in), transform var(--dur-exit) var(--ease-in);
}
.topic-card:not(.open) .fold-preview,
.topic-card.open .fold-detail {
  grid-template-rows: 1fr;
  transition: grid-template-rows var(--dur-enter) var(--ease-out);
}
.topic-card:not(.open) .fold-preview > .fold-inner,
.topic-card.open .fold-detail > .fold-inner {
  opacity: 1;
  transform: none;
  transition: opacity var(--dur-enter) var(--ease-out) 60ms, transform var(--dur-enter) var(--ease-out) 60ms;
}
.no-anim, .no-anim * { transition: none !important; }

/* 펼치기를 눌렀는데 데이터가 아직 오는 중일 때만 보이는 얇은 진행 막대 */
.topic-card.loading { cursor: progress; }
.topic-card.loading::before {
  content: "";
  position: absolute;
  top: -1px;
  left: 20px;
  right: 20px;
  height: 2px;
  border-radius: 2px;
  background: var(--primary);
  transform-origin: left;
  animation: load-bar 900ms var(--ease) infinite;
}
@keyframes load-bar { from { transform: scaleX(0); opacity: 1; } to { transform: scaleX(1); opacity: 0.2; } }

.topic-body { padding-top: 6px; }
.topic-desc { margin-bottom: 4px; }
.panel { border: 1px solid var(--border); border-radius: 12px; padding: 16px; margin-top: 14px; }
.comments-block { margin-top: 22px; }
.card-foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}
.topic-card-top { display: flex; gap: 6px; flex-wrap: wrap; }
.consensus-preview { color: var(--muted); margin: 0 0 6px; font-size: 14px; }

.preview-comments {
  list-style: none;
  margin: 10px 0 12px;
  padding: 10px 12px;
  background: var(--bg);
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 14px;
}
.preview-comments li { display: flex; gap: 8px; align-items: baseline; min-width: 0; }
.preview-comments .who { flex: none; font-size: 13px; }
.preview-comments .score { flex: none; font-size: 12px; color: var(--muted); }
.preview-body { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.more {
  position: relative;
  z-index: 1;
  min-height: 32px;
  padding: 4px 6px;
  margin: -4px -6px;
  font: inherit;
  font-weight: 600;
  color: var(--primary);
  background: none;
  border: none;
  border-radius: 8px;
  cursor: pointer;
}
.more:hover { background: var(--primary-soft); }
.draft-flag { display: inline-flex; align-items: center; gap: 4px; margin-left: 4px; color: var(--guide-ink); font-weight: 600; }


.empty { text-align: center; color: var(--muted); padding: 56px 16px; }

.skeleton { height: 96px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--border); position: relative; overflow: hidden; }
.skeleton::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, var(--bg), transparent);
  animation: shimmer 1.2s infinite;
}
@keyframes shimmer { from { transform: translateX(-100%); } to { transform: translateX(100%); } }

/* ---------------------------------------------------------------- 상세 */


.guideline { background: var(--guide-bg); border-color: var(--guide-border); }
.guideline h3 { color: var(--guide-ink); }

.ai-label { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--faint); margin-bottom: 8px; }
.ai-text { color: var(--faint); }
.ai-pending { color: var(--primary); font-weight: 600; animation: ai-pulse 1.4s ease-in-out infinite; }
@keyframes ai-pulse { 50% { opacity: 0.45; } }
.final-text { font-weight: 500; font-size: 17px; }
.consensus.is-final { border-color: var(--final); }
.consensus.is-final h3 { color: var(--final); }

.progress { height: 6px; background: var(--bg); border-radius: 999px; overflow: hidden; margin-top: 12px; }
.progress > div { height: 100%; background: var(--primary); border-radius: 999px; }

.admin-box { margin-top: 16px; padding-top: 14px; border-top: 1px dashed var(--border-strong); }
.admin-box summary { cursor: pointer; color: var(--muted); font-size: 14px; font-weight: 600; margin-bottom: 10px; min-height: 32px; display: flex; align-items: center; gap: 6px; }

.comments-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.comments-head h3 { margin: 0; }
.comment-form { margin: 14px 0 4px; }
.kbd-hint { margin-right: auto; color: var(--muted); font-size: 13px; }
@media (hover: none) { .kbd-hint { display: none; } } /* 터치 기기에는 키보드 단축키 안내를 숨긴다 */
.comments { list-style: none; margin: 8px 0 0; padding: 0; }
.comment { padding: 16px 0 12px; border-top: 1px solid var(--border); }
.comment:last-child { padding-bottom: 0; }
.comment-head { display: flex; gap: 8px; align-items: baseline; margin-bottom: 4px; }
.who { font-weight: 700; font-size: 14px; }
.who.author { color: var(--primary); }

.react {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
  min-width: 56px;
  justify-content: center;
  font: inherit;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  border-radius: 999px;
  padding: 4px 12px;
  cursor: pointer;
  transition: background-color 150ms var(--ease), border-color 150ms var(--ease), color 150ms var(--ease);
}
.react:hover { border-color: var(--border-strong); color: var(--text); }
.react.on { border-color: var(--primary); background: var(--primary-soft); color: var(--primary); font-weight: 700; }
.react.on .icon { fill: currentColor; fill-opacity: 0.25; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--surface);
  padding: 12px 18px;
  border-radius: 12px;
  font-size: 14px;
  max-width: calc(100% - 32px);
  box-shadow: 0 8px 24px rgb(0 0 0 / 0.18);
  animation: toast-in 200ms var(--ease);
}
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 8px); } }

/* ---------------------------------------------------------------- 첫 화면 연출 (intro.js) */

.intro-lock, .intro-lock body { overflow: hidden; }
.intro {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: #050c0d;
  cursor: pointer;
  overflow: hidden;
  color: #effffb;
}
.intro canvas { position: absolute; inset: 0; }
.intro:not(.replay):not(.ready) { cursor: default; } /* 첫 인트로는 글자가 완성되기 전엔 누를 수 없다 */
.intro::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(ellipse 70% 60% at 50% 44%, transparent 35%, rgb(0 0 0 / 0.6) 100%);
}
.intro-title, .intro-sub, .intro-stats {
  position: absolute;
  left: 50%;
  z-index: 1;
  white-space: nowrap;
  opacity: 0;
  transform: translate(-50%, 8px);
  transition: opacity 700ms var(--ease-out), transform 700ms var(--ease-out);
}
.intro-title {
  font-weight: 800;
  line-height: 1;
  transform: translate(-50%, -50%);
  text-shadow: 0 0 32px rgb(45 212 191 / 0.55), 0 0 2px rgb(255 255 255 / 0.6);
}
.intro-sub {
  width: max-content;
  max-width: calc(100vw - 32px);
  white-space: normal;
  text-align: center;
  line-height: 1.5;
  font-size: clamp(15px, 2.1vw, 20px);
  font-weight: 500;
  color: rgb(204 251 241 / 0.85);
  transition-delay: 150ms;
}
.intro-stats { font-size: 14px; color: rgb(153 246 228 / 0.7); font-variant-numeric: tabular-nums; letter-spacing: 0.02em; transition-delay: 300ms; }
.intro-title { transition-duration: 220ms; }
.intro.show-title .intro-title { opacity: 1; }
.intro.show-text .intro-sub, .intro.show-text .intro-stats { opacity: 1; transform: translate(-50%, 0); }
.intro-prompt {
  position: absolute;
  left: 50%;
  bottom: 12%;
  z-index: 1;
  transform: translateX(-50%);
  font-size: 14px;
  letter-spacing: 0.08em;
  color: rgb(204 251 241 / 0.75);
  opacity: 0;
  pointer-events: none;
  transition: opacity 600ms var(--ease-out);
}
.intro.ready .intro-prompt { opacity: 1; animation: intro-pulse 2.2s ease-in-out 600ms infinite; }
.intro.leaving-soon .intro-prompt { animation: none; opacity: 0; transition-duration: 150ms; }
@keyframes intro-pulse { 50% { opacity: 0.35; } }
.intro-skip {
  position: absolute;
  right: 20px;
  bottom: 20px;
  z-index: 1;
  min-height: 36px;
  padding: 6px 14px;
  font: inherit;
  font-size: 13px;
  color: rgb(204 251 241 / 0.7);
  background: rgb(255 255 255 / 0.06);
  border: 1px solid rgb(255 255 255 / 0.12);
  border-radius: 999px;
  cursor: pointer;
}
.intro-skip:hover { color: #fff; background: rgb(255 255 255 / 0.12); }
.intro.replay { animation: intro-in 350ms cubic-bezier(0.22, 1, 0.36, 1); }
@keyframes intro-in { from { opacity: 0; } }
.intro.leaving { opacity: 0; transition: opacity 450ms var(--ease-in); }

/* 큰 제목 → 헤더 로고로 날아가는 전환 */
::view-transition-group(gr-brand) { animation-duration: 800ms; animation-timing-function: cubic-bezier(0.22, 1, 0.36, 1); }
::view-transition-old(gr-brand), ::view-transition-new(gr-brand) { height: 100%; object-fit: contain; }
::view-transition-old(root) { animation: 500ms cubic-bezier(0.4, 0, 1, 1) both intro-fade-out; }
::view-transition-new(root) { animation: 600ms cubic-bezier(0.22, 1, 0.36, 1) 100ms both intro-fade-in; }
@keyframes intro-fade-out { to { opacity: 0; } }
@keyframes intro-fade-in { from { opacity: 0; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
