#pollsOpen { position: relative; }
.battle-badge { display: inline-block; vertical-align: baseline; border: 0; border-radius: 3px; padding: 1px 4px; margin-right: 5px; font: inherit; font-size: 10px; line-height: 16px; cursor: pointer; }
.battle-red { --battle-color: color-mix(in srgb, var(--live-color) 80%, var(--text-primary)); --battle-tint: color-mix(in srgb, var(--battle-color) 10%, transparent); }
.battle-blue { --battle-color: color-mix(in srgb, var(--link-color) 60%, var(--text-primary)); --battle-tint: color-mix(in srgb, var(--battle-color) 10%, transparent); }
.battle-badge { color: var(--battle-color); background: var(--battle-tint); }
.battle-tooltip { position: fixed; z-index: 110000; max-width: min(280px, calc(100vw - 16px)); padding: 12px 14px; border: 1px solid var(--battle-color); border-radius: 7px; color: var(--text-primary); background: var(--bg-color); box-shadow: var(--shadow-heavy); font-size: 12px; overflow-wrap: anywhere; }
.battle-tooltip strong { font-size: 13px; }
.battle-tooltip p { margin: 6px 0 0; color: var(--battle-color); }
.battle-choices { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 14px; position: relative; margin: 18px 0; }
.battle-choices::after { content: 'VS'; position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); background: var(--bg-color); color: var(--text-secondary); border-radius: 50%; padding: 5px; font-size: 10px; font-weight: bold; }
.battle-side { position: relative; display: flex; flex-direction: column; align-items: flex-start; gap: 12px; padding: 16px 13px; border: 1px solid var(--border-color); border-radius: 7px; background: var(--battle-tint); cursor: pointer; min-width: 0; }
.battle-side:has(input:checked), .battle-side.is-mine { border-color: var(--battle-color); box-shadow: inset 0 0 0 1px var(--battle-color); }
.battle-side input { position: absolute; top: 16px; right: 12px; width: 22px; height: 22px; margin: 0; opacity: 0; }
.battle-choice-indicator { position: absolute; top: 14px; right: 12px; display: grid; place-items: center; width: 22px; height: 22px; border: 2px solid var(--battle-color); border-radius: 50%; color: transparent; background: var(--bg-color); font-size: 14px; font-weight: 800; pointer-events: none; }
.battle-side:has(input:checked) .battle-choice-indicator { background: var(--battle-color); color: var(--battle-button-text, var(--card-color)); }
.battle-side:has(input:focus-visible) { outline: 2px solid var(--battle-color); outline-offset: 3px; }
.battle-side:has(input:disabled) { cursor: default; }
.battle-creator { flex-basis: 100%; color: var(--text-secondary); overflow-wrap: anywhere; }
.battle-side-name { color: var(--battle-color); font-size: 12px; font-weight: 600; }
.battle-option-text { font-size: 15px; line-height: 1.6; overflow-wrap: anywhere; }
.battle-side small { margin-top: auto; color: var(--text-secondary); font-size: 11px; }
.battle-score { display: flex; height: 5px; overflow: hidden; background: var(--link-color); border-radius: 4px; margin-bottom: 16px; }
.battle-red-bar { background: var(--live-color); transition: width .2s; }
.poll-create label.battle-red, .poll-create label.battle-blue { color: var(--battle-color); }
.poll-badge { position: absolute; top: -16px; right: -12px; padding: 1px 5px; border-radius: 7px 7px 7px 0; background: color-mix(in srgb, var(--live-color) 75%, var(--primary-dark)); color: var(--battle-button-text, var(--card-color)); font-size: 9px; line-height: 15px; white-space: nowrap; pointer-events: none; }
.poll-badge[hidden] { display: none; }
.poll-badge { font-variant-numeric: tabular-nums; pointer-events: auto; }
.poll-dialog { width: min(780px, calc(100vw - 32px)); max-height: min(760px, calc(100dvh - 48px)); padding: 0; border: 1px solid var(--border-color); border-radius: 10px; background: var(--bg-color); color: var(--text-primary); box-shadow: var(--shadow-heavy); margin: auto; }
.poll-dialog::backdrop { background: color-mix(in srgb, var(--primary-dark) 65%, transparent); }
.poll-dialog * { box-sizing: border-box; }
.poll-dialog button, .poll-dialog input, .poll-dialog textarea, .poll-dialog select { font: inherit; }
.poll-dialog button { cursor: pointer; }
.poll-dialog button:disabled { cursor: default; opacity: .5; }
.poll-dialog :focus-visible, #pollsOpen:focus-visible { outline: 2px solid var(--primary-color); outline-offset: 3px; }
.poll-header { display: flex; align-items: center; gap: 10px; margin: 0; padding: 15px 20px; border-bottom: 1px solid var(--border-color); }
.poll-header h2 { font-size: 16px; margin: 0; }
.poll-header .poll-icon { color: var(--primary-color); }
.poll-header button { border: 0; background: transparent; color: var(--text-secondary); border-radius: 4px; min-height: 32px; padding: 5px 10px; font-size: 12px; }
#pollCreateToggle { margin-left: auto; background: var(--msg-bg-color); color: var(--text-primary); border: 1px solid var(--primary-light); }
#pollClose { margin-left: auto; font-size: 22px; }
#pollCreateToggle:not([hidden]) + #pollClose { margin-left: 0; }
.poll-body { display: grid; grid-template-columns: minmax(0, 1fr) 235px; min-height: 320px; }
.poll-main { padding: 22px; min-width: 0; background-color: var(--bg-color) }
.poll-eyebrow { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; color: var(--text-secondary); font-size: 11px; margin-bottom: 12px; }
.poll-question { font-size: 19px; line-height: 1.55; margin: 0 0 8px; overflow-wrap: anywhere; white-space: pre-wrap; }
.poll-help { font-size: 12px; line-height: 1.7; color: var(--text-secondary); margin: 0 0 20px; }
.poll-primary { border: 0; border-radius: 5px; padding: 10px 18px; background: var(--primary-color); color: var(--battle-button-text, var(--card-color)); font-size: 13px; }
.poll-footer { display: flex; align-items: center; gap: 12px; justify-content: space-between; }
.poll-footer small { color: var(--text-secondary); font-size: 11px; }
.poll-history { padding: 20px 12px; border-left: 1px solid var(--border-color); background: var(--msg-bg-color); }
.poll-history h3 { font-size: 12px; font-weight: 500; color: var(--text-secondary); margin: 0 8px 12px; }
.poll-history-list { display: grid; gap: 6px; max-height: 460px; overflow-y: auto; scrollbar-width: thin; }
.poll-history button { width: 100%; padding: 11px; border: 1px solid transparent; border-radius: 5px; color: var(--text-primary); background: transparent; text-align: left; }
.poll-history button[aria-pressed="true"] { background: var(--card-color); border-color: var(--border-color); }
.poll-history button:hover { background: var(--card-color); }
.poll-history strong { display: block; font-size: 12px; font-weight: 500; line-height: 1.6; overflow-wrap: anywhere; }
.poll-history small { display: block; color: var(--text-secondary); font-size: 10px; margin-top: 5px; }
.poll-empty { padding: 38px 0; }
.poll-empty h3 { font-size: 18px; margin: 12px 0; }
.poll-status { padding: 0 20px; color: var(--text-secondary); font-size: 12px; line-height: 1.7; }
.poll-status:not(:empty) { padding-top: 12px; padding-bottom: 12px; }
.poll-status.is-error { color: color-mix(in srgb, var(--live-color) 80%, var(--text-primary)); }
.poll-create { display: grid; gap: 14px; }
.poll-create .battle-create-quota { margin: 0; font-weight: 600; }
.poll-create label { display: grid; gap: 7px; font-size: 12px; color: var(--text-primary); }
.poll-create textarea, .poll-create input, .poll-create select { width: 100%; padding: 10px; border: 1px solid var(--border-color); border-radius: 4px; background: var(--bg-color); color: var(--text-primary); font-size: 13px; }
.poll-create textarea { min-height: 80px; resize: vertical; }
.poll-chat-link { background: transparent; color: inherit; border: 0; padding: 3px 0; text-decoration: underline; cursor: pointer; font: inherit; }
@media (max-width: 768px) {
    .poll-dialog { width: calc(100vw - 20px); max-height: calc(100dvh - 24px); }
    .poll-header { padding: 10px 14px; }
    .poll-body { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) auto; }
    .poll-main { padding: 18px 16px; }
    .poll-history { border-left: 0; border-top: 1px solid var(--border-color); padding: 14px 10px; }
    .poll-history-list { max-height: 190px; }
    .poll-question { font-size: 17px; }
}

