/* Design tokens, reset, and typography. Change the look of the site here.
   Ported from the Notes site (raven / powder blue / poppy glass theme):
   #16171A raven black, #B0E0E6 powder blue, #E35335 poppy red.
   The theme is picked by js/theme.js, which sets saved-theme="light|dark"
   on <html>; the toggle button is wired up in js/ui.js. */

/* ═════════════ Tokens: light ═════════════ */
:root {
  /* Base palette (Notes: quartz.config.yaml → theme.colors.lightMode) */
  --light: #e4f4f6;
  --lightgray: #c4e5ea;
  --gray: #7d9298;
  --darkgray: #24272b;
  --dark: #16171a;
  --secondary: #16171a;
  --tertiary: #e35335;
  --highlight: rgba(22, 23, 26, 0.06);
  --textHighlight: rgba(227, 83, 53, 0.25);

  /* Type: SF Pro on Apple devices, Inter (Google Fonts) elsewhere. */
  --bodyFont:
    -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", "Helvetica Neue", system-ui,
    sans-serif;
  --headerFont:
    -apple-system, BlinkMacSystemFont, "SF Pro Display", "Inter", "Helvetica Neue", system-ui,
    sans-serif;
  --codeFont: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;

  /* Motion: Apple-style ease-out and a gentle spring with a hint of overshoot. */
  --ease: cubic-bezier(0.25, 0.1, 0.25, 1);
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --spring: cubic-bezier(0.34, 1.36, 0.64, 1);
  --dur-fast: 160ms;
  --dur: 280ms;
  --dur-slow: 480ms;

  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 18px;

  /* Brand */
  --brand-raven: #16171a;
  --brand-powder: #b0e0e6;
  --brand-poppy: #e35335;

  /* Light: powder-blue sidebar, paler powder reading area, raven text. */
  --ui-page: #e4f4f6;
  --ui-sidebar: var(--brand-powder);
  --ui-sidebar-edge: #93c9d1;
  --ui-surface: #f3fafb;
  --ui-surface-2: #d7eef1;
  --ui-hover: rgba(22, 23, 26, 0.05);
  --ui-active: rgba(22, 23, 26, 0.09);
  --ui-border: rgba(22, 23, 26, 0.1);
  --ui-border-strong: rgba(22, 23, 26, 0.2);
  --ui-text: #24272b;
  --ui-heading: var(--brand-raven);
  --ui-muted: #44535a;
  --ui-faint: #7d9298;

  /* Accents */
  --ui-link: var(--brand-raven);
  --ui-link-line: var(--brand-poppy);
  --ui-accent: var(--brand-poppy);
  --ui-accent-soft: rgba(227, 83, 53, 0.18);
  --ui-on-accent: var(--brand-raven);
  --ui-pill-bg: var(--brand-raven);
  --ui-pill-text: var(--brand-powder);

  /* Glass */
  --ui-glass: rgba(176, 224, 230, 0.72);
  --ui-glass-strong: rgba(243, 250, 251, 0.85);
  --ui-drawer-tint: rgba(228, 244, 246, 0.84);
  --ui-scrim: rgba(228, 244, 246, 0.5);
  --ui-sheen: linear-gradient(180deg, rgba(255, 255, 255, 0.6) 0%, rgba(255, 255, 255, 0) 100%);
  --ui-highlight: inset 0 1px 0 rgba(255, 255, 255, 0.7);
  --ui-shadow-sm: 0 1px 2px rgba(22, 23, 26, 0.05), 0 1px 3px rgba(22, 23, 26, 0.05);
  --ui-shadow: 0 1px 2px rgba(22, 23, 26, 0.05), 0 6px 20px rgba(22, 23, 26, 0.08);
  --ui-shadow-lg: 0 2px 6px rgba(22, 23, 26, 0.06), 0 24px 60px rgba(22, 23, 26, 0.18);
  --ui-callout-rgb: 227, 83, 53;

  /* Song Ratings only ------------------------------------------------- */

  /* Rating tiers keep their own colours (see .tier-* in components.css). */
  --tier-great: #34c759;
  --tier-good: #a4cf3c;
  --tier-okay: #ff9f0a;
  --tier-bad: #ff3b30;
  --on-tier: rgba(22, 23, 26, 0.88);
  --badge-gloss: linear-gradient(180deg, rgba(255, 255, 255, 0.3), rgba(255, 255, 255, 0) 60%);

  /* Field icons, drawn in --ui-muted (data URIs can't read variables). */
  --ui-icon-search: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 19.9 19.7'%3E%3Cg fill='none' stroke='%2344535a' stroke-width='1.5'%3E%3Cpath stroke-linecap='square' d='M18.5 18.3l-5.4-5.4'/%3E%3Ccircle cx='8' cy='8' r='7'/%3E%3C/g%3E%3C/svg%3E");
  --ui-icon-chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%2344535a' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");

  /* Behind the phone's status bar when installed (its text is always white). */
  --ui-status-scrim: linear-gradient(rgba(22, 23, 26, 0.32), rgba(22, 23, 26, 0.08));

  /* iOS navigation curve: fast start, long soft settle. */
  --ease-ios: cubic-bezier(0.32, 0.72, 0, 1);

  /* Liquid Glass (phone tab bar and round buttons): the powder glass tint,
     lit from above, with a bright rim. The lens marks the current tab. */
  --ui-liquid-sheen: linear-gradient(
    180deg,
    rgba(255, 255, 255, 0.65),
    rgba(255, 255, 255, 0.12) 55%,
    rgba(255, 255, 255, 0.24)
  );
  --ui-liquid-rim: rgba(255, 255, 255, 0.6);
  --ui-liquid-shadow: 0 10px 30px rgba(22, 23, 26, 0.14), 0 2px 6px rgba(22, 23, 26, 0.08);
  --ui-liquid-lens: linear-gradient(180deg, rgba(255, 255, 255, 0.95), rgba(243, 250, 251, 0.72));
  --ui-liquid-lens-edge: inset 0 1px 0 rgba(255, 255, 255, 0.9), inset 0 0 0 0.5px rgba(22, 23, 26, 0.06);

  color-scheme: light;
}

