/* YesNoWheel styles: responsive, light/dark themes, RTL aware */
:root {
  --bg: #fff4dc;
  --card: #fffaf0;
  --text: #1d1633;
  --muted: #5b5278;
  --border: #1d1633;
  --primary: #7a4dff;
  --primary-text: #ffffff;
  --danger: #d6361f;
  --sun: #ffc82e; --coral: #ff6a55; --mint: #47d6a4; --ink: #1d1633;
  --bw: 2px;
  --radius: 18px;
  --shadow: 6px 6px 0 #1d1633;
  --stage-text: var(--text);
}
[data-theme="dark"] {
  --bg: #17122b;
  --card: #241c42;
  --text: #fff4dc;
  --muted: #b9afd8;
  --border: #7a6fb0;
  --primary: #9b7bff;
  --primary-text: #17122b;
  --shadow: 6px 6px 0 #000;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
[hidden] { display: none !important; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: "Bricolage Grotesque", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans", "Noto Sans JP", "Noto Sans KR", "Noto Sans SC", "Noto Sans Arabic", Tahoma, sans-serif;
  line-height: 1.45;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; }

/* ---------- Header ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px;
  padding: 10px clamp(12px, 3vw, 28px);
  background: var(--card);
  border-bottom: var(--bw) solid var(--border);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 1.15rem; color: var(--text); text-decoration: none; }
.brand svg { width: 30px; height: 30px; }
.title-input { flex: 1 1 160px; min-width: 0; max-width: 320px; padding: 8px 12px; border: var(--bw) solid var(--border); border-radius: 10px; background: var(--bg); }
.spacer { flex: 1 1 0; }

.icon-btn {
  width: 38px; height: 38px; display: inline-grid; place-items: center;
  border: var(--bw) solid var(--border); border-radius: 10px; background: var(--card); font-size: 1.1rem;
}
.icon-btn:hover { background: var(--bg); }

.select, .input, .textarea {
  border: var(--bw) solid var(--border); border-radius: 10px; background: var(--bg); padding: 8px 10px; width: auto;
}
.input, .textarea { width: 100%; }
.textarea { resize: vertical; font-family: inherit; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .8rem; }

/* ---------- Segmented controls & buttons ---------- */
.seg { display: inline-flex; padding: 3px; border: var(--bw) solid var(--border); border-radius: 999px; background: var(--bg); flex-wrap: wrap; }
.seg button { border: 0; background: none; padding: 7px 14px; border-radius: 999px; color: var(--text); font-weight: 600; font-size: .9rem; }
.seg button.active { background: var(--primary); color: var(--primary-text); }

.btn {
  border: var(--bw) solid var(--border); background: var(--card); padding: 9px 16px; border-radius: 10px; font-weight: 600;
}
.btn:hover { background: var(--bg); }
.btn.primary { background: var(--primary); color: var(--primary-text); border-color: transparent; }
.btn.primary:hover { filter: brightness(1.08); background: var(--primary); }
.btn.danger { color: var(--danger); }
.btn.ghost { background: transparent; }
.btn.small { padding: 6px 10px; font-size: .82rem; border-radius: 8px; }
.btn.big { font-size: 1.1rem; padding: 12px 40px; border-radius: 999px; letter-spacing: .04em; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

/* ---------- Layout ---------- */
.layout {
  display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(320px, .85fr);
  gap: 24px; max-width: 1280px; margin: 0 auto; padding: 20px clamp(12px, 3vw, 28px) 40px; align-items: start;
}
.stage { display: flex; flex-direction: column; align-items: center; gap: 12px; color: var(--stage-text); text-align: center; }
.stage-title { margin: 4px 0 0; font-size: clamp(1.3rem, 3vw, 2rem); line-height: 1.2; word-break: break-word; }
.stage-desc { margin: 0; max-width: 560px; opacity: .8; }
.hint { margin: 4px 0 0; font-size: .8rem; opacity: .65; }

.wheel-wrap { position: relative; width: min(100%, 78vh, 640px); aspect-ratio: 1 / 1; }
.wheel-wrap canvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: manipulation; outline-offset: 4px; border-radius: 50%; }

.tally { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 8px 12px; }
.tally-label { font-weight: 700; }
.tally-items { display: inline-flex; gap: 8px; flex-wrap: wrap; }
.chip { display: inline-flex; gap: 8px; align-items: center; padding: 5px 12px; border-radius: 999px; background: var(--card); color: var(--text); border: var(--bw) solid var(--border); font-size: .95rem; }
.chip b { font-size: 1.05rem; }
.chip.yes { border-color: #10b981; }
.chip.no { border-color: #ef4444; }
.chip.maybe { border-color: #f59e0b; }

/* ---------- Panel ---------- */
.panel { background: var(--card); border: var(--bw) solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.tabs { display: flex; gap: 4px; border-bottom: var(--bw) solid var(--border); margin-bottom: 14px; }
.tab { border: 0; background: none; padding: 9px 14px; font-weight: 700; color: var(--muted); border-bottom: 3px solid transparent; }
.tab.active { color: var(--text); border-bottom-color: var(--primary); }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; font-size: .9rem; }
.field.inline { flex-direction: row; align-items: center; justify-content: space-between; }
.row-gap { display: inline-flex; gap: 8px; align-items: center; }
.toolbar { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0; }
.checks { display: flex; flex-wrap: wrap; gap: 6px 18px; margin: 8px 0; }
.check { display: inline-flex; align-items: center; gap: 8px; font-size: .92rem; cursor: pointer; margin-bottom: 4px; }
.check input { accent-color: var(--primary); width: 16px; height: 16px; }
.actions { border: var(--bw) solid var(--border); border-radius: 10px; padding: 8px 12px; margin: 10px 0; display: flex; flex-wrap: wrap; gap: 4px 16px; }
.actions legend { padding: 0 6px; font-size: .8rem; color: var(--muted); font-weight: 700; }
.h2 { font-size: 1rem; margin: 6px 0 8px; }

/* ---------- Entry list ---------- */
.entry-list { list-style: none; margin: 10px 0; padding: 0; max-height: 360px; overflow: auto; display: flex; flex-direction: column; gap: 6px; }
.row { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; padding: 6px; border: var(--bw) solid var(--border); border-radius: 10px; background: var(--bg); }
.row.is-hidden .c-text { opacity: .45; text-decoration: line-through; }
.row.dragging { opacity: .4; }
.row.over { outline: 2px dashed var(--primary); }
.handle { cursor: grab; user-select: none; color: var(--muted); padding: 0 4px; }
.c-color { width: 32px; height: 32px; padding: 0; border: var(--bw) solid var(--border); border-radius: 8px; background: none; cursor: pointer; }
.c-text { flex: 1 1 110px; min-width: 0; padding: 6px 8px; border: var(--bw) solid var(--border); border-radius: 8px; background: var(--card); }
.c-weight { width: 58px; padding: 6px; border: var(--bw) solid var(--border); border-radius: 8px; background: var(--card); }
.mini { width: 30px; height: 30px; display: inline-grid; place-items: center; border: var(--bw) solid var(--border); background: var(--card); border-radius: 8px; font-size: .85rem; padding: 0; }
.mini:hover { background: var(--bg); }
.img-row { flex-basis: 100%; display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.img-row .c-url { flex: 1 1 140px; min-width: 0; padding: 6px 8px; border: var(--bw) solid var(--border); border-radius: 8px; background: var(--card); }
.thumb { width: 30px; height: 30px; border-radius: 50%; object-fit: cover; border: var(--bw) solid var(--border); }

/* ---------- Results ---------- */
.history, .leaderboard { list-style: none; margin: 0 0 8px; padding: 0; max-height: 300px; overflow: auto; }
.history li { display: flex; justify-content: space-between; gap: 10px; padding: 6px 4px; border-bottom: var(--bw) solid var(--border); font-size: .92rem; }
.history time, .history .empty { color: var(--muted); font-size: .8rem; }
.leaderboard li { position: relative; display: flex; justify-content: space-between; gap: 10px; padding: 6px 10px; margin-bottom: 4px; border-radius: 8px; overflow: hidden; background: var(--bg); }
.leaderboard .bar { position: absolute; inset-block: 0; inset-inline-start: 0; background: var(--primary); opacity: .22; }
.leaderboard span, .leaderboard b { position: relative; }

/* ---------- Drawer ---------- */
.scrim { position: fixed; inset: 0; background: rgba(2, 6, 23, .45); z-index: 30; }
.drawer {
  position: fixed; top: 0; bottom: 0; inset-inline-end: 0; width: min(400px, 100vw); z-index: 40;
  background: var(--card); border-inline-start: var(--bw) solid var(--border); box-shadow: var(--shadow);
  transform: translateX(100%); visibility: hidden; transition: transform .25s ease, visibility .25s; display: flex; flex-direction: column;
}
[dir="rtl"] .drawer { transform: translateX(-100%); }
.drawer.open, [dir="rtl"] .drawer.open { transform: none; visibility: visible; }
.drawer-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 16px; border-bottom: var(--bw) solid var(--border); }
.drawer-head h2 { margin: 0; font-size: 1.1rem; }
.drawer-body { overflow: auto; padding: 8px 16px 28px; }
.group { padding: 12px 0; border-bottom: var(--bw) solid var(--border); display: flex; flex-direction: column; gap: 8px; }
.group:last-child { border-bottom: 0; }
.group h3 { margin: 0 0 2px; font-size: .85rem; color: var(--muted); }
.slider { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 4px 10px; font-size: .9rem; }
.slider input { grid-column: 1 / -1; accent-color: var(--primary); }
.palette-row { display: flex; gap: 8px; flex-wrap: wrap; }
.palette-row input { width: 36px; height: 36px; padding: 0; border: var(--bw) solid var(--border); border-radius: 8px; background: none; }
input[type="color"] { cursor: pointer; }

/* ---------- Modal ---------- */
.modal { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 16px; background: rgba(2, 6, 23, .55); }
.modal-card { width: min(440px, 100%); padding: 28px 24px; text-align: center; background: var(--card); border-radius: 20px; box-shadow: var(--shadow); animation: pop .4s cubic-bezier(.2, 1.4, .4, 1); }
.modal-kicker { margin: 0 0 8px; color: var(--muted); font-weight: 700; font-size: .8rem; }
.result-text { font-size: clamp(28px, 7vw, 46px); font-weight: 800; line-height: 1.15; word-break: break-word; }
.result-img { display: block; margin: 0 auto 10px; width: 96px; height: 96px; border-radius: 50%; object-fit: cover; }
.mystery-q { font-size: 72px; font-weight: 800; color: var(--primary); }
.result-meta { margin: 8px 0 0; color: var(--muted); min-height: 1.2em; }
.modal-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 18px; }
@keyframes pop { from { transform: scale(.6); opacity: 0; } to { transform: scale(1); opacity: 1; } }

#confetti { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 80; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); background: #0f172a; color: #fff; padding: 10px 18px; border-radius: 999px; opacity: 0; pointer-events: none; transition: .25s; z-index: 90; max-width: 90vw; text-align: center; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Presentation / embed ---------- */
.exit-present { display: none; }
body.present .topbar, body.present .panel, body.present .hint, body.present #spinBtn { display: none !important; }
body.present .layout { grid-template-columns: 1fr; max-width: none; min-height: 100vh; align-content: center; padding-top: 8px; }
body.present .wheel-wrap { width: min(94vw, 80vh, 1200px); }
body.present .exit-present { display: grid; position: fixed; top: 12px; inset-inline-end: 12px; width: 40px; height: 40px; place-items: center; border-radius: 50%; border: 0; background: rgba(15, 23, 42, .6); color: #fff; z-index: 25; }
body.embed .topbar, body.embed .panel, body.embed .hint { display: none !important; }
body.embed .layout { grid-template-columns: 1fr; padding: 8px; }
body.embed .wheel-wrap { width: min(100%, 90vh, 640px); }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .title-input { max-width: none; order: 5; flex-basis: 100%; }
  .wheel-wrap { width: min(100%, 560px); }
}
@media (prefers-reduced-motion: reduce) {
  .modal-card, .drawer, .toast { animation: none; transition: none; }
}

/* ---------- Restyle: cream paper, ink outlines, flat colour ---------- */
body { font-size: 1.02rem; }
.topbar { background: var(--card); border-bottom-width: 3px; }
.brand { font-size: 1.3rem; letter-spacing: -.01em; }
.title-input, .select, .input, .textarea { background: var(--bg); }
.seg button.active { background: var(--sun); color: var(--ink); }
.btn, .icon-btn, .mini { box-shadow: 0 3px 0 var(--border); transition: transform .08s, box-shadow .08s; }
.btn:active, .icon-btn:active, .mini:active { transform: translateY(3px); box-shadow: none; }
.btn:hover, .icon-btn:hover { background: var(--sun); color: var(--ink); }
.btn.primary { border-color: var(--border); }
.btn.primary:hover { background: var(--sun); color: var(--ink); filter: none; }
.btn.big { background: var(--coral); color: var(--ink); border-color: var(--border); font-weight: 800; box-shadow: 0 5px 0 var(--border); letter-spacing: .02em; }
.btn.big:hover { background: var(--sun); }
.btn.ghost, .btn.small.danger { box-shadow: none; }
.stage { background: var(--card); color: var(--text); border: 3px solid var(--border); border-radius: 24px; box-shadow: var(--shadow); padding: 22px clamp(12px, 3vw, 28px) 24px; }
.stage-title { font-weight: 800; letter-spacing: -.02em; }
.tab.active { border-bottom-color: var(--sun); }
.chip { font-weight: 600; }
.chip.yes { background: var(--mint); color: var(--ink); border-color: var(--ink); }
.chip.no { background: var(--coral); color: var(--ink); border-color: var(--ink); }
.chip.maybe { background: var(--sun); color: var(--ink); border-color: var(--ink); }
.leaderboard .bar { background: var(--mint); opacity: .6; }
.row.over { outline-color: var(--coral); }
.modal-card { border: 3px solid var(--border); box-shadow: var(--shadow); }
.toast { background: var(--ink); }
body.present .stage, body.embed .stage { border: 0; box-shadow: none; background: transparent; padding: 0; color: var(--stage-text); }

/* ---------- Guide, FAQ, footer ---------- */
.guide { max-width: 980px; margin: 0 auto; padding: 0 clamp(12px, 3vw, 28px) 20px; }
.guide h2 { font-size: clamp(1.5rem, 3.4vw, 2.1rem); line-height: 1.2; font-weight: 800; letter-spacing: -.01em; margin: 0 0 12px; }
.guide h3 { font-size: 1.2rem; margin: 22px 0 4px; }
.guide p { max-width: 68ch; margin: 0 0 14px; line-height: 1.7; }
.guide a { color: var(--text); text-decoration-thickness: 2px; text-underline-offset: 3px; }
.guide a:hover { background: var(--sun); color: var(--ink); }
.guide section { margin-top: 44px; }
.guide hr { border: 0; height: 30px; margin: 44px 0 0; position: relative; background: linear-gradient(var(--border), var(--border)) center / 100% 3px no-repeat; }
.guide hr::after { content: ""; position: absolute; left: 50%; top: 50%; width: 30px; height: 30px; margin: -15px 0 0 -15px; border: 3px solid var(--border); border-radius: 50%; background: conic-gradient(var(--primary) 0 25%, var(--sun) 0 50%, var(--coral) 0 75%, var(--mint) 0); }
.pills { list-style: none; padding: 0; margin: 0 0 14px; display: flex; flex-wrap: wrap; gap: 8px; }
.pills li { border: var(--bw) solid var(--border); border-radius: 999px; padding: 2px 14px; color: var(--ink); background: var(--sun); }
.pills li:nth-child(4n+1) { background: var(--mint); } .pills li:nth-child(4n+3) { background: #d9ccff; } .pills li:nth-child(4n) { background: #ffc2b8; }
.guide details { border: var(--bw) solid var(--border); border-radius: 14px; background: var(--card); margin-bottom: 10px; }
.guide summary { cursor: pointer; padding: 10px 16px; font-weight: 600; list-style: none; display: flex; justify-content: space-between; gap: 12px; }
.guide summary::-webkit-details-marker { display: none; }
.guide summary::after { content: "+"; font-weight: 800; }
.guide details[open] summary::after { content: "\2212"; }
.guide details[open] summary { background: var(--sun); color: var(--ink); border-bottom: var(--bw) solid var(--border); margin-bottom: 10px; border-radius: 11px 11px 0 0; }
.guide details p { padding: 0 16px; margin: 0 0 12px; }
.ad-slot { max-width: 980px; margin: 8px auto 0; min-height: 90px; border: 3px dashed var(--border); border-radius: 14px; display: grid; place-items: center; font-size: .9rem; color: var(--muted); }
.sitefoot { margin-top: 56px; background: var(--ink); color: #fff4dc; border-top: 3px solid var(--ink); }
.sitefoot .cols { max-width: 980px; margin: 0 auto; padding: 34px clamp(12px, 3vw, 28px); display: grid; grid-template-columns: 1.2fr 1fr 1fr 1fr; gap: 24px; }
.sitefoot b { display: block; margin-bottom: 6px; color: var(--sun); }
.sitefoot a { display: block; color: #fff4dc; margin-bottom: 6px; }
.sitefoot a:hover { background: var(--primary); }
body.present .guide, body.present .sitefoot, body.present .ad-slot, body.embed .guide, body.embed .sitefoot, body.embed .ad-slot { display: none !important; }
@media (max-width: 760px) { .sitefoot .cols { grid-template-columns: 1fr 1fr; } }

/* ---------- Header: nav bar + banner ---------- */
.topbar { gap: 8px 18px; padding-block: 8px; }
.brand { font-size: 1.6rem; font-weight: 800; letter-spacing: -.03em; }
.brand svg { width: 40px; height: 40px; }
.topnav { margin-inline-start: auto; display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; }
.nav-btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border: var(--bw) solid transparent; border-radius: 12px; background: none; color: var(--text); font-weight: 600; font-size: 1rem; text-decoration: none; }
.nav-btn:hover { background: var(--sun); color: var(--ink); border-color: var(--border); }
.nav-btn.share { background: var(--mint); color: var(--ink); border-color: var(--border); box-shadow: 0 3px 0 var(--border); }
.nav-btn.share:hover { background: var(--sun); }
.banner { display: flex; align-items: center; justify-content: space-between; gap: 20px; flex-wrap: wrap; padding: 14px clamp(12px, 3vw, 28px); background: var(--primary); color: #fff; border-bottom: 3px solid var(--border); }
[data-theme="dark"] .banner { color: var(--primary-text); }
.banner-title { font-size: clamp(1.5rem, 3.4vw, 2.2rem); font-weight: 800; line-height: 1.1; letter-spacing: -.02em; }
.banner-tag { margin: 2px 0 8px; opacity: .92; }
.banner .title-input { background: rgba(255, 255, 255, .18); border: 2px solid currentColor; color: inherit; max-width: 260px; padding: 5px 10px; }
.banner .title-input::placeholder { color: inherit; opacity: .75; }
.banner-ad { flex: 0 1 728px; min-height: 90px; display: grid; place-items: center; border: 3px dashed #fff4dc; border-radius: 12px; font-size: .9rem; opacity: .85; width: 100%; max-width: 728px; }
body.present .banner, body.embed .banner { display: none !important; }
@media (max-width: 900px) { .topnav { margin-inline-start: 0; } .banner-ad { flex-basis: 100%; max-width: none; } }

/* ---------- Wheel stage like Picker Wheel: sage backdrop, round floating buttons ---------- */
.stage { position: relative; background: #d9e0d4; }
[data-theme="dark"] .stage { background: #2b3a2a; }
.stage-title, .stage-desc, .hint, .tally-label { color: #1d1633; }
[data-theme="dark"] .stage-title, [data-theme="dark"] .stage-desc, [data-theme="dark"] .hint, [data-theme="dark"] .tally-label { color: #fff4dc; }
.fab-col { position: absolute; right: 12px; display: flex; flex-direction: column; gap: 10px; z-index: 3; }
.fab-col.top { top: 12px; } .fab-col.bottom { bottom: 12px; }
.fab { width: 46px; height: 46px; display: grid; place-items: center; padding: 0; border: 0; border-radius: 12px; background: #fff; color: #1d1633; font-size: 1.25rem; box-shadow: 0 2px 6px rgba(0,0,0,.25); }
.fab-col.bottom .fab { border-radius: 50%; width: 52px; height: 52px; }
.fab:hover { background: var(--sun); }
.fab.dark { background: #333; color: #fff; }
.fab.dark:hover { background: var(--primary); }
body.present .fab-col, body.embed .fab-col { display: none; }
@media (max-width: 560px) { .fab { width: 40px; height: 40px; } .fab-col.bottom .fab { width: 44px; height: 44px; } }
