/* =========================================================
   Tessera — Premium daily mosaic journal
   © Ofir Baranes 2026
   ========================================================= */

:root {
  /* terracotta palette (default) */
  --bg-0: #14080c;
  --bg-1: #1a1217;
  --bg-2: #221820;
  --surface: rgba(255, 240, 230, 0.04);
  --surface-2: rgba(255, 240, 230, 0.07);
  --surface-3: rgba(255, 240, 230, 0.10);
  --border: rgba(255, 220, 200, 0.10);
  --border-strong: rgba(255, 220, 200, 0.18);

  --text-1: #f6e9dc;
  --text-2: rgba(246, 233, 220, 0.74);
  --text-3: rgba(246, 233, 220, 0.50);
  --text-4: rgba(246, 233, 220, 0.32);

  --accent: #e0734b;
  --accent-2: #c54a3c;
  --accent-deep: #6d2440;
  --accent-soft: #f4a172;

  --tile-terracotta: #d8623d;
  --tile-amber: #e6b04a;
  --tile-sand: #d6b894;
  --tile-jade: #5a8c79;
  --tile-cobalt: #4b6fa8;
  --tile-plum: #7a4a6a;
  --tile-rose: #c87b8c;
  --tile-bone: #ece1cf;
  --tile-charcoal: #3a3036;

  --mood-warm: #e0734b;
  --mood-bright: #e6b04a;
  --mood-quiet: #8aa6a2;
  --mood-proud: #b48653;
  --mood-tender: #c87b8c;
  --mood-restless: #aa5f3b;
  --mood-dim: #5e5860;
  --mood-electric: #6d9bcf;

  --shadow-1: 0 8px 24px -8px rgba(0, 0, 0, 0.6);
  --shadow-2: 0 20px 50px -20px rgba(0, 0, 0, 0.7);
  --shadow-glow: 0 0 40px -10px rgba(224, 115, 75, 0.4);

  --radius-sm: 8px;
  --radius: 14px;
  --radius-lg: 22px;
  --radius-xl: 28px;

  --font-display: "Frank Ruhl Libre", "Heebo", serif;
  --font-body: "Heebo", system-ui, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, monospace;
  --font-script: "Instrument Serif", "Frank Ruhl Libre", serif;

  --ease-spring: cubic-bezier(.34, 1.56, .64, 1);
  --ease-soft: cubic-bezier(.22, 1, .36, 1);
  --ease-snap: cubic-bezier(.5, 0, 0, 1);
}

/* ----------  PALETTE: MIDNIGHT  ---------- */
[data-palette="midnight"] {
  --bg-0: #08091a;
  --bg-1: #0e1024;
  --bg-2: #14182f;
  --accent: #6d9bcf;
  --accent-2: #4b6fa8;
  --accent-deep: #232a55;
  --accent-soft: #a3c1e1;
  --surface: rgba(180, 200, 240, 0.04);
  --surface-2: rgba(180, 200, 240, 0.07);
  --surface-3: rgba(180, 200, 240, 0.10);
  --border: rgba(180, 200, 240, 0.10);
  --border-strong: rgba(180, 200, 240, 0.18);
  --text-1: #e7ecf6;
  --text-2: rgba(231, 236, 246, 0.74);
  --text-3: rgba(231, 236, 246, 0.50);
  --text-4: rgba(231, 236, 246, 0.32);
}

/* ----------  PALETTE: BONE  ---------- */
[data-palette="bone"] {
  --bg-0: #1b1813;
  --bg-1: #24201a;
  --bg-2: #2d2823;
  --accent: #d6b894;
  --accent-2: #b4926d;
  --accent-deep: #5a4733;
  --accent-soft: #ece1cf;
  --surface: rgba(255, 240, 220, 0.04);
  --surface-2: rgba(255, 240, 220, 0.08);
  --surface-3: rgba(255, 240, 220, 0.12);
  --border: rgba(255, 240, 220, 0.10);
  --border-strong: rgba(255, 240, 220, 0.20);
}

/* ----------  PALETTE: JADE  ---------- */
[data-palette="jade"] {
  --bg-0: #0a1612;
  --bg-1: #0f1d18;
  --bg-2: #14271f;
  --accent: #6fae93;
  --accent-2: #4f8a72;
  --accent-deep: #1f3b30;
  --accent-soft: #a3c9b6;
  --surface: rgba(200, 240, 220, 0.04);
  --surface-2: rgba(200, 240, 220, 0.07);
  --surface-3: rgba(200, 240, 220, 0.10);
  --border: rgba(200, 240, 220, 0.10);
  --border-strong: rgba(200, 240, 220, 0.18);
}

/* ----------  PALETTE: OXBLOOD  ---------- */
[data-palette="oxblood"] {
  --bg-0: #170609;
  --bg-1: #200a0e;
  --bg-2: #2b0e13;
  --accent: #b04a48;
  --accent-2: #842a30;
  --accent-deep: #420f15;
  --accent-soft: #d68080;
  --surface: rgba(255, 220, 220, 0.04);
  --surface-2: rgba(255, 220, 220, 0.07);
  --surface-3: rgba(255, 220, 220, 0.10);
  --border: rgba(255, 220, 220, 0.10);
  --border-strong: rgba(255, 220, 220, 0.18);
}

