/* Vibdocow UI */
:root {
  --pink: #ff2fd6;
  --cyan: #22e6ff;
  --gold: #ffc44d;
  --green: #2fff9e;
  --red: #ff3355;
  --bg: #070213;
  --ink: #f5f0ff;
  --line: rgba(255, 255, 255, 0.12);
  --glass: rgba(16, 9, 36, 0.62);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0; height: 100%; overflow: hidden;
  overscroll-behavior: none; background: var(--bg); color: var(--ink);
  font-family: "Avenir Next", "Trebuchet MS", "Segoe UI", system-ui, -apple-system, sans-serif;
  touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}
#bg { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }

#ui {
  position: fixed; inset: 0; z-index: 2;
  display: flex; flex-direction: column;
  padding: calc(env(safe-area-inset-top, 0px) + 8px) 12px calc(env(safe-area-inset-bottom, 0px) + 10px);
  gap: 8px;
}

/* ---------- header ---------- */
#hud { display: flex; align-items: center; gap: 8px; }
.brand { display: flex; align-items: center; gap: 6px; font-weight: 900; font-style: italic; letter-spacing: -0.5px; font-size: 15px;
  background: linear-gradient(90deg, var(--pink), var(--cyan)); -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 0 8px rgba(255, 47, 214, 0.5)); white-space: nowrap; }
.brand svg { width: 26px; height: 26px; flex: none; }
.hud-stats { display: flex; gap: 6px; margin-left: auto; align-items: center; }
.stat {
  background: var(--glass); border: 1px solid var(--line); border-radius: 10px;
  padding: 4px 8px; text-align: center; min-width: 52px;
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
}
.stat .k { display: block; font-size: 8px; letter-spacing: 1.5px; opacity: 0.65; font-weight: 700; }
.stat .v { display: block; font-size: 14px; font-weight: 800; font-variant-numeric: tabular-nums; }
#strikes { display: flex; gap: 3px; padding: 4px 7px; background: var(--glass); border: 1px solid var(--line); border-radius: 10px; align-items: center; }
#strikes .pie { width: 16px; height: 16px; opacity: 0.25; transition: all 0.2s; }
#strikes .pie.hit { opacity: 1; animation: splat 0.45s cubic-bezier(0.2, 2.4, 0.4, 1); }
@keyframes splat { 0% { transform: scale(0) rotate(-160deg); } 100% { transform: scale(1) rotate(0); } }
.icon-btn {
  width: 36px; height: 36px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--glass); color: var(--ink); display: flex; align-items: center; justify-content: center;
  cursor: pointer; -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
}
.icon-btn:active { transform: scale(0.9); }
.icon-btn svg { width: 17px; height: 17px; }
.icon-btn.off svg { opacity: 0.35; }

/* ---------- happiness meter ---------- */
#happiness {
  position: relative; height: 16px; border-radius: 9px; overflow: hidden;
  background: rgba(255, 255, 255, 0.08); border: 1px solid var(--line);
}
#happiness-fill {
  height: 100%; width: 35%;
  background: linear-gradient(90deg, var(--gold), var(--pink), var(--cyan));
  background-size: 200% 100%;
  animation: slide 3s linear infinite;
  transition: width 0.35s cubic-bezier(0.2, 1.4, 0.4, 1);
  box-shadow: 0 0 12px rgba(255, 47, 214, 0.7);
}
#happiness-fill.frenzy { animation: slide 0.5s linear infinite, frenzy-hue 0.5s linear infinite; }
@keyframes frenzy-hue { 0% { filter: hue-rotate(0deg); } 100% { filter: hue-rotate(360deg); } }
#happiness span {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-size: 8.5px; font-weight: 800; letter-spacing: 2.5px; text-shadow: 0 1px 3px rgba(0,0,0,0.8);
}
@keyframes slide { 0% { background-position: 0% 0; } 100% { background-position: 200% 0; } }

