:root {
  --bg: #f7f7fb;
  --surface: #ffffff;
  --text: #1c1b29;
  --muted: #55536b;
  --border: #dedcea;
  --accent: #4f46e5;
  --accent-text: #ffffff;
  --accent-soft: #eceafe;
  --focus: #f59e0b;
  --radius: 14px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12111a;
    --surface: #1d1c28;
    --text: #ecebf5;
    --muted: #aaa8c0;
    --border: #34324a;
    --accent: #8b85ff;
    --accent-text: #12111a;
    --accent-soft: #2a2747;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.6 var(--font); }
img, canvas, svg { max-width: 100%; }
a { color: var(--accent); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
h1, h2, h3 { line-height: 1.25; }
h1 { font-size: clamp(1.6rem, 4vw, 2.3rem); margin: 1.2rem 0 .4rem; }
h2 { font-size: 1.35rem; margin-top: 2rem; }

.wrap { max-width: 1180px; margin: 0 auto; padding: 0 16px; }
.skip { position: absolute; left: -999px; top: 8px; background: var(--surface); padding: 8px 12px; z-index: 10; }
.skip:focus { left: 8px; }

/* Header */
.site-header { background: var(--surface); border-bottom: 1px solid var(--border); }
.header-inner { display: flex; align-items: center; gap: 12px; min-height: 60px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 1.15rem; color: var(--text); text-decoration: none; margin-right: auto; }
.site-header .nav-toggle { display: none; } /* beats button.btn so it stays hidden on wide screens */
#site-nav ul { display: flex; flex-wrap: wrap; gap: 4px; list-style: none; margin: 0; padding: 0; }
#site-nav a { display: block; padding: 6px 10px; border-radius: 8px; color: var(--text); text-decoration: none; font-size: .95rem; }
#site-nav a:hover { background: var(--accent-soft); }
#site-nav a[aria-current="page"] { background: var(--accent); color: var(--accent-text); }
@media (max-width: 860px) {
  /* Without JS the links simply wrap below the logo; with JS they collapse behind the Menu button. */
  #site-nav { width: 100%; padding-bottom: 10px; }
  .js .site-header .nav-toggle { display: inline-flex; }
  .js #site-nav { display: none; }
  .js #site-nav.open { display: block; }
  .js #site-nav ul { flex-direction: column; }
}

/* Layout: content + sticky sidebar ad on wide screens */
.layout { display: block; padding-bottom: 2rem; }
.sidebar { display: none; }
@media (min-width: 1100px) {
  .layout--tool { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 32px; }
  .sidebar { display: block; padding-top: 1.4rem; }
  .sidebar .ad { position: sticky; top: 16px; }
}
main { min-width: 0; }
.lead { color: var(--muted); font-size: 1.08rem; margin-top: 0; }

/* Ad slots: fixed reserved heights => no layout shift when ads fill */
.ad { display: flex; align-items: center; justify-content: center; margin: 1.5rem auto; width: 100%; overflow: hidden;
      border: 1px dashed var(--border); border-radius: 8px; background: transparent; position: relative; }
.ad::before { content: attr(data-label); position: absolute; top: 2px; left: 8px; font-size: .68rem; color: var(--muted); letter-spacing: .04em; text-transform: uppercase; }
.ad--banner { min-height: 100px; max-width: 728px; }
.ad--rect { min-height: 280px; max-width: 336px; }
.ad--sky { min-height: 600px; max-width: 300px; margin-top: 0; }
@media (min-width: 768px) { .ad--banner { min-height: 90px; } }
.ad-placeholder { color: var(--muted); font-size: .85rem; }
.ad ins { width: 100%; }

/* Tool card */
.tool { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; }
.prose { max-width: 70ch; }
.prose p, .prose li { color: var(--text); }

/* Controls */
button, .btn, input, select, textarea { font: inherit; }
.btn, button.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 8px 16px;
  border-radius: 10px; border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer; text-decoration: none; }
.btn:hover { border-color: var(--accent); }
.btn.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.btn-big { min-height: 56px; font-size: 1.2rem; padding: 10px 32px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }
.linklike { background: none; border: 0; padding: 0; color: var(--accent); text-decoration: underline; cursor: pointer; }
input[type="text"], input[type="number"], select, textarea {
  min-height: 44px; padding: 8px 10px; border-radius: 10px; border: 1px solid var(--border); background: var(--bg); color: var(--text); width: 100%; }
textarea { min-height: 140px; resize: vertical; }
label { font-weight: 600; font-size: .95rem; }
.field { display: flex; flex-direction: column; gap: 4px; }
.fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 400; min-height: 44px; }
.check input { width: 20px; height: 20px; }
.hint { color: var(--muted); font-size: .9rem; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Result display shared by small tools */
.result { min-height: 7rem; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center;
  background: var(--accent-soft); border-radius: var(--radius); padding: 16px; margin: 12px 0; }
.result-big { font-size: clamp(2.5rem, 10vw, 4.5rem); font-weight: 800; line-height: 1.1; word-break: break-word; }
.result-sub { color: var(--muted); }
.center { text-align: center; }

/* Wheel */
.wheel-tool { display: grid; gap: 20px; }
@media (min-width: 760px) { .wheel-tool { grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); align-items: start; } }
.wheel-stage { position: relative; max-width: 520px; margin: 0 auto; width: 100%; }
.wheel-stage canvas { display: block; width: 100%; aspect-ratio: 1 / 1; height: auto; border-radius: 50%; cursor: pointer; }
.wheel-pointer { position: absolute; top: -6px; left: 50%; transform: translateX(-50%); width: 0; height: 0;
  border-left: 18px solid transparent; border-right: 18px solid transparent; border-top: 34px solid var(--text); filter: drop-shadow(0 2px 2px rgba(0,0,0,.3)); }