/* =========================================================
   BASE
   ========================================================= */
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { background: var(--bg-0); color-scheme: dark; }

body {
  font-family: var(--font-body);
  font-weight: 400;
  color: var(--text-1);
  background:
    radial-gradient(ellipse at top right, color-mix(in oklab, var(--accent) 14%, transparent) 0%, transparent 55%),
    radial-gradient(ellipse at bottom left, color-mix(in oklab, var(--accent-deep) 30%, transparent) 0%, transparent 50%),
    linear-gradient(180deg, var(--bg-0) 0%, var(--bg-1) 50%, var(--bg-0) 100%);
  background-attachment: fixed;
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

::selection { background: var(--accent); color: var(--bg-0); }

button { font: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, textarea, select { font: inherit; color: var(--text-1); }
a { color: var(--accent); text-decoration: none; }

/* =========================================================
   AMBIENT LAYERS
   ========================================================= */
.grain {
  position: fixed; inset: 0; z-index: 100; pointer-events: none;
  opacity: .35; mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='180' height='180'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0.4 0 0 0 0 0.3 0 0 0 0 0.2 0 0 0 0.45 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
}

.orb {
  position: fixed; border-radius: 50%; filter: blur(80px);
  z-index: 0; pointer-events: none; opacity: .55;
  animation: orbDrift 22s ease-in-out infinite;
}
.orb-1 { top: -120px; right: -80px; width: 480px; height: 480px;
  background: radial-gradient(circle, var(--accent) 0%, transparent 65%); }
.orb-2 { bottom: 5%; left: -160px; width: 540px; height: 540px;
  background: radial-gradient(circle, var(--accent-deep) 0%, transparent 65%);
  animation-delay: -8s; opacity: .4; }
.orb-3 { top: 35%; right: 35%; width: 320px; height: 320px;
  background: radial-gradient(circle, color-mix(in oklab, var(--accent-soft) 80%, transparent) 0%, transparent 70%);
  animation-delay: -14s; opacity: .25; }

@keyframes orbDrift {
  0%, 100% { transform: translate(0, 0) scale(1); }
  33%      { transform: translate(20px, -30px) scale(1.06); }
  66%      { transform: translate(-30px, 20px) scale(.94); }
}

/* =========================================================
   TOP BAR
   ========================================================= */
.topbar {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 28px;
  backdrop-filter: blur(24px) saturate(180%);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  background: linear-gradient(180deg, color-mix(in oklab, var(--bg-0) 88%, transparent), color-mix(in oklab, var(--bg-0) 50%, transparent));
  border-bottom: 1px solid var(--border);
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 40px; height: 40px; border-radius: 11px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, color-mix(in oklab, var(--accent) 22%, transparent), color-mix(in oklab, var(--accent-deep) 30%, transparent));
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow-1);
}
.brand-mark svg { display: block; }
.brand-text { display: flex; flex-direction: column; line-height: 1; }
.brand-name {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 22px;
  letter-spacing: .01em;
  background: linear-gradient(180deg, var(--text-1) 60%, color-mix(in oklab, var(--text-1) 60%, transparent) 100%);
  -webkit-background-clip: text; background-clip: text;
  color: transparent;
}
.brand-sub {
  font-size: 11px; font-weight: 500; letter-spacing: .08em;
  color: var(--text-3); margin-top: 4px; text-transform: lowercase;
}

.topbar-actions { display: flex; gap: 6px; }

.icon-btn {
  width: 40px; height: 40px; border-radius: 11px;
  display: grid; place-items: center;
  color: var(--text-2);
  border: 1px solid transparent;
  transition: all .25s var(--ease-soft);
}
.icon-btn:hover { background: var(--surface-2); color: var(--text-1); border-color: var(--border); transform: translateY(-1px); }
.icon-btn:active { transform: translateY(0) scale(.96); }

/* =========================================================
   HERO
   ========================================================= */
.hero {
  position: relative;
  margin: 24px 28px 0;
  border-radius: var(--radius-xl);
  overflow: hidden;
  min-height: 380px;
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow-2);
  isolation: isolate;
}

.hero-bg {
  position: absolute; inset: 0;
  background-size: cover; background-position: center;
  filter: saturate(1.05);
  z-index: -2;
}

.hero-gradient {
  position: absolute; inset: 0;
  background:
    linear-gradient(105deg,
      var(--bg-0) 0%,
      color-mix(in oklab, var(--bg-0) 90%, transparent) 28%,
      color-mix(in oklab, var(--bg-0) 50%, transparent) 55%,
      transparent 100%
    ),
    linear-gradient(0deg, color-mix(in oklab, var(--bg-0) 70%, transparent) 0%, transparent 50%);
  z-index: -1;
}

.hero-inner {
  position: relative;
  padding: 56px 48px 44px;
  max-width: 640px;
}

.hero-eyebrow {
  display: inline-flex; align-items: center; gap: 8px;
  font-family: var(--font-mono);
  font-size: 12px; font-weight: 500;
  color: var(--text-3);
  letter-spacing: .12em; text-transform: uppercase;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  backdrop-filter: blur(8px);
}
.hero-eyebrow .dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--accent); box-shadow: 0 0 12px var(--accent);
  animation: pulse 2s ease-in-out infinite;
}
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .4; } }