/* ---------- board ---------- */
#board-wrap { position: relative; flex: 1; display: flex; align-items: center; justify-content: center; min-height: 0; }
#board {
  position: relative;
  width: min(94vw, 100%, 46dvh);
  aspect-ratio: 1;
  display: grid; grid-template-columns: repeat(9, 1fr);
  background: var(--line);
  border: 2px solid rgba(255, 255, 255, 0.28);
  border-radius: 14px; overflow: hidden;
  box-shadow: 0 0 44px rgba(255, 47, 214, 0.28), 0 0 90px rgba(34, 230, 255, 0.12), inset 0 0 40px rgba(0, 0, 0, 0.45);
  -webkit-backdrop-filter: blur(7px); backdrop-filter: blur(7px);
}
.cell {
  position: relative; background: rgba(10, 6, 26, 0.78);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: clamp(15px, 4.8vw, 26px);
  cursor: pointer; color: var(--cyan);
}
.cell.br { box-shadow: inset -1px 0 0 var(--line); }
.cell.bb { box-shadow: inset 0 -1px 0 var(--line); }
.cell.br3 { box-shadow: inset -2px 0 0 rgba(255, 255, 255, 0.4); }
.cell.bb3 { box-shadow: inset 0 -2px 0 rgba(255, 255, 255, 0.4); }
.cell .num { pointer-events: none; }
.cell .notes {
  position: absolute; inset: 1px; display: none;
  grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr);
  pointer-events: none;
}
.cell .notes span { display: flex; align-items: center; justify-content: center; font-size: clamp(6px, 1.9vw, 10px); font-weight: 700; color: rgba(180, 220, 255, 0.75); }
.cell.given { color: #fdfbff; font-weight: 900; text-shadow: 0 0 10px rgba(255, 255, 255, 0.35); }
.cell.hint { color: var(--gold); text-shadow: 0 0 10px rgba(255, 196, 77, 0.6); }
.cell.user { color: var(--cyan); text-shadow: 0 0 10px rgba(34, 230, 255, 0.55); }
.cell.peer { background: rgba(120, 80, 255, 0.18); }
.cell.same { background: rgba(255, 47, 214, 0.22); }
.cell.sel {
  background: rgba(34, 230, 255, 0.26);
  box-shadow: inset 0 0 0 2px var(--cyan), inset 0 0 18px rgba(34, 230, 255, 0.4);
  z-index: 1;
}
.cell.correct { animation: pop 0.5s cubic-bezier(0.2, 2.2, 0.4, 1); background: rgba(47, 255, 158, 0.3); color: var(--green); }
.cell.wrong { animation: shakeX 0.5s; background: rgba(255, 51, 85, 0.4); color: var(--red); }
.cell.deny { animation: shakeX 0.3s; }
@keyframes pop { 0% { transform: scale(0.6); } 60% { transform: scale(1.25); } 100% { transform: scale(1); } }
@keyframes shakeX { 0%, 100% { transform: translateX(0); } 20% { transform: translateX(-4px); } 40% { transform: translateX(4px); } 60% { transform: translateX(-3px); } 80% { transform: translateX(3px); } }

#ui.shake { animation: ui-shake 0.45s; }
@keyframes ui-shake {
  0%, 100% { transform: translate(0, 0); }
  15% { transform: translate(-7px, 3px) rotate(-0.4deg); }
  35% { transform: translate(6px, -4px) rotate(0.4deg); }
  55% { transform: translate(-5px, -2px); }
  75% { transform: translate(4px, 3px); }
}

/* floating score pop */
.float-pop {
  position: absolute; transform: translate(-50%, 0); z-index: 6; pointer-events: none;
  font-weight: 900; font-size: 17px; color: var(--green);
  text-shadow: 0 0 12px rgba(47, 255, 158, 0.9), 0 2px 4px rgba(0,0,0,0.6);
  animation: float-up 0.9s ease-out forwards;
}
@keyframes float-up { 0% { opacity: 0; transform: translate(-50%, 6px) scale(0.6); } 20% { opacity: 1; transform: translate(-50%, 0) scale(1.25); } 100% { opacity: 0; transform: translate(-50%, -34px) scale(1); } }

/* combo */
#combo {
  position: absolute; left: 50%; top: 38%; transform: translate(-50%, -50%) scale(0);
  z-index: 6; pointer-events: none; font-weight: 900; font-style: italic; font-size: clamp(26px, 8vw, 44px);
  background: linear-gradient(90deg, var(--gold), var(--pink), var(--cyan));
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 0 16px rgba(255, 47, 214, 0.8));
  white-space: nowrap;
}
#combo.show { animation: combo-pop 0.8s cubic-bezier(0.2, 2, 0.4, 1) forwards; }
@keyframes combo-pop { 0% { transform: translate(-50%, -50%) scale(0) rotate(-8deg); } 30% { transform: translate(-50%, -50%) scale(1.3) rotate(3deg); } 60% { transform: translate(-50%, -50%) scale(1); } 100% { transform: translate(-50%, -60%) scale(1); opacity: 0; } }

