:root {
  --bg: #07060e;
  --bg2: #100c1d;
  --panel: rgba(23, 18, 40, 0.88);
  --panel-border: rgba(177, 140, 255, 0.16);
  --ink: #ece6fa;
  --muted: #9a8fb8;
  --green: #8aff6a;
  --purple: #b18cff;
  --red: #ff5d6c;
  --paper: #f2ead2;
  --paper-ink: #241b10;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

body {
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  background: var(--bg);
  color: var(--ink);
  font-family: "Outfit", system-ui, sans-serif;
  min-height: 100vh;
  line-height: 1.6;
  overflow-x: hidden;
}

/* ---------- Atmosphere layers ---------- */

.bg-grad {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(ellipse 90% 55% at 50% -12%, rgba(110, 60, 220, 0.22), transparent 70%),
    radial-gradient(ellipse 70% 45% at 85% 105%, rgba(60, 220, 120, 0.07), transparent 70%),
    radial-gradient(ellipse 60% 40% at 8% 90%, rgba(110, 60, 220, 0.09), transparent 70%);
}

.fog {
  position: fixed;
  z-index: 0;
  pointer-events: none;
  width: 55vmax;
  height: 55vmax;
  border-radius: 50%;
  filter: blur(40px);
  opacity: 0.4;
}
.fog.f1 { top: -20vmax; left: -15vmax; background: radial-gradient(circle, rgba(120, 70, 220, 0.12), transparent 60%); animation: fog-drift 30s ease-in-out infinite alternate; }
.fog.f2 { bottom: -25vmax; right: -18vmax; background: radial-gradient(circle, rgba(70, 220, 130, 0.07), transparent 60%); animation: fog-drift 38s ease-in-out infinite alternate-reverse; }

@keyframes fog-drift {
  from { transform: translate(0, 0) scale(1); }
  to { transform: translate(7vmax, 3vmax) scale(1.12); }
}

#fx {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  z-index: 1;
  pointer-events: none;
}

.wrap {
  position: relative;
  z-index: 2;
  max-width: 720px;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 4rem;
}

/* ---------- Type ---------- */

h1 {
  font-weight: 700;
  font-size: clamp(2.1rem, 6vw, 3.3rem);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  text-align: center;
  color: var(--green);
  text-shadow: 0 0 28px rgba(138, 255, 106, 0.35), 0 0 70px rgba(138, 255, 106, 0.12);
}

h2 {
  font-weight: 600;
  font-size: 1.25rem;
  letter-spacing: 0.02em;
  color: var(--purple);
  margin-bottom: 0.75rem;
}

.tagline { text-align: center; color: var(--muted); margin: 0.35rem auto 0.5rem; max-width: 560px; }

/* ---------- The hat ---------- */

.hat-stage {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 1.2rem 0 0.5rem;
}

.hat-stage-inner { position: relative; display: flex; flex-direction: column; align-items: center; }

.hat-float {
  width: clamp(240px, 55vw, 400px);
  animation: hat-bob 4.5s ease-in-out infinite;
  will-change: transform;
  outline: none;
}

.hat-float:focus-visible .hat-render { filter: drop-shadow(0 0 26px rgba(177, 140, 255, 0.7)); }

.hat-render {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 100 / 85;
  filter: drop-shadow(0 10px 34px rgba(122, 92, 255, 0.26));
}

@keyframes hat-bob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

.hat-shadow {
  width: 55%;
  height: 22px;
  margin-top: -4px;
  border-radius: 50%;
  background: radial-gradient(ellipse, rgba(0, 0, 0, 0.7), transparent 70%);
  animation: shadow-squash 4.5s ease-in-out infinite;
}

@keyframes shadow-squash {
  0%, 100% { transform: scale(1); opacity: 0.75; }
  50% { transform: scale(0.9); opacity: 0.55; }
}

.hat-float.rumble { animation: hat-rumble 0.1s linear infinite; }

@keyframes hat-rumble {
  0% { transform: translate(-2px, 1px); }
  25% { transform: translate(2px, -1px); }
  50% { transform: translate(-2px, -1px); }
  75% { transform: translate(2px, 1px); }
  100% { transform: translate(-2px, 1px); }
}

.hat-float.gulp .hat-render { animation: hat-gulp 0.4s ease-out; }

@keyframes hat-gulp {
  0% { filter: drop-shadow(0 10px 34px rgba(122, 92, 255, 0.26)) brightness(1); }
  30% { filter: drop-shadow(0 0 55px rgba(138, 255, 106, 0.75)) brightness(1.8); }
  100% { filter: drop-shadow(0 10px 34px rgba(122, 92, 255, 0.26)) brightness(1); }
}