.hero-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(48px, 7vw, 84px);
  line-height: .94;
  letter-spacing: -.015em;
  margin: 18px 0 22px;
  display: flex; flex-direction: column;
}
.hero-line-1 {
  color: var(--text-1);
  text-shadow: 0 2px 20px rgba(0, 0, 0, .4);
}
.hero-line-2 {
  font-family: var(--font-script);
  font-style: italic;
  font-weight: 400;
  color: var(--accent);
  font-size: .82em;
  margin-top: -4px;
}

.hero-lede {
  font-size: 18px; line-height: 1.6;
  color: var(--text-2);
  max-width: 480px;
  margin: 0 0 32px;
}

.hero-stats {
  display: flex; align-items: center; gap: 22px;
  padding: 18px 22px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  backdrop-filter: blur(20px);
  width: fit-content;
}
.hstat { display: flex; flex-direction: column; gap: 4px; }
.hstat-num {
  font-family: var(--font-mono); font-weight: 500;
  font-size: 22px; color: var(--text-1); line-height: 1;
}
.hstat-lbl { font-size: 11px; color: var(--text-3); letter-spacing: .08em; text-transform: uppercase; }
.hstat-sep {
  width: 1px; height: 32px; background: var(--border-strong);
}

/* =========================================================
   MAIN LAYOUT
   ========================================================= */
.main {
  max-width: 1240px;
  margin: 24px auto 120px;
  padding: 0 28px;
  display: grid;
  gap: 24px;
  grid-template-columns: 1fr 1fr;
}

.panel {
  background:
    linear-gradient(180deg, var(--surface-2) 0%, var(--surface) 100%);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 28px;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  box-shadow: var(--shadow-1);
  position: relative;
}
.panel::before {
  content: ""; position: absolute; inset: 0;
  border-radius: inherit; pointer-events: none;
  background: linear-gradient(135deg, color-mix(in oklab, var(--text-1) 4%, transparent), transparent 30%);
}

.panel--today,
.panel--mosaic,
.panel--insights,
.panel--history { grid-column: span 2; }

@media (min-width: 1080px) {
  .panel--today { grid-column: span 2; }
  .panel--mosaic { grid-column: span 2; }
  .panel--insights { grid-column: span 2; }
  .panel--history { grid-column: span 2; }
}

.panel-head {
  display: flex; justify-content: space-between; align-items: flex-start;
  margin-bottom: 24px;
  gap: 16px;
}
.panel-head-left { flex: 1; min-width: 0; }
.panel-title {
  font-family: var(--font-display); font-weight: 500;
  font-size: 26px; margin: 0 0 6px;
  letter-spacing: -.01em;
}
.panel-sub {
  font-size: 13px; color: var(--text-3); margin: 0;
}

/* =========================================================
   TODAY COMPOSER
   ========================================================= */
.composer {
  display: grid;
  grid-template-columns: minmax(220px, 280px) 1fr;
  gap: 28px;
  align-items: start;
}

@media (max-width: 720px) {
  .composer { grid-template-columns: 1fr; }
}

.composer-preview {
  position: sticky; top: 88px;
}

.preview-frame {
  display: flex; flex-direction: column; align-items: center; gap: 14px;
  padding: 24px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
}

.tile-preview {
  width: 200px; height: 200px;
  border-radius: 14px;
  position: relative;
  display: grid;
  place-items: center;
  grid-template-rows: auto auto;
  gap: 18px;
  transition: all .4s var(--ease-spring);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, .12),
    inset 0 -2px 8px rgba(0, 0, 0, .25),
    0 12px 30px -10px rgba(0, 0, 0, .6);
  overflow: hidden;
  isolation: isolate;
}
.tile-preview::before {
  content: ""; position: absolute; inset: 0; z-index: -1;
  background: var(--tile-color, var(--tile-terracotta));
  background-image:
    radial-gradient(circle at 30% 25%, rgba(255, 255, 255, .25) 0%, transparent 35%),
    radial-gradient(circle at 75% 75%, rgba(0, 0, 0, .25) 0%, transparent 45%);
}
.tile-preview::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='100' height='100'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='2.4' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 .25 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
  opacity: .8; mix-blend-mode: multiply;
}
.tile-preview[data-color="terracotta"] { --tile-color: var(--tile-terracotta); }
.tile-preview[data-color="amber"]      { --tile-color: var(--tile-amber); }
.tile-preview[data-color="sand"]       { --tile-color: var(--tile-sand); }
.tile-preview[data-color="jade"]       { --tile-color: var(--tile-jade); }
.tile-preview[data-color="cobalt"]     { --tile-color: var(--tile-cobalt); }
.tile-preview[data-color="plum"]       { --tile-color: var(--tile-plum); }
.tile-preview[data-color="rose"]       { --tile-color: var(--tile-rose); }
.tile-preview[data-color="bone"]       { --tile-color: var(--tile-bone); }
.tile-preview[data-color="charcoal"]   { --tile-color: var(--tile-charcoal); }

