/* ============================================================
   Makan Mana — Bukku internal lunch randomiser
   Self-contained (no external fonts/assets). Brand: teal + navy.
   ============================================================ */

:root {
  /* Brand */
  --brand-teal: #22B7C9;
  --brand-teal-2: #1AAFC0;
  --brand-teal-light: #7FE3ED;
  --brand-navy: #0C4A5C;
  --brand-navy-2: #0A3A48;

  /* Semantic (light theme defaults) */
  --bg-1: #eefafb;
  --bg-2: #dff2f5;
  --bg-3: #f7fdfd;
  --surface: #ffffff;
  --surface-2: #f2f9fa;
  --surface-border: #d8ebef;
  --text: #0c2e38;
  --text-muted: #5b7a83;
  --text-invert: #ffffff;
  --shadow-color: 12 74 92;
  --ring: var(--brand-teal);

  --radius-sm: 10px;
  --radius: 16px;
  --radius-lg: 26px;
  --radius-pill: 999px;

  --shadow-sm: 0 2px 8px rgb(var(--shadow-color) / 0.08);
  --shadow-md: 0 10px 30px rgb(var(--shadow-color) / 0.14);
  --shadow-lg: 0 24px 60px rgb(var(--shadow-color) / 0.24);

  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);

  --wheel-size: min(78vw, 460px);
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

[data-theme="dark"] {
  --bg-1: #072029;
  --bg-2: #0a2b36;
  --bg-3: #061a22;
  --surface: #0f3441;
  --surface-2: #123a49;
  --surface-border: #1c4d5e;
  --text: #e9f7f9;
  --text-muted: #93b6c0;
  --text-invert: #06222b;
  --shadow-color: 0 0 0;
  --shadow-sm: 0 2px 8px rgb(0 0 0 / 0.3);
  --shadow-md: 0 12px 34px rgb(0 0 0 / 0.45);
  --shadow-lg: 0 26px 64px rgb(0 0 0 / 0.55);
}

/* ---------- Reset ---------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--text);
  background: radial-gradient(1200px 800px at 15% -10%, var(--bg-3), transparent 60%),
              linear-gradient(160deg, var(--bg-1), var(--bg-2));
  background-attachment: fixed;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.4s ease, color 0.4s ease;
}

h1, h2, p { margin: 0; }
button { font-family: inherit; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

:focus-visible {
  outline: 3px solid var(--ring);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* ---------- Animated background blobs ---------- */
.bg-blobs { position: fixed; inset: 0; z-index: 0; pointer-events: none; overflow: hidden; }
.blob {
  position: absolute; border-radius: 50%; filter: blur(60px); opacity: 0.5;
  animation: float 18s ease-in-out infinite;
}
.blob-1 { width: 42vw; height: 42vw; left: -8vw; top: -6vw;
  background: radial-gradient(circle at 30% 30%, var(--brand-teal-light), transparent 70%); }
.blob-2 { width: 38vw; height: 38vw; right: -10vw; top: 20vh;
  background: radial-gradient(circle at 60% 40%, var(--brand-teal), transparent 70%);
  animation-delay: -6s; opacity: 0.32; }
.blob-3 { width: 34vw; height: 34vw; left: 20vw; bottom: -14vw;
  background: radial-gradient(circle at 50% 50%, var(--brand-navy), transparent 72%);
  animation-delay: -11s; opacity: 0.22; }

@keyframes float {
  0%, 100% { transform: translate(0, 0) scale(1); }
  33% { transform: translate(4vw, 5vh) scale(1.08); }
  66% { transform: translate(-3vw, -3vh) scale(0.95); }
}

