:root {
  --primary: #5769E7;
  --primary-dark: #4455c4;
  --coral: #FF7471;
  --ink: #161617;
  --muted: #6b6b76;
  --line: #e4e4ea;
  --bg: #ffffff;
  --panel: #f6f6fa;
  --surface: #ffffff;      /* inputs, cards, buttons */
  --tip-bg: #161617;       /* dark labels with light text */
  --tip-fg: #ffffff;
  --danger: #b3261e;
  --danger-line: #f0c9c6;
  --danger-bg: #fdf0ef;
  --ok: #1b7f46;
  --ok-bg: #e7f6ee;
  --chip: #f3f3f6;
  --radius: 12px;
}
/* dark mode: the moon button (bottom left) sets data-theme="dark" on <html>; light is the default */
:root[data-theme="dark"] {
  color-scheme: dark;
  --primary: #7383EE;
  --primary-dark: #8D9AF2;
  --ink: #ECECF1;
  --muted: #A3A3AF;
  --line: #34343C;
  --bg: #141416;
  --panel: #1C1C20;
  --surface: #232328;
  --tip-bg: #ECECF1;
  --tip-fg: #141416;
  --danger: #FF8A80;
  --danger-line: #5A2A27;
  --danger-bg: #2B1715;
  --ok: #5FD08F;
  --ok-bg: #16301F;
  --chip: #2A2A30;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: Inter, "Helvetica Neue", Arial, system-ui, sans-serif;
  color: var(--ink); background: var(--bg); line-height: 1.45;
}
a { color: var(--primary); }
h1, h2 { line-height: 1.15; margin: 0 0 .5em; }
.logo { display: inline-flex; align-items: center; gap: 8px; font-weight: 800; font-size: 28px; letter-spacing: -.02em; color: var(--ink); text-decoration: none; }
.logo i { width: 26px; height: 26px; border-radius: 6px; background: linear-gradient(135deg, var(--primary) 50%, var(--coral) 50%); display: inline-block; }
.center { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 24px 16px; }
.card { width: 100%; max-width: 380px; }
label { display: block; font-size: 14px; font-weight: 600; margin: 16px 0 6px; }
input[type=text], input[type=password], input[type=number], textarea {
  width: 100%; font: inherit; padding: 12px 14px; border: 1.5px solid var(--line); border-radius: 10px; background: var(--surface); color: var(--ink);
}
input:focus, textarea:focus, select:focus { outline: 3px solid rgba(87,105,231,.25); border-color: var(--primary); }
.btn {
  font: inherit; font-weight: 700; border: 0; border-radius: 999px; padding: 12px 28px; cursor: pointer;
  background: var(--primary); color: #fff; transition: background .15s, transform .05s;
}
.btn:hover { background: var(--primary-dark); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.block { width: 100%; margin-top: 20px; }
.btn.ghost { background: transparent; color: var(--ink); border: 1.5px solid var(--line); padding: 9px 18px; }
.btn.ghost:hover { background: var(--panel); }
.btn.danger { background: transparent; color: var(--danger); border: 1.5px solid var(--danger-line); padding: 9px 18px; }
.btn.danger:hover { background: var(--danger-bg); }
.msg { min-height: 1.4em; margin-top: 12px; font-size: 14px; }
.msg.err { color: var(--danger); }
.msg.ok { color: var(--ok); }
.muted { color: var(--muted); font-size: 14px; }
.tabs { display: flex; gap: 4px; background: var(--panel); border-radius: 999px; padding: 4px; margin-bottom: 8px; }
.tabs button { flex: 1; font: inherit; font-weight: 600; border: 0; background: transparent; padding: 8px; border-radius: 999px; cursor: pointer; color: var(--muted); }
.tabs button[aria-selected=true] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.12); }

