*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  font-family: 'Inter', sans-serif;
  height: 100%; overflow: hidden;
  background: linear-gradient(135deg, #0f0c29 0%, #302b63 50%, #24243e 100%);
  background-attachment: fixed;
  color: white;
}

/* Scrollbar */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(139,92,246,0.4); border-radius: 2px; }

/* Screens */
.screen {
  display: none;
  flex-direction: column;
  position: fixed; inset: 0;
  overflow: hidden;
}
.screen.active { display: flex; }

/* Orbs */
.orbs-container {
  position: fixed; inset: 0; pointer-events: none; z-index: 0; overflow: hidden;
}
.orb {
  position: absolute; border-radius: 50%; filter: blur(80px); opacity: 0.25;
}
.orb-1 {
  width: 400px; height: 400px;
  background: radial-gradient(circle, #7c3aed, transparent);
  top: -100px; left: -100px;
  animation: float 8s ease-in-out infinite;
}
.orb-2 {
  width: 350px; height: 350px;
  background: radial-gradient(circle, #3b82f6, transparent);
  bottom: -80px; right: -80px;
  animation: float 10s ease-in-out infinite reverse;
}
.orb-3 {
  width: 300px; height: 300px;
  background: radial-gradient(circle, #6366f1, transparent);
  top: 40%; left: 50%;
  transform: translate(-50%, -50%);
  animation: float 12s ease-in-out infinite;
}

/* Glass */
.glass {
  background: rgba(255,255,255,0.07);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 1rem;
}
.glass-sm {
  background: rgba(255,255,255,0.07);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 0.75rem;
}

/* Animations */
@keyframes slideUp {
  from { opacity: 0; transform: translateY(30px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}
@keyframes float {
  0%, 100% { transform: translateY(0); }
  50%       { transform: translateY(-20px); }
}
@keyframes pulse-ring {
  0%   { transform: scale(1); opacity: 0.6; }
  100% { transform: scale(1.5); opacity: 0; }
}
@keyframes checkmark {
  from { stroke-dashoffset: 100; }
  to   { stroke-dashoffset: 0; }
}
.animate-slide-up { animation: slideUp 0.5s ease forwards; }
.animate-fade-in  { animation: fadeIn 0.4s ease forwards; }

.stagger-1 { animation-delay: 0.05s; opacity: 0; }
.stagger-2 { animation-delay: 0.10s; opacity: 0; }
.stagger-3 { animation-delay: 0.15s; opacity: 0; }
.stagger-4 { animation-delay: 0.20s; opacity: 0; }
.stagger-5 { animation-delay: 0.25s; opacity: 0; }

/* Primary button */
.btn-primary {
  background: linear-gradient(135deg, #7c3aed, #6d28d9);
  border: none; color: white; font-weight: 600;
  border-radius: 0.875rem; cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 0 4px 20px rgba(124,58,237,0.4);
}
.btn-primary:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 6px 24px rgba(124,58,237,0.55);
}
.btn-primary:active:not(:disabled) { transform: translateY(0); }
.btn-primary:disabled {
  opacity: 0.4; cursor: not-allowed;
}

/* Ghost button */
.btn-ghost {
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.12);
  color: rgba(255,255,255,0.7);
  font-weight: 500; border-radius: 0.875rem; cursor: pointer;
  transition: all 0.2s ease;
}
.btn-ghost:hover {
  background: rgba(255,255,255,0.14);
  color: white;
}

/* Inputs */
input[type="text"],
input[type="number"],
textarea {
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.15);
  color: white;
  border-radius: 0.75rem;
  padding: 0.75rem 1rem;
  width: 100%;
  font-family: 'Inter', sans-serif;
  font-size: 0.95rem;
  transition: border-color 0.2s;
  outline: none;
}
input[type="text"]::placeholder,
input[type="number"]::placeholder,
textarea::placeholder { color: rgba(255,255,255,0.35); }
input[type="text"]:focus,
input[type="number"]:focus,
textarea:focus { border-color: rgba(139,92,246,0.6); }
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button { opacity: 0.4; }

/* Gender toggle */
.gender-btn {
  flex: 1; padding: 0.6rem 0.5rem; text-align: center;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.12);
  color: rgba(255,255,255,0.6); font-size: 0.875rem; font-weight: 500;
  cursor: pointer; border-radius: 0.625rem;
  transition: all 0.2s ease; font-family: 'Inter', sans-serif;
}
.gender-btn.active {
  background: rgba(124,58,237,0.4);
  border-color: rgba(139,92,246,0.7);
  color: white;
}
.gender-btn:hover:not(.active) {
  background: rgba(255,255,255,0.1);
  color: rgba(255,255,255,0.85);
}

/* Bottom nav */
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0;
  background: rgba(15,12,41,0.85);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border-top: 1px solid rgba(255,255,255,0.1);
  z-index: 100;
  display: flex; padding: 0.5rem 0 env(safe-area-inset-bottom, 0.5rem);
}
.nav-item {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; gap: 3px; padding: 0.4rem 0;
  cursor: pointer; transition: all 0.2s ease;
  background: none; border: none; color: rgba(255,255,255,0.4);
  font-family: 'Inter', sans-serif; font-size: 0.7rem; font-weight: 500;
}
.nav-item.active { color: #a78bfa; }
.nav-item:hover:not(.active) { color: rgba(255,255,255,0.7); }

/* ===== BLOB EMOTION CARDS ===== */

/* Pure border-radius morph — no rotate/scale so text stays upright */
@keyframes blob-morph {
  0%   { border-radius: 60% 40% 30% 70% / 60% 30% 70% 40%; }
  16%  { border-radius: 30% 70% 60% 40% / 50% 40% 60% 50%; }
  33%  { border-radius: 50% 50% 70% 30% / 30% 70% 40% 60%; }
  50%  { border-radius: 40% 60% 30% 70% / 70% 30% 60% 40%; }
  66%  { border-radius: 70% 30% 50% 50% / 40% 60% 30% 70%; }
  83%  { border-radius: 35% 65% 45% 55% / 55% 45% 70% 30%; }
  100% { border-radius: 60% 40% 30% 70% / 60% 30% 70% 40%; }
}

/* Responsive blob grid — auto adjusts columns to viewport */
.emotions-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
  /* vertical padding gives room for neon glow overflow */
  padding: 0.75rem 0;
}
@media (min-width: 480px)  { .emotions-grid { grid-template-columns: repeat(4, 1fr); } }
@media (min-width: 640px)  { .emotions-grid { grid-template-columns: repeat(5, 1fr); gap: 1.1rem; } }
@media (min-width: 900px)  { .emotions-grid { grid-template-columns: repeat(6, 1fr); gap: 1.25rem; } }
@media (min-width: 1200px) { .emotions-grid { grid-template-columns: repeat(8, 1fr); gap: 1.5rem; } }

/* Keep horizontal overflow disabled by default (desktop/tablet). */
#emotions-container {
  overflow-x: hidden !important;
}