/* ---------- Topbar ---------- */
.topbar {
  position: relative; z-index: 3;
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 16px clamp(16px, 4vw, 36px);
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-logo { height: 30px; width: auto; display: block; }
/* The logo is dark-ink (for light backgrounds); in dark mode sit it on a
   light chip so it stays legible without altering the brand colours. */
[data-theme="dark"] .brand-logo {
  background: #f5feff;
  padding: 4px 9px;
  border-radius: 9px;
  box-sizing: content-box;
}
.brand-divider { width: 1px; height: 24px; background: var(--surface-border); }
.brand-app {
  font-weight: 700; font-size: 0.95rem; letter-spacing: 0.2px;
  color: var(--text-muted); white-space: nowrap;
}

.topbar-actions { display: flex; align-items: center; gap: 8px; }
.icon-btn {
  position: relative;
  display: inline-flex; align-items: center; gap: 7px;
  border: 1px solid var(--surface-border);
  background: rgb(var(--shadow-color) / 0.02);
  backdrop-filter: blur(8px);
  color: var(--text);
  height: 40px; min-width: 40px; padding: 0 10px;
  border-radius: var(--radius-pill);
  cursor: pointer; font-size: 1rem; font-weight: 600;
  transition: transform 0.14s var(--ease-out), background 0.2s, border-color 0.2s, box-shadow 0.2s;
}
[data-theme="dark"] .icon-btn { background: rgb(255 255 255 / 0.04); }
.icon-btn:hover { transform: translateY(-2px); border-color: var(--brand-teal); box-shadow: var(--shadow-sm); }
.icon-btn:active { transform: translateY(0) scale(0.96); }
.icon-btn__glyph { font-size: 1.05rem; line-height: 1; }
.icon-btn.text-btn { padding: 0 14px; }
.icon-btn__label { font-size: 0.9rem; }
#soundToggle[aria-pressed="true"] { color: var(--brand-teal); border-color: var(--brand-teal); }
.icon-btn.has-filters { color: var(--brand-teal); border-color: var(--brand-teal); }

.filter-badge {
  position: absolute; top: -6px; right: -4px;
  min-width: 18px; height: 18px; padding: 0 4px;
  display: grid; place-items: center;
  background: var(--brand-teal); color: #062730;
  border-radius: var(--radius-pill); font-size: 0.72rem; font-weight: 800;
  box-shadow: var(--shadow-sm);
}
.filter-badge[hidden] { display: none; }

/* ---------- Main stage ---------- */
.stage {
  position: relative; z-index: 2;
  flex: 1;
  display: flex; flex-direction: column; align-items: center;
  padding: 8px clamp(16px, 4vw, 36px) 32px;
  width: 100%;
}

.hero { text-align: center; margin-bottom: 10px; }
.hero__title {
  font-size: clamp(2.1rem, 6vw, 3.4rem);
  font-weight: 800; letter-spacing: -1.5px; line-height: 1.05;
  background: linear-gradient(120deg, var(--brand-navy), var(--brand-teal));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
[data-theme="dark"] .hero__title {
  background: linear-gradient(120deg, var(--brand-teal-light), var(--brand-teal));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.hero__subtitle { margin-top: 8px; color: var(--text-muted); font-size: clamp(0.95rem, 2.6vw, 1.1rem); font-weight: 500; }

/* ---------- Filters ---------- */
.filters { width: 100%; max-width: 720px; margin: 6px 0 4px; overflow: hidden; }
.filters[hidden] { display: none; }
.filters.opening { animation: slideDown 0.28s var(--ease-out); }
.filters.locked { opacity: 0.55; pointer-events: none; } /* while the wheel is spinning */
@keyframes slideDown { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: translateY(0); } }
.filters__inner {
  background: var(--surface); border: 1px solid var(--surface-border);
  border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow-sm);
  display: flex; flex-direction: column; gap: 12px;
}
.filters__group { display: flex; flex-direction: column; gap: 8px; }
.filters__label { font-size: 0.75rem; font-weight: 700; text-transform: uppercase; letter-spacing: 1px; color: var(--text-muted); }
.filters__chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 1px solid var(--surface-border); background: var(--surface-2);
  color: var(--text); padding: 6px 12px; border-radius: var(--radius-pill);
  cursor: pointer; font-size: 0.85rem; font-weight: 600;
  transition: transform 0.12s var(--ease-out), background 0.18s, border-color 0.18s, color 0.18s;
}
.chip:hover { transform: translateY(-2px); border-color: var(--brand-teal); }
.chip[aria-pressed="true"] {
  background: linear-gradient(135deg, var(--brand-teal), var(--brand-teal-2));
  color: #062730; border-color: transparent; box-shadow: var(--shadow-sm);
}
.link-btn {
  background: none; border: none; color: var(--brand-navy); cursor: pointer;
  font-weight: 700; font-size: 0.85rem; padding: 4px 2px; align-self: flex-start;
  text-decoration: underline; text-underline-offset: 3px;
}
.link-btn:hover { color: var(--brand-teal-2); }
[data-theme="dark"] .link-btn { color: var(--brand-teal); }
[data-theme="dark"] .link-btn:hover { color: var(--brand-teal-light); }
/* centre the veto link under the "Spin lagi" button (overrides align-self) */
.result-card__actions--secondary .link-btn { align-self: center; }

