/* ===========================
   THEME TOKENS
   =========================== */

:root {
  --bg-0: #07090A;
  --bg-1: #0C0F10;
  --bg-2: #10141A;
  --line: #1A1E20;
  --line-2: #252A2E;
  --text-0: #E8EDE9;
  --text-1: #A8B0AC;
  --text-2: #6B7570;
  --text-3: #3A4240;
  --accent: #7FD4A3;
  --accent-soft: #2E5A42;
  --warn: #EA8C3A;
  --danger: #EF4444;

  --font-display: 'Space Grotesk', 'Onest', ui-sans-serif, system-ui, sans-serif;
  --font-body: 'Onest', ui-sans-serif, system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;

  --radius-lg: 22px;
  --radius-md: 14px;
  --radius-sm: 8px;
}

/* ---- Luminous (default) ---- */
body[data-theme="luminous"] {
  --bg-0: #07090A;
  --bg-1: #0C0F10;
  --bg-2: #10141A;
  --line: #1A1E20;
  --line-2: #252A2E;
  --text-0: #E8EDE9;
  --text-1: #A8B0AC;
  --text-2: #6B7570;
  --text-3: #3A4240;
}

/* ---- Editorial (warm paper) ---- */
body[data-theme="editorial"] {
  --bg-0: #F4EFE6;
  --bg-1: #EEE7D9;
  --bg-2: #E6DDC9;
  --line: #D8CEB6;
  --line-2: #B9AC8E;
  --text-0: #1E1915;
  --text-1: #3C342A;
  --text-2: #6B6254;
  --text-3: #9A8F7C;
  --accent: #8B3A1E;
  --accent-soft: #E8D9C0;
  --warn: #A86A1E;
  --danger: #7E2424;

  --font-display: 'Instrument Serif', 'Fraunces', Georgia, serif;
  --font-body: 'Onest', ui-sans-serif, system-ui, sans-serif;
  --radius-lg: 4px;
  --radius-md: 2px;
  --radius-sm: 2px;
}

/* ---- Terminal (CRT mono) ---- */
body[data-theme="terminal"] {
  --bg-0: #020604;
  --bg-1: #050B07;
  --bg-2: #081008;
  --line: #1A2A1E;
  --line-2: #25402C;
  --text-0: #B8FFC8;
  --text-1: #7FD4A3;
  --text-2: #4A8A68;
  --text-3: #2E5A42;
  --accent: #B8FFC8;
  --accent-soft: #1A2A1E;

  --font-display: 'JetBrains Mono', ui-monospace, monospace;
  --font-body: 'JetBrains Mono', ui-monospace, monospace;
  --radius-lg: 0;
  --radius-md: 0;
  --radius-sm: 0;
}

/* ---- Accent hue swap ---- */
body[data-accent="amber"] { --accent: #E8A94A; --accent-soft: #4A3A1E; }
body[data-accent="lime"] { --accent: #C6F24A; --accent-soft: #3A4A1E; }
body[data-accent="magenta"] { --accent: #E84A9B; --accent-soft: #4A1E3A; }
body[data-accent="cyan"] { --accent: #4ADCE8; --accent-soft: #1E3A4A; }

/* ===========================
   GLOBAL
   =========================== */

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg-0);
  color: var(--text-0);
  font-family: var(--font-body);
  overflow-x: hidden;
}

* { font-family: inherit; }

.tabular { font-variant-numeric: tabular-nums; }
.display { font-family: var(--font-display); }
.mono { font-family: var(--font-mono); }

body[data-theme="editorial"] .display {
  font-weight: 400;
  letter-spacing: -0.02em;
}
body[data-theme="terminal"] .display {
  font-weight: 500;
  letter-spacing: -0.01em;
  text-transform: uppercase;
}

/* ===========================
   AMBIENT BACKGROUND
   =========================== */

#ambient-bg {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}

#ambient-bg::before {
  content: "";
  position: absolute;
  inset: -20%;
  background:
    radial-gradient(ellipse 50% 40% at 20% 30%, color-mix(in oklch, var(--accent) 18%, transparent), transparent 60%),
    radial-gradient(ellipse 40% 50% at 80% 70%, color-mix(in oklch, var(--accent) 10%, transparent), transparent 60%);
  filter: blur(60px);
  opacity: 0.55;
  animation: driftA 24s ease-in-out infinite alternate;
}

#ambient-bg::after {
  content: "";
  position: absolute;
  inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='3'/%3E%3CfeColorMatrix values='0 0 0 0 0.9 0 0 0 0 0.9 0 0 0 0 0.9 0 0 0 0.6 0'/%3E%3C/filter%3E%3Crect width='200' height='200' filter='url(%23n)'/%3E%3C/svg%3E");
  opacity: 0.035;
  mix-blend-mode: overlay;
}

