/* ===========================================================
   Punchline Parlour — CIO Factory / orient-luxury design system
   =========================================================== */

:root[data-theme="dark"] {
  --bg: #09080b;
  --surface: #131117;
  --surface-raised: #18151d;
  --text: #ece5d6;
  --text-muted: #a89a80;
  --gold: #c9a84c;
  --gold-soft: #8a7233;
  --gold-line: rgba(201, 168, 76, 0.28);
  --shadow: rgba(0, 0, 0, 0.55);
  --danger: #d97757;
  --ok: #7ea87e;
}

:root[data-theme="light"] {
  --bg: #f0ebe0;
  --surface: #faf7f0;
  --surface-raised: #ffffff;
  --text: #241f16;
  --text-muted: #6c5f45;
  --gold: #8a6820;
  --gold-soft: #b08d3e;
  --gold-line: rgba(138, 104, 32, 0.32);
  --shadow: rgba(80, 65, 30, 0.18);
  --danger: #a8452b;
  --ok: #3f6b3f;
}

/* Category accent hues — a small dot of colour per joke type, still gold-led */
:root {
  --cat-programming: #6fa3a0;
  --cat-dark: #8c6fb0;
  --cat-pun: #c98a9e;
  --cat-spooky: #cf8a4c;
  --cat-christmas: #7fa06a;
  --cat-misc: #c9a84c;
  --cat-any: #c9a84c;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  min-height: 100%;
}

body {
  font-family: 'Cormorant Garamond', Georgia, serif;
  font-size: 18px;
  line-height: 1.5;
  transition: background-color 0.4s ease, color 0.4s ease;
  overflow-x: hidden;
}

::selection { background: var(--gold); color: var(--bg); }

:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 3px;
}

a { color: var(--gold); }

/* ---------- Grain overlay ---------- */
.grain-overlay {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 999;
  mix-blend-mode: soft-light;
  opacity: 0.55;
}
.grain-overlay::before {
  content: "";
  position: absolute;
  inset: -20%;
  filter: url(#grainFilter);
  background: #808080;
  width: 140%;
  height: 140%;
}

/* ---------- Header ---------- */
.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.75rem clamp(1.25rem, 4vw, 3rem) 1rem;
  border-bottom: 1px solid var(--gold-line);
}

.brand { display: flex; align-items: center; gap: 0.75rem; }

.brand-glyph {
  font-size: 1.6rem;
  color: var(--gold);
  line-height: 1;
}

.brand-text { display: flex; flex-direction: column; }

.brand-name {
  font-family: 'Cinzel', serif;
  font-weight: 600;
  font-size: 1.5rem;
  letter-spacing: 0.04em;
  color: var(--text);
}

.brand-tagline {
  font-family: 'Syne', sans-serif;
  font-size: 0.68rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.theme-toggle {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: transparent;
  border: 1px solid var(--gold-line);
  color: var(--text);
  font-family: 'Syne', sans-serif;
  font-size: 0.75rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 0.55rem 1rem;
  border-radius: 999px;
  cursor: pointer;
  transition: border-color 0.25s ease, background-color 0.25s ease, transform 0.15s ease;
}
.theme-toggle:hover { border-color: var(--gold); background: var(--surface); }
.theme-toggle:active { transform: scale(0.97); }
.theme-toggle-icon { font-size: 0.95rem; color: var(--gold); }

:root[data-theme="light"] .theme-toggle-label::before { content: "Ink & Shadow Mode"; }
:root[data-theme="light"] .theme-toggle-label { font-size: 0; }
:root[data-theme="light"] .theme-toggle-label::before { font-size: 0.75rem; }

/* ---------- Layout ---------- */
.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 2rem;
  padding: clamp(1.5rem, 4vw, 3rem);
  align-items: start;
  max-width: 1200px;
  margin: 0 auto;
}

@media (max-width: 880px) {
  .layout { grid-template-columns: 1fr; }
}

/* ---------- Stage / joke card ---------- */
.stage { display: flex; flex-direction: column; gap: 1.25rem; }

.marquee-card {
  position: relative;
  padding: 14px;
  border-radius: 4px;
  background: linear-gradient(180deg, var(--surface-raised), var(--surface));
  box-shadow: 0 30px 60px -25px var(--shadow), 0 2px 0 var(--gold-line) inset;
  min-height: 320px;
}

/* Marquee lightbulb chase — the signature element.
   Four strips of repeating dot bulbs, each animated along its own axis so the
   lights appear to travel clockwise around the whole card, vaudeville-sign style. */
