:root {
  --pink: #ff2ea6;
  --orange: #ff8a3d;
  --yellow: #ffe14d;
  --purple: #7b2ff7;
  --cyan: #29f1c3;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #14071f;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.bg {
  position: fixed;
  inset: 0;
  z-index: 0;
  background: radial-gradient(circle at 30% 20%, #2a0f4a, #14071f 60%);
}

.glow {
  position: absolute;
  border-radius: 50%;
  filter: blur(60px);
  opacity: 0.55;
  will-change: transform;
}
.g1 { width: 60vmax; height: 60vmax; left: -20vmax; top: -20vmax; background: var(--pink); animation: drift1 18s ease-in-out infinite; }
.g2 { width: 55vmax; height: 55vmax; right: -22vmax; top: 10vmax; background: var(--purple); animation: drift2 22s ease-in-out infinite; }
.g3 { width: 50vmax; height: 50vmax; left: 10vmax; bottom: -25vmax; background: var(--cyan); animation: drift3 26s ease-in-out infinite; }

@keyframes drift1 {
  0%, 100% { transform: translate(0, 0) scale(1); }
  50% { transform: translate(8vmax, 6vmax) scale(1.15); }
}
@keyframes drift2 {
  0%, 100% { transform: translate(0, 0) scale(1); }
  50% { transform: translate(-6vmax, 8vmax) scale(1.1); }
}
@keyframes drift3 {
  0%, 100% { transform: translate(0, 0) scale(1); }
  50% { transform: translate(5vmax, -7vmax) scale(1.2); }
}

.stage {
  position: relative;
  z-index: 1;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(1.5rem, 6vh, 3rem);
  padding: 2rem 1.25rem;
  text-align: center;
}

.title {
  margin: 0;
  font-size: clamp(1.8rem, 7vw, 2.6rem);
  font-weight: 800;
  letter-spacing: -0.02em;
  color: #fff;
  text-shadow: 0 0 30px rgba(255, 46, 166, 0.6);
}
.title .bang {
  display: inline-block;
  color: var(--yellow);
  animation: wiggle 2.4s ease-in-out infinite;
}
@keyframes wiggle {
  0%, 100% { transform: rotate(0deg); }
  25% { transform: rotate(-12deg); }
  75% { transform: rotate(12deg); }
}

.orb-wrap {
  position: relative;
  width: clamp(200px, 55vw, 300px);
  height: clamp(200px, 55vw, 300px);
  display: flex;
  align-items: center;
  justify-content: center;
}

.ring {
  position: absolute;
  inset: -14px;
  border-radius: 50%;
  background: conic-gradient(from 0deg, var(--pink), var(--orange), var(--yellow), var(--cyan), var(--purple), var(--pink));
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 6px), #000 calc(100% - 5px));
  mask: radial-gradient(farthest-side, transparent calc(100% - 6px), #000 calc(100% - 5px));
  animation: spin-slow 10s linear infinite;
  opacity: 0.9;
}

.orb {
  position: relative;
  width: 100%;
  height: 100%;
  border-radius: 42% 58% 63% 37% / 41% 44% 56% 59%;
  background: conic-gradient(from 120deg, var(--pink), var(--purple), var(--cyan), var(--orange), var(--pink));
  box-shadow: 0 0 60px rgba(255, 46, 166, 0.55), inset 0 0 50px rgba(255, 255, 255, 0.15);
  animation: float 5s ease-in-out infinite, morph 7s ease-in-out infinite, spin-slow 16s linear infinite;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transform-origin: center;
}

.orb-inner {
  position: absolute;
  inset: 14%;
  border-radius: inherit;
  background: radial-gradient(circle at 35% 30%, rgba(255,255,255,0.55), rgba(255,255,255,0) 60%);
  mix-blend-mode: screen;
  animation: morph 7s ease-in-out infinite reverse;
}

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-14px); }
}
@keyframes morph {
  0%, 100% { border-radius: 42% 58% 63% 37% / 41% 44% 56% 59%; }
  33% { border-radius: 63% 37% 41% 59% / 55% 40% 60% 45%; }
  66% { border-radius: 37% 63% 55% 45% / 63% 58% 42% 37%; }
}
@keyframes spin-slow {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

/* ---- Deciding state: the orb goes into "blender" mode ---- */
.orb-wrap.deciding .orb {
  animation: spin-fast 0.5s linear infinite, squish 0.35s ease-in-out infinite, hue-cycle 1.2s linear infinite;
  box-shadow: 0 0 90px rgba(255, 138, 61, 0.8), inset 0 0 60px rgba(255,255,255,0.25);
}
.orb-wrap.deciding .ring {
  animation: spin-fast 0.8s linear infinite;
}
.orb-wrap.deciding .orb-inner {
  animation: hue-cycle 1.2s linear infinite reverse;
}
@keyframes spin-fast {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}
@keyframes squish {
  0%, 100% { transform: scale(1, 1); }
  50% { transform: scale(0.82, 1.18); }
}
@keyframes hue-cycle {
  from { filter: hue-rotate(0deg) saturate(1.4); }
  to { filter: hue-rotate(360deg) saturate(1.4); }
}

/* ---- Reveal state: orb hides, result card pops ---- */
.orb-wrap.reveal .orb,
.orb-wrap.reveal .ring {
  opacity: 0;
  transform: scale(0.4);
  transition: opacity 0.35s ease, transform 0.35s ease;
}

.result-card {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  border-radius: 32px;
  background: linear-gradient(145deg, rgba(255,255,255,0.14), rgba(255,255,255,0.04));
  border: 1px solid rgba(255,255,255,0.25);
  backdrop-filter: blur(6px);
  box-shadow: 0 0 70px rgba(123, 47, 247, 0.6);
  animation: pop-in 0.5s cubic-bezier(.34,1.56,.64,1);
}
.result-card[hidden] { display: none; }

@keyframes pop-in {
  0% { opacity: 0; transform: scale(0.3) rotate(-10deg); }
  60% { opacity: 1; transform: scale(1.08) rotate(3deg); }
  100% { opacity: 1; transform: scale(1) rotate(0deg); }
}

.result-emoji {
  font-size: clamp(3.2rem, 14vw, 5rem);
  filter: drop-shadow(0 6px 18px rgba(0,0,0,0.35));
}
.result-name {
  font-size: clamp(1.2rem, 5vw, 1.6rem);
  font-weight: 800;
  color: #fff;
  padding: 0 1rem;
}

.hint {
  margin: 0;
  color: rgba(255,255,255,0.8);
  font-size: 1rem;
  font-weight: 600;
  min-height: 1.4em;
  transition: opacity 0.3s ease;
}

.tap-fallback {
  appearance: none;
  border: 1px solid rgba(255,255,255,0.3);
  background: rgba(255,255,255,0.08);
  color: rgba(255,255,255,0.85);
  font-size: 0.85rem;
  font-weight: 600;
  padding: 0.6rem 1.1rem;
  border-radius: 999px;
  cursor: pointer;
}
.tap-fallback:active { background: rgba(255,255,255,0.18); }

/* ══════════════════════════════════════════════════════════════════════
   Options editor (profile mode only)
   ══════════════════════════════════════════════════════════════════════ */
:root {
  --ink: #fff;
  --ink-dim: rgba(255, 255, 255, 0.74);
  --ink-faint: rgba(255, 255, 255, 0.5);
  --glass: rgba(255, 255, 255, 0.07);
  --glass-hi: rgba(255, 255, 255, 0.13);
  --stroke: rgba(255, 255, 255, 0.16);
  --stroke-hi: rgba(255, 255, 255, 0.3);
  --panel: rgba(30, 13, 54, 0.82);
  --danger: #ff6b7d;
  --ok: var(--cyan);
  --grad: linear-gradient(120deg, var(--pink), var(--purple) 55%, var(--cyan));
}

/* ── Gear button ─────────────────────────────────────────────────────── */
.gear {
  position: fixed;
  top: calc(env(safe-area-inset-top, 0px) + 0.85rem);
  right: calc(env(safe-area-inset-right, 0px) + 0.85rem);
  z-index: 5;
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  border: 1px solid var(--stroke);
  border-radius: 50%;
  background: var(--glass);
  backdrop-filter: blur(8px);
  color: var(--ink-dim);
  cursor: pointer;
  transition: transform 0.2s cubic-bezier(0.22, 1, 0.36, 1),
              color 0.2s ease, border-color 0.2s ease, background 0.2s ease;
}
.gear[hidden] { display: none; }
.gear:hover { color: var(--ink); border-color: var(--stroke-hi); background: var(--glass-hi); }
.gear:active { transform: scale(0.92); }
.gear:focus-visible { outline: 2px solid var(--cyan); outline-offset: 3px; }
.gear svg { transition: transform 0.5s cubic-bezier(0.22, 1, 0.36, 1); }
.gear:hover svg { transform: rotate(45deg); }

/* ── Shared button vocabulary ────────────────────────────────────────── */
.btn {
  appearance: none;
  font: inherit;
  font-weight: 700;
  font-size: 0.92rem;
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 0.62rem 1.05rem;
  min-height: 44px;
  cursor: pointer;
  color: var(--ink);
  transition: transform 0.12s ease, filter 0.18s ease, background 0.18s ease,
              border-color 0.18s ease, opacity 0.18s ease;
}
.btn:active { transform: scale(0.97); }
.btn:focus-visible { outline: 2px solid var(--cyan); outline-offset: 2px; }
.btn[disabled] { opacity: 0.5; cursor: default; }
.btn.primary { background: var(--grad); box-shadow: 0 6px 20px rgba(123, 47, 247, 0.4); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: var(--glass); border-color: var(--stroke); color: var(--ink-dim); }
.btn.ghost:hover { background: var(--glass-hi); color: var(--ink); }
.btn.danger { background: transparent; border-color: rgba(255, 107, 125, 0.55); color: var(--danger); }
.btn.danger:hover { background: rgba(255, 107, 125, 0.14); }

.icon-btn {
  appearance: none;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border: 1px solid var(--stroke);
  border-radius: 12px;
  background: var(--glass);
  color: var(--ink-dim);
  cursor: pointer;
  transition: background 0.18s ease, color 0.18s ease;
}
.icon-btn:hover { background: var(--glass-hi); color: var(--ink); }
.icon-btn:focus-visible { outline: 2px solid var(--cyan); outline-offset: 2px; }

/* ── Editor & modal dialogs ──────────────────────────────────────────── */
.editor, .modal {
  margin: auto;
  border: 0;
  padding: 0;
  background: transparent;
  color: var(--ink);
  overflow: visible;
}
.editor { width: min(600px, 100%); }
.modal { width: min(440px, 100%); }
.editor::backdrop, .modal::backdrop {
  background: rgba(8, 3, 18, 0.55);
  backdrop-filter: blur(10px);
}
.editor[open], .modal[open] { animation: dlg-in 0.26s cubic-bezier(0.22, 1, 0.36, 1); }
.editor::backdrop, .modal::backdrop { animation: fade-in 0.26s ease; }
@keyframes dlg-in {
  from { opacity: 0; transform: translateY(14px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

.editor-panel, .modal-panel {
  background: var(--panel);
  border: 1px solid var(--stroke);
  border-radius: 24px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.55), 0 0 0 1px rgba(255, 255, 255, 0.04) inset;
  backdrop-filter: blur(20px);
}
.editor-panel {
  padding: 1.1rem 1.1rem calc(1.1rem + env(safe-area-inset-bottom, 0px));
  max-height: min(88dvh, 760px);
  display: flex;
  flex-direction: column;
}

.editor-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.9rem;
}
.editor-title {
  margin: 0;
  font-size: 1.3rem;
  font-weight: 800;
  letter-spacing: -0.01em;
}
.editor-sub { margin: 0.15rem 0 0; font-size: 0.85rem; color: var(--ink-dim); }

/* ── Lock bar ─────────────────────────────────────────────────────────── */
.lockbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.7rem 0.7rem 0.7rem 0.95rem;
  margin-bottom: 0.9rem;
  border: 1px solid var(--stroke);
  border-radius: 16px;
  background: linear-gradient(120deg, rgba(255, 46, 166, 0.14), rgba(41, 241, 195, 0.1));
}
.lockbar[hidden] { display: none; }
.lockbar-text { display: flex; align-items: center; gap: 0.55rem; font-size: 0.88rem; color: var(--ink); }
.lockbar-emoji { font-size: 1.1rem; }
.lockbar .btn { flex: none; }

/* ── Food grid ───────────────────────────────────────────────────────── */
.food-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(92px, 1fr));
  gap: 0.6rem;
  overflow-y: auto;
  padding: 0.15rem;
  margin: 0 -0.15rem;
}
.food-tile {
  position: relative;
  appearance: none;
  aspect-ratio: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  padding: 0.4rem;
  border: 1px solid var(--stroke);
  border-radius: 16px;
  background: var(--glass);
  color: var(--ink);
  cursor: pointer;
  text-align: center;
  transition: transform 0.15s cubic-bezier(0.22, 1, 0.36, 1),
              background 0.18s ease, border-color 0.18s ease;
  animation: tile-in 0.32s cubic-bezier(0.22, 1, 0.36, 1) both;
}
.food-tile:hover { background: var(--glass-hi); border-color: var(--stroke-hi); transform: translateY(-2px); }
.food-tile:active { transform: scale(0.96); }
.food-tile:focus-visible { outline: 2px solid var(--cyan); outline-offset: 2px; }
.food-tile .em { font-size: clamp(1.7rem, 7vw, 2.2rem); line-height: 1; filter: drop-shadow(0 3px 8px rgba(0, 0, 0, 0.35)); }
.food-tile .nm {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--ink-dim);
  line-height: 1.15;
  max-width: 100%;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.food-tile .pencil {
  position: absolute;
  top: 5px;
  right: 5px;
  opacity: 0;
  color: var(--ink-faint);
  transition: opacity 0.18s ease;
}
.food-tile:hover .pencil, .food-tile:focus-visible .pencil { opacity: 1; }