body[data-grain="off"] #ambient-bg::after { display: none; }
body[data-ambient="off"] #ambient-bg::before { display: none; }

body[data-theme="editorial"] #ambient-bg::before {
  background:
    radial-gradient(ellipse 60% 50% at 30% 20%, rgba(139, 58, 30, 0.15), transparent 60%),
    radial-gradient(ellipse 50% 40% at 70% 80%, rgba(168, 106, 30, 0.1), transparent 60%);
  opacity: 0.6;
}

body[data-theme="terminal"] #ambient-bg::before {
  background:
    radial-gradient(ellipse 40% 30% at 50% 50%, rgba(184, 255, 200, 0.08), transparent 70%);
  opacity: 1;
}
body[data-theme="terminal"] #ambient-bg::after {
  background-image:
    repeating-linear-gradient(0deg, rgba(127, 212, 163, 0.04) 0 1px, transparent 1px 3px);
  opacity: 1;
  mix-blend-mode: normal;
}

@keyframes driftA {
  0%   { transform: translate(0, 0) rotate(0deg); }
  50%  { transform: translate(4%, -3%) rotate(4deg); }
  100% { transform: translate(-3%, 4%) rotate(-3deg); }
}

/* ===========================
   TIMER ANIMATIONS
   =========================== */

@keyframes rec-glow {
  0%, 100% {
    box-shadow:
      0 0 120px 0 color-mix(in oklch, var(--danger) 25%, transparent),
      inset 0 0 60px color-mix(in oklch, var(--danger) 4%, transparent);
  }
  50% {
    box-shadow:
      0 0 280px 0 color-mix(in oklch, var(--danger) 55%, transparent),
      inset 0 0 120px color-mix(in oklch, var(--danger) 10%, transparent);
  }
}
.rec-glow { animation: rec-glow 2.4s ease-in-out infinite; }

@keyframes colon-blink-red {
  0%, 49.9% { opacity: 1; }
  50%, 100% { opacity: 0.15; }
}
.colon-red { animation: colon-blink-red 1s steps(1) infinite; display: inline-block; color: var(--danger); }
.colon-static { display: inline-block; color: var(--text-2); opacity: 0.5; }

@keyframes rec-dot {
  0%, 100% { opacity: 0.4; transform: scale(1); box-shadow: 0 0 0 rgba(239, 68, 68, 0); }
  50% { opacity: 1; transform: scale(1.6); box-shadow: 0 0 24px rgba(239, 68, 68, 0.9), 0 0 48px rgba(239, 68, 68, 0.4); }
}
.rec-dot { animation: rec-dot 1.2s ease-in-out infinite; }

@keyframes digit-roll {
  0% { transform: translateY(100%); opacity: 0; }
  100% { transform: translateY(0); opacity: 1; }
}
.digit-roll { animation: digit-roll 0.36s cubic-bezier(0.22, 1, 0.36, 1); }

/* ===========================
   REVEAL / ENTRANCES
   =========================== */

@keyframes fade-up {
  from { opacity: 0; transform: translateY(16px); filter: blur(6px); }
  to { opacity: 1; transform: translateY(0); filter: blur(0); }
}
.fade-up { animation: fade-up 0.6s cubic-bezier(0.22, 1, 0.36, 1) both; }

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
.fade-in { animation: fade-in 0.3s ease both; }

@keyframes scale-in {
  from { opacity: 0; transform: scale(0.96); }
  to { opacity: 1; transform: scale(1); }
}
.scale-in { animation: scale-in 0.4s cubic-bezier(0.22, 1, 0.36, 1) both; }

