:root {
  --c-deep: #9d1c52;
  --c-bright: #e61089;
  --c-pink: #ec86b0;
  --c-pink-tint: #fce4ee;
  --c-ink: #404040;
  --c-paper: #faf6f1;
  --c-paper-2: #f3ece2;
  --c-line: rgba(64,64,64,0.16);
  --c-line-strong: rgba(64,64,64,0.5);
  --shadow-paper: 0 1px 0 rgba(64,64,64,0.04), 0 18px 30px -20px rgba(157,28,82,0.18);
  --font-sans: "Pretendard Variable", "Pretendard", -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  --font-serif: "Noto Serif KR", "Nanum Myeongjo", "Apple SD Gothic Neo", serif;
  --font-mono: "JetBrains Mono", "D2Coding", "SF Mono", ui-monospace, monospace;
  --font-display: var(--font-sans);
  --t-fast: 280ms;
  --t-base: 520ms;
  --t-slow: 900ms;
  --paper-grain: 1;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; overscroll-behavior: none; }
@media (max-width: 720px) {
  html, body {
    height: auto;
    min-height: 100%;
    overflow-y: auto;
    overscroll-behavior: auto;
  }
}
body {
  font-family: var(--font-sans);
  color: var(--c-ink);
  background: var(--c-paper);
  font-feature-settings: "ss01", "ss02";
  -webkit-font-smoothing: antialiased;
  letter-spacing: -0.01em;
}

#root { height: 100%; }

button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; letter-spacing: inherit; }
a { color: inherit; text-decoration: none; }

/* ─── App shell ──────────────────────────────────────────── */
.zip-app {
  position: fixed; inset: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 56px;
  background: var(--c-paper);
  overflow: hidden;
}
@media (max-width: 720px) {
  .zip-app { grid-template-columns: minmax(0, 1fr); }
}

.zip-stage {
  position: relative;
  overflow: hidden;
  isolation: isolate;
}

/* paper-grain overlay (driven by --paper-grain) */
.zip-stage::before {
  content: ""; position: absolute; inset: 0; pointer-events: none; z-index: 5;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='220' height='220'><filter id='n'><feTurbulence baseFrequency='0.82' numOctaves='2' seed='4'/><feColorMatrix values='0 0 0 0 0.25  0 0 0 0 0.25  0 0 0 0 0.25  0 0 0 0.12 0'/></filter><rect width='220' height='220' filter='url(%23n)'/></svg>");
  opacity: calc(var(--paper-grain) * 0.6);
  mix-blend-mode: multiply;
}
.zip-stage::after {
  content: ""; position: absolute; inset: 0; pointer-events: none; z-index: 5;
  background:
    radial-gradient(ellipse 80% 60% at 50% 0%, rgba(236,134,176,0.10), transparent 70%),
    radial-gradient(ellipse 60% 50% at 100% 100%, rgba(157,28,82,0.06), transparent 70%);
}

/* ─── Right-side rail (vertical nav) ─────────────────────── */
.rail {
  position: relative;
  display: flex; flex-direction: column;
  align-items: stretch; justify-content: stretch;
  border-left: 1px solid var(--c-line);
  background: var(--c-paper-2);
  z-index: 10;
}
.rail-tab {
  flex: 1;
  display: flex; align-items: center; justify-content: center;
  writing-mode: vertical-rl;
  text-orientation: mixed;
  padding: 18px 0;
  font-size: 13px; font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--c-ink);
  border-bottom: 1px solid var(--c-line);
  transition: background 180ms, color 180ms;
  position: relative;
}
.rail-tab:last-child { border-bottom: 0; }
.rail-tab[data-active="true"] {
  background: var(--c-deep);
  color: #fff;
}
.rail-tab:hover:not([data-active="true"]) { background: rgba(157,28,82,0.06); }
.rail-tab .rail-num {
  position: absolute; top: 14px; left: 50%; transform: translateX(-50%);
  font-family: var(--font-mono);
  writing-mode: horizontal-tb;
  font-size: 10px; opacity: 0.6;
  letter-spacing: 0;
}
.rail-tab .rail-arrow {
  position: absolute; bottom: 14px; left: 50%; transform: translateX(-50%);
  writing-mode: horizontal-tb;
  font-size: 12px; opacity: 0.55;
}