/* ---------- mood cow ---------- */
#moodcow {
  position: absolute; top: -30px; left: -14px; width: 86px; height: auto; z-index: 7;
  pointer-events: none; filter: drop-shadow(0 4px 14px rgba(255, 47, 214, 0.45));
  animation: cow-bob 2.6s ease-in-out infinite;
}
@keyframes cow-bob { 0%, 100% { transform: translateY(0) rotate(-3deg); } 50% { transform: translateY(-5px) rotate(3deg); } }
.moodcow .ex, .moodcow .mo { display: none; }
.moodcow[data-mood="idle"] .ex-open, .moodcow[data-mood="idle"] .mo-smile,
.moodcow[data-mood="happy"] .ex-happy, .moodcow[data-mood="happy"] .mo-grin,
.moodcow[data-mood="shock"] .ex-shock, .moodcow[data-mood="shock"] .mo-open,
.moodcow[data-mood="dizzy"] .ex-dizzy, .moodcow[data-mood="dizzy"] .mo-frown,
.moodcow[data-mood="party"] .ex-party, .moodcow[data-mood="party"] .mo-grin,
.moodcow[data-mood="sad"] .ex-sad, .moodcow[data-mood="sad"] .mo-frown { display: block; }
.moodcow[data-blink="1"] .ex-open { display: none; }
.moodcow[data-blink="1"] .ex-blink { display: block; }

/* oracle bubble */
#oracle {
  position: absolute; top: -14px; right: -6px; z-index: 8; max-width: 62%;
  background: var(--glass); border: 1px solid rgba(255, 196, 77, 0.5); border-radius: 14px;
  padding: 8px 11px; font-size: 11.5px; line-height: 1.35; font-weight: 600;
  opacity: 0; transform: translateY(6px) scale(0.9); transition: all 0.25s cubic-bezier(0.2, 1.6, 0.4, 1);
  pointer-events: none; -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
  box-shadow: 0 4px 20px rgba(255, 196, 77, 0.25);
}
#oracle.show { opacity: 1; transform: translateY(0) scale(1); }