.tile-glyph {
  font-family: var(--font-display);
  font-size: 56px;
  color: rgba(0, 0, 0, .35);
  text-shadow: 0 1px 0 rgba(255, 255, 255, .25);
  line-height: 1;
}
.tile-word {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 22px;
  color: rgba(0, 0, 0, .55);
  text-shadow: 0 1px 0 rgba(255, 255, 255, .2);
  letter-spacing: -.01em;
  max-width: 80%;
  text-align: center;
  line-height: 1.1;
  word-break: break-word;
}
.tile-preview[data-color="charcoal"] .tile-glyph,
.tile-preview[data-color="charcoal"] .tile-word,
.tile-preview[data-color="plum"] .tile-glyph,
.tile-preview[data-color="plum"] .tile-word,
.tile-preview[data-color="cobalt"] .tile-glyph,
.tile-preview[data-color="cobalt"] .tile-word {
  color: rgba(255, 245, 230, .8);
  text-shadow: 0 -1px 0 rgba(0, 0, 0, .25);
}

.preview-meta {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
}
.preview-date {
  font-family: var(--font-mono);
  font-size: 12px; color: var(--text-3);
  letter-spacing: .08em; text-transform: uppercase;
}
.preview-mood-tag {
  font-size: 12px;
  padding: 4px 12px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-2);
}

/* ---- Controls ---- */
.composer-controls { display: flex; flex-direction: column; gap: 18px; }
.control-row { display: flex; flex-direction: column; gap: 10px; }
.control-label {
  font-size: 12px;
  color: var(--text-3);
  letter-spacing: .08em;
  text-transform: uppercase;
  font-weight: 500;
}

.swatch-row, .glyph-row, .mood-row {
  display: flex; flex-wrap: wrap; gap: 8px;
}

.swatch {
  width: 36px; height: 36px;
  border-radius: 10px;
  border: 2px solid transparent;
  position: relative;
  transition: all .25s var(--ease-spring);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .15), inset 0 -2px 4px rgba(0, 0, 0, .2);
}
.swatch:hover { transform: translateY(-2px) scale(1.06); }
.swatch.is-active {
  border-color: var(--text-1);
  box-shadow: 0 0 0 3px var(--bg-0), 0 0 0 4px var(--accent), inset 0 1px 0 rgba(255, 255, 255, .15);
}

.swatch--terracotta { background: var(--tile-terracotta); }
.swatch--amber      { background: var(--tile-amber); }
.swatch--sand       { background: var(--tile-sand); }
.swatch--jade       { background: var(--tile-jade); }
.swatch--cobalt     { background: var(--tile-cobalt); }
.swatch--plum       { background: var(--tile-plum); }
.swatch--rose       { background: var(--tile-rose); }
.swatch--bone       { background: var(--tile-bone); }
.swatch--charcoal   { background: var(--tile-charcoal); }

.glyph-btn {
  width: 38px; height: 38px;
  border-radius: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-2);
  font-size: 18px;
  display: grid; place-items: center;
  transition: all .25s var(--ease-spring);
}
.glyph-btn:hover { background: var(--surface-2); color: var(--text-1); transform: translateY(-2px); }
.glyph-btn.is-active {
  background: var(--accent);
  color: var(--bg-0);
  border-color: var(--accent);
  transform: scale(1.05);
}

.mood-chip {
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-2);
  font-size: 13px;
  transition: all .2s var(--ease-soft);
}
.mood-chip:hover { background: var(--surface-2); color: var(--text-1); }
.mood-chip.is-active {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: var(--bg-0);
  border-color: transparent;
  font-weight: 500;
}

.word-input, .note-input {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  font-family: var(--font-display);
  font-size: 18px;
  color: var(--text-1);
  transition: border-color .2s, background .2s;
}
.note-input {
  font-family: var(--font-body);
  font-size: 14px;
  resize: vertical;
  min-height: 56px;
}
.word-input::placeholder, .note-input::placeholder { color: var(--text-4); }
.word-input:focus, .note-input:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--surface-2);
  box-shadow: 0 0 0 3px color-mix(in oklab, var(--accent) 20%, transparent);
}

.composer-actions {
  display: flex; justify-content: flex-end; gap: 10px;
  margin-top: 8px;
}

.primary-btn {
  display: inline-flex; align-items: center; gap: 10px;
  padding: 12px 24px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 14px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: var(--bg-0);
  box-shadow:
    0 4px 14px -2px color-mix(in oklab, var(--accent) 50%, transparent),
    inset 0 1px 0 rgba(255, 255, 255, .25);
  transition: all .25s var(--ease-spring);
}
.primary-btn:hover {
  transform: translateY(-2px);
  box-shadow:
    0 8px 24px -4px color-mix(in oklab, var(--accent) 60%, transparent),
    inset 0 1px 0 rgba(255, 255, 255, .25);
}
.primary-btn:active { transform: translateY(0) scale(.98); }

.ghost-btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 11px 18px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text-2);
  font-size: 13px;
  transition: all .2s var(--ease-soft);
}
.ghost-btn:hover { background: var(--surface-2); color: var(--text-1); }