/* mobile nav fallback */
.mobile-rail {
  display: none;
  position: fixed; top: 14px; right: 14px; z-index: 50;
  background: var(--c-paper-2);
  border: 1px solid var(--c-line);
  border-radius: 999px;
  padding: 6px;
  gap: 4px;
}
@media (max-width: 720px) {
  .mobile-rail { display: inline-flex; }
  .rail { display: none; }
}
.mobile-rail-dot {
  width: 28px; height: 28px;
  border-radius: 999px;
  display: inline-flex; align-items: center; justify-content: center;
  font-family: var(--font-mono); font-size: 10px;
  color: var(--c-ink); background: transparent;
}
.mobile-rail-dot[data-active="true"] { background: var(--c-deep); color: #fff; }

/* ─── Screen container (stack-fade transitions) ─────────── */
.screen-stack { position: absolute; inset: 0; perspective: 1600px; }
.screen-card {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  background: var(--c-paper);
  transform-origin: 50% 50%;
  box-shadow: var(--shadow-paper);
}
.screen-card[data-state="entering"]  { }
.screen-card[data-state="leaving"]   { opacity: 0; pointer-events: none; }
.screen-card[data-state="exited"]    { display: none; }

/* flipY enter: home flies in from the side after intro */
@keyframes zoomSettle {
  from { opacity: 0; transform: scale(1.14); }
  to   { opacity: 1; transform: scale(1); }
}
.screen-card[data-flip-in="true"] {
  animation: zoomSettle 0.65s cubic-bezier(0.19, 1, 0.22, 1) forwards;
}

/* ─── Left control panel — container-relative text sizing ── */
.ctrl-panel {
  container-type: inline-size;
  overflow: hidden;
}
/* headline scales with the panel's own width, not the viewport */
.ctrl-panel .headline {
  font-size: clamp(22px, 12cqi, 32px) !important;
}
.ctrl-panel .subhead {
  font-size: clamp(13px, 4.8cqi, 15px) !important;
  max-width: 100%;
}

/* ─── Typography utilities ──────────────────────────────── */
.eyebrow {
  font-family: var(--font-mono);
  font-size: 11px; letter-spacing: 0.16em; text-transform: uppercase;
  color: var(--c-deep); font-weight: 600;
}
.headline {
  font-family: var(--font-display);
  font-weight: 800;
  line-height: 1.08;
  letter-spacing: -0.025em;
  color: var(--c-ink);
  text-wrap: balance;
}
.zip-app[data-typeset="mix"] .headline { font-family: var(--font-serif); font-weight: 700; }

.subhead {
  font-size: 15px; color: var(--c-ink);
  line-height: 1.6;
  opacity: 0.78;
  max-width: 56ch;
}

/* ─── Card primitives ───────────────────────────────────── */
.card {
  background: #fff;
  border: 1px solid var(--c-line);
  border-radius: 4px;
  box-shadow: 0 1px 0 rgba(64,64,64,0.03);
}
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  background: var(--c-pink-tint);
  color: var(--c-deep);
  border: 1px solid rgba(157,28,82,0.12);
  white-space: nowrap;
}
.chip[data-stance="반대"]      { background: #efefef; color: var(--c-ink); border-color: var(--c-line); }
.chip[data-stance="중립·언급"] { background: #fff; color: var(--c-ink); }
.chip-cat { background: transparent; color: var(--c-deep); border-color: rgba(157,28,82,0.3); }
.pledge-list-item {
  width: 100%;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 7px;
  padding: 8px 10px;
  border: 1px solid rgba(64,64,64,0.10);
  border-left: 3px solid var(--pledge-cat-color, var(--c-deep));
  background: rgba(250,246,241,0.58);
  text-align: left;
  cursor: default;
}
.pledge-list-item:hover {
  background: #fff;
  border-color: rgba(64,64,64,0.18);
  border-left-color: var(--pledge-cat-color, var(--c-deep));
}
.pledge-list-chip {
  margin-top: 1px;
}
.pledge-list-cats {
  min-width: 0;
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 5px;
}
.pledge-list-title {
  min-width: 0;
  font-size: 13px;
  font-weight: 650;
  line-height: 1.45;
  color: var(--c-ink);
  overflow-wrap: anywhere;
  margin-right: 2px;
}

.btn-pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 14px;
  border: 1px solid var(--c-line);
  border-radius: 999px;
  font-size: 13px; font-weight: 500;
  background: #fff;
  transition: all 150ms;
  white-space: nowrap;
}
.btn-pill:hover { border-color: var(--c-deep); color: var(--c-deep); }
.btn-pill[data-active="true"] {
  background: var(--c-ink); color: #fff; border-color: var(--c-ink);
}

.select-pill {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 8px 14px;
  border: 1px solid var(--c-line);
  border-radius: 999px;
  font-size: 13px;
  background: #fff;
  cursor: pointer;
  appearance: none; -webkit-appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'><path d='M1 1l4 4 4-4' stroke='%23404040' fill='none' stroke-width='1.5'/></svg>");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 30px;
}

/* ─── Paper stack (rail accent + intro) ─────────────────── */
.paper {
  position: absolute;
  background: #fff;
  border: 1px solid var(--c-line);
  box-shadow:
    0 1px 0 rgba(64,64,64,0.04),
    0 22px 36px -22px rgba(157,28,82,0.30);
}

/* ─── Scroll regions ────────────────────────────────────── */
.scroll-y { overflow-y: auto; overflow-x: hidden; }
.scroll-y::-webkit-scrollbar { width: 8px; }
.scroll-y::-webkit-scrollbar-thumb { background: rgba(157,28,82,0.25); border-radius: 99px; }
.scroll-y::-webkit-scrollbar-track { background: transparent; }

/* ─── Misc ──────────────────────────────────────────────── */
.ruled {
  background-image: linear-gradient(var(--c-line) 1px, transparent 1px);
  background-size: 100% 28px;
  background-position: 0 27px;
}
.party-dot {
  display: inline-block; width: 8px; height: 8px; border-radius: 999px;
  vertical-align: 1px; margin-right: 5px;
}

.fold {
  position: absolute; top: 0; right: 0;
  width: 28px; height: 28px;
  /* top-right triangle = paper backside, bottom-left = shadow cast by fold */
  background: linear-gradient(225deg, var(--c-paper-2) 50%, rgba(64,64,64,0.07) 50%);
}

.fold-accent {
  background: var(--c-deep);
}

/* Actually cut the corner so fold doesn't look like an extra sheet on top */
.card:has(> .fold) {
  clip-path: polygon(0 0, calc(100% - 28px) 0, 100% 28px, 100% 100%, 0 100%);
  border-radius: 0;
}

/* prevent layout shift while React loads */
.boot {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  color: var(--c-deep); font-family: var(--font-mono); font-size: 12px;
  letter-spacing: 0.1em;
}

/* Hide tweaks panel host stays small */
.zip-app[data-edit-off] .tweaks-panel-host { display: none !important; }

/* ─── Mobile bottom nav ─────────────────────────────────── */
.mobile-bottom-nav {
  display: none;
  position: fixed;
  left: 0; right: 0; bottom: 0;
  height: 64px;
  background: rgba(255, 255, 255, 0.94);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  border-top: 1px solid var(--c-line);
  z-index: 100;
  padding-bottom: env(safe-area-inset-bottom);
}
.mobile-bottom-nav-inner {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  height: 64px;
}
.mob-tab {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 3px;
  color: rgba(64, 64, 64, 0.5);
  font-size: 9px;
  font-family: var(--font-mono);
  letter-spacing: 0.04em;
  transition: color 150ms;
  position: relative;
}
.mob-tab svg {
  width: 22px;
  height: 22px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.mob-tab[data-active="true"] {
  color: var(--c-deep);
}
.mob-tab[data-active="true"]::after {
  content: "";
  position: absolute;
  top: 6px;
  left: 50%;
  transform: translateX(-50%);
  width: 22px;
  height: 2px;
  background: var(--c-deep);
  border-radius: 2px;
}

@media (max-width: 720px) {
  .mobile-bottom-nav { display: block; }
  .mobile-rail { display: none !important; }
  .rail { display: none !important; }
}

/* ─── Mobile shell overrides ────────────────────────────── */
@media (max-width: 720px) {
  .zip-app {
    position: relative;
    inset: auto;
    grid-template-columns: 1fr;
    min-height: 100dvh;
    overflow: visible;
  }
  .zip-stage {
    overflow: visible;
    isolation: auto;
    min-height: 100dvh;
  }
  /* paper grain is decorative; clip it to viewport on mobile */
  .zip-stage::before,
  .zip-stage::after {
    position: fixed;
    inset: 0;
    z-index: 1;
  }
  .screen-stack {
    position: relative;
    inset: auto;
    perspective: none;
    min-height: 100dvh;
  }
  .screen-card {
    position: relative;
    inset: auto;
    min-height: 100dvh;
    box-shadow: none;
  }
  /* Leaving screens collapse so the page doesn't double in height */
  .screen-card[data-state="leaving"] {
    display: none;
  }
  /* Inner scroll containers flow naturally on mobile */
  .scroll-y {
    overflow: visible;
    height: auto;
  }

  /* 2-column screen layouts → stack */
  .screen-2col {
    display: block !important;
    height: auto !important;
  }
  .screen-2col > .ctrl-panel {
    border-right: 0 !important;
    border-bottom: 1px solid var(--c-line);
    padding: 28px 20px !important;
  }
  .screen-2col > .ctrl-panel .headline {
    font-size: clamp(26px, 8vw, 36px) !important;
  }
  /* Mobile reserves room above the bottom nav */
  .screen-2col > .scroll-y,
  .screen-2col > div:last-child {
    padding: 24px 20px 96px !important;
    overflow: visible !important;
    height: auto !important;
  }
  /* keep intro centered without nav padding */
  .screen-card:has(.zip-paper-stage) {
    padding-bottom: 0 !important;
  }

  /* Intro: lock the page so the scale(4) exit animation doesn't escape */
  .zip-app[data-current="intro"] {
    overflow: hidden;
    height: 100dvh;
  }
  .zip-app[data-current="intro"] .zip-stage {
    overflow: hidden;
    height: 100dvh;
  }

  /* Floating share button — move to bottom-left to clear bottom nav */
  .share-btn-floating {
    top: auto !important;
    right: auto !important;
    left: 16px !important;
    bottom: 80px !important;
    padding: 9px 14px !important;
  }
}

/* ─── Pledge expand (single cell that grows downward) ── */
.pledge-list-item[data-expanded="true"] {
  background: #fff;
  border-color: var(--pledge-cat-color, var(--c-deep));
  box-shadow: 0 8px 20px -12px rgba(157, 28, 82, 0.25);
}
.pledge-list-head {
  width: 100%;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 7px;
}
.pledge-list-details {
  width: 100%;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px dashed var(--c-line);
  animation: pledgeExpandOpen 240ms cubic-bezier(.2, .8, .2, 1);
  overflow: hidden;
}
@keyframes pledgeExpandOpen {
  from { opacity: 0; max-height: 0; padding-top: 0; margin-top: 0; border-top-color: transparent; }
  to   { opacity: 1; max-height: 600px; }
}

/* ─── Tweaks panel: trim on mobile so it doesn't hide content ── */
@media (max-width: 720px) {
  .tweaks-panel-host {
    bottom: 84px !important;
  }

  /* Compact candidate card */
  .candidate-card {
    grid-template-columns: 56px 1fr !important;
    gap: 12px !important;
    padding: 14px 14px !important;
  }
  .candidate-card .candidate-portrait {
    width: 56px !important;
    height: 68px !important;
  }
  .candidate-card .candidate-portrait > div {
    font-size: 7px !important;
  }

  /* Ranking row → vertical stack */
  .rank-row {
    grid-template-columns: 44px 1fr 56px !important;
    grid-template-areas:
      "rank name total"
      "bar bar bar" !important;
    gap: 8px 12px !important;
    padding: 12px 14px !important;
  }
  .rank-row .rank-col-rank  { grid-area: rank; }
  .rank-row .rank-col-name  { grid-area: name; }
  .rank-row .rank-col-bar   { grid-area: bar; }
  .rank-row .rank-col-total { grid-area: total; }
  .rank-header { display: none !important; }
  .podium-grid {
    grid-template-columns: 1fr !important;
    gap: 10px !important;
  }

  /* Articles row → stack */
  .article-row {
    grid-template-columns: 1fr !important;
    gap: 12px !important;
    padding: 18px 0 !important;
  }
  .article-row .article-thumb {
    width: 100% !important;
    aspect-ratio: 16/9 !important;
  }

  /* Bubble chart: detail becomes bottom sheet */
  .bubble-detail {
    position: fixed !important;
    inset: auto 0 0 0 !important;
    width: 100% !important;
    max-height: 70dvh !important;
    border-radius: 18px 18px 0 0 !important;
    z-index: 90 !important;
    padding: 18px 18px 84px !important;
    box-shadow: 0 -20px 50px -16px rgba(157, 28, 82, 0.35) !important;
    overflow-y: auto !important;
  }
  .bubble-stage {
    min-height: 360px !important;
  }
}