/* ---------- pad ---------- */
#pad { display: flex; flex-direction: column; gap: 8px; }
#nums { display: grid; grid-template-columns: repeat(9, 1fr); gap: 6px; }
.num-btn {
  position: relative; aspect-ratio: 1 / 1.15; border-radius: 12px; border: 1px solid var(--line);
  background: var(--glass); color: var(--ink); font-size: clamp(16px, 5vw, 24px); font-weight: 800;
  cursor: pointer; -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
  box-shadow: 0 3px 0 rgba(255, 255, 255, 0.08), 0 6px 16px rgba(0, 0, 0, 0.35);
  transition: transform 0.06s;
  font-family: inherit;
}
.num-btn:active { transform: scale(0.88); }
.num-btn .cnt {
  position: absolute; top: 2px; right: 5px; font-size: 9px; font-weight: 700;
  color: var(--gold); opacity: 0.9;
}
.num-btn.done { opacity: 0.35; }
#tools { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
.tool-btn {
  display: flex; align-items: center; justify-content: center; gap: 7px;
  height: 44px; border-radius: 13px; border: 1px solid var(--line);
  background: var(--glass); color: var(--ink); font-size: 13px; font-weight: 800;
  letter-spacing: 0.5px; cursor: pointer; -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
  font-family: inherit;
}
.tool-btn:active { transform: scale(0.94); }
.tool-btn svg { width: 17px; height: 17px; }
.tool-btn.active { border-color: var(--cyan); box-shadow: 0 0 14px rgba(34, 230, 255, 0.45); color: var(--cyan); }