.food-tile.add {
  border-style: dashed;
  border-color: var(--stroke-hi);
  background: transparent;
  color: var(--ink-dim);
}
.food-tile.add .plus { font-size: 1.9rem; font-weight: 300; line-height: 1; }
.food-tile.add .nm { color: var(--ink-faint); }
.food-tile.add:hover { color: var(--ink); border-color: var(--cyan); background: rgba(41, 241, 195, 0.08); }

.food-grid.locked .food-tile { cursor: default; }

@keyframes tile-in {
  from { opacity: 0; transform: translateY(8px) scale(0.94); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.editor-foot {
  margin: 0.85rem 0 0;
  min-height: 1.1em;
  font-size: 0.82rem;
  font-weight: 600;
  text-align: center;
  color: var(--ink-dim);
}
.editor-foot.ok { color: var(--cyan); }
.editor-foot.err { color: var(--danger); }

/* ── Edit modal ──────────────────────────────────────────────────────── */
.modal-panel { padding: 1.3rem 1.25rem calc(1.25rem + env(safe-area-inset-bottom, 0px)); }
.modal-title { margin: 0 0 0.9rem; font-size: 1.15rem; font-weight: 800; text-align: center; }
.emoji-preview {
  width: 84px;
  height: 84px;
  margin: 0 auto 0.9rem;
  display: grid;
  place-items: center;
  font-size: 3rem;
  border-radius: 20px;
  background: var(--glass);
  border: 1px solid var(--stroke);
  filter: drop-shadow(0 6px 16px rgba(0, 0, 0, 0.35));
}
.emoji-picks {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.35rem;
  margin-bottom: 1rem;
}
.emoji-pick {
  appearance: none;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  font-size: 1.3rem;
  border: 1px solid transparent;
  border-radius: 11px;
  background: var(--glass);
  cursor: pointer;
  transition: transform 0.12s ease, background 0.15s ease, border-color 0.15s ease;
}
.emoji-pick:hover { background: var(--glass-hi); }
.emoji-pick:active { transform: scale(0.9); }
.emoji-pick.sel { border-color: var(--cyan); background: rgba(41, 241, 195, 0.16); }
.emoji-pick:focus-visible { outline: 2px solid var(--cyan); outline-offset: 2px; }

.fields { display: flex; gap: 0.7rem; }
.field { display: flex; flex-direction: column; gap: 0.35rem; }
.field-grow { flex: 1; }
.field-label { font-size: 0.72rem; font-weight: 700; letter-spacing: 0.02em; text-transform: uppercase; color: var(--ink-dim); }
.field-input {
  appearance: none;
  font: inherit;
  color: var(--ink);
  background: rgba(0, 0, 0, 0.22);
  border: 1px solid var(--stroke);
  border-radius: 12px;
  padding: 0.65rem 0.75rem;
  min-height: 46px;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.field-input::placeholder { color: var(--ink-faint); }
.field-input:focus { outline: none; border-color: var(--cyan); background: rgba(0, 0, 0, 0.32); }
.emoji-field { width: 70px; text-align: center; font-size: 1.35rem; }

.modal-error { margin: 0.85rem 0 0; font-size: 0.82rem; font-weight: 600; color: var(--danger); text-align: center; }
.modal-error[hidden] { display: none; }

.modal-actions { display: flex; align-items: center; gap: 0.55rem; margin-top: 1.15rem; }
.modal-actions .spacer { flex: 1; }
.modal-actions .btn.danger[hidden] { display: none; }

/* ── Toast ───────────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 1.5rem);
  transform: translateX(-50%) translateY(10px);
  z-index: 6;
  padding: 0.7rem 1.1rem;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid var(--stroke);
  backdrop-filter: blur(12px);
  color: var(--ink);
  font-size: 0.85rem;
  font-weight: 600;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
  opacity: 0;
  transition: opacity 0.22s ease, transform 0.22s ease;
}
.toast[hidden] { display: none; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.busy { position: relative; color: transparent !important; pointer-events: none; }
.busy::after {
  content: "";
  position: absolute;
  inset: 0;
  margin: auto;
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 460px) {
  .editor-panel { border-radius: 22px 22px 0 0; max-height: 90dvh; }
  .editor, .modal { margin: auto auto 0; }
  .editor[open], .modal[open] { animation: sheet-in 0.28s cubic-bezier(0.22, 1, 0.36, 1); }
}
@keyframes sheet-in {
  from { opacity: 0; transform: translateY(28px); }
  to   { opacity: 1; transform: translateY(0); }
}

@media (prefers-reduced-motion: reduce) {
  .orb, .orb-inner, .ring, .glow, .title .bang { animation: none !important; }
  .editor[open], .modal[open], .editor::backdrop, .modal::backdrop,
  .food-tile, .toast, .busy::after { animation: none !important; }
  .gear svg, .btn, .food-tile { transition: none !important; }
}
