/* ShadowEscaper shared design system — "Tide"
   Phase 1: tokens + non-visual primitives are loaded by every page.
   Phase 2 will migrate page-specific styles onto these tokens. */

:root {
  /* Palette */
  --ink-900: #0B1020;
  --ink-800: #141A2E;
  --ink-700: #1F2742;
  --surface: rgba(255, 255, 255, 0.06);
  --line: rgba(255, 255, 255, 0.14);

  --accent: #5EE6C5;
  --accent-2: #7AA2FF;
  --ok: #3DDC84;
  --warn: #FFB454;
  --err: #FF6B7A;

  --text: #F2F4FA;
  --text-mute: #9AA3BE;

  /* Type scale (rem, base 16) */
  --fs-xs: 0.75rem;
  --fs-sm: 0.875rem;
  --fs-base: 1rem;
  --fs-md: 1.125rem;
  --fs-lg: 1.375rem;
  --fs-xl: 1.75rem;
  --fs-2xl: 2.25rem;
  --fs-3xl: 3rem;
  --fs-display: clamp(2.75rem, 7vw, 5.5rem);

  /* Spacing */
  --s-1: 4px;
  --s-2: 8px;
  --s-3: 12px;
  --s-4: 16px;
  --s-5: 24px;
  --s-6: 32px;
  --s-7: 48px;
  --s-8: 64px;

  /* Radius */
  --r-sm: 8px;
  --r-md: 14px;
  --r-lg: 20px;
  --r-pill: 999px;

  /* Shadow */
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.2);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.18);
  --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.24);

  /* Motion */
  --motion: 200ms cubic-bezier(.2, .8, .2, 1);
}

/* Base focus ring (works on every page regardless of theme) */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

/* Reduced motion: kill non-essential animation */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}

/* Screen-reader-only utility */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Toast container (used by SE.toast()) */
.se-toast-stack {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 99999;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
  max-width: min(420px, calc(100vw - 40px));
}

.se-toast {
  pointer-events: auto;
  padding: 14px 18px;
  border-radius: var(--r-md);
  font-size: var(--fs-sm);
  font-weight: 600;
  background: var(--ink-800);
  color: var(--text);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: flex-start;
  gap: 10px;
  animation: se-toast-in 220ms cubic-bezier(.2, .8, .2, 1);
  word-break: break-word;
}

.se-toast--error { border-left: 3px solid var(--err); }
.se-toast--success { border-left: 3px solid var(--ok); }
.se-toast--warn { border-left: 3px solid var(--warn); }
.se-toast--info { border-left: 3px solid var(--accent); }

@keyframes se-toast-in {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Shared glass utility (does not override page-specific .glass) */
.glass-shared {
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-md);
  border-radius: var(--r-lg);
  position: relative;
}
@supports (backdrop-filter: blur(1px)) {
  .glass-shared {
    backdrop-filter: blur(20px) saturate(140%);
    -webkit-backdrop-filter: blur(20px) saturate(140%);
  }
}
@supports not (backdrop-filter: blur(1px)) {
  .glass-shared { background: var(--ink-700); }
}

/* Button primitives (opt-in via .se-btn) */
.se-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 20px;
  border-radius: var(--r-pill);
  font-size: var(--fs-sm);
  font-weight: 700;
  letter-spacing: -0.01em;
  border: 1px solid transparent;
  cursor: pointer;
  transition: transform var(--motion), background var(--motion), box-shadow var(--motion);
  text-decoration: none;
  font-family: inherit;
}
.se-btn:hover { transform: translateY(-1px); }
.se-btn:active { transform: translateY(0); }
.se-btn[disabled], .se-btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.se-btn--primary {
  background: var(--accent);
  color: var(--ink-900);
}
.se-btn--primary:hover { box-shadow: 0 8px 20px rgba(94, 230, 197, 0.3); }

.se-btn--ghost {
  background: transparent;
  color: var(--text);
  border-color: var(--line);
}
.se-btn--ghost:hover { background: var(--surface); }

.se-btn--danger {
  background: var(--err);
  color: var(--ink-900);
}