/* ---------- overlays ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 50;
  display: flex; align-items: center; justify-content: center;
  background: rgba(5, 2, 15, 0.55);
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
  padding: 18px;
}
.overlay.hidden { display: none; }
.card {
  width: min(92vw, 430px); max-height: 92dvh; overflow-y: auto;
  border-radius: 26px; padding: 26px 22px; text-align: center; position: relative;
  border: 2px solid transparent;
  background:
    linear-gradient(165deg, rgba(46, 22, 82, 0.92), rgba(12, 7, 30, 0.96)) padding-box,
    linear-gradient(130deg, var(--pink), var(--cyan), var(--gold), var(--pink)) border-box;
  background-size: auto, 300% 300%;
  animation: border-slide 7s linear infinite;
  box-shadow: 0 0 70px rgba(255, 47, 214, 0.35), 0 30px 80px rgba(0, 0, 0, 0.6);
}
@keyframes border-slide { 0% { background-position: 0 0, 0% 50%; } 100% { background-position: 0 0, 300% 50%; } }
.logo {
  font-size: clamp(42px, 12vw, 62px); font-weight: 900; font-style: italic; letter-spacing: -2.5px;
  line-height: 1; margin: 2px 0 6px;
  background: linear-gradient(90deg, var(--pink), var(--gold), var(--cyan), var(--pink));
  background-size: 300% 100%; -webkit-background-clip: text; background-clip: text; color: transparent;
  animation: slide 5s linear infinite;
  filter: drop-shadow(0 0 22px rgba(255, 47, 214, 0.65));
}
#tagline { font-size: 13px; font-weight: 600; opacity: 0.85; min-height: 18px; transition: opacity 0.3s; font-style: italic; }
.menu-cow { width: 110px; margin: 10px auto 4px; display: block; animation: cow-bob 2.6s ease-in-out infinite; filter: drop-shadow(0 6px 18px rgba(34, 230, 255, 0.4)); }
.howto { font-size: 11.5px; opacity: 0.7; line-height: 1.5; margin: 10px auto 14px; max-width: 300px; }
.diff-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }
.diff-btn {
  border-radius: 16px; padding: 12px 8px; cursor: pointer; text-align: center;
  border: 1px solid var(--line); background: rgba(255, 255, 255, 0.05); color: var(--ink);
  font-family: inherit; transition: transform 0.08s;
}
.diff-btn:active { transform: scale(0.94); }
.diff-btn b { display: block; font-size: 16px; font-weight: 900; letter-spacing: 1px; }
.diff-btn span { display: block; font-size: 9.5px; opacity: 0.7; margin-top: 3px; font-style: italic; }
.diff-btn[data-diff="easy"] { border-color: rgba(47, 255, 158, 0.5); }
.diff-btn[data-diff="medium"] { border-color: rgba(34, 230, 255, 0.5); }
.diff-btn[data-diff="hard"] { border-color: rgba(255, 196, 77, 0.55); }
.diff-btn[data-diff="mayhem"] { border-color: rgba(255, 51, 85, 0.6); box-shadow: 0 0 18px rgba(255, 51, 85, 0.25); }
#menu-bests { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin-top: 14px; }
.best-chip {
  font-size: 10px; font-weight: 700; letter-spacing: 0.5px; padding: 4px 9px;
  border-radius: 20px; background: rgba(255, 255, 255, 0.07); border: 1px solid var(--line);
}
.chips { display: flex; gap: 8px; justify-content: center; margin-top: 14px; flex-wrap: wrap; }
.chip {
  display: flex; align-items: center; gap: 6px; padding: 7px 12px; border-radius: 20px;
  border: 1px solid var(--line); background: rgba(255, 255, 255, 0.05);
  font-size: 11px; font-weight: 800; cursor: pointer; color: var(--ink); font-family: inherit;
}
.chip .dot { width: 8px; height: 8px; border-radius: 50%; background: #555; }
.chip.on .dot { background: var(--green); box-shadow: 0 0 8px var(--green); }
.chip-val { opacity: 0.75; font-size: 10px; }

.btn {
  display: block; width: 100%; margin-top: 12px; padding: 15px; border-radius: 16px;
  border: none; cursor: pointer; font-family: inherit;
  font-size: 16px; font-weight: 900; letter-spacing: 1.5px; color: #14061f;
  background: linear-gradient(90deg, var(--pink), #b44dff, var(--cyan));
  background-size: 200% 100%; animation: slide 4s linear infinite;
  box-shadow: 0 6px 24px rgba(255, 47, 214, 0.5);
  transition: transform 0.07s;
}
.btn:active { transform: scale(0.95); }
.btn.ghost { background: rgba(255, 255, 255, 0.08); color: var(--ink); box-shadow: none; border: 1px solid var(--line); }
.btn.small { padding: 11px; font-size: 13px; }

.big-title {
  font-size: clamp(24px, 7.5vw, 34px); font-weight: 900; font-style: italic; letter-spacing: -1px;
  background: linear-gradient(90deg, var(--gold), var(--pink), var(--cyan));
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 0 16px rgba(255, 196, 77, 0.5));
  margin: 4px 0 10px;
}
.stat-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 4px; border-bottom: 1px dashed rgba(255, 255, 255, 0.12);
  font-size: 13px; font-weight: 700;
}
.stat-row span { opacity: 0.65; letter-spacing: 1px; font-size: 11px; }
.stat-row b { font-size: 16px; font-variant-numeric: tabular-nums; }

/* loading */
#load-bar { height: 12px; border-radius: 7px; background: rgba(255, 255, 255, 0.08); border: 1px solid var(--line); overflow: hidden; margin: 14px 0 8px; }
#load-fill { height: 100%; width: 0%; background: linear-gradient(90deg, var(--pink), var(--cyan)); box-shadow: 0 0 12px rgba(34, 230, 255, 0.7); transition: width 0.15s; }
#load-quip { font-size: 12.5px; font-style: italic; opacity: 0.8; min-height: 17px; }
.loading-cow { width: 90px; margin: 6px auto; display: block; animation: cow-spin 1.6s linear infinite; filter: drop-shadow(0 0 16px rgba(255, 47, 214, 0.6)); }
@keyframes cow-spin { 0% { transform: rotate(0) scale(1); } 50% { transform: rotate(180deg) scale(1.15); } 100% { transform: rotate(360deg) scale(1); } }

/* toast */
#toast {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom, 0px) + 18px); transform: translate(-50%, 20px);
  z-index: 80; background: var(--glass); border: 1px solid rgba(255, 196, 77, 0.55);
  padding: 10px 16px; border-radius: 14px; font-size: 12.5px; font-weight: 700;
  opacity: 0; transition: all 0.25s; pointer-events: none; max-width: 88vw; text-align: center;
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.5);
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-height: 640px) {
  #board { width: min(94vw, 40dvh); }
  .num-btn { aspect-ratio: 1 / 1; }
  .tool-btn { height: 38px; }
  #moodcow { width: 64px; top: -22px; }
}