/* ═════════════ Tokens: dark ═════════════ */
/* Raven page, powder-blue headings and links, poppy accents. */
:root[saved-theme="dark"] {
  /* Base palette (Notes: quartz.config.yaml → theme.colors.darkMode) */
  --light: #16171a;
  --lightgray: #2c3036;
  --gray: #5f7075;
  --darkgray: #ddeff2;
  --dark: #b0e0e6;
  --secondary: #b0e0e6;
  --tertiary: #e35335;
  --highlight: rgba(176, 224, 230, 0.06);
  --textHighlight: rgba(227, 83, 53, 0.3);

  --ui-page: var(--brand-raven);
  --ui-sidebar: #1d1f23;
  --ui-sidebar-edge: #2c3036;
  --ui-surface: #212429;
  --ui-surface-2: #1b1d21;
  --ui-hover: rgba(176, 224, 230, 0.06);
  --ui-active: rgba(176, 224, 230, 0.1);
  --ui-border: rgba(176, 224, 230, 0.1);
  --ui-border-strong: rgba(176, 224, 230, 0.2);
  --ui-text: #ddeff2;
  --ui-heading: var(--brand-powder);
  --ui-muted: #93a9ae;
  --ui-faint: #5f7075;

  --ui-link: var(--brand-powder);
  --ui-link-line: var(--brand-poppy);
  --ui-accent: var(--brand-poppy);
  --ui-accent-soft: rgba(227, 83, 53, 0.24);
  --ui-on-accent: var(--brand-raven);
  --ui-pill-bg: var(--brand-poppy);
  --ui-pill-text: var(--brand-raven);

  --ui-glass: rgba(29, 31, 35, 0.72);
  --ui-glass-strong: rgba(33, 36, 41, 0.84);
  --ui-drawer-tint: rgba(22, 23, 26, 0.82);
  --ui-scrim: rgba(5, 6, 7, 0.5);
  --ui-sheen: linear-gradient(180deg, rgba(176, 224, 230, 0.05) 0%, rgba(176, 224, 230, 0) 100%);
  --ui-highlight: inset 0 1px 0 rgba(176, 224, 230, 0.06);
  --ui-shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --ui-shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.35);
  --ui-shadow-lg: 0 2px 8px rgba(0, 0, 0, 0.4), 0 28px 70px rgba(0, 0, 0, 0.6);
  --ui-callout-rgb: 227, 83, 53;

  --tier-great: #30d158;
  --tier-good: #a8d64a;
  --tier-okay: #ffb340;
  --tier-bad: #ff453a;

  --ui-icon-search: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 19.9 19.7'%3E%3Cg fill='none' stroke='%2393a9ae' stroke-width='1.5'%3E%3Cpath stroke-linecap='square' d='M18.5 18.3l-5.4-5.4'/%3E%3Ccircle cx='8' cy='8' r='7'/%3E%3C/g%3E%3C/svg%3E");
  --ui-icon-chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%2393a9ae' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");

  --ui-status-scrim: rgba(22, 23, 26, 0.55);

  --ui-liquid-sheen: linear-gradient(
    180deg,
    rgba(176, 224, 230, 0.14),
    rgba(176, 224, 230, 0.03) 55%,
    rgba(176, 224, 230, 0.07)
  );
  --ui-liquid-rim: rgba(176, 224, 230, 0.14);
  --ui-liquid-shadow: 0 10px 30px rgba(0, 0, 0, 0.5), 0 2px 6px rgba(0, 0, 0, 0.35);
  --ui-liquid-lens: linear-gradient(180deg, rgba(176, 224, 230, 0.18), rgba(176, 224, 230, 0.08));
  --ui-liquid-lens-edge: inset 0 1px 0 rgba(176, 224, 230, 0.18), inset 0 0 0 0.5px rgba(176, 224, 230, 0.1);

  color-scheme: dark;
}

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