.hat-hint { color: var(--muted); font-size: 0.9rem; margin-top: 0.4rem; text-align: center; }

.count-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0.9rem auto 0;
  padding: 0.45rem 1.2rem;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  color: var(--muted);
  font-size: 0.95rem;
}
.count-chip strong { color: var(--green); font-size: 1.25rem; font-variant-numeric: tabular-nums; }
.count-chip.bump strong { animation: count-bump 0.4s ease-out; }

@keyframes count-bump {
  0% { transform: scale(1); }
  40% { transform: scale(1.5); color: #fff; }
  100% { transform: scale(1); }
}

/* ---------- Cards & forms ---------- */

.card {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 16px;
  padding: 1.6rem;
  margin: 1.5rem 0;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
}

label { display: block; color: var(--muted); font-size: 0.88rem; margin: 0.9rem 0 0.3rem; }

input[type="text"], input[type="password"], textarea {
  width: 100%;
  background: rgba(7, 6, 14, 0.65);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  color: var(--ink);
  font-family: inherit;
  font-size: 1rem;
  padding: 0.75rem 0.9rem;
  transition: border-color 0.15s;
}

input:focus, textarea:focus {
  outline: none;
  border-color: var(--purple);
  box-shadow: 0 0 0 3px rgba(177, 140, 255, 0.16);
}

textarea { min-height: 110px; resize: vertical; }

input, textarea, .reveal-text, .hist-item { -webkit-user-select: text; user-select: text; }

.pills { display: flex; gap: 0.5rem; margin-top: 0.3rem; flex-wrap: wrap; }
.pills input { position: absolute; opacity: 0; pointer-events: none; }
.pills span {
  display: inline-block;
  padding: 0.45rem 1.1rem;
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
  transition: all 0.15s;
}
.pills input:checked + span { border-color: var(--green); color: var(--green); background: rgba(138, 255, 106, 0.09); }
.pills input:focus-visible + span { outline: 2px solid var(--purple); }

button {
  font-family: inherit;
  font-size: 1rem;
  font-weight: 600;
  background: linear-gradient(160deg, #7444e0, #4b2a99);
  color: #fff;
  border: none;
  border-radius: 12px;
  padding: 0.8rem 1.7rem;
  cursor: pointer;
  margin-top: 1.1rem;
  transition: transform 0.12s, filter 0.15s;
  box-shadow: 0 6px 24px rgba(116, 68, 224, 0.35);
}

button:hover { filter: brightness(1.15); transform: translateY(-1px); }
button:disabled { opacity: 0.5; cursor: wait; transform: none; }

button.big {
  display: block;
  width: 100%;
  font-size: 1.15rem;
  letter-spacing: 0.04em;
  padding: 0.95rem;
  background: linear-gradient(160deg, #1f8a32, #145220);
  box-shadow: 0 6px 28px rgba(31, 138, 50, 0.35);
}

button.ghost {
  background: transparent;
  border: 1px solid var(--panel-border);
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 400;
  padding: 0.45rem 0.9rem;
  margin-top: 0;
  box-shadow: none;
}
button.ghost:hover { color: var(--ink); border-color: var(--purple); }
button.danger:hover { color: var(--red); border-color: var(--red); }

.msg { margin-top: 0.9rem; padding: 0.7rem 1rem; border-radius: 10px; display: none; }
.msg.show { display: block; animation: msg-in 0.25s ease-out; }
.msg.ok { background: rgba(138, 255, 106, 0.1); color: var(--green); border: 1px solid rgba(138, 255, 106, 0.35); }
.msg.err { background: rgba(255, 93, 108, 0.1); color: var(--red); border: 1px solid rgba(255, 93, 108, 0.35); }

@keyframes msg-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.charcount { text-align: right; color: var(--muted); font-size: 0.8rem; margin-top: 0.25rem; }

.footer { text-align: center; margin-top: 2rem; color: var(--muted); font-size: 0.9rem; }
.footer a { color: var(--purple); }

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.5rem;
  color: var(--muted);
  flex-wrap: wrap;
}
.topbar .actions { display: flex; gap: 0.5rem; }

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

/* ---------- Flying slip ---------- */

.flying-slip {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 50;
  max-width: 240px;
  padding: 0.7rem 0.9rem;
  background: var(--paper);
  color: var(--paper-ink);
  font-size: 0.82rem;
  line-height: 1.4;
  border-radius: 4px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.8);
  pointer-events: none;
  will-change: transform, opacity;
}

/* ---------- Reveal overlay ---------- */

.reveal-overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
  background: rgba(5, 4, 10, 0.88);
  animation: overlay-in 0.25s ease-out;
}