.mq {
  position: absolute;
  pointer-events: none;
  background-repeat: repeat;
}
.mq-top, .mq-bottom {
  height: 7px;
  left: 10px;
  right: 10px;
  background-image: radial-gradient(circle at 3px 3px, var(--gold) 0 2px, transparent 2.6px);
  background-size: 18px 7px;
}
.mq-left, .mq-right {
  width: 7px;
  top: 10px;
  bottom: 10px;
  background-image: radial-gradient(circle at 3px 3px, var(--gold) 0 2px, transparent 2.6px);
  background-size: 7px 18px;
}
.mq-top { top: 0; animation: mq-chase-x 1.4s linear infinite; }
.mq-bottom { bottom: 0; animation: mq-chase-x-rev 1.4s linear infinite; }
.mq-right { right: 0; animation: mq-chase-y 1.4s linear infinite; }
.mq-left { left: 0; animation: mq-chase-y-rev 1.4s linear infinite; }

@keyframes mq-chase-x { from { background-position: 0 0; } to { background-position: 18px 0; } }
@keyframes mq-chase-x-rev { from { background-position: 18px 0; } to { background-position: 0 0; } }
@keyframes mq-chase-y { from { background-position: 0 0; } to { background-position: 0 18px; } }
@keyframes mq-chase-y-rev { from { background-position: 0 18px; } to { background-position: 0 0; } }

@media (prefers-reduced-motion: reduce) {
  .mq { animation: none !important; opacity: 0.7; }
}

.card-inner {
  position: relative;
  background: var(--bg);
  border: 1px solid var(--gold-line);
  border-radius: 2px;
  padding: clamp(1.5rem, 4vw, 2.75rem);
  min-height: 290px;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.card-meta { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; }

.chip {
  font-family: 'Syne', sans-serif;
  font-size: 0.68rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  padding: 0.3rem 0.7rem;
  border-radius: 999px;
  border: 1px solid var(--gold-line);
  color: var(--text-muted);
}

.chip-category {
  color: var(--bg);
  background: var(--accent, var(--gold));
  border-color: transparent;
  font-weight: 700;
}

.chip-id {
  margin-left: auto;
  font-family: 'IBM Plex Mono', monospace;
  color: var(--text-muted);
  border-style: dashed;
}

.marquee-card[data-category="Programming"] .chip-category { --accent: var(--cat-programming); }
.marquee-card[data-category="Dark"] .chip-category { --accent: var(--cat-dark); }
.marquee-card[data-category="Pun"] .chip-category { --accent: var(--cat-pun); }
.marquee-card[data-category="Spooky"] .chip-category { --accent: var(--cat-spooky); }
.marquee-card[data-category="Christmas"] .chip-category { --accent: var(--cat-christmas); }
.marquee-card[data-category="Misc"] .chip-category { --accent: var(--cat-misc); }

.joke-text { flex: 1; display: flex; flex-direction: column; gap: 1.1rem; justify-content: center; }

.setup {
  font-size: clamp(1.35rem, 2.6vw, 1.9rem);
  font-weight: 500;
  margin: 0;
  color: var(--text);
}

.delivery {
  font-size: clamp(1.35rem, 2.6vw, 1.9rem);
  font-weight: 600;
  font-style: italic;
  color: var(--gold);
  margin: 0;
  animation: reveal-pop 0.45s cubic-bezier(0.2, 0.9, 0.3, 1.2);
}

@keyframes reveal-pop {
  from { opacity: 0; transform: translateY(6px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.reveal-btn {
  align-self: flex-start;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  background: transparent;
  border: 1px solid var(--gold);
  color: var(--gold);
  font-family: 'Syne', sans-serif;
  font-size: 0.85rem;
  letter-spacing: 0.05em;
  padding: 0.65rem 1.25rem;
  border-radius: 999px;
  cursor: pointer;
  transition: background-color 0.2s ease, color 0.2s ease, transform 0.15s ease;
}
.reveal-btn:hover { background: var(--gold); color: var(--bg); }
.reveal-btn:active { transform: scale(0.97); }
.reveal-icon { font-size: 1rem; }

.rimshot {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.85);
  font-family: 'Cinzel', serif;
  font-size: 1.6rem;
  letter-spacing: 0.05em;
  color: var(--gold);
  background: var(--surface-raised);
  border: 1px solid var(--gold);
  padding: 0.5rem 1.5rem;
  border-radius: 999px;
  box-shadow: 0 20px 40px -15px var(--shadow);
  opacity: 0;
  pointer-events: none;
  white-space: nowrap;
}
.rimshot.is-active {
  animation: rimshot-flash 0.9s ease-out forwards;
}
@keyframes rimshot-flash {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.7); }
  25% { opacity: 1; transform: translate(-50%, -50%) scale(1.05); }
  70% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(1.02); }
}
.rimshot-cymbal { display: inline-block; }