/* min-width:0 prevents grid cells from growing beyond their track size */
.emotions-grid {
  min-width: 0;
}

/* The card IS the blob — background color + animation applied directly */
.emotion-blob-card {
  position: relative;
  cursor: pointer;
  user-select: none;
  aspect-ratio: 1 / 1;
  min-width: 0;       /* prevent cell blowout from long text */
  overflow: hidden;   /* clip text to blob shape */
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--blob-shape, 60% 40% 30% 70% / 60% 30% 70% 40%);
  animation: blob-morph 12s ease-in-out infinite;
  opacity: 0.78;
  transition: opacity 0.25s ease, filter 0.25s ease, box-shadow 0.25s ease;
}
.emotion-blob-card:hover {
  opacity: 0.95;
  filter: brightness(1.18);
}
.emotion-blob-card:active {
  filter: brightness(0.85);
}
.emotion-blob-card.selected {
  opacity: 1;
  box-shadow:
    0 0 0 2px rgba(255,255,255,0.88),
    0 6px 18px rgba(0,0,0,0.22);
  filter: brightness(1.08) saturate(1.04);
}

.blob-label {
  position: relative;
  z-index: 2;
  transform: scale(calc(1 / var(--blob-scale, 1)));
  transform-origin: center;
  font-size: 0.6rem;
  font-weight: 800;
  color: #ffffff;
  text-align: center;
  padding: 0.5rem 0.4rem;
  line-height: 1.2;
  letter-spacing: 0.01em;
  text-shadow:
    0 1px 8px rgba(0,0,0,0.85),
    0 0 16px rgba(0,0,0,0.6);
  pointer-events: none;
  width: 100%;
  overflow-wrap: break-word;
  word-break: break-word;
  hyphens: auto;
}
@media (min-width: 640px)  { .blob-label { font-size: 0.5rem; } }
@media (min-width: 900px)  { .blob-label { font-size: 0.5rem; } }
@media (min-width: 1200px) { .blob-label { font-size: 0.5rem; } }

.blob-card-wrapper {
  position: relative;
  --blob-scale: 1;
  --blob-tx: 0px;
  --blob-ty: 0px;
}