/* Layout primitives */
.se-container { max-width: 1040px; margin: 0 auto; padding: 0 16px; }
.se-stack > * + * { margin-top: var(--s-4); }
.se-cluster { display: flex; flex-wrap: wrap; gap: var(--s-3); align-items: center; }

/* ARIA tab styling */
.se-tablist { display: flex; gap: 4px; }
[role="tab"] { cursor: pointer; }
[role="tab"][aria-selected="true"] { font-weight: 700; }

/* Truly hidden elements */
[hidden] { display: none !important; }

/* ════════════════════════════════════════════════════════════
   Tide visual system — Phase 2 page primitives
   Pages opt-in by adding the .tide class to <body>; once opted in,
   the page's own inline styles continue to layer on top.
   ════════════════════════════════════════════════════════════ */

body.tide {
  background: var(--ink-900);
  color: var(--text);
  font-family: "Inter", "SF Pro Text", -apple-system, BlinkMacSystemFont,
               "PingFang SC", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  letter-spacing: -0.012em;
}

/* Drifting gradient backdrop — replaces the 5 floating blobs.
   Pages add <div class="tide-bg"></div> as the first child of body. */
.tide-bg {
  position: fixed;
  inset: 0;
  z-index: -2;
  background:
    radial-gradient(60vw 60vw at 15% 25%, rgba(94, 230, 197, 0.18), transparent 60%),
    radial-gradient(50vw 50vw at 85% 75%, rgba(122, 162, 255, 0.20), transparent 60%),
    var(--ink-900);
  overflow: hidden;
  animation: tide-drift 40s ease-in-out infinite alternate;
}
@keyframes tide-drift {
  from { background-position: 0% 0%, 100% 100%, 0 0; }
  to   { background-position: 10% 5%, 90% 95%,  0 0; }
}
.tide-bg::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='200' height='200'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2'/><feColorMatrix values='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.4 0'/></filter><rect width='100%25' height='100%25' filter='url(%23n)'/></svg>");
  opacity: 0.35;
  mix-blend-mode: overlay;
}

/* Tide glass — used by .tide-card and .tide-nav */
.tide-glass {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--line);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.08),
    0 8px 32px rgba(0, 0, 0, 0.35);
  position: relative;
}
@supports (backdrop-filter: blur(1px)) {
  .tide-glass {
    backdrop-filter: blur(20px) saturate(140%);
    -webkit-backdrop-filter: blur(20px) saturate(140%);
  }
}
@supports not (backdrop-filter: blur(1px)) {
  .tide-glass { background: var(--ink-700); }
}

.tide-card {
  border-radius: var(--r-lg);
  padding: 28px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--line);
}

/* Forms */
.tide-input {
  width: 100%;
  padding: 12px 14px;
  border-radius: var(--r-md);
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.25);
  color: var(--text);
  font: inherit;
  outline: none;
  transition: border var(--motion), box-shadow var(--motion), background var(--motion);
}
.tide-input::placeholder { color: var(--text-mute); }
.tide-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(94, 230, 197, 0.18);
  background: rgba(0, 0, 0, 0.35);
}
.tide-label {
  display: block;
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--text-mute);
  margin: 12px 0 6px;
}

/* Tab bar (used by login/admin/panel) */
.tide-tabbar {
  display: inline-flex;
  gap: 4px;
  padding: 4px;
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--line);
  border-radius: var(--r-pill);
}
.tide-tab {
  border: 0;
  border-radius: var(--r-pill);
  padding: 8px 16px;
  background: transparent;
  color: var(--text-mute);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: color var(--motion), background var(--motion);
}
.tide-tab[aria-selected="true"] {
  background: var(--accent);
  color: var(--ink-900);
}
.tide-tab:hover { color: var(--text); }
.tide-tab[aria-selected="true"]:hover { color: var(--ink-900); }

/* Status pills */
.tide-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: var(--r-pill);
  font-size: var(--fs-xs);
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.tide-pill--ok    { background: rgba(61, 220, 132, 0.14); color: var(--ok); }
.tide-pill--warn  { background: rgba(255, 180, 84, 0.14); color: var(--warn); }
.tide-pill--err   { background: rgba(255, 107, 122, 0.14); color: var(--err); }
.tide-pill--info  { background: rgba(94, 230, 197, 0.14); color: var(--accent); }