.flag-row { display: flex; gap: 0.4rem; flex-wrap: wrap; min-height: 1.5rem; }

.flag-badge {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.68rem;
  letter-spacing: 0.03em;
  padding: 0.25rem 0.55rem;
  border-radius: 3px;
  background: var(--surface-raised);
  border: 1px solid var(--gold-line);
  color: var(--text-muted);
}
.flag-badge.is-clean { color: var(--ok); border-color: var(--ok); }

/* ---------- Stage actions ---------- */
.stage-actions { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; }

.fetch-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  background: var(--gold);
  color: var(--bg);
  border: none;
  font-family: 'Syne', sans-serif;
  font-weight: 700;
  font-size: 0.85rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  padding: 0.85rem 1.6rem;
  border-radius: 999px;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.2s ease, opacity 0.2s ease;
  box-shadow: 0 12px 25px -12px var(--shadow);
}
.fetch-btn:hover { transform: translateY(-1px); box-shadow: 0 16px 30px -12px var(--shadow); }
.fetch-btn:active { transform: translateY(0) scale(0.98); }
.fetch-btn:disabled { opacity: 0.55; cursor: wait; transform: none; }
.fetch-btn.primary { width: 100%; justify-content: center; }
.fetch-icon { animation: dice-idle 3.4s ease-in-out infinite; display: inline-block; }
@keyframes dice-idle {
  0%, 100% { transform: rotate(0deg); }
  50% { transform: rotate(14deg); }
}

.status-note {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.82rem;
  color: var(--danger);
  margin: 0;
}
.status-note.is-info { color: var(--text-muted); }

/* ---------- Control panel ---------- */
.control-panel {
  background: var(--surface);
  border: 1px solid var(--gold-line);
  border-radius: 4px;
  overflow: hidden;
  align-self: start;
}

.panel-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface-raised);
  color: var(--text);
  border: none;
  border-bottom: 1px solid var(--gold-line);
  font-family: 'Cinzel', serif;
  font-size: 1rem;
  letter-spacing: 0.03em;
  padding: 1rem 1.25rem;
  cursor: pointer;
}
.panel-toggle-chevron { color: var(--gold); transition: transform 0.25s ease; }
.panel-toggle[aria-expanded="false"] .panel-toggle-chevron { transform: rotate(-90deg); }

.panel-body {
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}
.panel-body[hidden] { display: none; }

.panel-field { border: none; margin: 0; padding: 0; }
.panel-field legend {
  font-family: 'Syne', sans-serif;
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 0 0 0.65rem;
}
.optional-tag {
  font-size: 0.62rem;
  color: var(--gold-soft);
  border: 1px solid var(--gold-line);
  padding: 0.1rem 0.4rem;
  border-radius: 999px;
  text-transform: none;
  letter-spacing: 0.02em;
  margin-left: 0.35rem;
}

.radio-row { display: flex; gap: 0.5rem; margin-bottom: 0.75rem; }

.radio-pill, .check-pill {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-family: 'Syne', sans-serif;
  font-size: 0.78rem;
  color: var(--text-muted);
  border: 1px solid var(--gold-line);
  border-radius: 999px;
  padding: 0.4rem 0.85rem;
  cursor: pointer;
  transition: border-color 0.2s ease, color 0.2s ease, background-color 0.2s ease;
  user-select: none;
}
.radio-pill input, .check-pill input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
}
.radio-pill:has(input:checked), .check-pill:has(input:checked),
.radio-pill.is-checked, .check-pill.is-checked {
  border-color: var(--gold);
  color: var(--bg);
  background: var(--gold);
}
.radio-pill:has(input:focus-visible), .check-pill:has(input:focus-visible) {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

.checkbox-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}
.checkbox-grid[data-disabled="true"] {
  opacity: 0.4;
  pointer-events: none;
}

.field-hint {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.72rem;
  color: var(--danger);
  margin: 0.5rem 0 0;
}

/* ---------- Footer ---------- */
.site-footer {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 2rem 1rem 3rem;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.75rem;
  color: var(--text-muted);
}
.footer-dot { color: var(--gold-line); }

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  .fetch-icon, .delivery, .rimshot.is-active { animation: none !important; }
}