/* Compose the existing site tokens; do not redefine the shared theme palette. */
.poll-dialog { background: var(--chat-bg); }
.poll-header { background: var(--card-color); }
.poll-history { background: var(--bg-color); }
.poll-create input, .poll-create textarea, .poll-create select { background: var(--bg-color); border-color: var(--primary-light); }
.poll-create input::placeholder, .poll-create textarea::placeholder { color: var(--text-light); opacity: 1; }
.poll-create label.battle-red input, .poll-create label.battle-blue input { background: color-mix(in srgb, var(--battle-color) 12%, var(--bg-color)); border-color: var(--battle-color); }
.poll-create input:focus-visible, .poll-create textarea:focus-visible { outline: none; border-color: var(--battle-color, var(--link-color)); box-shadow: inset 0 0 0 1px var(--battle-color, var(--link-color)); }
#pollHistoryPanel:not([open]) > .poll-history-list { display: none; }
.poll-dialog :focus-visible { outline-color: var(--link-color); }
.poll-state { display: inline-flex; align-items: center; gap: 4px; padding: 2px 6px; border-radius: 4px; color: color-mix(in srgb, var(--live-color) 80%, var(--text-primary)); background: color-mix(in srgb, var(--live-color) 10%, transparent); border: 1px solid color-mix(in srgb, var(--live-color) 45%, transparent); font-size: 11px; font-weight: 700; line-height: 1.5; white-space: nowrap; }
.poll-state::before { content: ''; width: 5px; height: 5px; border-radius: 50%; background: currentColor; }
.poll-state.is-ended { background: transparent; }
.poll-history h3.poll-history-heading { color: color-mix(in srgb, var(--live-color) 80%, var(--text-primary)); font-weight: 700; }
.poll-history-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 6px; }
.poll-history-meta small { margin: 0; }
.poll-history-meta .poll-state { font-size: 10px; padding: 1px 4px; }
.poll-history summary { display: none; }
[data-theme="dark"] .poll-dialog { --battle-button-text: var(--text-primary); color-scheme: dark; border-color: var(--primary-light); }
[data-theme="dark"] .poll-dialog .poll-history { border-color: var(--primary-color); }
[data-theme="dark"] .poll-help { color: var(--text-light); }
[data-theme="dark"] .poll-primary:disabled { background: var(--msg-bg-color); color: var(--text-light); opacity: 1; }
[data-theme="dark"] .battle-side:has(input:checked) .battle-choice-indicator { color: var(--card-color); }
@media (max-width: 768px) {
    .poll-history summary { display: flex; justify-content: space-between; align-items: center; padding: 8px; color: var(--text-primary); font-size: 13px; cursor: pointer; list-style: none; }
    .poll-history summary::-webkit-details-marker { display: none; }
    .poll-history summary::after { content: '展开 ＋'; color: var(--text-secondary); font-size: 11px; }
    .poll-history details[open] summary::after { content: '收起 −'; }
    .poll-history details[open] summary { margin-bottom: 10px; }
}

[data-theme="dark"] .poll-badge { color: var(--text-primary); }

[data-theme="dark"] .poll-dialog::backdrop { background: color-mix(in srgb, var(--card-color) 75%, transparent); }
