  :root {
    color-scheme: light;
    --page:            #f9f9f7;
    --surface-1:       #fcfcfb;
    --text-primary:    #0b0b0b;
    --text-secondary:  #52514e;
    --text-muted:      #898781;
    --gridline:        #e1e0d9;
    --baseline:        #c3c2b7;
    --border:          rgba(11,11,11,0.10);
    --positive:        #2a78d6;
    --negative:        #e34948;
    --midpoint:        #f0efec;
  }
  @media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
      color-scheme: dark;
      --page:            #0d0d0d;
      --surface-1:       #1a1a19;
      --text-primary:    #ffffff;
      --text-secondary:  #c3c2b7;
      --text-muted:      #898781;
      --gridline:        #2c2c2a;
      --baseline:        #383835;
      --border:          rgba(255,255,255,0.10);
      --positive:        #3987e5;
      --negative:        #e66767;
      --midpoint:        #383835;
    }
  }
  :root[data-theme="dark"] {
    color-scheme: dark;
    --page:            #0d0d0d;
    --surface-1:       #1a1a19;
    --text-primary:    #ffffff;
    --text-secondary:  #c3c2b7;
    --text-muted:      #898781;
    --gridline:        #2c2c2a;
    --baseline:        #383835;
    --border:          rgba(255,255,255,0.10);
    --positive:        #3987e5;
    --negative:        #e66767;
    --midpoint:        #383835;
  }

  * { box-sizing: border-box; }
  body {
    margin: 0;
    background: var(--page);
    color: var(--text-primary);
    font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  }
  main {
    max-width: 880px;
    margin: 0 auto;
    padding: 32px 20px 64px;
  }
  h1 {
    font-size: clamp(18px, 4.5vw, 22px);
    margin: 60px 0 4px;
  }
  .subtitle {
    color: var(--text-secondary);
    font-size: 14px;
    margin: 0 0 28px;
  }
  .card {
    margin-bottom: 24px;
  }

  /* countdown */
  .countdown-label { font-size: 13px; color: var(--text-secondary); margin-bottom: 8px; }
  .countdown-dday {
    display: block;
    font-size: clamp(32px, 10vw, 56px);
    font-weight: 700;
    line-height: 1;
    margin-bottom: 16px;
    color: inherit;
    text-decoration: none;
    cursor: pointer;
  }
  .countdown-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
  }
  .countdown-unit {
    flex: 1 1 56px;
    background: var(--page);
    border-radius: 8px;
    padding: 10px 4px;
    text-align: center;
  }
  .countdown-unit[hidden] { display: none; }
  .countdown-value {
    font-size: clamp(20px, 5.5vw, 28px);
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    line-height: 1;
  }
  .countdown-unit-label { font-size: 11px; color: var(--text-secondary); margin-top: 6px; }
  .countdown-meta { font-size: 12px; color: var(--text-muted); margin-top: 14px; }

  /* pollster tabs */
  .pollster-tabs {
    display: flex;
    justify-content: flex-end;
    gap: 4px;
    margin-bottom: 20px;
    border-bottom: 1px solid var(--border);
  }
  .pollster-tab {
    appearance: none;
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px 14px;
    font-size: 13px;
    font-family: inherit;
    color: var(--text-secondary);
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
  }
  .pollster-tab.active {
    color: var(--text-primary);
    font-weight: 600;
    border-bottom-color: var(--positive);
  }
  .empty-state { font-size: 13px; color: var(--text-muted); padding: 24px 0; }

  /* hero */
  .hero-row { display: flex; gap: 32px; flex-wrap: wrap; align-items: baseline; }
  .hero { }
  .hero-label { font-size: 13px; color: var(--text-secondary); margin-bottom: 6px; }
  .hero-value { font-size: clamp(32px, 9vw, 48px); font-weight: 600; line-height: 1; }
  .hero-value.positive { color: var(--positive); }
  .hero-value.negative { color: var(--negative); }
  .hero-meta { font-size: 12px; color: var(--text-muted); margin-top: 8px; }

  /* legend */
  .legend { display: flex; gap: 20px; margin: 24px 0 12px; }
  .legend-item { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-secondary); }
  .legend-key { width: 16px; height: 2px; border-radius: 1px; }
  .legend-key.positive { background: var(--positive); }
  .legend-key.negative { background: var(--negative); }

  .chart-wrap { overflow-x: auto; }
  svg { display: block; width: 100%; min-width: 640px; height: auto; }
  .gridline { stroke: var(--gridline); stroke-width: 1; }
  .axis-text { fill: var(--text-muted); font-size: 11px; }
  .series-positive { stroke: var(--positive); }
  .series-negative { stroke: var(--negative); }
  .end-dot { stroke: var(--surface-1); stroke-width: 2; }
  .end-label { font-size: 12px; font-weight: 600; }
  .end-label.positive { fill: var(--positive); }
  .end-label.negative { fill: var(--negative); }

  .crosshair { stroke: var(--baseline); stroke-width: 1; pointer-events: none; }
  .hover-dot { pointer-events: none; }

  #tooltip {
    position: fixed;
    pointer-events: none;
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px 10px;
    font-size: 12px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.12);
    opacity: 0;
    transition: opacity 0.08s ease;
    white-space: nowrap;
  }
  #tooltip .tt-date { color: var(--text-muted); margin-bottom: 4px; }
  #tooltip .tt-row { display: flex; align-items: center; gap: 6px; }
  #tooltip .tt-key { width: 10px; height: 2px; }
  #tooltip .tt-key.positive { background: var(--positive); }
  #tooltip .tt-key.negative { background: var(--negative); }
  #tooltip .tt-val { font-weight: 600; color: var(--text-primary); margin-left: auto; }
  #tooltip .tt-name { color: var(--text-secondary); }

  table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
  }
  th, td {
    text-align: left;
    padding: 8px 10px;
    border-bottom: 1px solid var(--gridline);
    font-variant-numeric: tabular-nums;
  }
  th { color: var(--text-secondary); font-weight: 500; }
  td.num { text-align: right; }
  td.cell-best { color: var(--positive); font-weight: 700; }
  td.cell-worst { color: var(--negative); font-weight: 700; }
  .source-note { font-size: 12px; color: var(--text-muted); margin-top: 8px; }

  details { margin-top: 20px; }
  details summary {
    cursor: pointer;
    font-size: 18px;
    color: var(--text-secondary);
    padding: 4px 0;
  }

  .site-footer {
    display: flex;
    gap: 16px;
    margin-top: 32px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
    font-size: 12px;
  }
  .site-footer a {
    color: var(--text-muted);
    text-decoration: none;
  }
  .site-footer a:hover { text-decoration: underline; }

  @media (max-width: 600px) {
    main { padding: 20px 14px 48px; }
    .card { margin-bottom: 16px; }
    .hero-row { gap: 20px; }
    .countdown-grid { gap: 8px; }
  }

  /* 채팅(게시판+실시간 혼합) */
  .chat-toggle {
    position: fixed;
    right: 20px;
    bottom: 20px;
    width: 52px;
    height: 52px;
    border-radius: 50%;
    border: none;
    background: var(--positive);
    color: #fff;
    font-size: 22px;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(0,0,0,0.2);
    z-index: 60;
  }
  .chat-toggle.hidden { display: none; }

  .chat-panel {
    position: fixed;
    right: 20px;
    top: 20px;
    bottom: 84px;
    width: 420px;
    max-width: calc(100vw - 40px);
    height: auto;
    display: none;
    flex-direction: column;
    z-index: 60;
  }
  .chat-panel.open { display: flex; }

  @media (max-width: 1399px) {
    .chat-panel.open { bottom: 20px; }
  }

  /* 실제 카드처럼 보이는 시각적 껍데기는 이 안쪽 래퍼가 담당한다 (배경/테두리/
     둥근 모서리/overflow:hidden). #chatPanel 자체는 overflow를 hidden으로 두지
     않아야, 왼쪽에 책갈피처럼 튀어나온 펼침 버튼이 잘리지 않는다. */
  .chat-panel-inner {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: 0 8px 28px rgba(0,0,0,0.18);
    overflow: hidden;
  }

  .chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 14px;
    background: var(--midpoint);
    border-bottom: 1px solid var(--border);
    border-radius: 12px 12px 0 0;
    font-size: 14px;
    font-weight: 600;
  }
  .chat-close {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 16px;
    cursor: pointer;
    padding: 2px 6px;
  }

  /* 채팅창 왼쪽 옆구리에 붙는 책갈피 모양 펼침 버튼. #chatPanel이 fixed/sticky로
     자기 위치를 잡아주므로, 이 버튼은 그 자식으로 두면 별도 계산 없이 항상
     채팅창 왼쪽 가장자리에 붙어 따라다닌다. */
  .chat-expand-tab {
    position: absolute;
    left: -24px;
    top: 96px;
    width: 26px;
    height: 56px;
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-right: none;
    border-radius: 8px 0 0 8px;
    box-shadow: -6px 3px 10px -3px rgba(0,0,0,0.18);
    color: var(--text-secondary);
    font-size: 14px;
    cursor: pointer;
    transition: color 0.18s ease;
  }
  .chat-expand-tab:hover { color: var(--text-primary); }
  .chat-expand-tab.active { color: var(--positive); }
  /* 버튼 모양(책갈피 테두리)은 고정해두고, 화살표 아이콘만 뒤집는다 — 버튼 전체를
     돌리면 둥근 모서리까지 반대쪽으로 넘어가서 모양이 어색해진다. */
  .chat-expand-tab-icon { display: inline-block; transition: transform 0.18s ease; }
  .chat-expand-tab.active .chat-expand-tab-icon { transform: rotate(180deg); }

  /* 채팅창 옆(또는 위)으로 밀려나오는 확장 시트. 채팅창이 본문 위에 겹쳐 뜨는
     플로팅 패널인 1400px 미만에서는 시트도 채팅창과 같은 자리에 겹쳐서 뜨고,
     채팅창이 본문 옆에 나란히 고정되는 1400px 이상에서는 아래 미디어쿼리로
     본문과 채팅창 사이를 채우며 옆으로 슬라이드하는 형태로 바뀐다. */
  .chat-expand-sheet {
    position: fixed;
    /* 채팅창 헤더(펼침/닫기 버튼)는 이 시트보다 z-index가 낮은 채팅창 위에 그대로
       남아있으므로, 헤더 높이(~48px)만큼은 겹치지 않게 아래에서부터 띄운다 —
       그래야 시트가 열린 상태에서도 펼침/닫기 버튼을 계속 누를 수 있다. */
    top: 76px;
    bottom: 32px;
    right: 20px;
    left: auto;
    width: 420px;
    max-width: calc(100vw - 40px);
    background: var(--surface-1);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: 0 8px 28px rgba(0,0,0,0.18);
    z-index: 61;
    display: none;
    overflow: auto;
  }
  .chat-expand-sheet.open { display: block; }

  .chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 10px 12px;
    display: flex;
    flex-direction: column;
    gap: 10px;
  }
  .chat-message-row { display: flex; gap: 8px; align-items: flex-start; }
  .chat-message:hover .chat-message-delete { visibility: visible; }
  .chat-message-delete {
    visibility: hidden;
    margin-left: auto;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 12px;
    cursor: pointer;
    padding: 0 2px;
    flex: 0 0 auto;
  }
  .chat-message-delete:hover { color: var(--negative); }
  .chat-staff-badge {
    font-size: 10px;
    font-weight: 700;
    color: var(--positive);
    border: 1px solid var(--positive);
    border-radius: 4px;
    padding: 0 4px;
    margin-left: 4px;
  }
  .chat-message-avatar { flex: 0 0 auto; }
  .chat-avatar-img { width: 26px; height: 26px; border-radius: 50%; display: block; }
  .chat-avatar-fallback {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: var(--midpoint);
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  .chat-message-body { flex: 1; min-width: 0; }
  .chat-youtube-embed {
    position: relative;
    width: 100%;
    padding-top: 56.25%; /* 16:9 */
    margin-top: 6px;
    border-radius: 8px;
    overflow: hidden;
    background: #000;
  }
  .chat-youtube-embed iframe {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    border: 0;
  }
  .chat-image-embed {
    display: block;
    margin-top: 6px;
    max-width: 220px;
    border-radius: 8px;
    overflow: hidden;
    border: none;
    background: none;
    padding: 0;
    cursor: zoom-in;
  }
  .chat-image-embed img {
    display: block;
    width: 100%;
    max-height: 220px;
    object-fit: cover;
  }

  /* 이미지를 새 탭으로 여는 대신, 화면 전체를 덮는 라이트박스로 원본 크기를 보여준다.
     모바일에서도 화면 꽉 차게 뜨도록 100dvh를 쓰고(주소창이 접히고 펼쳐지며 뷰포트
     높이가 바뀌는 문제 방지, 미지원 브라우저는 100vh로 자동 대체), 여백도 좁은
     화면에서는 더 줄인다. */
  .image-lightbox {
    position: fixed;
    inset: 0;
    height: 100vh;
    height: 100dvh;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 32px;
    z-index: 100;
    cursor: zoom-out;
  }
  .image-lightbox[hidden] { display: none; }
  .image-lightbox img {
    display: block;
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border-radius: 8px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.4);
  }
  @media (max-width: 600px) {
    .image-lightbox { padding: 12px; }
  }
  .chat-message-name { font-size: 12px; font-weight: 600; color: var(--text-secondary); }
  .chat-message-text { font-size: 13px; word-break: break-word; }
  .chat-reactions { display: inline-flex; gap: 6px; margin-left: 6px; vertical-align: middle; }
  .chat-reaction-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 11px;
    padding: 0;
    cursor: pointer;
  }
  .chat-reaction-btn.active { color: var(--positive); font-weight: 600; }
  .chat-reaction-btn.chat-reaction-dislike.active { border-color: var(--negative); color: var(--negative); }
  .chat-reaction-btn:disabled { opacity: 0.5; cursor: default; }

  .chat-user-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-top: 1px solid var(--border);
    font-size: 12px;
  }
  .chat-user-bar .chat-user-name { flex: 1; font-weight: 600; }
  .chat-logout-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 12px;
    cursor: pointer;
    text-decoration: underline;
  }

  .chat-login-prompt {
    padding: 14px 12px;
    border-top: 1px solid var(--border);
    text-align: center;
    font-size: 12px;
    color: var(--text-secondary);
  }
  .chat-login-prompt p { margin: 0 0 8px; }
  #googleSignInBtn { display: inline-flex; justify-content: center; width: 100%; }

  .chat-form {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 10px 12px;
    border-top: 1px solid var(--border);
  }
  .chat-form-row {
    display: flex;
    gap: 6px;
  }
  .chat-image-preview-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 6px;
    background: var(--page);
    border: 1px solid var(--border);
    border-radius: 8px;
  }
  /* [hidden] 자체가 display:none이지만, 위 규칙과 특이성이 같아서(둘 다 클래스/속성
     선택자 1개) 나중에 로드되는 이 규칙이 이겨버린다 — hidden 속성만으로는 안 감춰지는
     문제가 있어 명시적으로 다시 덮어쓴다. */
  .chat-image-preview-bar[hidden] { display: none; }
  .chat-image-preview-bar img {
    width: 32px;
    height: 32px;
    border-radius: 6px;
    object-fit: cover;
    display: block;
    flex: 0 0 auto;
  }
  .chat-image-preview-label {
    font-size: 12px;
    color: var(--text-secondary);
    flex: 1;
    min-width: 0;
  }
  .chat-image-preview-remove {
    flex: 0 0 auto;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 13px;
    cursor: pointer;
    padding: 2px 6px;
  }
  .chat-image-preview-remove:hover { color: var(--negative); }
  .chat-image-btn {
    flex: 0 0 auto;
    background: none;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 15px;
    line-height: 1;
    padding: 8px 9px;
    cursor: pointer;
    color: var(--text-secondary);
  }
  .chat-image-btn:hover { background: var(--border); }
  .chat-image-btn:disabled { opacity: 0.5; cursor: default; }
  .chat-form input {
    flex: 1;
    min-width: 0;
    padding: 8px 10px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--page);
    color: var(--text-primary);
    font-size: 13px;
  }
  .chat-form button {
    padding: 8px 14px;
    border-radius: 8px;
    border: none;
    background: var(--positive);
    color: #fff;
    font-size: 13px;
    cursor: pointer;
  }

  /* 넓은 화면에서는 채팅 패널을 본문 오른쪽에 나란히 붙이고, main+패널을 하나의
     묶음으로 봐서 그 전체를 가운데 정렬한다 (패널만 별도로 오른쪽에 떠 있지
     않도록). 토글 버튼은 숨기고 패널은 항상 열어둔다. */
  @media (min-width: 1400px) {
    .layout {
      display: flex;
      justify-content: center;
      align-items: flex-start;
      gap: 32px;
    }
    main { margin: 0; }
    .chat-toggle { display: none; }
    /* 이 화면 폭에서는 채팅창이 항상 열려 있고 다시 열 토글 버튼도 숨겨져 있어서,
       닫기 버튼을 눌러도 실제로 닫히지 않는다 — 그래서 아예 숨긴다. */
    .chat-close { display: none; }
    .chat-panel {
      display: flex;
      position: sticky;
      top: 32px;
      right: auto;
      bottom: auto;
      height: calc(100vh - 64px);
    }

    /* 본문을 밀어내지 않고, 본문 위에 떠 있는 형태로 왼쪽으로 밀려나온다. 오른쪽은
       채팅창과 딱 붙지 않고 채팅창 아래로 겹치게(채팅창 z-index가 더 높아서 위에 보임)
       그 너비만큼 파고든다. (JS가 본문/채팅창의 실제 위치를 측정해서 left/right를 잡아준다.) */
    .chat-expand-sheet {
      position: fixed;
      top: 52px;
      bottom: 52px;
      left: auto;
      right: 460px;
      width: auto;
      max-width: none;
      z-index: 59;
    }
  }