/* ---------- Wheel ---------- */
.wheel-area {
  position: relative; margin: 14px 0 6px;
  display: grid; place-items: center;
}
.wheel-wrap {
  position: relative;
  width: var(--wheel-size); height: var(--wheel-size);
  display: grid; place-items: center;
  animation: wheelDrift 7s ease-in-out infinite alternate;
}
.wheel-wrap.spinning { animation: none; }
.wheel-wrap.nudge { animation: nudge 0.7s var(--ease-out); }
@keyframes wheelDrift { from { transform: rotate(-1.4deg); } to { transform: rotate(1.4deg); } }
@keyframes nudge {
  0% { transform: rotate(0); } 25% { transform: rotate(7deg); }
  55% { transform: rotate(-5deg); } 80% { transform: rotate(2deg); } 100% { transform: rotate(0); }
}

.wheel {
  width: 100%; height: 100%; display: block;
  border-radius: 50%;
  filter: drop-shadow(0 18px 40px rgb(var(--shadow-color) / 0.28));
  will-change: transform, filter;
}

/* Pointer / flapper at 12 o'clock */
.pointer {
  position: absolute; top: -6px; left: 50%; z-index: 4;
  transform: translateX(-50%);
  transform-origin: 50% 20%;
  width: 40px; height: 46px;
  filter: drop-shadow(0 4px 6px rgb(var(--shadow-color) / 0.35));
  transition: transform 0.09s cubic-bezier(0.2, 0.8, 0.3, 1);
}
.pointer::before {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(180deg, #ff6b6b, #e23c3c);
  clip-path: polygon(50% 100%, 0 0, 100% 0);
  border-radius: 4px;
}
.pointer.kick { transform: translateX(-50%) rotate(-14deg); }

/* Center hub / SPIN button */
.hub {
  position: absolute; z-index: 5;
  width: 27%; height: 27%; border-radius: 50%;
  border: 5px solid #fff;
  background:
    radial-gradient(circle at 35% 30%, #56d3e2, var(--brand-teal) 45%, var(--brand-teal-2) 100%);
  color: #fff; font-weight: 800; letter-spacing: 1px;
  font-size: clamp(0.9rem, 3.2vw, 1.25rem);
  cursor: pointer;
  box-shadow: 0 8px 20px rgb(var(--shadow-color) / 0.4), inset 0 2px 8px rgb(255 255 255 / 0.5), inset 0 -6px 12px rgb(0 0 0 / 0.15);
  display: grid; place-items: center;
  animation: breathe 2.6s ease-in-out infinite;
  transition: transform 0.12s var(--ease-out), box-shadow 0.2s, filter 0.15s;
}
.hub__label { pointer-events: none; text-shadow: 0 1px 2px rgb(0 0 0 / 0.25); }
.hub:hover { filter: brightness(1.08); transform: translateY(-2px); animation-play-state: paused; }
.hub:active { transform: scale(0.93); }
.hub.spinning {
  cursor: progress; opacity: 0.72; animation: none; filter: saturate(0.85);
  pointer-events: none;
}
.hub[disabled] { cursor: not-allowed; opacity: 0.5; animation: none; filter: grayscale(0.4); }
@keyframes breathe { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.045); } }

/* ---------- Controls ---------- */
.controls { display: flex; flex-direction: column; align-items: center; gap: 8px; margin-top: 6px; }
.cta {
  display: inline-flex; align-items: center; gap: 10px;
  border: none; cursor: pointer;
  padding: 14px 30px; border-radius: var(--radius-pill);
  font-size: 1.05rem; font-weight: 800; color: #fff;
  background: linear-gradient(120deg, var(--brand-navy), var(--brand-teal));
  background-size: 180% 100%;
  box-shadow: var(--shadow-md);
  transition: transform 0.14s var(--ease-out), box-shadow 0.2s, background-position 0.5s;
}
.cta:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); background-position: 100% 0; }
.cta:active { transform: translateY(-1px) scale(0.97); }
.cta:disabled { opacity: 0.55; cursor: progress; transform: none; box-shadow: var(--shadow-sm); }
.cta__dice { font-size: 1.2rem; display: inline-block; }
.cta:hover .cta__dice { animation: diceRoll 0.6s var(--ease-out); }
@keyframes diceRoll { 0% { transform: rotate(0); } 100% { transform: rotate(360deg); } }
.pool-count { color: var(--text-muted); font-size: 0.85rem; font-weight: 600; min-height: 1.1em; }