.danger-btn {
  padding: 11px 18px;
  border-radius: 999px;
  border: 1px solid color-mix(in oklab, #d04848 40%, transparent);
  background: color-mix(in oklab, #d04848 12%, transparent);
  color: #f4a8a8;
  font-size: 13px;
  transition: all .2s;
}
.danger-btn:hover { background: color-mix(in oklab, #d04848 22%, transparent); }

/* =========================================================
   STATS GRID
   ========================================================= */
.stats-grid {
  grid-column: span 2;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
}

.stat-card {
  position: relative;
  display: flex; align-items: center; gap: 14px;
  padding: 20px;
  background: linear-gradient(180deg, var(--surface-2), var(--surface));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  backdrop-filter: blur(20px);
  color: var(--accent);
  transition: all .3s var(--ease-soft);
  overflow: hidden;
}
.stat-card:hover {
  transform: translateY(-2px);
  border-color: var(--border-strong);
  box-shadow: var(--shadow-1);
}
.stat-icon {
  width: 44px; height: 44px;
  border-radius: 12px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, color-mix(in oklab, var(--accent) 20%, transparent), color-mix(in oklab, var(--accent-deep) 30%, transparent));
  color: var(--accent);
  flex-shrink: 0;
}
.stat-body { flex: 1; min-width: 0; }
.stat-num {
  font-family: var(--font-mono); font-weight: 500;
  font-size: 26px; color: var(--text-1); line-height: 1;
}
.stat-lbl {
  font-size: 11px; color: var(--text-3); letter-spacing: .08em;
  text-transform: uppercase; margin-top: 6px;
}
.stat-spark { width: 80px; height: 26px; opacity: .8; }
.stat-pill {
  font-family: var(--font-mono); font-size: 11px;
  padding: 4px 10px; border-radius: 999px;
  background: var(--surface-2); color: var(--text-3);
  border: 1px solid var(--border);
}
.stat-ring { flex-shrink: 0; }

/* =========================================================
   MOSAIC BOARD
   ========================================================= */
.seg-toggle {
  display: inline-flex;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px;
  gap: 2px;
}
.seg-btn {
  padding: 8px 16px;
  border-radius: 999px;
  font-size: 13px;
  color: var(--text-3);
  transition: all .2s var(--ease-soft);
}
.seg-btn:hover { color: var(--text-1); }
.seg-btn.is-active {
  background: var(--accent);
  color: var(--bg-0);
  font-weight: 500;
}

.mosaic-controls {
  display: flex; align-items: center; gap: 14px;
  margin-bottom: 20px;
}
.step-btn {
  width: 36px; height: 36px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-2);
  font-size: 18px;
  display: grid; place-items: center;
  transition: all .2s;
}
.step-btn:hover { background: var(--surface-2); color: var(--text-1); border-color: var(--border-strong); }
.mosaic-period {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 20px;
  min-width: 180px;
}
.mosaic-meter {
  margin-inline-start: auto;
  font-family: var(--font-mono); font-size: 12px;
  color: var(--text-3);
}

.mosaic-board {
  display: grid;
  gap: 4px;
  padding: 6px;
  border-radius: var(--radius);
  background: linear-gradient(180deg, color-mix(in oklab, var(--bg-0) 50%, transparent), var(--surface));
  border: 1px solid var(--border);
  min-height: 200px;
  position: relative;
}

.mosaic-board[data-view="year"] {
  grid-template-columns: repeat(53, 1fr);
}
.mosaic-board[data-view="month"] {
  grid-template-columns: repeat(7, 1fr);
  max-width: 540px;
  gap: 8px;
  padding: 14px;
  margin: 0 auto;
}
.mosaic-board[data-view="week"] {
  grid-template-columns: repeat(7, 1fr);
  max-width: 720px;
  gap: 12px;
  padding: 18px;
  margin: 0 auto;
}

.mtile {
  aspect-ratio: 1;
  border-radius: 3px;
  background: var(--surface);
  position: relative;
  cursor: pointer;
  transition: transform .15s var(--ease-spring), box-shadow .15s var(--ease-spring);
  isolation: isolate;
}
.mtile::before {
  content: ""; position: absolute; inset: 0; border-radius: inherit;
  background: var(--mt-color, transparent);
  background-image:
    radial-gradient(circle at 30% 25%, rgba(255, 255, 255, .18) 0%, transparent 40%),
    radial-gradient(circle at 70% 75%, rgba(0, 0, 0, .15) 0%, transparent 45%);
  z-index: -1;
}
.mtile[data-filled="true"] {
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .08), 0 1px 2px rgba(0, 0, 0, .2);
}
.mtile[data-filled="true"]:hover {
  transform: scale(1.4); z-index: 2;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, .15),
    0 8px 20px rgba(0, 0, 0, .5);
  border-radius: 5px;
}
.mtile[data-filled="false"] {
  background: color-mix(in oklab, var(--text-1) 4%, transparent);
}
.mtile[data-filled="false"]:hover { background: color-mix(in oklab, var(--text-1) 8%, transparent); }

.mosaic-board[data-view="month"] .mtile,
.mosaic-board[data-view="week"] .mtile {
  border-radius: 8px;
  display: grid;
  grid-template-rows: 1fr auto;
  padding: 8px;
}
.mosaic-board[data-view="month"] .mtile[data-filled="true"]:hover,
.mosaic-board[data-view="week"] .mtile[data-filled="true"]:hover {
  transform: scale(1.06); border-radius: 10px;
}