/* Over-scroll ("rubber-band"): browsers fill the area past the page with the
   root element's background colour only, so the page colour sits on <html>.
   App feel: no pinch / double-tap zoom, no text inflation. */
html {
  background-color: var(--ui-page);
  overflow-x: clip;
  touch-action: pan-x pan-y;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  transition: background-color var(--dur-slow) var(--ease);
}

/* No transitions until the page is set up. <html> has a style before the
   stylesheets arrive, so without this it would fade in from white on every
   load. js/ui.js adds .ui-ready; after that, colours cross-fade on toggle. */
html:not(.ui-ready),
html:not(.ui-ready) *,
html:not(.ui-ready) *::before,
html:not(.ui-ready) *::after {
  transition: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  background-color: transparent; /* must stay clear: the sidebar strip sits under it */
  color: var(--ui-text);
  font-family: var(--bodyFont);
  font-size: 1rem;
  line-height: 1.5;
  letter-spacing: -0.003em;
  overflow-x: clip;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  -webkit-tap-highlight-color: transparent;
}

/* Installed as an app, pages scroll under the phone's status bar, so it gets
   a frosted edge that fades out below it (iOS's scroll-edge effect). The
   tint keeps the status bar's white text readable in light mode. Its height
   is 0 everywhere else (no status-bar inset). */
