/* SaiOS base: tokens, themes, reset and shared components.
   Light palette on :root; dark palette under prefers-color-scheme (unless light is forced)
   and again under [data-theme="dark"] so an explicit choice wins either way. */

:root {
  color-scheme: light;

  --font-ui: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-display: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Inter", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: "SF Mono", "JetBrains Mono", ui-monospace, Menlo, Consolas, "Liberation Mono", monospace;
  --font-script: "Sacramento", "Snell Roundhand", "Segoe Script", "Brush Script MT", cursive;

  --text: #1d1d1f;
  --text-2: #45454a;
  --text-3: #6b6b73;
  --text-on-accent: #ffffff;
  --surface: #ffffff;
  --surface-2: #f5f5f7;
  --surface-3: #ebebef;
  --grouped-bg: #f2f2f7;
  --fill: rgba(120, 120, 128, 0.12);
  --fill-2: rgba(120, 120, 128, 0.2);
  --fill-hover: rgba(120, 120, 128, 0.18);
  --hairline: rgba(0, 0, 0, 0.1);
  --hairline-2: rgba(0, 0, 0, 0.16);

  --glass-bg: rgba(246, 246, 249, 0.6);
  --glass-bg-strong: rgba(250, 250, 252, 0.84);
  --glass-edge: rgba(255, 255, 255, 0.6);
  --glass-shine: rgba(255, 255, 255, 0.85);
  --glass-blur: blur(28px) saturate(180%);
  --window-bg: #ffffff;
  --window-glass: rgba(236, 237, 243, 0.82);
  --sidebar-bg: rgba(255, 255, 255, 0.46);
  --toolbar-bg: rgba(255, 255, 255, 0.7);
  --menu-bg: rgba(242, 242, 246, 0.86);
  --dock-bg: rgba(255, 255, 255, 0.3);
  --dock-dot: rgba(0, 0, 0, 0.55);
  --scrim: rgba(12, 14, 24, 0.28);

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.08);
  --shadow-md: 0 8px 24px rgba(20, 24, 40, 0.14), 0 2px 6px rgba(20, 24, 40, 0.08);
  --shadow-lg: 0 24px 64px rgba(20, 24, 40, 0.26), 0 8px 18px rgba(20, 24, 40, 0.12);
  --shadow-window: 0 0 0 0.5px rgba(0, 0, 0, 0.22), 0 30px 80px rgba(10, 14, 30, 0.34), 0 10px 26px rgba(10, 14, 30, 0.16);
  --shadow-window-idle: 0 0 0 0.5px rgba(0, 0, 0, 0.18), 0 16px 44px rgba(10, 14, 30, 0.22);

  --radius-window: 16px;
  --radius-panel: 12px;
  --radius-card: 14px;
  --radius-control: 8px;

  --tl-red: #ff5f57;
  --tl-yellow: #febc2e;
  --tl-green: #28c840;
  --tl-off: #cfcfd4;

  --ok: #1a7f3c;
  --ok-bg: rgba(52, 199, 89, 0.16);
  --warn: #9a5b00;
  --warn-bg: rgba(255, 159, 10, 0.18);
  --bad: #c62f2f;
  --bad-bg: rgba(255, 69, 58, 0.14);

  /* Accent (blue by default); fills stay AA with white text, inks stay AA on surfaces. */
  --accent: #0071e3;
  --accent-ink: #0062c4;
  --accent-soft: rgba(0, 113, 227, 0.14);
  --folder-a: #8ccdfb;
  --folder-b: #4aa6ee;
  --folder-glyph: #2f7fc9;

  --menubar-h: 28px;
  --dock-h: 86px;
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  --ease-spring: cubic-bezier(0.34, 1.4, 0.64, 1);
}