.wheel-winner { min-height: 3.2rem; text-align: center; font-size: 1.4rem; font-weight: 700; margin: 10px 0 0; }
.choice-list { list-style: none; padding: 0; margin: 8px 0; max-height: 420px; overflow-y: auto; display: grid; gap: 6px; }
.choice-list li { display: flex; gap: 6px; align-items: center; }
.choice-swatch { flex: 0 0 14px; height: 14px; border-radius: 4px; }
.choice-list input { flex: 1; min-height: 40px; }
.icon-btn { min-width: 40px; min-height: 40px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer; font-size: 1.1rem; line-height: 1; }
.icon-btn:hover { border-color: #dc2626; color: #dc2626; }
.add-row { display: flex; gap: 6px; }
.add-row input { flex: 1; }
.status { min-height: 1.5rem; color: var(--muted); font-size: .9rem; }

/* Coin */
.coin-wrap { perspective: 800px; display: flex; justify-content: center; margin: 10px 0; }
.coin { width: 160px; height: 160px; position: relative; transform-style: preserve-3d; transition: transform 1.2s cubic-bezier(.2,.7,.2,1); }
.coin-face { position: absolute; inset: 0; border-radius: 50%; display: flex; align-items: center; justify-content: center; backface-visibility: hidden;
  font-weight: 800; font-size: 1.3rem; color: #4a3300; background: radial-gradient(circle at 35% 30%, #ffe28a, #e0a800 70%, #b07f00); border: 6px solid #c99600; }
.coin-face.tails { transform: rotateY(180deg); background: radial-gradient(circle at 35% 30%, #f1f1f1, #b9b9c4 70%, #8a8a99); border-color: #9a9aa8; color: #2a2a35; }

/* Dice */
.dice { display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; }
.die { width: 72px; height: 72px; border-radius: 14px; background: var(--surface); border: 2px solid var(--text); display: flex; align-items: center; justify-content: center; font-size: 1.8rem; font-weight: 800; }
.die.rolling { animation: shake .4s ease-in-out; }
@keyframes shake { 0%,100% { transform: rotate(0); } 25% { transform: rotate(-12deg); } 75% { transform: rotate(12deg); } }

/* Teams / colors / chips */
.teams { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-top: 12px; }
.team { background: var(--bg); border: 1px solid var(--border); border-radius: 10px; padding: 12px; }
.team h3 { margin: 0 0 6px; font-size: 1.05rem; }
.team ol { margin: 0; padding-left: 1.3rem; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.chip { padding: 6px 12px; border-radius: 999px; background: var(--surface); border: 1px solid var(--border); font-weight: 700; font-size: 1.2rem; }
.swatches { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.swatch { border-radius: 12px; overflow: hidden; border: 1px solid var(--border); background: var(--surface); }
.swatch-color { height: 110px; }
.swatch-info { padding: 8px 10px; font-family: ui-monospace, Consolas, monospace; font-size: .85rem; }
.swatch-info button { margin-top: 4px; }

/* FAQ, related, footer */
.faq details { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 0 14px; margin: 8px 0; }
.faq summary { cursor: pointer; font-weight: 600; padding: 12px 0; min-height: 44px; }
.faq details p { margin-top: 0; }
.cards { list-style: none; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; }
.cards a { display: flex; align-items: center; gap: 10px; padding: 14px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; text-decoration: none; color: var(--text); font-weight: 600; min-height: 56px; }
.cards a:hover { border-color: var(--accent); }
.card-emoji { font-size: 1.4rem; }
.site-footer { border-top: 1px solid var(--border); background: var(--surface); padding: 20px 0; color: var(--muted); font-size: .9rem; }
.footer-links { list-style: none; padding: 0; display: flex; gap: 18px; flex-wrap: wrap; margin: 0 0 8px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
.card-sub { display: block; font-weight: 400; font-size: .85rem; color: var(--muted); }
.presets { margin-bottom: 1.5rem; }
.lang-switch { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.lang-switch ul { list-style: none; display: flex; flex-wrap: wrap; gap: 4px 14px; margin: 0; padding: 0; }
.lang-switch a { color: var(--muted); }
.lang-switch a[aria-current="page"] { color: var(--text); font-weight: 600; text-decoration: none; }
/* Wheel ideas guide */
.ideas li { margin-bottom: .6rem; }
.idea-preview { color: var(--muted); }
.idea-spin { white-space: nowrap; font-weight: 600; }

/* Wheel side panel: tabs, themes, custom colors */
.list-head { margin: 6px 0 0; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 12px; }
.tabs [role="tab"] { background: none; border: 0; border-bottom: 3px solid transparent; padding: 8px 12px; min-height: 44px;
  font: inherit; font-weight: 600; color: var(--muted); cursor: pointer; }
.tabs [role="tab"][aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); }
.panel-h { font-size: 1rem; margin: 14px 0 6px; }
.themes { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 8px; }
.theme-btn { display: flex; flex-direction: column; gap: 6px; padding: 8px; min-height: 44px; border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface); color: var(--text); font: inherit; font-size: .9rem; text-align: left; cursor: pointer; }
.theme-btn:hover { border-color: var(--accent); }
.theme-btn[aria-pressed="true"] { border-color: var(--accent); box-shadow: inset 0 0 0 2px var(--accent); }
.theme-strip { display: block; height: 14px; border-radius: 4px; }
.palette { list-style: none; padding: 0; margin: 8px 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 6px; }
.palette li { display: flex; align-items: center; gap: 6px; }
.palette input[type="color"] { width: 44px; height: 40px; padding: 2px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); cursor: pointer; }
.palette code { flex: 1; font-size: .85rem; }
.icon-btn[disabled] { opacity: .4; cursor: not-allowed; }

/* Winner overlay with fireworks */
.win-overlay { position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center; padding: 16px;
  background: rgba(10, 9, 20, .72); animation: win-fade .2s ease-out; }
.win-fx { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.win-box { position: relative; max-width: min(92vw, 760px); padding: 24px 28px; text-align: center; background: var(--surface); color: var(--text);
  border-radius: 18px; box-shadow: 0 20px 60px rgba(0, 0, 0, .45); animation: win-pop .4s cubic-bezier(.2, 1.4, .4, 1); }
.win-label { margin: 0; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; font-size: .85rem; font-weight: 700; }
.win-name { margin: 6px 0 18px; font-size: clamp(2.2rem, 8vw, 5.5rem); font-weight: 800; line-height: 1.1; word-break: break-word; }
.win-box .btn-row { justify-content: center; margin-bottom: 0; }
@keyframes win-pop { from { transform: scale(.6); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes win-fade { from { opacity: 0; } to { opacity: 1; } }

/* Fullscreen tool card (real fullscreen or the pinned fallback on iPhone) */
.tool { position: relative; }
.tool-bar { display: flex; justify-content: flex-end; margin: -10px -10px 6px 0; }
.fs-btn { min-height: 36px; padding: 4px 12px; font-size: .9rem; }
.fs-brand { display: none; }
.tool:fullscreen, .tool.is-fullscreen { display: flex; flex-direction: column; justify-content: center; justify-content: safe center;
  background: var(--bg); border: 0; border-radius: 0; padding: 64px 24px 44px; overflow: auto; }
.tool.is-fullscreen { position: fixed; inset: 0; z-index: 50; }
.fs-lock, .fs-lock body { overflow: hidden; }
.tool:fullscreen > :not(.tool-bar):not(.fs-brand):not(.win-overlay),
.tool.is-fullscreen > :not(.tool-bar):not(.fs-brand):not(.win-overlay) { width: 100%; max-width: 960px; margin-inline: auto; }
.tool:fullscreen .tool-bar, .tool.is-fullscreen .tool-bar { position: absolute; top: 12px; right: 16px; margin: 0; z-index: 5; }
.tool:fullscreen .fs-brand, .tool.is-fullscreen .fs-brand { display: block; position: absolute; bottom: 12px; right: 18px;
  font-weight: 700; font-size: .95rem; color: var(--muted); letter-spacing: .02em; }
.tool:fullscreen .result, .tool.is-fullscreen .result { min-height: 38vh; }
.tool:fullscreen .result-big, .tool.is-fullscreen .result-big { font-size: clamp(3rem, 14vw, 10rem); }
/* On the wheel, fullscreen shows just the wheel, the Spin button and the result */
.tool:fullscreen .wheel-side, .tool.is-fullscreen .wheel-side,
.tool:fullscreen #history-wrap, .tool.is-fullscreen #history-wrap { display: none; }
.tool:fullscreen .wheel-tool, .tool.is-fullscreen .wheel-tool { grid-template-columns: 1fr; }
.tool:fullscreen .wheel-stage, .tool.is-fullscreen .wheel-stage { max-width: min(74vh, 92vw); }
.tool:fullscreen .wheel-winner, .tool.is-fullscreen .wheel-winner { font-size: clamp(1.4rem, 3.5vw, 2.6rem); }
.tool:fullscreen .btn-big, .tool.is-fullscreen .btn-big { min-height: 64px; padding: 12px 48px; font-size: 1.5rem; }

/* Tool colors (shared "Colors" panel). Custom properties are set on .tool by common.js. */
.tool-bar { position: relative; gap: 6px; }
.style-btn { min-height: 36px; padding: 4px 12px; font-size: .9rem; }
.tool { background: var(--tool-bg, var(--surface)); color: var(--tool-text, var(--text)); }
.tool:fullscreen, .tool.is-fullscreen { background: var(--tool-bg, var(--bg)); }
.tool.tool--styled { border-color: var(--tool-soft); }
.tool.tool--styled .btn.btn-primary { background: var(--tool-accent); border-color: var(--tool-accent); color: var(--tool-accent-text); }
.tool.tool--styled .result { background: var(--tool-soft); }
.tool.tool--styled .hint, .tool.tool--styled .result-sub, .tool.tool--styled .fs-brand { color: var(--tool-muted); }
.tool.tool--styled .tabs [role="tab"][aria-selected="true"] { color: var(--tool-text); border-bottom-color: var(--tool-accent); }
.tool.tool--styled .tabs [role="tab"] { color: var(--tool-muted); }
.style-panel { position: absolute; top: calc(100% + 6px); right: 0; z-index: 30; width: min(340px, 86vw); padding: 14px;
  background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 12px; box-shadow: 0 12px 36px rgba(0, 0, 0, .25); text-align: left; }
.style-panel .hint { color: var(--muted); margin: 4px 0 10px; }
.style-title { margin: 0; font-weight: 700; }
.style-presets { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.style-preset { display: inline-flex; align-items: center; gap: 6px; min-height: 36px; padding: 4px 10px; border: 1px solid var(--border); border-radius: 999px;
  background: var(--surface); color: var(--text); font: inherit; font-size: .88rem; cursor: pointer; }
.style-preset[aria-pressed="true"] { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.style-dot { width: 18px; height: 18px; border-radius: 50%; border: 1px solid var(--border); }
.style-row { display: flex; align-items: center; gap: 10px; margin: 6px 0; font-weight: 400; }
.style-row input[type="color"] { width: 44px; height: 36px; padding: 2px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); cursor: pointer; }
.style-panel .btn-row { margin: 10px 0 0; }
.tool.tool--styled .linklike, .tool.tool--styled a:not(.btn) { color: var(--tool-text); }
.style-controls .style-reset { margin-top: 8px; }
.style-controls .style-reset + .btn { margin: 8px 0 0 6px; }
#tool-style-slot .style-presets { margin-top: 4px; }
.win-name--long { font-size: clamp(1.6rem, 5.5vw, 3.4rem); }
.win-sub { margin: -10px 0 16px; color: var(--muted); font-size: 1rem; word-break: break-word; }
.style-sub { margin: 10px 0 2px; font-weight: 700; font-size: .95rem; }
.style-row span { flex: 1; }
.style-hex { font-size: .85rem; color: var(--muted); }
.style-custom-hint { margin: 0 0 4px; }
/* Result box colors: yes/no answers are green/red unless a custom result text color is chosen */
.result-big[data-answer="yes"] { color: #059669; }
.result-big[data-answer="no"] { color: #dc2626; }
.tool.tool--styled .result { color: var(--tool-result-text); }
.tool.tool--styled .result .result-sub { color: inherit; opacity: .75; }
.tool.has-result-text .result-big[data-answer] { color: inherit; }

/* Secret Santa */
.santa-more { margin: 10px 0; }
.santa-more summary { cursor: pointer; font-weight: 600; min-height: 44px; display: flex; align-items: center; }
.santa-more .field { margin-top: 10px; }
.santa-h { font-size: 1.15rem; margin: 18px 0 4px; }
.santa-links { list-style: none; padding: 0; margin: 10px 0; display: grid; gap: 6px; }
.santa-links li { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 6px 10px; border: 1px solid var(--border); border-radius: 10px; background: var(--bg); }
.santa-giver { flex: 1; font-weight: 600; min-width: 8ch; word-break: break-word; }
.santa-all { margin: 8px 0 0; }
.santa-reveal { text-align: center; padding: 10px 0; }
.santa-hello { font-size: clamp(1.5rem, 5vw, 2.2rem); font-weight: 800; margin: 6px 0; }
.santa-details { list-style: none; padding: 0; margin: 8px 0; color: var(--muted); }
.santa-slips { display: none; }
@media print {
  body.print-slips * { visibility: hidden; }
  body.print-slips .santa-slips, body.print-slips .santa-slips * { visibility: visible; }
  body.print-slips .santa-slips { display: grid; grid-template-columns: 1fr 1fr; gap: 0; position: absolute; left: 0; top: 0; width: 100%; color: #000; }
  .santa-slip { border: 1px dashed #888; padding: 14px 16px; break-inside: avoid; text-align: center; font-family: system-ui, sans-serif; }
  .slip-for { font-weight: 700; font-size: 14pt; margin: 0 0 8px; }
  .slip-fold { font-size: 8pt; color: #666; margin: 0 0 8px; }
  .slip-who { font-size: 20pt; font-weight: 800; margin: 0 0 6px; }
  .slip-extra { font-size: 10pt; margin: 0; }
}
/* Secret Santa QR dialog: white code area so phones can scan it in dark mode too */
.santa-links .btn { min-height: 38px; padding: 6px 12px; font-size: .9rem; }
.qr-box { width: min(92vw, 420px); }
.qr-name { font-size: clamp(1.6rem, 6vw, 2.4rem); font-weight: 800; margin: 4px 0 10px; word-break: break-word; }
.qr-code { background: #fff; padding: 8px; border-radius: 12px; margin: 0 auto 10px; width: min(72vw, 320px); }
.qr-code svg { display: block; width: 100%; height: auto; }
.qr-box .btn-row { justify-content: center; }