.mtile-day {
  align-self: end;
  font-family: var(--font-mono); font-size: 11px;
  color: rgba(0, 0, 0, .55);
  font-weight: 500;
  z-index: 1;
}
.mosaic-board[data-view="week"] .mtile-day { font-size: 14px; }
.mtile[data-filled="false"] .mtile-day { color: var(--text-4); }
.mtile[data-color="charcoal"] .mtile-day,
.mtile[data-color="plum"] .mtile-day,
.mtile[data-color="cobalt"] .mtile-day {
  color: rgba(255, 245, 230, .65);
}

.mtile-word {
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 600;
  color: rgba(0, 0, 0, .65);
  z-index: 1;
  line-height: 1.1;
  text-align: start;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.mtile[data-color="charcoal"] .mtile-word,
.mtile[data-color="plum"] .mtile-word,
.mtile[data-color="cobalt"] .mtile-word {
  color: rgba(255, 245, 230, .8);
}

.mosaic-board[data-view="year"] .mtile-day,
.mosaic-board[data-view="year"] .mtile-word { display: none; }

.mtile[data-color="terracotta"] { --mt-color: var(--tile-terracotta); }
.mtile[data-color="amber"]      { --mt-color: var(--tile-amber); }
.mtile[data-color="sand"]       { --mt-color: var(--tile-sand); }
.mtile[data-color="jade"]       { --mt-color: var(--tile-jade); }
.mtile[data-color="cobalt"]     { --mt-color: var(--tile-cobalt); }
.mtile[data-color="plum"]       { --mt-color: var(--tile-plum); }
.mtile[data-color="rose"]       { --mt-color: var(--tile-rose); }
.mtile[data-color="bone"]       { --mt-color: var(--tile-bone); }
.mtile[data-color="charcoal"]   { --mt-color: var(--tile-charcoal); }

.mosaic-legend {
  display: flex; align-items: center; gap: 6px;
  margin-top: 14px; font-size: 11px; color: var(--text-3);
  font-family: var(--font-mono);
}
.legend-label { letter-spacing: .04em; }
.legend-cell {
  width: 12px; height: 12px; border-radius: 3px;
}
.legend-cell--0 { background: color-mix(in oklab, var(--text-1) 4%, transparent); }
.legend-cell--1 { background: color-mix(in oklab, var(--accent) 25%, transparent); }
.legend-cell--2 { background: color-mix(in oklab, var(--accent) 50%, transparent); }
.legend-cell--3 { background: color-mix(in oklab, var(--accent) 75%, transparent); }
.legend-cell--4 { background: var(--accent); }

/* =========================================================
   INSIGHTS
   ========================================================= */
.insights-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 18px;
}

.insight-card {
  padding: 22px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex; flex-direction: column; align-items: center; gap: 16px;
  text-align: center;
}
.insight-title {
  font-family: var(--font-display); font-weight: 500;
  font-size: 16px;
  margin: 0; color: var(--text-1);
  align-self: flex-start;
}

.donut-wrap {
  position: relative;
  width: 180px; height: 180px;
}
#donut-svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.donut-center {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 4px;
}
.donut-num {
  font-family: var(--font-mono); font-weight: 500;
  font-size: 28px; line-height: 1; color: var(--text-1);
}
.donut-lbl { font-size: 11px; color: var(--text-3); letter-spacing: .08em; text-transform: uppercase; }

.donut-legend {
  list-style: none; padding: 0; margin: 0;
  display: flex; flex-wrap: wrap; gap: 8px;
  justify-content: center;
}
.donut-legend li {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 11px; color: var(--text-2);
}
.donut-legend li::before {
  content: ""; width: 8px; height: 8px; border-radius: 2px;
  background: var(--leg-color);
}

#bars-svg { width: 100%; height: 160px; }
.bar-rect { transition: opacity .2s; }
.bar-rect:hover { opacity: .7; }

.insight-foot {
  font-size: 11px; color: var(--text-3); margin: 0;
  font-family: var(--font-mono); letter-spacing: .04em;
}

.words-cloud {
  display: flex; flex-wrap: wrap; gap: 8px;
  justify-content: center; align-items: baseline;
  min-height: 140px;
  align-content: center;
}
.cword {
  font-family: var(--font-display);
  font-weight: 500;
  color: var(--text-1);
  padding: 4px 12px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  transition: all .2s var(--ease-soft);
}
.cword:hover { background: var(--surface-3); transform: translateY(-2px); }

/* =========================================================
   HISTORY
   ========================================================= */
.history-filters {
  display: flex; gap: 10px; flex-wrap: wrap;
  margin-bottom: 18px;
}

.search-wrap {
  position: relative; flex: 1; min-width: 220px;
}
.search-wrap svg {
  position: absolute; right: 14px; top: 50%; transform: translateY(-50%);
  color: var(--text-3);
}
#history-search {
  width: 100%;
  padding: 11px 38px 11px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 13px;
}
#history-search:focus {
  outline: none; border-color: var(--accent); background: var(--surface-2);
}

.filter-select {
  padding: 11px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 13px;
  color: var(--text-2);
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'><path d='M1 1l5 5 5-5' stroke='%23999' stroke-width='1.5' fill='none' stroke-linecap='round'/></svg>");
  background-repeat: no-repeat;
  background-position: left 14px center;
  padding-inline-start: 32px;
}