.stagger > * { opacity: 0; animation: fade-up 0.6s cubic-bezier(0.22, 1, 0.36, 1) forwards; }
.stagger > *:nth-child(1) { animation-delay: 0.02s; }
.stagger > *:nth-child(2) { animation-delay: 0.08s; }
.stagger > *:nth-child(3) { animation-delay: 0.14s; }
.stagger > *:nth-child(4) { animation-delay: 0.20s; }
.stagger > *:nth-child(5) { animation-delay: 0.26s; }
.stagger > *:nth-child(6) { animation-delay: 0.32s; }
.stagger > *:nth-child(7) { animation-delay: 0.38s; }
.stagger > *:nth-child(8) { animation-delay: 0.44s; }

/* ===========================
   HABIT CHECKOFF BURST
   =========================== */

.burst {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: visible;
}
.burst .p {
  position: absolute;
  left: 50%; top: 50%;
  width: 6px; height: 6px;
  background: var(--accent);
  border-radius: 50%;
  transform: translate(-50%, -50%);
  animation: burst-p 0.8s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}
@keyframes burst-p {
  0%   { opacity: 1; transform: translate(-50%, -50%) translate(0, 0) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -50%) translate(var(--tx), var(--ty)) scale(0.4); }
}

/* Habit card hover lift */
.habit-card {
  transition:
    transform 0.35s cubic-bezier(0.22, 1, 0.36, 1),
    background 0.3s ease,
    border-color 0.3s ease,
    box-shadow 0.4s ease;
}
.habit-card:hover { transform: translateY(-2px); }
.habit-card[data-done="true"] {
  box-shadow: 0 10px 40px -10px color-mix(in oklch, var(--accent) 40%, transparent);
}

/* Check circle ring draw */
@keyframes ring-pop {
  0% { transform: scale(0.5); opacity: 0; }
  60% { transform: scale(1.1); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}
.ring-pop { animation: ring-pop 0.35s cubic-bezier(0.34, 1.56, 0.64, 1) both; }

/* ===========================
   PROGRESS BAR SHIMMER
   =========================== */

.progress-fill {
  position: relative;
  overflow: hidden;
  transition: width 0.9s cubic-bezier(0.22, 1, 0.36, 1);
}
.progress-fill::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.5), transparent);
  animation: shimmer 2.4s ease-in-out infinite;
}
@keyframes shimmer {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(200%); }
}

/* ===========================
   HEATMAP CELLS
   =========================== */

.heat-cell {
  transition:
    background 0.3s ease,
    transform 0.3s cubic-bezier(0.22, 1, 0.36, 1),
    box-shadow 0.3s ease;
  border-radius: 3px;
}
body[data-theme="terminal"] .heat-cell { border-radius: 0; }
body[data-theme="editorial"] .heat-cell { border-radius: 1px; }

.heat-cell:hover {
  transform: scale(1.4);
  z-index: 2;
  box-shadow: 0 0 12px color-mix(in oklch, var(--accent) 60%, transparent);
}

@keyframes heat-pulse {
  0%, 100% { box-shadow: 0 0 0 0 color-mix(in oklch, var(--accent) 45%, transparent); }
  50% { box-shadow: 0 0 0 4px color-mix(in oklch, var(--accent) 0%, transparent); }
}
.heat-recent { animation: heat-pulse 2.6s ease-in-out infinite; }

/* ===========================
   TAG PILLS
   =========================== */

.pill {
  transition:
    transform 0.25s cubic-bezier(0.22, 1, 0.36, 1),
    background 0.25s ease,
    border-color 0.25s ease,
    color 0.25s ease,
    box-shadow 0.3s ease;
}
.pill:hover { transform: translateY(-1px); }
.pill[data-active="true"] {
  box-shadow: 0 6px 20px -8px color-mix(in oklch, var(--accent) 50%, transparent);
}

/* ===========================
   CARD SURFACES
   =========================== */

.surface {
  background: var(--bg-1);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  position: relative;
  overflow: hidden;
}

body[data-theme="editorial"] .surface {
  background: var(--bg-1);
  border: 1px solid var(--line);
  box-shadow: 0 1px 0 rgba(0,0,0,0.03);
}
body[data-theme="terminal"] .surface {
  background: var(--bg-1);
  border: 1px solid var(--line-2);
}