.blob-info-btn {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: rgba(255,255,255,0.18);
  border: 1px solid rgba(255,255,255,0.4);
  color: rgba(255,255,255,0.95);
  font-size: 0.65rem;
  font-weight: 700;
  font-style: italic;
  font-family: 'Inter', sans-serif;
  cursor: pointer;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, transform 0.15s;
  padding: 0;
  line-height: 1;
  backdrop-filter: blur(4px);
}
.blob-info-btn:hover {
  background: rgba(255,255,255,0.45);
  transform: scale(1.18);
}

/* Pause heavy animations when tab is hidden */
.app-paused .orb,
.app-paused .emotion-blob-card,
.app-paused .emotion-modal-blob-bg,
.app-paused .check-circle::before {
  animation-play-state: paused !important;
}

/* ===== EMOTION INFO MODAL ===== */
.emotion-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  animation: fadeIn 0.2s ease;
}
.emotion-modal-overlay.hidden { display: none; }

.emotion-modal-card {
  width: 100%;
  max-width: 320px;
  border-radius: 1.5rem;
  position: relative;
  overflow: hidden;
  animation: slideUp 0.28s ease;
}

.emotion-modal-blob-bg {
  position: absolute;
  width: 220px;
  height: 220px;
  top: -70px;
  right: -70px;
  border-radius: 60% 40% 30% 70% / 60% 30% 70% 40%;
  animation: blob-morph 10s ease-in-out infinite;
  opacity: 0.3;
  pointer-events: none;
}

.emotion-modal-content {
  position: relative;
  z-index: 2;
  padding: 1.75rem;
}

.emotion-modal-close {
  position: absolute;
  top: 0.9rem;
  right: 0.9rem;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.18);
  color: rgba(255,255,255,0.8);
  font-size: 1.1rem;
  font-weight: 300;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
  z-index: 3;
  line-height: 1;
  font-family: sans-serif;
  padding: 0;
}
.emotion-modal-close:hover { background: rgba(255,255,255,0.22); }

/* Emotion pills */
.pill-positive {
  background: rgba(16,185,129,0.25);
  border: 1px solid rgba(16,185,129,0.4);
  color: #6ee7b7;
  padding: 0.25rem 0.7rem; border-radius: 9999px; font-size: 0.8rem; font-weight: 500;
  display: inline-block;
}
.pill-negative {
  background: rgba(244,63,94,0.25);
  border: 1px solid rgba(244,63,94,0.4);
  color: #fda4af;
  padding: 0.25rem 0.7rem; border-radius: 9999px; font-size: 0.8rem; font-weight: 500;
  display: inline-block;
}
.pill-neutral {
  background: rgba(148,163,184,0.2);
  border: 1px solid rgba(148,163,184,0.35);
  color: #cbd5e1;
  padding: 0.25rem 0.7rem; border-radius: 9999px; font-size: 0.8rem; font-weight: 500;
  display: inline-block;
}

/* Tab content scrollable area */
.tab-content {
  display: none;
  flex-direction: column;
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden; /* prevent horizontal scroll from blobs/glows */
  padding-bottom: 6rem;
}
.tab-content.active { display: flex; }

.canvas-stage {
  flex: 1;
  overflow-y: auto;
  overflow-x: auto;
  padding: 0.75rem 1.25rem 8rem;
  position: relative;
  z-index: 1;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-x pan-y;
}

#emotions-canvas {
  width: auto;
  height: auto;
  display: block;
  touch-action: pan-x pan-y;
}