.history-list {
  list-style: none; padding: 0; margin: 0;
  display: flex; flex-direction: column; gap: 8px;
}
.hentry {
  display: grid;
  grid-template-columns: 56px 1fr auto;
  gap: 14px; align-items: center;
  padding: 12px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: all .2s var(--ease-soft);
}
.hentry:hover {
  background: var(--surface-2);
  border-color: var(--border-strong);
  transform: translateX(-2px);
}
.hentry-tile {
  width: 48px; height: 48px;
  border-radius: 10px;
  display: grid; place-items: center;
  background: var(--mt-color, var(--tile-terracotta));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .15), inset 0 -2px 4px rgba(0, 0, 0, .15);
  font-size: 22px;
  color: rgba(0, 0, 0, .55);
}
.hentry-tile[data-color="terracotta"] { --mt-color: var(--tile-terracotta); }
.hentry-tile[data-color="amber"]      { --mt-color: var(--tile-amber); }
.hentry-tile[data-color="sand"]       { --mt-color: var(--tile-sand); }
.hentry-tile[data-color="jade"]       { --mt-color: var(--tile-jade); }
.hentry-tile[data-color="cobalt"]     { --mt-color: var(--tile-cobalt); color: rgba(255, 245, 230, .8); }
.hentry-tile[data-color="plum"]       { --mt-color: var(--tile-plum); color: rgba(255, 245, 230, .8); }
.hentry-tile[data-color="rose"]       { --mt-color: var(--tile-rose); }
.hentry-tile[data-color="bone"]       { --mt-color: var(--tile-bone); }
.hentry-tile[data-color="charcoal"]   { --mt-color: var(--tile-charcoal); color: rgba(255, 245, 230, .8); }

.hentry-body { min-width: 0; }
.hentry-word {
  font-family: var(--font-display); font-weight: 600;
  font-size: 16px; color: var(--text-1);
  line-height: 1.2;
}
.hentry-meta {
  display: flex; gap: 10px; align-items: center;
  font-size: 11px; color: var(--text-3); margin-top: 4px;
}
.hentry-date { font-family: var(--font-mono); letter-spacing: .04em; }
.hentry-mood {
  padding: 2px 8px; border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
}
.hentry-note {
  font-size: 12px; color: var(--text-2);
  margin-top: 4px;
  font-style: italic;
}
.hentry-actions { display: flex; gap: 4px; }

.empty-state {
  display: flex; flex-direction: column; align-items: center; gap: 12px;
  padding: 48px 24px;
  text-align: center;
}
.empty-image {
  width: 160px; height: 160px;
  border-radius: var(--radius);
  object-fit: cover;
  opacity: .8;
  filter: saturate(.9);
}
.empty-text {
  color: var(--text-3); font-size: 14px; line-height: 1.6;
  max-width: 240px;
}

/* =========================================================
   FAB
   ========================================================= */
.fab {
  position: fixed;
  bottom: 28px;
  inset-inline-end: 28px;
  width: 64px; height: 64px;
  border-radius: 50%;
  display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: var(--bg-0);
  box-shadow:
    0 12px 30px -8px color-mix(in oklab, var(--accent) 60%, transparent),
    inset 0 1px 0 rgba(255, 255, 255, .25),
    inset 0 -3px 8px rgba(0, 0, 0, .15);
  z-index: 40;
  transition: all .3s var(--ease-spring);
  animation: fabFloat 3.5s ease-in-out infinite;
}
@keyframes fabFloat {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}
.fab:hover {
  transform: translateY(-4px) scale(1.06);
  box-shadow:
    0 20px 40px -8px color-mix(in oklab, var(--accent) 70%, transparent),
    inset 0 1px 0 rgba(255, 255, 255, .25);
}
.fab:active { transform: translateY(0) scale(.95); }

/* =========================================================
   SHEETS (modals)
   ========================================================= */
.sheet {
  position: fixed; inset: 0;
  z-index: 200;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.sheet[hidden] { display: none; }
.sheet-backdrop {
  position: absolute; inset: 0;
  background: rgba(0, 0, 0, .65);
  backdrop-filter: blur(8px);
  animation: bdFade .25s ease;
}
@keyframes bdFade { from { opacity: 0; } to { opacity: 1; } }
.sheet-card {
  position: relative;
  max-width: 540px; width: 100%;
  max-height: 86vh;
  background: linear-gradient(180deg, var(--bg-2) 0%, var(--bg-1) 100%);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-2);
  display: flex; flex-direction: column;
  animation: sheetIn .35s var(--ease-spring);
  overflow: hidden;
}
@keyframes sheetIn {
  from { transform: translateY(20px) scale(.96); opacity: 0; }
  to   { transform: translateY(0)    scale(1);   opacity: 1; }
}
.sheet-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
}
.sheet-head h3 {
  font-family: var(--font-display); font-weight: 500;
  font-size: 20px; margin: 0;
}
.sheet-body {
  padding: 20px 24px 28px;
  overflow-y: auto;
}

