/**
 * dong-ui — CloudCLI-inspired design tokens (original reimplementation).
 * Light: warm cream. Dark: near-black. Toggle via html.dark + theme.js.
 */

:root {
  --background: 44 22% 96%;
  --foreground: 36 25% 4%;
  --card: 0 0% 100%;
  --card-foreground: 36 25% 4%;
  --popover: 0 0% 100%;
  --popover-foreground: 36 25% 4%;
  --primary: 221.2 83.2% 53.3%;
  --primary-foreground: 210 40% 98%;
  --secondary: 44 15% 91%;
  --secondary-foreground: 36 15% 18%;
  --muted: 44 15% 91%;
  --muted-foreground: 40 5% 44%;
  --accent: 44 15% 91%;
  --accent-foreground: 36 15% 18%;
  --destructive: 0 84.2% 60.2%;
  --destructive-foreground: 210 40% 98%;
  --border: 44 14% 87%;
  --input: 44 14% 87%;
  --ring: 221.2 83.2% 53.3%;
  --radius: 0.5rem;

  --bg-hex: #f6f4ef;
  --fg-hex: #0d0b08;
  --card-hex: #ffffff;
  --primary-hex: #2563eb;
  --muted-hex: #ebeae5;
  --muted-fg-hex: #76726b;
  --border-hex: #e2e0d9;
  --theme-color: #f6f4ef;

  --nav-glass-bg: 44 22% 96% / 0.7;
  --nav-glass-blur: 20px;
  --nav-glass-saturate: 1.8;

  --font-sans: "Encode Sans", -apple-system, BlinkMacSystemFont, "Segoe UI",
    Roboto, "Helvetica Neue", Arial, sans-serif;
  --app-accent: hsl(var(--primary));

  /* Compatibility aliases for existing app CSS (do not clobber HSL tokens) */
  --bg: hsl(var(--background));
  --bg-deep: hsl(var(--secondary));
  --bg-mid: hsl(var(--secondary));
  --bg-raised: hsl(var(--card));
  --bg-card: hsl(var(--card));
  --bg-elevated: hsl(var(--secondary));
  --ink: hsl(var(--foreground));
  --text: hsl(var(--foreground));
  --text-dim: hsl(var(--muted-foreground));
  --text-mute: hsl(var(--muted-foreground));
  --muted-text: hsl(var(--muted-foreground));
  --line: hsl(var(--border));
  --surface: hsl(var(--card) / 0.85);
  --font-body: var(--font-sans);
  --font-ui: var(--font-sans);
  --font-display: var(--font-sans);

  color-scheme: light;
}

html.dark {
  --background: 0 0% 8%;
  --foreground: 40 8% 93%;
  --card: 0 0% 12%;
  --card-foreground: 40 8% 93%;
  --popover: 0 0% 12%;
  --popover-foreground: 40 8% 93%;
  --primary: 217.2 91.2% 59.8%;
  --primary-foreground: 0 0% 8%;
  --secondary: 0 0% 17%;
  --secondary-foreground: 40 8% 93%;
  --muted: 0 0% 17%;
  --muted-foreground: 0 0% 72%;
  --accent: 0 0% 17%;
  --accent-foreground: 40 8% 93%;
  --destructive: 0 62.8% 30.6%;
  --destructive-foreground: 40 8% 93%;
  --border: 0 0% 17%;
  --input: 0 0% 23%;
  --ring: 217.2 91.2% 59.8%;

  --bg-hex: #141414;
  --fg-hex: #efeeec;
  --card-hex: #1f1f1f;
  --primary-hex: #3b82f6;
  --muted-hex: #2b2b2b;
  --muted-fg-hex: #b8b8b8;
  --border-hex: #2b2b2b;
  --theme-color: #141414;

  --nav-glass-bg: 0 0% 12% / 0.55;
  --nav-glass-blur: 24px;
  --nav-glass-saturate: 1.6;

  --bg: hsl(var(--background));
  --bg-deep: hsl(0 0% 6%);
  --bg-mid: hsl(var(--secondary));
  --bg-raised: hsl(var(--card));
  --bg-card: hsl(var(--card));
  --bg-elevated: hsl(var(--secondary));
  --ink: hsl(var(--foreground));
  --text: hsl(var(--foreground));
  --text-dim: hsl(var(--muted-foreground));
  --text-mute: hsl(var(--muted-foreground));
  --muted-text: hsl(var(--muted-foreground));
  --line: hsl(var(--border));
  --surface: hsl(var(--card) / 0.9);

  color-scheme: dark;
}

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

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

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-sans);
  color: hsl(var(--foreground));
  background: hsl(var(--background));
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body,
div,
section,
article,
aside,
header,
footer,
nav,
main,
h1,
h2,
h3,
h4,
h5,
h6,
p,
span,
ul,
ol,
li,
table,
tr,
td,
th,
form,
label {
  transition: background-color 200ms ease-in-out, border-color 200ms ease-in-out,
    color 200ms ease-in-out;
}

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