.canvas-perf {
  position: sticky;
  top: 0.25rem;
  margin-left: auto;
  width: max-content;
  z-index: 12;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  color: rgba(255,255,255,0.92);
  background: rgba(15,12,41,0.72);
  border: 1px solid rgba(255,255,255,0.16);
  border-radius: 0.6rem;
  padding: 0.3rem 0.55rem;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.test-perf {
  position: sticky;
  top: 0.35rem;
}

/* Stat card */
.stat-card {
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 0.875rem;
  padding: 1rem; text-align: center; flex: 1;
}

/* Danger zone */
.danger-zone {
  border: 1px solid rgba(244,63,94,0.35);
  border-radius: 1rem;
  background: rgba(244,63,94,0.05);
  padding: 1.25rem;
}

/* Success checkmark animation */
.check-circle {
  width: 72px; height: 72px;
  border-radius: 50%;
  background: rgba(16,185,129,0.2);
  border: 2px solid rgba(16,185,129,0.5);
  display: flex; align-items: center; justify-content: center;
  position: relative;
}
.check-circle::before {
  content: '';
  position: absolute; inset: -6px;
  border-radius: 50%;
  border: 2px solid rgba(16,185,129,0.2);
  animation: pulse-ring 1.5s ease-out infinite;
}

/* Scrollable main content */
#screen-main { overflow: hidden; }
.main-inner {
  flex: 1; display: flex; flex-direction: column;
  overflow: hidden; position: relative; z-index: 1;
}

/* Sticky finish button */
.finish-bar {
  position: fixed;
  bottom: 4rem;
  left: 0; right: 0;
  padding: 0.75rem 1.25rem;
  background: linear-gradient(to top, rgba(15,12,41,0.95), transparent);
  z-index: 50;
}

/* Section category header */
.cat-header {
  display: flex; align-items: center; gap: 0.5rem;
  font-size: 0.75rem; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.07em; margin-bottom: 0.625rem; padding: 0 0.125rem;
}
.cat-header-dot { width: 7px; height: 7px; border-radius: 50%; }

/* Logo gradient box */
.logo-box {
  background: linear-gradient(135deg, #7c3aed, #4f46e5);
  border-radius: 1.25rem;
  padding: 1rem;
  box-shadow: 0 8px 32px rgba(124,58,237,0.45);
  display: inline-flex; align-items: center; justify-content: center;
}

/* Profile icon circle */
.profile-icon-circle {
  width: 48px; height: 48px; border-radius: 50%;
  background: linear-gradient(135deg, #7c3aed, #4f46e5);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}

/* Empty state */
.empty-state {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 1rem; padding: 3rem 2rem; text-align: center;
  opacity: 0.65;
}

/* Session cards */
.session-card {
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.09);
  border-radius: 0.875rem;
  padding: 1rem;
  margin-bottom: 0.625rem;
  transition: all 0.2s ease;
}
.session-card:hover {
  background: rgba(255,255,255,0.08);
  border-color: rgba(255,255,255,0.15);
}

/* Date group header */
.date-group-header {
  font-size: 0.7rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.08em;
  color: rgba(255,255,255,0.35);
  padding: 0.75rem 0 0.375rem;
}

/* Scrollable welcome/profile */
.screen-scroll { overflow-y: auto; flex: 1; }

/* Input label */
.field-label {
  display: block; font-size: 0.8rem; font-weight: 500;
  color: rgba(255,255,255,0.55); margin-bottom: 0.4rem;
}

/* Tab header */
.tab-header { padding: 1rem 1.25rem 0.5rem; flex-shrink: 0; }

/* ===== DESKTOP LAYOUT ===== */
/* Center content on wide screens */
@media (min-width: 900px) {
  .tab-header { padding: 1.25rem 2rem 0.75rem; }

  #emotions-container {
    padding: 1.25rem 2rem !important;
    padding-bottom: 8rem !important;
  }

  #journal-content,
  #settings-content,
  .canvas-stage {
    padding-left: 2rem !important;
    padding-right: 2rem !important;
    max-width: 960px;
    margin: 0 auto;
    width: 100%;
  }

  .finish-bar {
    padding: 0.75rem 2rem;
  }
  .finish-bar button {
    max-width: 480px;
    margin: 0 auto;
    display: block;
  }

  .screen-scroll > div {
    max-width: 540px;
    margin: 0 auto;
  }
}

/* ===== MOBILE FISHEYE HORIZONTAL SCROLL ===== */
@media (max-width: 639px) {
  /* Horizontal pan is handled by the whole emotions container */
  #emotions-container {
    overflow-x: auto !important;
    overflow-y: auto;
    padding-top: 2.8rem !important;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  #emotions-container::-webkit-scrollbar { display: none; }

  .category-scroll-wrap {
    overflow: visible;
    width: max-content;
    min-width: 100%;
    margin: 0;
  }

  /* Keep a stable 7-column layout on mobile */
  .emotions-grid {
    --blob-base-size: 68px;
    --blob-gap: 10px;
    gap: var(--blob-gap);
    grid-template-columns: repeat(7, var(--blob-base-size));
    padding: 30px 1.25rem;
    width: max-content;
    min-width: unset;
  }

  .cat-header {
    width: min(100%, calc(100vw - 2.5rem));
    margin-left: auto;
    margin-right: auto;
    justify-content: center;
    text-align: center;
    transform: translateX(var(--cat-header-shift, 0px));
    transition: transform 0.08s linear;
    z-index: 6;
  }

  .blob-card-wrapper {
    width: var(--blob-base-size);
    height: var(--blob-base-size);
    transform: translate(var(--blob-tx), var(--blob-ty));
    transition: transform 0.12s ease-out;
  }

  .emotion-blob-card {
    width: 100%;
    height: 100%;
    aspect-ratio: auto;
    transform: scale(var(--blob-scale, 1));
    transition: transform 0.12s ease-out, opacity 0.25s ease, filter 0.25s ease, box-shadow 0.25s ease;
    animation: none;
  }

  .emotion-blob-card.selected { animation: none; }
}