.settings-group {
  margin-bottom: 24px;
}
.settings-group h4 {
  font-family: var(--font-display); font-weight: 500;
  font-size: 14px;
  color: var(--text-2);
  margin: 0 0 12px;
  letter-spacing: .04em;
}

.palette-row {
  display: flex; flex-wrap: wrap; gap: 8px;
}
.pal-btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 8px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 13px;
  color: var(--text-2);
  transition: all .2s;
}
.pal-btn:hover { background: var(--surface-2); color: var(--text-1); }
.pal-btn.is-active {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: var(--bg-0);
  border-color: transparent;
}
.pal-dot { width: 12px; height: 12px; border-radius: 50%; }
.pal-dot--terracotta { background: linear-gradient(135deg, #e0734b, #6d2440); }
.pal-dot--midnight   { background: linear-gradient(135deg, #6d9bcf, #232a55); }
.pal-dot--bone       { background: linear-gradient(135deg, #d6b894, #5a4733); }
.pal-dot--jade       { background: linear-gradient(135deg, #6fae93, #1f3b30); }
.pal-dot--oxblood    { background: linear-gradient(135deg, #b04a48, #420f15); }

.year-row {
  display: flex; align-items: center; gap: 16px;
}
.year-row > span {
  font-family: var(--font-display); font-weight: 500;
  font-size: 22px; color: var(--text-1);
  min-width: 80px; text-align: center;
}

.data-actions {
  display: flex; flex-wrap: wrap; gap: 10px;
}
.import-label {
  cursor: pointer;
}

.settings-help {
  font-size: 12px; color: var(--text-3); line-height: 1.6;
  margin: 10px 0 0;
}

.toggle {
  display: inline-flex; align-items: center; gap: 12px;
  cursor: pointer; user-select: none;
}
.toggle input { display: none; }
.toggle-slider {
  width: 44px; height: 24px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  position: relative;
  transition: background .2s;
}
.toggle-slider::before {
  content: ""; position: absolute;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: var(--text-2);
  top: 2px; right: 2px;
  transition: all .25s var(--ease-spring);
}
.toggle input:checked + .toggle-slider { background: var(--accent); border-color: var(--accent); }
.toggle input:checked + .toggle-slider::before { right: calc(100% - 20px); background: var(--bg-0); }
.toggle-label { font-size: 13px; color: var(--text-2); }

/* About */
.about-lede {
  font-family: var(--font-script);
  font-size: 22px; line-height: 1.5;
  color: var(--text-1);
  font-style: italic;
  margin: 0 0 16px;
}
.about-lede em { color: var(--accent); font-style: normal; font-family: var(--font-display); font-weight: 600; }
.about-h {
  font-family: var(--font-display); font-weight: 500;
  font-size: 14px; color: var(--text-2);
  margin: 24px 0 10px; letter-spacing: .04em;
}
.about-list { padding-inline-start: 18px; margin: 0; }
.about-list li { font-size: 14px; line-height: 1.7; color: var(--text-2); margin-bottom: 6px; }
.about-list strong { color: var(--text-1); }
.copyright {
  font-size: 11px;
  color: var(--text-4);
  margin: 24px 0 0;
  text-align: center;
  font-family: var(--font-mono);
  letter-spacing: .02em;
}

/* =========================================================
   TOAST
   ========================================================= */
.toast {
  position: fixed;
  bottom: 100px;
  left: 50%; transform: translateX(-50%) translateY(40px);
  z-index: 300;
  padding: 12px 20px;
  background: rgba(20, 8, 12, .92);
  backdrop-filter: blur(20px);
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  font-size: 13px;
  color: var(--text-1);
  box-shadow: var(--shadow-2);
  opacity: 0;
  pointer-events: none;
  transition: all .35s var(--ease-spring);
}
.toast.is-show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* =========================================================
   RESPONSIVE
   ========================================================= */
@media (max-width: 720px) {
  .topbar { padding: 14px 18px; }
  .hero { margin: 16px 18px 0; min-height: 320px; }
  .hero-inner { padding: 40px 24px 32px; }
  .hero-title { font-size: clamp(40px, 11vw, 60px); }
  .main { padding: 0 18px; margin: 16px auto 100px; gap: 16px; }
  .panel { padding: 20px; }
  .panel-title { font-size: 22px; }
  .mosaic-controls { flex-wrap: wrap; }
  .mosaic-meter { width: 100%; order: 99; }
  .fab { width: 56px; height: 56px; bottom: 20px; inset-inline-end: 20px; }
  .hero-stats { gap: 14px; padding: 14px 16px; }
  .hstat-num { font-size: 18px; }
  .stat-card { padding: 16px; }
}

@media (max-width: 540px) {
  .hero-title { font-size: 44px; }
  .hero-lede { font-size: 16px; }
  .panel { padding: 18px; border-radius: var(--radius); }
  .composer { gap: 22px; }
  .preview-frame { padding: 18px; }
  .tile-preview { width: 160px; height: 160px; }
  .tile-glyph { font-size: 44px; }
  .tile-word { font-size: 18px; }
}

@media (max-width: 380px) {
  .topbar { padding: 12px 14px; }
  .brand-name { font-size: 18px; }
  .brand-sub { font-size: 10px; }
  .hero { margin: 12px 14px 0; }
  .hero-inner { padding: 32px 18px 24px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