:root[data-accent="purple"] { --accent: #7c3aed; --accent-ink: #6d28d9; --accent-soft: rgba(124, 58, 237, 0.14); --folder-a: #cbb0fb; --folder-b: #9a6cf0; --folder-glyph: #6f45cf; }
:root[data-accent="pink"] { --accent: #c8286a; --accent-ink: #b01f5c; --accent-soft: rgba(200, 40, 106, 0.13); --folder-a: #f7b1cd; --folder-b: #e56a9e; --folder-glyph: #b8386f; }
:root[data-accent="orange"] { --accent: #c25e00; --accent-ink: #a14e00; --accent-soft: rgba(194, 94, 0, 0.14); --folder-a: #fcc88f; --folder-b: #f39a3f; --folder-glyph: #b86412; }
:root[data-accent="green"] { --accent: #16833a; --accent-ink: #11702f; --accent-soft: rgba(22, 131, 58, 0.14); --folder-a: #a4e2b4; --folder-b: #4cbd72; --folder-glyph: #268a47; }
:root[data-accent="graphite"] { --accent: #5e5e66; --accent-ink: #4e4e55; --accent-soft: rgba(94, 94, 102, 0.16); --folder-a: #cfcfd6; --folder-b: #9c9ca6; --folder-glyph: #6c6c75; }

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --text: #f5f5f7;
    --text-2: #c7c7cc;
    --text-3: #9d9da5;
    --surface: #1f1f22;
    --surface-2: #27272b;
    --surface-3: #303035;
    --grouped-bg: #000000;
    --fill: rgba(140, 140, 150, 0.2);
    --fill-2: rgba(140, 140, 150, 0.3);
    --fill-hover: rgba(140, 140, 150, 0.28);
    --hairline: rgba(255, 255, 255, 0.1);
    --hairline-2: rgba(255, 255, 255, 0.17);
    --glass-bg: rgba(40, 40, 46, 0.56);
    --glass-bg-strong: rgba(34, 34, 39, 0.86);
    --glass-edge: rgba(255, 255, 255, 0.14);
    --glass-shine: rgba(255, 255, 255, 0.24);
    --window-bg: #1e1e21;
    --window-glass: rgba(40, 40, 46, 0.8);
    --sidebar-bg: rgba(255, 255, 255, 0.07);
    --toolbar-bg: rgba(30, 30, 34, 0.7);
    --menu-bg: rgba(42, 42, 47, 0.88);
    --dock-bg: rgba(34, 36, 46, 0.42);
    --dock-dot: rgba(255, 255, 255, 0.82);
    --scrim: rgba(0, 0, 0, 0.45);
    --shadow-window: 0 0 0 0.5px rgba(0, 0, 0, 0.7), 0 0 0 1px rgba(255, 255, 255, 0.08) inset, 0 30px 80px rgba(0, 0, 0, 0.55), 0 10px 26px rgba(0, 0, 0, 0.35);
    --shadow-window-idle: 0 0 0 0.5px rgba(0, 0, 0, 0.6), 0 16px 44px rgba(0, 0, 0, 0.4);
    --tl-off: #4b4b52;
    --ok: #4cd67a;
    --warn: #ffb547;
    --bad: #ff6f66;
    --accent-ink: #5aa9ff;
  }
  :root:not([data-theme="light"])[data-accent="purple"] { --accent-ink: #b794ff; }
  :root:not([data-theme="light"])[data-accent="pink"] { --accent-ink: #ff7eb0; }
  :root:not([data-theme="light"])[data-accent="orange"] { --accent-ink: #ffab52; }
  :root:not([data-theme="light"])[data-accent="green"] { --accent-ink: #4fdc7b; }
  :root:not([data-theme="light"])[data-accent="graphite"] { --accent-ink: #c2c2c9; }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --text: #f5f5f7;
  --text-2: #c7c7cc;
  --text-3: #9d9da5;
  --surface: #1f1f22;
  --surface-2: #27272b;
  --surface-3: #303035;
  --grouped-bg: #000000;
  --fill: rgba(140, 140, 150, 0.2);
  --fill-2: rgba(140, 140, 150, 0.3);
  --fill-hover: rgba(140, 140, 150, 0.28);
  --hairline: rgba(255, 255, 255, 0.1);
  --hairline-2: rgba(255, 255, 255, 0.17);
  --glass-bg: rgba(40, 40, 46, 0.56);
  --glass-bg-strong: rgba(34, 34, 39, 0.86);
  --glass-edge: rgba(255, 255, 255, 0.14);
  --glass-shine: rgba(255, 255, 255, 0.24);
  --window-bg: #1e1e21;
  --window-glass: rgba(40, 40, 46, 0.8);
  --sidebar-bg: rgba(255, 255, 255, 0.07);
  --toolbar-bg: rgba(30, 30, 34, 0.7);
  --menu-bg: rgba(42, 42, 47, 0.88);
  --dock-bg: rgba(34, 36, 46, 0.42);
  --dock-dot: rgba(255, 255, 255, 0.82);
  --scrim: rgba(0, 0, 0, 0.45);
  --shadow-window: 0 0 0 0.5px rgba(0, 0, 0, 0.7), 0 0 0 1px rgba(255, 255, 255, 0.08) inset, 0 30px 80px rgba(0, 0, 0, 0.55), 0 10px 26px rgba(0, 0, 0, 0.35);
  --shadow-window-idle: 0 0 0 0.5px rgba(0, 0, 0, 0.6), 0 16px 44px rgba(0, 0, 0, 0.4);
  --tl-off: #4b4b52;
  --ok: #4cd67a;
  --warn: #ffb547;
  --bad: #ff6f66;
  --accent-ink: #5aa9ff;
}
:root[data-theme="dark"][data-accent="purple"] { --accent-ink: #b794ff; }
:root[data-theme="dark"][data-accent="pink"] { --accent-ink: #ff7eb0; }
:root[data-theme="dark"][data-accent="orange"] { --accent-ink: #ffab52; }
:root[data-theme="dark"][data-accent="green"] { --accent-ink: #4fdc7b; }
:root[data-theme="dark"][data-accent="graphite"] { --accent-ink: #c2c2c9; }

/* Solid surfaces for people who ask for less transparency. */
:root[data-transparency="reduced"] {
  --glass-bg: var(--surface-2);
  --glass-bg-strong: var(--surface);
  --window-bg: var(--surface);
  --window-glass: var(--surface-2);
  --sidebar-bg: var(--surface-2);
  --toolbar-bg: var(--surface);
  --menu-bg: var(--surface-2);
  --dock-bg: var(--surface-2);
  --glass-blur: none;
}
@media (prefers-reduced-transparency: reduce) {
  :root:not([data-transparency="full"]) {
    --glass-bg: var(--surface-2);
    --glass-bg-strong: var(--surface);
    --window-bg: var(--surface);
    --window-glass: var(--surface-2);
    --sidebar-bg: var(--surface-2);
    --toolbar-bg: var(--surface);
    --menu-bg: var(--surface-2);
    --dock-bg: var(--surface-2);
    --glass-blur: none;
  }
}

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

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: var(--font-ui);
  font-size: 13px;
  line-height: 1.4;
  color: var(--text);
  background: #1c2340;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  overflow: hidden;
}

body.is-simple {
  overflow: auto;
  background: var(--surface);
}

img,
svg {
  display: block;
  max-width: 100%;
}

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

button {
  cursor: default;
  background: none;
  border: 0;
  padding: 0;
}

a {
  color: var(--accent-ink);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
  text-underline-offset: 2px;
}

[hidden] {
  display: none !important;
}

:focus {
  outline: none;
}

:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent) 55%, transparent);
  outline-offset: 2px;
  border-radius: 6px;
}

::selection {
  background: color-mix(in srgb, var(--accent) 28%, transparent);
}

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

.skip-link {
  position: fixed;
  left: 12px;
  top: 8px;
  z-index: 10000;
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--text-on-accent);
  font-weight: 600;
  transform: translateY(-160%);
  transition: transform 0.2s var(--ease);
}

.skip-link:focus-visible {
  transform: none;
  outline-offset: 3px;
}

.icon {
  flex: none;
}

/* Thin, rounded scrollbars that stay out of the way. */
.scroll {
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: var(--fill-2) transparent;
}

.scroll::-webkit-scrollbar {
  width: 11px;
  height: 11px;
}

.scroll::-webkit-scrollbar-thumb {
  background: var(--fill-2);
  border-radius: 999px;
  border: 3px solid transparent;
  background-clip: padding-box;
}

.scroll::-webkit-scrollbar-track {
  background: transparent;
}

/* ---------- Glass ---------- */

.glass {
  background: var(--glass-bg);
  -webkit-backdrop-filter: var(--glass-blur);
  backdrop-filter: var(--glass-blur);
  box-shadow: inset 0 0.5px 0 var(--glass-shine), inset 0 0 0 0.5px var(--glass-edge), var(--shadow-md);
}

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 28px;
  padding: 0 13px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 500;
  line-height: 1;
  white-space: nowrap;
  color: var(--text);
  background: var(--fill);
  transition: background-color 0.15s var(--ease), transform 0.15s var(--ease), box-shadow 0.15s var(--ease);
  text-decoration: none;
  user-select: none;
}

.btn:hover {
  background: var(--fill-hover);
  text-decoration: none;
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: var(--accent);
  color: var(--text-on-accent);
  box-shadow: 0 1px 2px color-mix(in srgb, var(--accent) 40%, transparent), inset 0 0.5px 0 rgba(255, 255, 255, 0.35);
}

.btn-primary:hover {
  background: color-mix(in srgb, var(--accent) 88%, black);
}

.btn-glass {
  background: var(--glass-bg-strong);
  -webkit-backdrop-filter: var(--glass-blur);
  backdrop-filter: var(--glass-blur);
  box-shadow: inset 0 0.5px 0 var(--glass-shine), 0 0 0 0.5px var(--hairline), var(--shadow-sm);
}

.btn-quiet {
  background: transparent;
}

.btn-quiet:hover {
  background: var(--fill);
}

.btn-lg {
  min-height: 36px;
  padding: 0 18px;
  font-size: 14px;
}

.btn-icon {
  width: 28px;
  min-height: 28px;
  padding: 0;
  border-radius: 999px;
}

.btn[disabled],
.btn[aria-disabled="true"] {
  opacity: 0.45;
  pointer-events: none;
}

/* Toolbar capsule groups (back/forward, view switcher). */
.capsule {
  display: inline-flex;
  align-items: center;
  height: 30px;
  padding: 2px;
  gap: 2px;
  border-radius: 999px;
  background: var(--glass-bg-strong);
  box-shadow: inset 0 0.5px 0 var(--glass-shine), 0 0 0 0.5px var(--hairline), var(--shadow-sm);
}

.capsule > button {
  display: grid;
  place-items: center;
  height: 26px;
  min-width: 30px;
  padding: 0 7px;
  border-radius: 999px;
  color: var(--text-2);
  transition: background-color 0.15s var(--ease), color 0.15s var(--ease);
}

.capsule > button:hover:not([disabled]) {
  background: var(--fill);
  color: var(--text);
}

.capsule > button[aria-pressed="true"],
.capsule > button[aria-checked="true"] {
  background: var(--fill-2);
  color: var(--text);
}

.capsule > button[disabled] {
  opacity: 0.35;
}

/* Segmented control. */
.segmented {
  display: inline-flex;
  padding: 2px;
  border-radius: 9px;
  background: var(--fill);
  gap: 2px;
}

.segmented button {
  min-height: 24px;
  padding: 0 12px;
  border-radius: 7px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-2);
  transition: background-color 0.15s var(--ease), color 0.15s var(--ease), box-shadow 0.15s var(--ease);
}

.segmented button[aria-selected="true"],
.segmented button[aria-checked="true"],
.segmented button[aria-pressed="true"] {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.14), 0 0 0 0.5px rgba(0, 0, 0, 0.06);
}

:root[data-theme="dark"] .segmented button[aria-selected="true"],
:root[data-theme="dark"] .segmented button[aria-checked="true"],
:root[data-theme="dark"] .segmented button[aria-pressed="true"] {
  background: #5b5b62;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .segmented button[aria-selected="true"],
  :root:not([data-theme="light"]) .segmented button[aria-checked="true"],
  :root:not([data-theme="light"]) .segmented button[aria-pressed="true"] {
    background: #5b5b62;
  }
}

/* ---------- Form fields ---------- */

.field {
  width: 100%;
  min-height: 32px;
  padding: 6px 11px;
  border-radius: 9px;
  border: 0;
  background: var(--fill);
  color: var(--text);
  box-shadow: inset 0 0 0 0.5px var(--hairline);
  transition: box-shadow 0.15s var(--ease), background-color 0.15s var(--ease);
}

.field::placeholder {
  color: var(--text-3);
}

.field:focus-visible,
.field:focus {
  outline: none;
  background: var(--surface);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 45%, transparent), inset 0 0 0 1px var(--accent);
}

textarea.field {
  resize: vertical;
  line-height: 1.5;
}

.search-field {
  position: relative;
  display: flex;
  align-items: center;
}

.search-field .icon {
  position: absolute;
  left: 10px;
  color: var(--text-3);
  pointer-events: none;
}

.search-field .field {
  padding-left: 30px;
  border-radius: 999px;
  min-height: 30px;
  background: var(--glass-bg-strong);
  box-shadow: inset 0 0.5px 0 var(--glass-shine), 0 0 0 0.5px var(--hairline), var(--shadow-sm);
}

/* ---------- Chips ---------- */

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 26px;
  padding: 0 10px 0 4px;
  border-radius: 999px;
  background: var(--fill);
  color: var(--text);
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
  line-height: 1;
  transition: background-color 0.15s var(--ease), transform 0.15s var(--ease);
}

button.chip:hover,
a.chip:hover {
  background: var(--fill-hover);
  text-decoration: none;
}

button.chip:active {
  transform: scale(0.97);
}

.chip--plain {
  padding: 0 10px;
}

.chip-mark {
  display: grid;
  place-items: center;
  width: 19px;
  height: 19px;
  border-radius: 6px;
  background: #fff;
  box-shadow: 0 0 0 0.5px rgba(0, 0, 0, 0.12);
  flex: none;
}

.chip-mark img {
  width: 14px;
  height: 14px;
  object-fit: contain;
}

.chip-mono {
  font-size: 8px;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: #fff;
  background: var(--chip-tone, #6b7280);
  box-shadow: none;
}

.chip-count {
  display: inline-grid;
  place-items: center;
  min-width: 17px;
  height: 17px;
  padding: 0 5px;
  margin-right: -4px;
  border-radius: 999px;
  background: var(--surface);
  color: var(--text-2);
  font-size: 10.5px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 20px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  background: var(--fill);
  color: var(--text-2);
  white-space: nowrap;
}

.pill--accent {
  background: var(--accent-soft);
  color: var(--accent-ink);
}

.pill--ok {
  background: var(--ok-bg);
  color: var(--ok);
}

.pill--warn {
  background: var(--warn-bg);
  color: var(--warn);
}

.pill--bad {
  background: var(--bad-bg);
  color: var(--bad);
}

.kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  border-radius: 5px;
  font-family: var(--font-ui);
  font-size: 11px;
  font-weight: 600;
  color: var(--text-2);
  background: var(--surface);
  box-shadow: 0 0 0 0.5px var(--hairline-2), 0 1px 0 var(--hairline-2);
}

/* ---------- App icons (Dock, phone home screen, Spotlight) ---------- */

/* The artwork is an SVG from js/lib/appicons.js; the box only sizes it and adds a shadow
   that follows the squircle's outline. */
.app-icon {
  --size: 52px;
  --icon-shadow: drop-shadow(0 1.5px 2.5px rgba(0, 0, 0, 0.22));
  position: relative;
  display: block;
  width: var(--size);
  height: var(--size);
  flex: none;
  filter: var(--icon-shadow);
}

.app-icon .app-svg {
  display: block;
  width: 100%;
  height: 100%;
}

/* ---------- Covers ---------- */

.cover {
  position: relative;
  aspect-ratio: 16 / 10;
  width: 100%;
  max-width: 100%;
  border-radius: 12px;
  overflow: hidden;
  background: linear-gradient(145deg, var(--cover-from, #1d2a44), var(--cover-to, #3a4d78));
  isolation: isolate;
}

.cover-art {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

/* ---------- HUD (small confirmations) ---------- */

.hud {
  position: fixed;
  left: 50%;
  bottom: calc(var(--dock-h) + 28px);
  z-index: 9500;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 18px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  background: var(--glass-bg-strong);
  -webkit-backdrop-filter: var(--glass-blur);
  backdrop-filter: var(--glass-blur);
  box-shadow: inset 0 0.5px 0 var(--glass-shine), 0 0 0 0.5px var(--hairline), var(--shadow-lg);
  transform: translate(-50%, 12px);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.25s var(--ease), opacity 0.25s var(--ease);
}

.hud.is-visible {
  transform: translate(-50%, 0);
  opacity: 1;
}

.hud .icon {
  color: var(--accent-ink);
}

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

:root[data-motion="reduced"] *,
:root[data-motion="reduced"] *::before,
:root[data-motion="reduced"] *::after {
  animation-duration: 0.01ms !important;
  animation-iteration-count: 1 !important;
  transition-duration: 0.01ms !important;
}

/* Containers that take focus programmatically (windows, dialogs) don't need a ring. */
[tabindex="-1"]:focus,
[tabindex="-1"]:focus-visible {
  outline: none;
}
