:root {
  --bg: #f4f1ff;
  --bg-2: #fef0f6;
  --card: #ffffff;
  --ink: #241c3a;
  --muted: #7a7290;
  --line: #eae4fb;
  --brand: #6d5efc;
  --brand-ink: #ffffff;
  --accent: #ff5ea2;
  --ok: #16b981;
  --shadow: 0 18px 40px -20px rgba(80, 60, 180, 0.45);
  --radius: 18px;
  --font-body: "Space Grotesk", ui-rounded, "Segoe UI", system-ui, sans-serif;
  --font-display: "Unbounded", "Space Grotesk", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  font-family: var(--font-body);
  color: var(--ink);
  background:
    radial-gradient(1100px 600px at 15% -5%, var(--bg-2), transparent 60%),
    radial-gradient(1000px 700px at 100% 0%, #e8f0ff, transparent 55%),
    var(--bg);
  min-height: 100vh;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.wrap {
  max-width: 640px;
  margin: 0 auto;
  padding: 28px 18px 72px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: center;
  margin: 8px 0 4px;
}
.brand a { text-decoration: none; color: inherit; }
.brand .logo { font-size: 30px; }
.brand h1 {
  font-family: var(--font-display);
  font-size: 26px;
  margin: 0;
  letter-spacing: -1px;
  font-weight: 800;
  background: linear-gradient(90deg, var(--brand), var(--accent));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.tagline {
  text-align: center;
  color: var(--muted);
  margin: 0 0 22px;
  font-weight: 600;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
}

h2 { font-family: var(--font-display); font-weight: 700; font-size: 21px; letter-spacing: -0.5px; margin: 0 0 14px; }

label { display: block; font-weight: 700; font-size: 14px; margin: 0 0 6px; }
.hint { color: var(--muted); font-size: 13px; font-weight: 600; }

input[type="text"],
input[type="email"],
input[type="number"] {
  width: 100%;
  font: inherit;
  padding: 12px 14px;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  background: #fbfaff;
  color: var(--ink);
  transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 4px rgba(109, 94, 252, 0.15);
}

.field { margin-bottom: 18px; }

.options { display: flex; flex-direction: column; gap: 12px; }

.opt-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border: 1.5px dashed var(--line);
  border-radius: 14px;
  background: #fbfaff;
}
.opt-row .grow { flex: 1; }
.opt-main { flex: 1; display: flex; flex-direction: column; gap: 8px; }

.type-toggle {
  display: inline-flex;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  background: #fff;
}
.type-toggle button {
  border: 0;
  background: transparent;
  padding: 8px 10px;
  font: inherit;
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
  color: var(--muted);
}
.type-toggle button.active { background: var(--brand); color: #fff; }

.icon-btn {
  border: 0;
  background: #fff;
  border: 1.5px solid var(--line);
  color: var(--muted);
  width: 38px;
  height: 38px;
  border-radius: 10px;
  font-size: 18px;
  cursor: pointer;
  flex: none;
}
.icon-btn:hover { color: var(--accent); border-color: var(--accent); }

.img-drop {
  display: flex;
  align-items: center;
  gap: 10px;
}
.img-preview {
  width: 46px; height: 46px;
  border-radius: 10px;
  object-fit: cover;
  border: 1.5px solid var(--line);
  display: none;
}
.img-preview.show { display: block; }
.file-label {
  font-size: 13px;
  font-weight: 700;
  color: var(--brand);
  cursor: pointer;
  padding: 8px 12px;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  background: #fff;
}
.file-label input { display: none; }

.btn {
  font: inherit;
  font-weight: 800;
  border: 0;
  border-radius: 12px;
  padding: 13px 18px;
  cursor: pointer;
  transition: transform 0.08s, box-shadow 0.15s, background 0.15s;
}
.btn:active { transform: translateY(1px) scale(0.99); }
.btn-primary {
  background: linear-gradient(90deg, var(--brand), #8a6bff);
  color: var(--brand-ink);
  box-shadow: 0 12px 24px -12px rgba(109, 94, 252, 0.9);
  width: 100%;
  font-size: 16px;
}
.btn-primary:disabled { opacity: 0.6; cursor: not-allowed; }
.btn-ghost {
  background: #fff;
  border: 1.5px solid var(--line);
  color: var(--brand);
  font-weight: 700;
}
.btn-add {
  background: #fff;
  border: 1.5px dashed var(--brand);
  color: var(--brand);
  width: 100%;
  margin-top: 12px;
}

.reveal-choices { display: flex; flex-direction: column; gap: 10px; }
.choice {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 14px;
  border: 1.5px solid var(--line);
  border-radius: 14px;
  cursor: pointer;
  background: #fbfaff;
}
.choice.selected { border-color: var(--brand); background: #f3f0ff; }
.choice input { margin-top: 3px; }
.choice .t { font-weight: 800; }
.choice .d { color: var(--muted); font-size: 13px; }

.threshold-extra {
  margin-top: 12px;
  padding-top: 14px;
  border-top: 1px dashed var(--line);
  display: none;
}
.threshold-extra.show { display: block; }

.row { display: flex; gap: 12px; align-items: center; }
.check { display: flex; gap: 8px; align-items: center; font-weight: 700; font-size: 14px; }
.check input { width: auto; }

/* ---- BIG BALLOT (vote page) --------------------------------------- */
/* On the vote page the choices become huge, full-bleed tiles.        */
.vote-page .wrap { max-width: 1080px; }
/* Results / hidden states stay comfortably narrow & centered.         */
.vote-page .card { max-width: 560px; margin-left: auto; margin-right: auto; }

.ballot-stage { width: 100%; }

.ballot-q {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(22px, 3.8vw, 40px);
  letter-spacing: -0.8px;
  line-height: 1.08;
  text-align: center;
  margin: 4px auto 22px;
  max-width: 900px;
}

.big-ballot {
  display: grid;
  gap: 18px;
  min-height: min(72vh, 700px);
}
.big-ballot.cols-2 { grid-template-columns: 1fr 1fr; }
.big-ballot.cols-3 { grid-template-columns: repeat(3, 1fr); }
.big-ballot.grid-2x2 { grid-template-columns: 1fr 1fr; }
.big-ballot.cols-auto { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }

.big-opt {
  position: relative;
  overflow: hidden;
  border: 0;
  border-radius: 28px;
  background: var(--tile, var(--brand));
  color: #fff;
  cursor: pointer;
  padding: 26px;
  min-height: 200px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 22px 45px -24px rgba(20, 10, 60, 0.7);
  transition: transform 0.16s cubic-bezier(0.2, 0.8, 0.2, 1), box-shadow 0.2s, filter 0.2s;
}
.big-opt::before {
  /* subtle sheen so flat gradients feel tactile */
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(120% 80% at 20% 0%, rgba(255, 255, 255, 0.28), transparent 60%);
  z-index: 1;
  pointer-events: none;
}
.big-opt:hover { transform: translateY(-6px) scale(1.015); box-shadow: 0 34px 60px -22px rgba(20, 10, 60, 0.75); }
.big-opt:active { transform: translateY(-2px) scale(0.995); }
.big-opt:disabled { cursor: default; }

.big-opt-label {
  position: relative;
  z-index: 2;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(30px, 5vw, 66px);
  line-height: 1.03;
  letter-spacing: -1px;
  text-align: center;
  text-shadow: 0 3px 22px rgba(0, 0, 0, 0.28);
  overflow-wrap: break-word; /* only break a word if it truly can't fit */
  max-width: 100%;
}
/* Smaller labels as tiles get narrower, so words stay on one line. */
.big-ballot.cols-3 .big-opt-label { font-size: clamp(22px, 2.9vw, 44px); }
.big-ballot.grid-2x2 .big-opt-label { font-size: clamp(24px, 3.4vw, 50px); }
.big-ballot.cols-auto .big-opt-label { font-size: clamp(22px, 2.6vw, 40px); }

/* Image tiles: photo fills the tile, caption sits over a scrim */
.big-opt.is-image { padding: 0; }
.big-opt-img { position: absolute; inset: 0; background-size: cover; background-position: center; z-index: 0; }
.big-opt-scrim {
  position: absolute; inset: 0; z-index: 1;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.62), rgba(0, 0, 0, 0.04) 55%);
}
.big-opt.is-image .big-opt-label {
  position: absolute; z-index: 2; left: 0; right: 0; bottom: 22px; padding: 0 22px;
  font-size: clamp(22px, 3.4vw, 44px);
}

/* Selected / dimmed feedback after a tap */
.big-opt-check {
  position: absolute; z-index: 3; top: 16px; right: 20px;
  width: 46px; height: 46px; border-radius: 50%;
  background: #fff; color: #16b981;
  display: flex; align-items: center; justify-content: center;
  font-size: 26px; font-weight: 900;
  opacity: 0; transform: scale(0.3);
  transition: opacity 0.25s, transform 0.3s cubic-bezier(0.2, 1.5, 0.4, 1);
}
.big-opt.chosen { outline: 5px solid #fff; outline-offset: -9px; }
.big-opt.chosen .big-opt-check { opacity: 1; transform: scale(1); }
.big-opt.dimmed { filter: saturate(0.5) brightness(0.72); transform: scale(0.98); }

@media (max-width: 680px) {
  .vote-page .wrap { max-width: 100%; }
  .big-ballot,
  .big-ballot.cols-2,
  .big-ballot.cols-3,
  .big-ballot.grid-2x2,
  .big-ballot.cols-auto {
    grid-template-columns: 1fr;
    min-height: 0;
  }
  .big-opt { min-height: 26vh; }
}

/* ---- CREATE PAGE (WYSIWYG editable tiles) ------------------------- */
.create-page .wrap { max-width: 1080px; }
/* Keep the settings card, submit button, errors & success centered/narrow. */
.create-page .card,
.create-page #createBtn,
.create-page #err { max-width: 560px; margin-left: auto; margin-right: auto; }
.create-page #createBtn { display: block; margin-top: 20px; }
.reveal-card { margin-top: 20px; }
.reveal-card > label { margin-bottom: 10px; }

/* Big editable question, styled like the ballot question.
   Scoped under .create-page so it beats the global input[type=text] rule. */
.create-page input.create-q {
  display: block;
  width: 100%;
  max-width: 860px;
  margin: 4px auto 20px;
  background: transparent;
  border: none;
  border-bottom: 2px dashed transparent;
  border-radius: 0;
  box-shadow: none;
  outline: none;
  text-align: center;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(22px, 3.8vw, 40px);
  letter-spacing: -0.8px;
  color: var(--ink);
  padding: 4px 0;
}
.create-page input.create-q::placeholder { color: var(--muted); }
.create-page input.create-q:focus { border-bottom-color: var(--line); box-shadow: none; }

/* Editable tiles are shorter than the real ballot so the form stays usable */
.create-page .big-ballot { min-height: 0; }
.create-page .big-opt { min-height: clamp(170px, 24vh, 230px); }
.big-opt.edit { cursor: default; flex-direction: column; gap: 12px; padding: 20px; }
.big-opt.edit:hover { transform: none; } /* don't lift while editing */

.big-opt input.tile-input {
  position: relative;
  z-index: 2;
  width: 100%;
  background: transparent;
  border: none;
  border-radius: 0;
  box-shadow: none;
  outline: none;
  padding: 0;
  color: #fff;
  text-align: center;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(26px, 4vw, 52px);
  letter-spacing: -1px;
  text-shadow: 0 3px 22px rgba(0, 0, 0, 0.28);
}
.big-opt input.tile-input:focus { box-shadow: none; }
.big-opt input.tile-input::placeholder { color: rgba(255, 255, 255, 0.55); }
.big-ballot.cols-3 .tile-input { font-size: clamp(20px, 2.6vw, 38px); }
.big-ballot.grid-2x2 .tile-input { font-size: clamp(22px, 3vw, 42px); }
.big-ballot.cols-auto .tile-input { font-size: clamp(20px, 2.4vw, 34px); }

/* Corner chips (type toggle + remove) */
.tile-chip {
  position: absolute;
  z-index: 5;
  top: 12px;
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 4px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.4);
  background: rgba(255, 255, 255, 0.2);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
}
.tile-chip.type { left: 12px; }
.tile-chip.type button {
  border: none;
  background: transparent;
  color: rgba(255, 255, 255, 0.85);
  font: inherit;
  font-weight: 800;
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
  border-radius: 999px;
  padding: 5px 9px;
}
.tile-chip.type button.on { background: #fff; color: var(--ink); }
.tile-chip.remove {
  right: 12px;
  width: 30px;
  height: 30px;
  padding: 0;
  justify-content: center;
  color: #fff;
  font-weight: 800;
  cursor: pointer;
  background: rgba(0, 0, 0, 0.3);
  border-color: rgba(255, 255, 255, 0.35);
}
.tile-chip.remove:hover { background: rgba(0, 0, 0, 0.5); }

/* Image tile: upload prompt + caption */
.tile-upload {
  position: relative;
  z-index: 3;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  color: #fff;
  text-align: center;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(16px, 2vw, 24px);
  line-height: 1.1;
  padding: 12px 18px;
  border-radius: 16px;
  border: 2px dashed rgba(255, 255, 255, 0.65);
}
.tile-upload .add-plus { font-size: 34px; line-height: 1; }
.tile-upload.has {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  flex-direction: row;
  font-size: 13px;
  font-weight: 700;
  padding: 7px 12px;
  border-style: solid;
  border-color: rgba(255, 255, 255, 0.45);
  background: rgba(0, 0, 0, 0.4);
}
.big-opt input.tile-caption {
  position: absolute;
  z-index: 3;
  left: 16px;
  right: 16px;
  bottom: 16px;
  width: auto;
  color: #fff;
  text-align: center;
  border-radius: 10px;
  padding: 8px 10px;
  border: 1px solid rgba(255, 255, 255, 0.35);
  background: rgba(0, 0, 0, 0.35);
  box-shadow: none;
  font: inherit;
  font-weight: 700;
  outline: none;
}
.big-opt input.tile-caption:focus { box-shadow: none; border-color: rgba(255, 255, 255, 0.7); }
.big-opt input.tile-caption::placeholder { color: rgba(255, 255, 255, 0.7); }

/* The tile a pasted image will land in gets a clear ring. */
.big-opt.edit.active-paste {
  outline: 3px solid #fff;
  outline-offset: -6px;
  box-shadow: 0 0 0 4px rgba(109, 94, 252, 0.55), 0 22px 45px -24px rgba(20, 10, 60, 0.7);
}

/* "Add option" tile */
.big-opt.add-tile {
  background: transparent;
  border: 2.5px dashed var(--line);
  color: var(--brand);
  box-shadow: none;
  flex-direction: column;
  gap: 4px;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 17px;
}
.big-opt.add-tile::before { display: none; }
.big-opt.add-tile .add-plus { font-size: 42px; line-height: 1; }
.big-opt.add-tile:hover {
  transform: translateY(-4px) scale(1.01);
  border-color: var(--brand);
  box-shadow: var(--shadow);
}

/* Results bars */
.bars { display: flex; flex-direction: column; gap: 14px; }
.bar-item .bar-top {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 6px; gap: 10px;
}
.bar-item .bar-label { font-weight: 800; display: flex; align-items: center; gap: 10px; }
.bar-item .bar-label img { width: 34px; height: 34px; border-radius: 8px; object-fit: cover; }
.bar-item .bar-num { font-weight: 800; color: var(--muted); font-size: 14px; }
.bar-track {
  height: 16px; background: var(--line); border-radius: 999px; overflow: hidden;
}
.bar-fill {
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--brand), var(--accent));
  transition: width 0.8s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.bar-item.winner .bar-fill { background: linear-gradient(90deg, var(--ok), #34d399); }
.bar-item.winner .bar-label::after { content: " 👑"; }

.progress {
  text-align: center;
  padding: 10px 0;
}
.progress .big { font-size: 40px; font-weight: 900; }
.progress-track {
  height: 12px; background: var(--line); border-radius: 999px; overflow: hidden; margin: 14px 0 6px;
}
.progress-fill {
  height: 100%; background: linear-gradient(90deg, var(--brand), var(--accent));
  transition: width 0.6s ease; border-radius: 999px;
}

/* Share links */
.share {
  display: flex; gap: 8px; align-items: center;
  background: #fbfaff; border: 1.5px solid var(--line);
  border-radius: 12px; padding: 8px 8px 8px 14px; margin-top: 8px;
}
.share code {
  flex: 1; font-family: ui-monospace, monospace; font-size: 13px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted);
}
.copy-btn {
  border: 0; background: var(--brand); color: #fff; font-weight: 800;
  padding: 8px 14px; border-radius: 9px; cursor: pointer; font: inherit; font-weight: 800; font-size: 13px;
}
.copy-btn.done { background: var(--ok); }

.notice {
  padding: 12px 14px; border-radius: 12px; font-weight: 700; font-size: 14px; margin-bottom: 16px;
}
.notice.err { background: #fff0f3; color: #c0295f; border: 1.5px solid #ffd6e2; }
.notice.ok { background: #ecfdf5; color: #0f8a63; border: 1.5px solid #c6f2df; }

.center { text-align: center; }
.mt { margin-top: 18px; }
.muted { color: var(--muted); }
.spin { animation: spin 0.8s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

.footer {
  text-align: center; color: var(--muted); font-size: 13px; margin-top: 26px; font-weight: 600;
}
.footer a { color: var(--brand); text-decoration: none; }

/* ---- Auth widget --------------------------------------------------- */
.auth-slot {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  min-height: 34px;
  margin-bottom: 2px;
}
.auth-slot:empty { display: none; }
.auth-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 6px 4px 8px;
  box-shadow: var(--shadow);
}
.auth-pic { width: 26px; height: 26px; border-radius: 50%; object-fit: cover; flex: none; }
.auth-initial {
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--brand); color: #fff; font-weight: 800; font-size: 13px;
}
.auth-name {
  font-weight: 700; font-size: 13px; max-width: 130px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.auth-link { font-weight: 700; font-size: 13px; color: var(--brand); text-decoration: none; padding: 0 4px; }
.auth-link:hover { text-decoration: underline; }
.auth-signout {
  border: 0; background: transparent; color: var(--muted);
  font: inherit; font-weight: 700; font-size: 13px; cursor: pointer;
  padding: 4px 8px; border-radius: 999px;
}
.auth-signout:hover { color: var(--accent); }

/* ---- Optional-question toggle -------------------------------------- */
.title-toggle-btn {
  border: 0; background: transparent; color: var(--muted);
  font: inherit; font-weight: 700; font-size: 13px; cursor: pointer;
  padding: 2px 8px; border-radius: 8px; margin: -8px 0 12px;
}
.title-toggle-btn:hover { color: var(--accent); }
.title-toggle-btn.is-off { color: var(--brand); }

/* ---- Dashboard ("My surveys") -------------------------------------- */
.dash-list { display: flex; flex-direction: column; gap: 12px; }
.dash-card {
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  flex-wrap: wrap;
  background: var(--card); border: 1px solid var(--line);
  border-radius: 16px; padding: 16px 18px; box-shadow: var(--shadow);
}
.dash-main { min-width: 0; flex: 1 1 240px; }
.dash-title {
  font-family: var(--font-display); font-weight: 700; font-size: 18px;
  letter-spacing: -0.3px; overflow-wrap: anywhere;
}
.dash-meta {
  color: var(--muted); font-size: 13px; font-weight: 600;
  display: flex; flex-wrap: wrap; gap: 6px; margin-top: 5px;
}
.dash-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.dash-btn { padding: 8px 12px; font-size: 13px; text-decoration: none; }
.dash-btn.danger { color: #c0295f; border-color: #ffd6e2; }
.dash-btn.danger:hover { background: #fff0f3; }
.dash-signin { display: flex; justify-content: center; margin-top: 14px; }

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15121f; --bg-2: #1c1530; --card: #201a30; --ink: #f0ecff;
    --muted: #a79fc4; --line: #322a48; --shadow: 0 18px 40px -20px rgba(0,0,0,0.6);
  }
  input[type="text"], input[type="email"], input[type="number"] { background: #191426; }
  .opt-row, .choice, .threshold-extra ~ *, .share, .type-toggle button:not(.active) { background: #191426; }
  .type-toggle, .icon-btn, .file-label { background: #191426; }
  .choice.selected { background: #241c3a; }
  .bar-item.winner .bar-label, .progress .big { color: var(--ink); }
}