/* ---------- History strip ---------- */
.history { width: 100%; max-width: 720px; margin-top: 26px; }
.history__heading {
  font-size: 0.75rem; font-weight: 700; text-transform: uppercase; letter-spacing: 1.2px;
  color: var(--text-muted); margin-bottom: 10px; text-align: center;
}
.history__strip {
  display: flex; gap: 8px; flex-wrap: wrap; justify-content: center;
}
.history-chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--surface); border: 1px solid var(--surface-border);
  border-radius: var(--radius-pill); padding: 6px 12px; font-size: 0.82rem; font-weight: 600;
  color: var(--text); text-decoration: none; box-shadow: var(--shadow-sm);
  animation: popIn 0.3s var(--ease-spring) both;
  transition: transform 0.12s var(--ease-out), border-color 0.18s;
}
.history-chip:hover { transform: translateY(-2px); border-color: var(--brand-teal); }
.history-chip__when { color: var(--text-muted); font-weight: 500; font-size: 0.74rem; }
@keyframes popIn { from { opacity: 0; transform: scale(0.8); } to { opacity: 1; transform: scale(1); } }

/* ---------- Footer ---------- */
.site-footer {
  position: relative; z-index: 2;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 18px; color: var(--text-muted); font-size: 0.78rem; text-align: center;
}
.site-footer__legal { opacity: 0.8; }

/* ---------- Confetti ---------- */
.confetti-canvas {
  position: fixed; inset: 0; z-index: 52; pointer-events: none;
  width: 100%; height: 100%;
}