.nav-glass {
  background: hsl(var(--nav-glass-bg));
  backdrop-filter: blur(var(--nav-glass-blur)) saturate(var(--nav-glass-saturate));
  -webkit-backdrop-filter: blur(var(--nav-glass-blur))
    saturate(var(--nav-glass-saturate));
}

.ui-card {
  background: hsl(var(--card));
  color: hsl(var(--card-foreground));
  border: 1px solid hsl(var(--border) / 0.7);
  border-radius: calc(var(--radius) + 4px);
  box-shadow: 0 1px 2px hsl(0 0% 0% / 0.04);
}

.ui-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  height: 2.5rem;
  padding: 0 1rem;
  border-radius: var(--radius);
  border: 1px solid transparent;
  font-family: var(--font-sans);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  background: hsl(var(--primary));
  color: hsl(var(--primary-foreground));
  transition: background-color 150ms ease, border-color 150ms ease,
    transform 100ms ease;
}

.ui-btn:hover {
  filter: brightness(1.05);
}

.ui-btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px hsl(var(--ring) / 0.35);
}

.ui-btn-ghost {
  background: hsl(var(--secondary));
  color: hsl(var(--secondary-foreground));
  border-color: hsl(var(--border) / 0.6);
}

.dong-theme-toggle {
  position: fixed;
  top: max(0.75rem, env(safe-area-inset-top));
  right: max(0.75rem, env(safe-area-inset-right));
  z-index: 1000;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.75rem;
  height: 1.75rem;
  padding: 0;
  border: 1px solid hsl(var(--border) / 0.7);
  border-radius: 999px;
  background: hsl(var(--card) / 0.85);
  backdrop-filter: blur(12px) saturate(1.4);
  -webkit-backdrop-filter: blur(12px) saturate(1.4);
  color: hsl(var(--foreground));
  cursor: pointer;
  box-shadow: 0 1px 8px hsl(0 0% 0% / 0.08);
}

.dong-theme-toggle:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px hsl(var(--ring) / 0.35);
}

.dong-theme-toggle__track {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 0.35rem;
}

.dong-theme-toggle__icon {
  width: 0.85rem;
  height: 0.85rem;
  opacity: 0.45;
}

.dong-theme-toggle__icon.is-active {
  opacity: 1;
  color: hsl(var(--primary));
}

.dong-theme-toggle__knob {
  position: absolute;
  top: 2px;
  left: 2px;
  width: calc(1.75rem - 6px);
  height: calc(1.75rem - 6px);
  border-radius: 999px;
  background: hsl(var(--primary));
  transition: transform 180ms cubic-bezier(0.4, 0, 0.2, 1);
  pointer-events: none;
}

html.dark .dong-theme-toggle__knob {
  transform: translateX(1rem);
}

.dong-topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  min-height: 3rem;
  padding: 0.5rem 1rem;
  padding-top: max(0.5rem, env(safe-area-inset-top));
  border-bottom: 1px solid hsl(var(--border) / 0.5);
}

.dong-topbar .dong-theme-toggle {
  position: static;
}