/* app shell */
.topbar { display: flex; align-items: center; justify-content: space-between; padding: 14px 24px; border-bottom: 1px solid var(--line); gap: 12px; flex-wrap: wrap; }
.topbar .right { display: flex; align-items: center; gap: 12px; }
.topbar .right { flex-wrap: wrap; }
.topbar .right a { font-weight: 600; text-decoration: none; }
.topbar .right a:hover { text-decoration: underline; }
[hidden] { display: none !important; }
.narrow { max-width: 380px; }
.setup { max-width: 560px; }
.setup .switch { border-bottom: 1px solid var(--line); }
.setup .setnote { margin: 4px 0 4px; }
.setup .fontlist { grid-template-columns: repeat(2, 1fr); max-height: none; }
.setup .presets { grid-template-columns: repeat(3, 1fr); }
@media (max-width: 520px) { .setup .presets, .setup .fontlist { grid-template-columns: repeat(2, 1fr); } }
.h2 { font-size: 18px; margin: 28px 0 10px; }
.check { display: inline-flex; align-items: center; gap: 6px; margin: 0; font-weight: 600; }
.wrap { max-width: 880px; margin: 0 auto; padding: 32px 20px; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.list { list-style: none; margin: 16px 0 0; padding: 0; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.list li { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.list li:last-child { border-bottom: 0; }
.pill { font-size: 12px; font-weight: 700; padding: 3px 10px; border-radius: 999px; background: var(--ok-bg); color: var(--ok); }
.pill.closed { background: var(--chip); color: var(--muted); }

/* presenter */
.present { display: grid; grid-template-columns: minmax(0, 1fr) 320px; grid-template-rows: minmax(0, 1fr); height: calc(100vh - 62px); }
.stage { position: relative; padding: 24px 32px; display: flex; flex-direction: column; min-width: 0; min-height: 0; overflow: hidden; }
.tabs[hidden] { display: none; }
.stage h1 { font-size: clamp(18px, 2vw, 28px); font-weight: 800; letter-spacing: -.01em; text-align: center; margin: 0 auto .25em; max-width: 960px; }
.subtitle { text-align: center; color: var(--muted); font-size: clamp(14px, 1.3vw, 18px); margin: 0 auto 8px; max-width: 760px; }
.subtitle[hidden] { display: none; }
.vote .sub { color: var(--muted); font-size: 16px; margin: -8px 0 18px; }
.vote .sub[hidden] { display: none; }
.joinbar { display: inline-flex; flex-wrap: wrap; gap: 6px 14px; align-items: baseline; background: var(--panel); border-radius: 10px; padding: 8px 14px; font-size: 16px; margin-bottom: 10px; align-self: center; justify-content: center; }
.joinbar b { font-size: 24px; letter-spacing: .06em; }
.copylink { font: inherit; font-size: 24px; font-weight: 700; letter-spacing: .02em; color: var(--primary); background: none; border: 0; padding: 0; cursor: pointer; text-decoration: underline; text-underline-offset: 4px; }
.copylink:hover { color: var(--primary-dark); }
.qricon { align-self: center; display: inline-flex; padding: 4px; margin-left: -4px; border: 0; border-radius: 6px; background: transparent; color: var(--ink); cursor: pointer; }
.qricon:hover { background: var(--surface); color: var(--primary); }
.qricon:focus-visible { outline: 3px solid rgba(87,105,231,.4); }
.joinbar { position: relative; padding-right: 22px; }
.joinx { position: absolute; top: -8px; right: -8px; width: 20px; height: 20px; padding: 0; border: 1px solid var(--line); border-radius: 50%; background: var(--surface); color: var(--muted); font-size: 14px; line-height: 18px; cursor: pointer; box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.joinx:hover { background: var(--tip-bg); border-color: var(--tip-bg); color: var(--tip-fg); }
.joinx:focus-visible { outline: 3px solid rgba(87,105,231,.4); }
.copylink:focus-visible { outline: 3px solid rgba(87,105,231,.4); border-radius: 4px; }
.copylink.copied { color: var(--ok); text-decoration: none; }
.cloudbox { flex: 1; min-height: 0; position: relative; }
.cloudbox svg { width: 100%; height: 100%; display: block; }
.cloudbox .empty { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 18px; text-align: center; padding: 20px; }
.presets { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.preset { display: flex; height: 30px; padding: 0; border: 2px solid transparent; border-radius: 8px; overflow: hidden; cursor: pointer; background: var(--surface); outline: 1px solid var(--line); }
.preset i { flex: 1; }
.preset[aria-pressed=true] { border-color: var(--primary); }
.preset:focus-visible { outline: 3px solid rgba(87,105,231,.4); }
.mytpl { margin-top: 12px; }
.tpl-h { font-size: 12px; font-weight: 700; color: var(--muted); margin-bottom: 6px; }
.tpl { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.tpl .tplbtn { width: 96px; flex: none; }
.tplname { flex: 1; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tplx { border: 0; background: transparent; cursor: pointer; color: var(--muted); font-size: 18px; line-height: 1; padding: 2px 6px; border-radius: 6px; }
.tplx:hover { background: var(--surface); color: var(--danger); }
.swatches { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.swatch { position: relative; width: 38px; height: 38px; }
.swatch input[type=color] { width: 38px; height: 38px; padding: 0; border: 2px solid var(--surface); border-radius: 50%; outline: 1px solid var(--line); background: none; cursor: pointer; overflow: hidden; }
.swatch input[type=color]::-webkit-color-swatch-wrapper { padding: 0; }
.swatch input[type=color]::-webkit-color-swatch { border: 0; border-radius: 50%; }
.swatch input[type=color]::-moz-color-swatch { border: 0; border-radius: 50%; }
.swatch button { position: absolute; top: -6px; right: -6px; width: 18px; height: 18px; padding: 0; border: 0; border-radius: 50%; background: var(--tip-bg); color: var(--tip-fg); font-size: 13px; line-height: 18px; cursor: pointer; opacity: 0; }
.swatch:hover button, .swatch:focus-within button { opacity: 1; }
.cloudbox .empty[hidden] { display: none; }
.cloud-word { cursor: default; }
.side { border-left: 1px solid var(--line); background: var(--panel); padding: 20px; overflow-y: auto; }
.side h2 { font-size: 19px; font-weight: 800; text-transform: uppercase; letter-spacing: .04em; color: var(--primary); margin: 26px 0 10px; }
.side h2:first-child { margin-top: 0; }
.sidehead { display: flex; align-items: center; justify-content: space-between; font-size: 13px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; margin-bottom: 14px; }
.iconbtn { border: 0; background: transparent; cursor: pointer; font-size: 24px; line-height: 1; padding: 2px 10px; border-radius: 8px; color: var(--muted); }
.iconbtn:hover { background: var(--surface); color: var(--ink); }
.present.nopanel { grid-template-columns: minmax(0, 1fr); }
/* full screen: no top bar, the cloud uses the whole screen */
.fsexit { display: none; }
/* top bar hidden (☰ button, or full screen): a floating ☰ brings it back */
.menubtn { width: 40px; height: 40px; padding: 0; border: 1.5px solid var(--line); border-radius: 10px; background: var(--surface); cursor: pointer; display: inline-flex; align-items: center; justify-content: center; }
.menubtn:hover { background: var(--panel); }
.menubtn:focus-visible { outline: 3px solid rgba(87,105,231,.4); }
.menubtn span, .menubtn span::before, .menubtn span::after { display: block; width: 18px; height: 2px; border-radius: 2px; background: var(--ink); position: relative; }
.menubtn span::before, .menubtn span::after { content: ''; position: absolute; left: 0; }
.menubtn span::before { top: -6px; }
.menubtn span::after { top: 6px; }
.floatmenu { display: none; }
.tbicon { width: 40px; height: 40px; padding: 0; border: 1.5px solid var(--line); border-radius: 10px; background: var(--surface); color: var(--ink); cursor: pointer; display: inline-flex; align-items: center; justify-content: center; }
.tbicon:hover { background: var(--panel); color: var(--primary); }
.tbicon:focus-visible { outline: 3px solid rgba(87,105,231,.4); }
.tbicon[aria-pressed=false] { color: var(--muted); border-style: dashed; }
body.nobar .topbar { display: none; }
@media (min-width: 861px) { body.nobar .present { height: 100vh; } }
body.nobar .floatmenu { display: inline-flex; position: fixed; top: 12px; right: 12px; z-index: 20; opacity: .45; transition: opacity .2s; }
body.nobar .floatmenu:hover, body.nobar .floatmenu:focus-visible { opacity: 1; }
/* keep the corner ☰ clear of the panel's × and the QR card */
body.nobar .sidehead { padding-right: 48px; }
body.nobar .present.nopanel .qrcard { top: 64px; }
body.nobar .present.nopanel .qrhide { top: 54px; }
body.isfs .fsexit { display: block; position: fixed; bottom: 16px; left: 68px; z-index: 20; background: var(--surface); opacity: .35; transition: opacity .2s; }
body.isfs .fsexit:hover, body.isfs .fsexit:focus-visible { opacity: 1; }
.present.nopanel .side { display: none; }
.stat { display: flex; gap: 20px; }
.stat div { font-size: 12px; color: var(--muted); }
.stat b { display: block; font-size: 26px; color: var(--ink); }
.switch { display: flex; align-items: center; justify-content: space-between; padding: 8px 0; font-size: 15px; }
.switch input { width: 40px; height: 22px; accent-color: var(--primary); }
select { font: inherit; padding: 8px 10px; border-radius: 8px; border: 1.5px solid var(--line); background: var(--surface); color: var(--ink); }
.words { list-style: none; padding: 0; margin: 0; }
.words li { display: flex; justify-content: space-between; align-items: center; padding: 6px 0; border-bottom: 1px solid var(--line); font-size: 15px; }
.words li button { border: 0; background: transparent; cursor: pointer; color: var(--muted); font-size: 18px; line-height: 1; padding: 2px 6px; border-radius: 6px; }
.words li button:hover { background: var(--surface); color: var(--danger); }
.words .n { color: var(--muted); font-variant-numeric: tabular-nums; margin-right: 8px; }
.words li button.unhide { font-size: 13px; font-weight: 700; color: var(--primary); border: 1.5px solid var(--line); padding: 3px 10px; border-radius: 999px; background: var(--surface); }
.words li button.unhide:hover { color: var(--primary-dark); border-color: var(--primary); }
.cloud-word { cursor: pointer; }
.wordpop { position: absolute; z-index: 5; display: flex; align-items: center; gap: 5px; padding: 3px 8px; background: var(--tip-bg); color: var(--tip-fg); border-radius: 7px; font-size: 12px; font-weight: 600; line-height: 1.4; white-space: nowrap; pointer-events: none; box-shadow: 0 2px 8px rgba(22,22,23,.2); }
.wordpop .wp-dot, .wordpop .wp-tip { opacity: .7; font-weight: 400; }
.wordpop button { display: none; font: inherit; font-weight: 700; color: #fff; background: var(--primary); border: 0; border-radius: 5px; padding: 1px 7px; cursor: pointer; }
.wordpop.touch { pointer-events: auto; }
.wordpop.touch .wp-tip { display: none; }
.wordpop.touch button { display: inline-block; }

/* voter */
.vote { width: 100%; max-width: 480px; }
.vote h1 { font-size: 26px; font-weight: 700; margin-bottom: 16px; }
.hint { font-size: 14px; color: var(--muted); margin: 8px 0 0; }
.thanks { color: var(--ok); font-size: 15px; margin-top: 10px; min-height: 1.4em; }

@media (max-width: 860px) {
  .present { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto; height: auto; }
  .stage { overflow: visible; }
  .cloudbox { height: 55vh; flex: none; }
  .side { border-left: 0; border-top: 1px solid var(--line); }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* QR code */
.qrcard { position: absolute; top: 24px; right: 32px; width: 116px; padding: 8px 8px 6px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 4px; font: inherit; color: var(--ink); box-shadow: 0 1px 4px rgba(0,0,0,.06); }
.qrcard:hover { border-color: var(--primary); }
.qrcard[hidden] { display: none; }
.qrcard svg { width: 100%; height: auto; display: block; }
.qrcard small { font-size: 12px; font-weight: 600; color: var(--muted); }
.stage.hasqr h1, .stage.hasqr .subtitle { padding: 0 132px; }
.qrmodal { position: fixed; inset: 0; background: rgba(22,22,23,.65); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 16px; }
.qrmodal[hidden] { display: none; }
.qrbox { background: var(--surface); border-radius: 20px; padding: 28px 32px; text-align: center; max-width: 94vw; max-height: 96vh; overflow: auto; }
.qrbox svg { width: min(62vmin, 520px); height: auto; display: block; margin: 0 auto; }
.qrcap { font-size: 18px; font-weight: 700; margin: 14px 0 2px; }
.qrurl { margin: 0; color: var(--muted); font-size: 14px; word-break: break-all; }
.qrcode { margin: 6px 0 16px; font-size: 16px; }
@media (max-width: 860px) { .qrcard { display: none; } .stage.hasqr h1, .stage.hasqr .subtitle { padding: 0; } }

.qrhide { position: absolute; top: 14px; right: 24px; width: 24px; height: 24px; padding: 0; border: 0; border-radius: 50%; background: var(--tip-bg); color: var(--tip-fg); font-size: 16px; line-height: 24px; cursor: pointer; opacity: 0; transition: opacity .15s; z-index: 2; }
.qrhide[hidden] { display: none; }
.stage:hover .qrhide, .qrhide:focus-visible { opacity: 1; }
@media (max-width: 860px) { .qrhide { display: none; } }

/* per-cloud font (title, instructions) */
.stage h1, .stage .subtitle, .vote h1, .vote .sub, .vhead h1, .vhead .subtitle { font-family: var(--wc-font, inherit); }
.fontlist { display: grid; gap: 6px; max-height: 260px; overflow-y: auto; padding: 2px; }
.fontopt { display: flex; align-items: center; justify-content: space-between; gap: 10px; width: 100%; text-align: left; font: inherit; padding: 8px 12px; border: 2px solid transparent; outline: 1px solid var(--line); border-radius: 8px; background: var(--surface); cursor: pointer; color: var(--ink); }
.fontopt:hover { background: var(--panel); }
.fontopt[aria-pressed=true] { border-color: var(--primary); }
.fontopt .fp { font-size: 20px; line-height: 1.2; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fontopt .fn { font-size: 11px; color: var(--muted); flex: none; }

/* light / dark switch, bottom-left corner of every page */
.themebtn { position: fixed; left: 16px; bottom: 16px; z-index: 30; width: 40px; height: 40px; padding: 0; border: 1.5px solid var(--line); border-radius: 50%; background: var(--surface); color: var(--ink); cursor: pointer; display: inline-flex; align-items: center; justify-content: center; box-shadow: 0 2px 8px rgba(0,0,0,.12); opacity: .75; transition: opacity .2s; }
.themebtn:hover, .themebtn:focus-visible { opacity: 1; color: var(--primary); }
.themebtn:focus-visible { outline: 3px solid rgba(87,105,231,.4); }
.themebtn[aria-pressed=true] { color: var(--primary); }