/* ---------- Result overlay / card ---------- */
.result-overlay {
  position: fixed; inset: 0; z-index: 50;
  display: grid; place-items: center; padding: 20px;
  background: rgb(6 30 38 / 0.42); backdrop-filter: blur(4px);
  animation: fadeIn 0.24s ease-out;
}
.result-overlay[hidden] { display: none; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.result-card {
  position: relative;
  width: min(92vw, 420px);
  background: var(--surface); border: 1px solid var(--surface-border);
  border-radius: var(--radius-lg); padding: 30px 26px 24px;
  box-shadow: var(--shadow-lg); text-align: center;
  transform-origin: bottom center;
  animation: cardRise 0.5s var(--ease-spring) both;
}
@keyframes cardRise {
  from { opacity: 0; transform: translateY(28px) scale(0.9); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
.result-card__close {
  position: absolute; top: 12px; right: 12px;
  width: 32px; height: 32px; border-radius: 50%;
  border: none; background: var(--surface-2); color: var(--text-muted);
  cursor: pointer; font-size: 0.9rem; transition: background 0.18s, color 0.18s, transform 0.12s;
}
.result-card__close:hover { background: var(--brand-teal); color: #fff; transform: rotate(90deg); }
.result-card__eyebrow { color: var(--text-muted); font-weight: 700; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 1px; }
.result-card__emoji {
  font-size: 3.4rem; margin: 8px 0 4px;
  animation: emojiPop 0.6s var(--ease-spring) 0.12s both;
}
@keyframes emojiPop { 0% { transform: scale(0) rotate(-30deg); } 70% { transform: scale(1.25) rotate(8deg); } 100% { transform: scale(1) rotate(0); } }
.result-card__name {
  font-size: clamp(1.5rem, 6vw, 2rem); font-weight: 800; letter-spacing: -0.5px;
  color: var(--text); line-height: 1.1; min-height: 1.1em;
}
.result-card__name.scramble { color: var(--brand-teal); }
.result-card__meta { margin-top: 8px; color: var(--text-muted); font-weight: 600; font-size: 0.92rem; }
.result-card__desc { margin-top: 10px; color: var(--text); font-size: 0.95rem; opacity: 0.85; }
.result-card__actions { display: flex; gap: 10px; margin-top: 20px; }
.result-card__actions--secondary { flex-direction: column; align-items: center; gap: 8px; margin-top: 14px; }
.btn {
  flex: 1; display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 12px 16px; border-radius: var(--radius-pill); font-weight: 700; font-size: 0.92rem;
  cursor: pointer; text-decoration: none; border: 1px solid transparent;
  transition: transform 0.12s var(--ease-out), box-shadow 0.2s, background 0.2s;
}
.btn:hover { transform: translateY(-2px); }
.btn:active { transform: scale(0.97); }
.btn--primary { background: linear-gradient(120deg, var(--brand-teal), var(--brand-teal-2)); color: #062730; box-shadow: var(--shadow-sm); }
.btn--ghost { background: var(--surface-2); color: var(--text); border-color: var(--surface-border); }
.btn--solid { background: var(--brand-navy); color: #fff; flex: initial; padding: 12px 24px; }
[data-theme="dark"] .btn--solid { background: var(--brand-teal); color: #062730; }

/* ---------- Empty / error state ---------- */
.empty-state {
  position: fixed; inset: 0; z-index: 45;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 10px; padding: 24px; text-align: center;
  background: rgb(6 30 38 / 0.5); backdrop-filter: blur(6px);
}
.empty-state[hidden] { display: none; }
.empty-state__emoji { font-size: 3.6rem; animation: emojiPop 0.6s var(--ease-spring) both; }
.empty-state__title { color: #fff; font-size: 1.5rem; font-weight: 800; }
.empty-state__msg { color: rgb(255 255 255 / 0.85); font-size: 0.95rem; }
.empty-state__msg code, .help-sheet code { background: rgb(255 255 255 / 0.16); padding: 2px 7px; border-radius: 6px; font-size: 0.9em; }
.empty-state .btn { margin-top: 8px; }

/* ---------- Help sheet ---------- */
.help-overlay {
  position: fixed; inset: 0; z-index: 55; display: grid; place-items: center; padding: 20px;
  background: rgb(6 30 38 / 0.42); backdrop-filter: blur(4px); animation: fadeIn 0.24s ease-out;
}
.help-overlay[hidden] { display: none; }
.help-sheet {
  position: relative; width: min(92vw, 420px);
  background: var(--surface); border: 1px solid var(--surface-border);
  border-radius: var(--radius-lg); padding: 26px; box-shadow: var(--shadow-lg);
  animation: cardRise 0.4s var(--ease-spring) both;
}
.help-sheet__title { font-size: 1.3rem; font-weight: 800; margin-bottom: 16px; }
.help-sheet__list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 10px; }
.help-sheet__list li { display: flex; align-items: center; gap: 12px; color: var(--text); font-size: 0.92rem; }
.help-sheet__list span { color: var(--text-muted); }
kbd {
  min-width: 30px; text-align: center;
  background: var(--surface-2); border: 1px solid var(--surface-border);
  border-bottom-width: 2px; border-radius: 6px; padding: 3px 8px;
  font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 0.8rem; font-weight: 700; color: var(--text);
}
.help-sheet__foot { margin-top: 16px; color: var(--text-muted); font-size: 0.82rem; }
.help-sheet code { background: var(--surface-2); color: var(--brand-teal); }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 28px; z-index: 60; transform: translateX(-50%) translateY(20px);
  background: var(--brand-navy); color: #fff; padding: 12px 20px; border-radius: var(--radius-pill);
  font-weight: 700; font-size: 0.9rem; box-shadow: var(--shadow-lg); opacity: 0;
  transition: opacity 0.25s, transform 0.3s var(--ease-spring);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
[data-theme="dark"] .toast { background: var(--brand-teal); color: #062730; }

/* ---------- Responsive ---------- */
@media (max-width: 560px) {
  :root { --wheel-size: min(86vw, 400px); }
  .brand-app { display: none; }
  .brand-divider { display: none; }
  .icon-btn__label { display: none; }
  .icon-btn.text-btn { padding: 0 12px; }
  .result-card__actions { flex-direction: column; }
}

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.05ms !important; }
  .blob, .wheel-wrap, .hub { animation: none !important; }
}