@keyframes overlay-in { from { opacity: 0; } to { opacity: 1; } }

.reveal-slip {
  width: min(660px, 94vw);
  max-height: 86vh;
  overflow-y: auto;
  background:
    radial-gradient(ellipse 120% 100% at 50% 0%, rgba(255, 250, 235, 0.5), transparent 60%),
    var(--paper);
  color: var(--paper-ink);
  border-radius: 8px;
  padding: clamp(1.4rem, 4vw, 2.4rem);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.4), 0 30px 90px rgba(0, 0, 0, 0.9);
  will-change: transform;
}

.reveal-kind {
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: #7a4a2f;
  border-bottom: 1px solid rgba(36, 27, 16, 0.2);
  padding-bottom: 0.6rem;
  margin-bottom: 1rem;
}

.reveal-text {
  font-size: clamp(1.25rem, 3.2vw, 1.7rem);
  font-weight: 500;
  line-height: 1.5;
  min-height: 3em;
  overflow-wrap: break-word;
}

.reveal-text.typing::after { content: "▌"; animation: caret 0.7s steps(1) infinite; color: #7a4a2f; }

@keyframes caret { 50% { opacity: 0; } }

.reveal-meta {
  font-size: 0.85rem;
  color: #6b5d44;
  margin-top: 1.4rem;
  border-top: 1px solid rgba(36, 27, 16, 0.2);
  padding-top: 0.8rem;
}

.reveal-actions { display: flex; gap: 0.6rem; flex-wrap: wrap; margin-top: 1.2rem; }
.reveal-actions button { margin-top: 0; }
.reveal-actions .ghost { color: #55492f; border-color: rgba(36, 27, 16, 0.35); }
.reveal-actions .ghost:hover { color: #241b10; border-color: #241b10; }

/* ---------- History drawer ---------- */

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 55;
  width: min(440px, 100vw);
  height: 100dvh;
  background: rgba(13, 10, 24, 0.97);
  border-left: 1px solid var(--panel-border);
  box-shadow: -30px 0 80px rgba(0, 0, 0, 0.6);
  transform: translateX(105%);
  transition: transform 0.3s cubic-bezier(.2,.8,.3,1);
  display: flex;
  flex-direction: column;
}
.drawer.open { transform: translateX(0); }

.drawer-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.1rem 1.25rem 0.8rem;
  border-bottom: 1px solid var(--panel-border);
}
.drawer-head h2 { margin: 0; font-size: 1.15rem; }

.drawer-body { overflow-y: auto; padding: 0.5rem 1.25rem 2rem; flex: 1; }

.hist-item {
  border-bottom: 1px solid rgba(177, 140, 255, 0.1);
  padding: 1rem 0;
}
.hist-item .meta { color: var(--muted); font-size: 0.78rem; margin-top: 0.3rem; }
.hist-item .actions { display: flex; gap: 0.4rem; margin-top: 0.55rem; }

.badge {
  font-size: 0.68rem;
  padding: 0.1rem 0.55rem;
  border-radius: 999px;
  border: 1px solid var(--panel-border);
  color: var(--muted);
  vertical-align: middle;
  margin-right: 0.3rem;
}
.badge.q { border-color: var(--purple); color: var(--purple); }

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 1.6rem;
  transform: translateX(-50%) translateY(20px);
  z-index: 70;
  background: rgba(23, 18, 40, 0.97);
  border: 1px solid var(--panel-border);
  color: var(--ink);
  padding: 0.8rem 1.3rem;
  border-radius: 12px;
  box-shadow: 0 16px 50px rgba(0, 0, 0, 0.6);
  opacity: 0;
  transition: opacity 0.25s, transform 0.25s;
  pointer-events: none;
  max-width: 92vw;
  text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { border-color: rgba(255, 93, 108, 0.5); color: #ffb3ba; }

/* ---------- Misc ---------- */

.hat-mini .hat-float { width: clamp(160px, 36vw, 220px); }
.hat-mini .hat-shadow { height: 14px; }

@media (prefers-reduced-motion: reduce) {
  .hat-float, .hat-shadow, .fog { animation: none !important; }
}