body::after {
  content: "";
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 60;
  height: calc(env(safe-area-inset-top) * 1.35);
  pointer-events: none;
  background: var(--ui-status-scrim);
  --ui-backdrop: blur(16px) saturate(180%);
  -webkit-backdrop-filter: var(--ui-backdrop);
  backdrop-filter: var(--ui-backdrop);
  -webkit-mask-image: linear-gradient(#000 70%, transparent);
  mask-image: linear-gradient(#000 70%, transparent);
}

::selection {
  background: var(--ui-accent-soft);
  color: var(--ui-heading);
}

/* ═════════════ Type ═════════════ */
h1,
h2,
h3,
h4,
h5,
h6 {
  font-family: var(--headerFont);
  color: var(--ui-heading);
  font-weight: 650;
  letter-spacing: -0.022em;
  line-height: 1.15;
  margin: 0 0 0.5em;
}

h1 {
  font-size: 2.4rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.1;
  margin-bottom: 0.5rem;
  overflow-wrap: break-word;
}

h2 { font-size: 1.55rem; }
h3 { font-size: 1.25rem; }

p { margin: 0 0 1em; }

strong {
  color: var(--ui-heading);
  font-weight: 650;
}

.muted { color: var(--ui-muted); }

/* No long-press link previews or image save menus */
a,
img {
  -webkit-touch-callout: none;
}

a {
  font-weight: 500;
  color: var(--ui-link);
  text-decoration: none;
  transition:
    color var(--dur-fast) var(--ease),
    background-color var(--dur-fast) var(--ease),
    text-decoration-color var(--dur-fast) var(--ease);
}

/* Links inside text: poppy underline that fills on hover (Notes' internal links). */
.prose a,
.review a,
.detail-hero-sub a,
.empty-state a:not(.button),
.section-link,
.track-nav a {
  padding: 0;
  border-radius: 3px;
  text-decoration: underline;
  text-decoration-thickness: 2px;
  text-underline-offset: 0.2em;
  text-decoration-color: var(--ui-link-line);
  overflow-wrap: anywhere;
}

.prose a:hover,
.review a:hover,
.detail-hero-sub a:hover,
.empty-state a:not(.button):hover,
.section-link:hover,
.track-nav a:hover {
  text-decoration-color: var(--ui-accent);
  background-color: var(--ui-accent-soft);
}

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

a:focus-visible,
button:focus-visible {
  outline: 2px solid var(--ui-accent);
  outline-offset: 2px;
}

/* ═════════════ Fields: the search-pill look ═════════════ */
/* 16px text stops iPhones zooming in on focus. */
input[type="search"],
input[type="text"],
input[type="number"],
select,
textarea {
  font: inherit;
  font-size: 16px;
  color: var(--ui-heading);
  border: 1px solid var(--ui-border);
  border-radius: 999px;
  padding: 0.6em 1.1em;
  background-color: var(--ui-surface);
  background-image: var(--ui-sheen);
  box-shadow: var(--ui-shadow-sm), var(--ui-highlight);
  transition:
    background-color var(--dur-slow) var(--ease),
    border-color var(--dur) var(--ease),
    color var(--dur-slow) var(--ease),
    box-shadow var(--dur) var(--ease);
}

input::placeholder,
textarea::placeholder {
  color: var(--ui-faint);
  font-weight: 450;
}

input:hover,
select:hover,
textarea:hover {
  border-color: var(--ui-border-strong);
}

input[type="search"],
input[type="text"],
input[type="number"],
select,
textarea {
  outline: none;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--ui-border-strong);
  box-shadow: var(--ui-shadow), var(--ui-highlight), 0 0 0 3px var(--ui-accent-soft);
}

input[type="search"] {
  -webkit-appearance: none;
  appearance: none;
  padding-left: 2.5em;
  background-image: var(--ui-icon-search), var(--ui-sheen);
  background-repeat: no-repeat;
  background-position: 0.95em center, 0 0;
  background-size: 16px 16px, 100% 100%;
}

select {
  appearance: none;
  padding-right: 2.4em;
  background-image: var(--ui-icon-chevron), var(--ui-sheen);
  background-repeat: no-repeat;
  background-position: right 1em center, 0 0;
  background-size: 10px 6px, 100% 100%;
  cursor: pointer;
}

textarea {
  border-radius: var(--radius);
  padding: 0.85em 1.1em;
  line-height: 1.6;
  resize: vertical;
}

/* ═════════════ Scrollbars ═════════════ */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--ui-border-strong) transparent;
}

::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

::-webkit-scrollbar-thumb {
  background: var(--ui-border-strong);
  border: 3px solid transparent;
  border-radius: 999px;
  background-clip: padding-box;
}

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

/* No scrollbars on phones; swiping still scrolls. */
@media (max-width: 800px) {
  * {
    scrollbar-width: none;
  }

  ::-webkit-scrollbar {
    display: none;
    width: 0;
    height: 0;
  }

  /* iOS large titles (34pt) */
  h1 { font-size: 2.125rem; }
  h2 { font-size: 1.35rem; }
}

/* ═════════════ Motion ═════════════ */

/* Page entrance. js/nav.js inserts a new <main> on every navigation, so this
   replays each time. `backwards`, not `both`: a held transform would linger. */
@keyframes ui-page-enter {
  from {
    opacity: 0;
    transform: translateY(10px);
    filter: blur(3px);
  }
  to {
    opacity: 1;
    transform: none;
    filter: none;
  }
}

@keyframes ui-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes ui-sheet-in {
  from {
    opacity: 0;
    transform: translateY(-8px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* Phones: iOS navigation. Going deeper (album → song) slides the new page in
   from the right, going back slides it in from the left; switching tabs
   cross-fades. js/nav.js picks the direction (html[data-nav]). */
@keyframes ios-push-in {
  from {
    opacity: 0;
    transform: translateX(32%);
  }
  40% {
    opacity: 1;
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@keyframes ios-pop-in {
  from {
    opacity: 0;
    transform: translateX(-24%);
  }
  40% {
    opacity: 1;
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* Sun/moon icon spins in when the theme flips. */
@keyframes ui-icon-in {
  from {
    opacity: 0;
    transform: rotate(-90deg) scale(0.6);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

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