/* ==========================================================================
   Privily — shared design system
   Warm near-black, one muted brass accent, serif display + clean sans + mono.
   Legacy token names are kept as aliases so any inline style keeps working.
   ========================================================================== */

:root {
  /* Surfaces */
  --bg-dark: #fbf8ef;
  --bg-core: #fbf8ef;
  --bg: #fbf8ef;
  --bg-panel: #fffdf7;
  --bg-card: #fffdf7;
  --panel: #fffdf7;
  --bg-panel-light: #f2ecdf;
  --bg-hover: #eee7d8;

  /* Text */
  --text-main: #130f02;
  --text: #130f02;
  --text-muted: #6b6558;
  --muted: #6b6558;
  --ivory: #130f02;

  /* Lines */
  --border: rgba(19, 15, 2, 0.12);
  --border-hover: rgba(19, 15, 2, 0.25);

  /* Accent (brass) — used sparingly */
  --primary: #ff550c;
  --primary-hover: #e94600;
  --primary-glow: rgba(255, 85, 12, 0.17);
  /* Orange for small text: the fill orange is only ~3:1 on the light surfaces */
  --primary-ink: #b03a08;
  --on-primary: #fffaf1;
  --accent: #ff550c;
  --cyan: #226c68;

  /* Status */
  --success: #28745a;
  --error: #b83b2e;
  --danger: #b83b2e;
  --red: #b83b2e;
  --warning: #8a5610;
  /* Solid danger buttons keep white text readable in both themes */
  --danger-solid: #b83b2e;

  /* Notifications (flash messages / alerts) */
  --alert-error-fg: #8f2a1f;
  --alert-error-bg: #fbe9e5;
  --alert-error-border: rgba(184, 59, 46, 0.32);
  --alert-success-fg: #1c5e46;
  --alert-success-bg: #e6f2ec;
  --alert-success-border: rgba(40, 116, 90, 0.3);

  /* Blurred secrets glow in the text colour so they stay visible */
  --blur-glow: rgba(19, 15, 2, 0.62);
  --placeholder: #6f695d;

  /* Opaque bar painted behind the phone status bar (iOS installed app) */
  --status-bar-bg: var(--bg-dark);

  /* Glass */
  --glass: rgba(255, 253, 247, 0.8);
  --glass-strong: rgba(255, 253, 247, 0.94);
  --glass-hover: rgba(19, 15, 2, 0.04);

  /* Type */
  --font-display: 'Instrument Serif', 'Iowan Old Style', 'Times New Roman', serif;
  --font-body: 'Geist', system-ui, sans-serif;
  --font-mono: 'Geist Mono', ui-monospace, 'SF Mono', Menlo, Consolas, monospace;

  --ease-smooth: cubic-bezier(0.22, 0.8, 0.24, 1);
  --radius: 10px;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  /* Keep content clear of the notch / rounded corners in landscape. */
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
  font-family: var(--font-body);
  background-color: var(--bg-dark);
  color: var(--text-main);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  line-height: 1.6;
}

/*
 * The installed iPhone app draws a translucent status bar (clock, signal,
 * battery) over the page. This opaque strip sits behind it so scrolled content
 * never shows through; env() is 0 everywhere else, so it takes no space.
 */
body::after {
  content: "";
  position: fixed;
  top: 0;
  right: 0;
  left: 0;
  z-index: 450;
  height: env(safe-area-inset-top);
  background: var(--status-bar-bg);
  pointer-events: none;
}

::selection { background: rgba(255, 85, 12, 0.18); color: var(--text-main); }

:focus-visible { outline: 1px solid var(--primary); outline-offset: 3px; }

/* Film grain — a static texture that takes the "flat digital" edge off */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 200;
  pointer-events: none;
  opacity: 0.055;
  mix-blend-mode: multiply;
  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.85' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 1  0 0 0 0 1  0 0 0 0 1  0 0 0 0.7 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
}

/* --------------------------------------------------------------------------
   Ambient background (kept from the original: gradient, grid, floating blobs)
   -------------------------------------------------------------------------- */