/* Subtle inner glow on hover for surfaces */
.surface-glow:hover {
  border-color: var(--line-2);
}

/* ===========================
   NUMBER ROLLUP
   =========================== */

.num-rollup {
  display: inline-flex;
  overflow: hidden;
  vertical-align: baseline;
}
.num-rollup .col {
  display: inline-block;
  position: relative;
  overflow: hidden;
  line-height: 1;
}
.num-rollup .track {
  display: flex;
  flex-direction: column;
  transition: transform 0.7s cubic-bezier(0.22, 1, 0.36, 1);
}

/* ===========================
   BUTTONS
   =========================== */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 22px;
  border-radius: 9999px;
  font-weight: 600;
  font-size: 13px;
  letter-spacing: 0.04em;
  transition: transform 0.2s ease, filter 0.2s ease, background 0.2s ease;
  cursor: pointer;
  border: none;
}
body[data-theme="editorial"] .btn,
body[data-theme="terminal"] .btn {
  border-radius: 2px;
  text-transform: uppercase;
}
.btn:hover { filter: brightness(1.1); transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn:disabled { cursor: not-allowed; filter: grayscale(0.6) brightness(0.6); }

.btn-primary { background: var(--accent); color: var(--bg-0); }
.btn-ghost { background: transparent; color: var(--text-0); border: 1px solid var(--line-2); }
.btn-stop { background: var(--text-0); color: var(--bg-0); }

/* ===========================
   SELECT / INPUTS
   =========================== */

input[type="checkbox"] { accent-color: var(--accent); }
textarea, input { font-family: inherit; color: var(--text-0); }
textarea.code-view { font-family: var(--font-mono); }

/* ===========================
   TWEAKS PANEL
   =========================== */

.tweaks-panel {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 50;
  background: var(--bg-1);
  border: 1px solid var(--line-2);
  border-radius: 14px;
  padding: 16px;
  width: 280px;
  backdrop-filter: blur(20px);
  box-shadow: 0 20px 60px -20px rgba(0,0,0,0.6);
}
body[data-theme="editorial"] .tweaks-panel {
  border-radius: 2px;
  box-shadow: 0 2px 0 var(--line);
}

.tweak-chip {
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid var(--line-2);
  font-size: 11px;
  background: transparent;
  color: var(--text-1);
  cursor: pointer;
  transition: all 0.2s ease;
}
.tweak-chip[data-active="true"] {
  background: var(--accent);
  color: var(--bg-0);
  border-color: var(--accent);
}
body[data-theme="editorial"] .tweak-chip,
body[data-theme="terminal"] .tweak-chip {
  border-radius: 2px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

/* ===========================
   REDUCED MOTION
   =========================== */

body[data-animation="low"] * {
  animation-duration: 0.15s !important;
  transition-duration: 0.15s !important;
}
body[data-animation="low"] .rec-glow,
body[data-animation="low"] .heat-recent,
body[data-animation="low"] .progress-fill::after,
body[data-animation="low"] #ambient-bg::before { animation: none !important; }

/* ===========================
   SCROLLBAR
   =========================== */

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--line-2); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-3); }

/* ===========================
   TERMINAL SPECIFICS
   =========================== */

body[data-theme="terminal"] .surface {
  position: relative;
}
body[data-theme="terminal"] .surface::before {
  content: "+";
  position: absolute;
  top: -6px; left: -6px;
  color: var(--text-2);
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1;
}

body[data-theme="terminal"] .bracket-label::before { content: "["; margin-right: 2px; }
body[data-theme="terminal"] .bracket-label::after { content: "]"; margin-left: 2px; }

/* ===========================
   EDITORIAL SPECIFICS
   =========================== */

body[data-theme="editorial"] .display {
  font-style: italic;
}
body[data-theme="editorial"] .display.not-italic {
  font-style: normal;
}
body[data-theme="editorial"] .section-label {
  font-family: var(--font-display);
  font-style: italic;
  font-size: 14px;
  letter-spacing: 0;
  text-transform: none;
  color: var(--text-2);
}

/* util */
.no-scrollbar::-webkit-scrollbar { display: none; }