.ambient-light,
.ambient-bg {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  overflow: hidden;
  background: radial-gradient(ellipse 80% 60% at 50% -10%, #fff1d8 0%, #fbf8ef 62%);
}

.grid-overlay,
.grid-mesh {
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(19, 15, 2, 0.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(19, 15, 2, 0.05) 1px, transparent 1px);
  background-size: 64px 64px;
  -webkit-mask-image: radial-gradient(ellipse at center, #000 0%, transparent 75%);
  mask-image: radial-gradient(ellipse at center, #000 0%, transparent 75%);
}

.grid-mesh { position: fixed; z-index: -1; }

.blob {
  position: absolute;
  filter: blur(110px);
  opacity: 0.28;
  animation: float 18s ease-in-out infinite;
  will-change: transform;
}
.blob-1 { top: -18%; left: -12%; width: 46vw; height: 46vw; background: radial-gradient(circle, rgba(201, 169, 110, 0.6), transparent 70%); }
.blob-2 { bottom: -18%; right: -12%; width: 46vw; height: 46vw; background: radial-gradient(circle, rgba(120, 140, 150, 0.55), transparent 70%); animation-delay: -8s; }

/* --------------------------------------------------------------------------
   Shared keyframes
   -------------------------------------------------------------------------- */
@keyframes float { 0%, 100% { transform: translate(0, 0); } 50% { transform: translate(-28px, 28px); } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { opacity: 0; transform: translateY(24px); } to { opacity: 1; transform: translateY(0); } }
@keyframes slideDown { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: translateY(0); } }
@keyframes spin { to { transform: rotate(360deg); } }

/* Scroll / load reveal (progressive: content is visible without JS) */
.js .reveal { opacity: 0; transform: translateY(18px); transition: opacity 0.8s var(--ease-smooth), transform 0.8s var(--ease-smooth); transition-delay: var(--d, 0s); }
.js .reveal.in { opacity: 1; transform: none; }

/* --------------------------------------------------------------------------
   Brand
   -------------------------------------------------------------------------- */
.brand {
  display: inline-flex;
  align-items: center;
  gap: 11px;
  font-family: var(--font-body);
  font-weight: 500;
  font-size: 0.98rem;
  letter-spacing: -0.005em;
  color: var(--text-main);
  text-decoration: none;
}
.brand-mark {
  position: relative;
  width: 20px;
  height: 20px;
  border: 1.5px solid var(--text-main);
  border-radius: 6px;
  flex-shrink: 0;
}
.brand-mark::after {
  content: "";
  position: absolute;
  right: -3px;
  bottom: -3px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--primary);
  box-shadow: 0 0 0 2px var(--bg-dark);
}

/* --------------------------------------------------------------------------
   Small shared primitives
   -------------------------------------------------------------------------- */
.eyebrow {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  font-weight: 500;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.serif { font-family: var(--font-display); font-weight: 400; letter-spacing: -0.01em; }
.serif em { font-style: italic; color: var(--primary); }

.blur-text {
  color: transparent;
  text-shadow: 0 0 9px var(--blur-glow);
  user-select: none;
  transition: text-shadow 0.3s ease;
}
.blur-text:hover { text-shadow: 0 0 5px var(--blur-glow); }

/* Alerts */
.alert {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 13px 15px;
  border-radius: 8px;
  font-size: 0.88rem;
  line-height: 1.45;
  border: 1px solid var(--border);
}
.alert-error { background: var(--alert-error-bg); color: var(--alert-error-fg); border-color: var(--alert-error-border); }
.alert-success { background: var(--alert-success-bg); color: var(--alert-success-fg); border-color: var(--alert-success-border); }
.alert svg { flex-shrink: 0; }

/* Modal backdrop shared by dashboard / admin / registration */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(20px, env(safe-area-inset-top)) max(20px, env(safe-area-inset-right)) max(20px, env(safe-area-inset-bottom)) max(20px, env(safe-area-inset-left));
  background: rgba(6, 6, 7, 0.78);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}
.modal-overlay.active { opacity: 1; pointer-events: all; }

/* Scrollbars */
* { scrollbar-width: thin; scrollbar-color: rgba(19, 15, 2, 0.2) transparent; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(19, 15, 2, 0.16); border-radius: 8px; }
::-webkit-scrollbar-thumb:hover { background: rgba(19, 15, 2, 0.28); }

button, input, select, textarea { font: inherit; }
button { color: inherit; }

/* Plain text links (no component class) stay legible on light and dark pages. */
a:not([class]) { color: var(--primary-ink); text-underline-offset: 3px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; }
  .js .reveal { opacity: 1; transform: none; }
}

/* Shared light editorial chrome (page headers only, not headers inside cards) */
body > header {
  background: var(--glass-strong) !important;
  border-bottom-color: var(--border);
}
.brand-mark { border-color: var(--text-main); }
.brand-mark::after { box-shadow: 0 0 0 2px var(--bg-dark); }
.btn-primary { background: var(--primary); color: #fffaf1; }
.btn-primary:hover { background: var(--primary-hover); color: #fffaf1; }
.btn-logout, .nav-link { color: var(--text-muted); }
.nav-link:hover, .btn-logout:hover { color: var(--text-main); }

/* Account-selected themes. The saved preference wins over the device default. */
html[data-theme="dark"] {
  --bg-dark: #0d0f12; --bg-core: #0d0f12; --bg: #0d0f12;
  --bg-panel: #15181c; --bg-card: #15181c; --panel: #15181c;
  --bg-panel-light: #1b1f24; --bg-hover: #20252b;
  --text-main: #f4f2ec; --text: #f4f2ec; --ivory: #f4f2ec;
  --text-muted: #a4a5a6; --muted: #a4a5a6;
  --border: rgba(255,255,255,.11); --border-hover: rgba(255,255,255,.22);
  --primary-ink: #ff8a5e; --on-primary: #fff;
  --glass: rgba(21,24,28,.82); --glass-strong: rgba(21,24,28,.94);
  --glass-hover: rgba(255,255,255,.04); --status-bar-bg: #090a0b;
}
html[data-theme="ember"] {
  --bg-dark: #1a100e; --bg-core: #1a100e; --bg: #1a100e;
  --bg-panel: #241614; --bg-card: #241614; --panel: #241614;
  --bg-panel-light: #321c17; --bg-hover: #42231c;
  --text-main: #fff2e9; --text: #fff2e9; --ivory: #fff2e9;
  --text-muted: #c49c8d; --muted: #c49c8d;
  --border: rgba(255,211,191,.15); --border-hover: rgba(255,211,191,.3);
  --primary: #ff7041; --primary-hover: #ff8d66; --primary-ink: #ffac8d;
  --on-primary: #24100d; --glass: rgba(36,22,20,.84);
  --glass-strong: rgba(36,22,20,.95); --glass-hover: rgba(255,211,191,.06);
  --status-bar-bg: #160b09;
}
html[data-theme="dark"] body,
html[data-theme="ember"] body { background-color: var(--bg-dark); color: var(--text-main); }
html[data-theme="dark"] .ambient-bg,
html[data-theme="ember"] .ambient-bg {
  background: radial-gradient(ellipse 80% 60% at 50% -10%, rgba(255,91,26,.15), var(--bg-dark) 65%);
}
html[data-theme="light"] { color-scheme: light; }
html[data-theme="dark"],
html[data-theme="ember"] { color-scheme: dark; }
