/* ================================================================
   MelodyLog - shared styles (base, index, auth)
   Design tokens: ink + terracotta accent, cool neutrals, Outfit type.
   Radius lock: buttons full-pill, frames 16px, inputs 10px.
   Motion (Emil-style): custom easings only, entries from >=.95 scale,
   :active scale(.97), hover gated to fine pointers, reduced-motion ok.
   ================================================================ */

:root {
  /* palette */
  --ink: #1c1d22;
  --ink-2: #565a66;
  --ink-3: #8a8f9d;
  --bg: #f7f7f8;
  --surface: #ffffff;
  --surface-2: #efeff1;
  --border: rgba(28, 29, 34, 0.09);
  --border-2: rgba(28, 29, 34, 0.16);
  --accent: #c85f3d;          /* terracotta, the single accent */
  --accent-strong: #b4502e;  /* AA on white */
  --accent-soft: rgba(200, 95, 61, 0.09);
  --accent-border: rgba(200, 95, 61, 0.28);
  --danger: #c23b3b;
  --shadow-sm: 0 1px 2px rgba(20, 21, 26, 0.05);
  --shadow-md: 0 4px 14px rgba(20, 21, 26, 0.07);
  --shadow-lg: 0 18px 44px -22px rgba(20, 21, 26, 0.22);
  --header-bg: rgba(255, 255, 255, 0.86);
  /* composer palette (light) */
  --cc0: #6b7fa8; --cc1: #b0714e; --cc2: #6f8f6a; --cc3: #a98a3f;
  --cc4: #a06a7e; --cc5: #4e8d8a; --cc6: #7a6f9e;
  /* motion */
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --ease-in-out: cubic-bezier(0.77, 0, 0.175, 1);
}

@media (prefers-color-scheme: dark) {
  :root {
    --ink: #e9e9ee;
    --ink-2: #a7abb8;
    --ink-3: #6f7480;
    --bg: #131418;
    --surface: #1b1c22;
    --surface-2: #22242c;
    --border: rgba(255, 255, 255, 0.09);
    --border-2: rgba(255, 255, 255, 0.18);
    --accent: #e08661;
    --accent-strong: #e08661;
    --accent-soft: rgba(224, 134, 97, 0.13);
    --accent-border: rgba(224, 134, 97, 0.34);
    --danger: #e06565;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.35);
    --shadow-lg: 0 18px 44px -18px rgba(0, 0, 0, 0.6);
    --header-bg: rgba(19, 20, 24, 0.82);
    --cc0: #93a8d4; --cc1: #d59a70; --cc2: #92bd8a; --cc3: #d2b26a;
    --cc4: #cd94a9; --cc5: #6fc2be; --cc6: #b9a6e0;
  }
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  font-family: 'Outfit', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

img, svg { display: block; max-width: 100%; }
a { color: var(--accent-strong); }
button { font-family: inherit; }

/* Anchor targets must clear the sticky site header (65px) and land the
   whole section heading in view. Applied to every scroll target. */
section[id] { scroll-margin-top: 84px; }

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

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

.mono {
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}

/* ============ Header ============ */
.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--header-bg);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border-bottom: 1px solid var(--border);
}
.header-inner {
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 1.25rem;
  height: 64px;
  display: flex;
  align-items: center;
  gap: 1.5rem;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  font-weight: 700;
  font-size: 1.06rem;
  letter-spacing: -0.02em;
  color: var(--ink);
  text-decoration: none;
  white-space: nowrap;
}
.brand-mark {
  width: 30px;
  height: 30px;
  border-radius: 9px;
  background: var(--ink);
  color: var(--bg);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.95rem;
  flex-shrink: 0;
}
.header-nav {
  display: flex;
  gap: 0.35rem;
  margin-left: 0.5rem;
}
.header-nav a {
  padding: 0.4rem 0.8rem;
  border-radius: 999px;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--ink-2);
  text-decoration: none;
  transition: color 160ms var(--ease-out), background 160ms var(--ease-out);
}
@media (hover: hover) and (pointer: fine) {
  .header-nav a:hover { color: var(--ink); background: var(--surface-2); }
}
.header-auth {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 0.6rem;
}
.btn.header-burger {
  display: none;
  margin-left: auto;
}
@media (max-width: 760px) {
  .header-nav { display: none; }
  .btn.header-burger { display: inline-flex; }
  .header-nav.open {
    display: flex;
    flex-direction: column;
    position: absolute;
    top: 64px;
    left: 0;
    right: 0;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 0.6rem 1rem 1rem;
    gap: 0.2rem;
    box-shadow: var(--shadow-lg);
  }
  .header-nav.open a { padding: 0.65rem 0.9rem; font-size: 1rem; }
}
@media (max-width: 480px) {
  .header-auth .btn-ghost { display: none; }  /* keep one CTA on small phones */
}

/* ============ Buttons ============ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  padding: 0.5rem 1.2rem;
  border-radius: 999px;
  font-weight: 600;
  font-size: 0.9rem;
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition:
    transform 160ms var(--ease-out),
    background 200ms var(--ease-out),
    border-color 200ms var(--ease-out),
    color 200ms var(--ease-out),
    box-shadow 200ms var(--ease-out),
    opacity 200ms var(--ease-out);
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.45; cursor: default; }

.btn-primary { background: var(--ink); color: var(--bg); box-shadow: var(--shadow-sm); }
@media (hover: hover) and (pointer: fine) {
  .btn-primary:hover { background: #2e3038; box-shadow: var(--shadow-md); }
}
@media (prefers-color-scheme: dark) {
  @media (hover: hover) and (pointer: fine) {
    .btn-primary:hover { background: #2c2e37; }
  }
}

.btn-accent { background: var(--accent-strong); color: #fff; box-shadow: var(--shadow-sm); }
@media (hover: hover) and (pointer: fine) {
  .btn-accent:hover { background: #9c4224; box-shadow: var(--shadow-md); }
}
@media (prefers-color-scheme: dark) {
  .btn-accent { background: var(--accent); color: #141517; }
  @media (hover: hover) and (pointer: fine) {
    .btn-accent:hover { background: #e99a78; }
  }
}

.btn-ghost {
  background: transparent;
  color: var(--ink);
  border-color: var(--border-2);
}
@media (hover: hover) and (pointer: fine) {
  .btn-ghost:hover { border-color: var(--ink-3); background: var(--surface-2); }
}

.btn-sm { padding: 0.32rem 0.85rem; font-size: 0.82rem; }
.btn-lg { padding: 0.68rem 1.5rem; font-size: 0.98rem; }

/* ============ User menu ============ */
.user-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent-strong);
  border: 1px solid var(--accent-border);
  font-weight: 700;
  font-size: 0.85rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 160ms var(--ease-out);
}
.user-avatar:active { transform: scale(0.94); }
.user-menu {
  position: relative;
}
.user-dropdown {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  min-width: 230px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow-lg);
  padding: 0.45rem;
  transform-origin: top right;
  opacity: 0;
  transform: scale(0.95);
  /* visibility keeps the closed dropdown out of hit-testing (no ghost
     clicks on page content underneath); delayed so the fade can play */
  visibility: hidden;
  transition: opacity 140ms var(--ease-out), transform 140ms var(--ease-out),
    visibility 0s linear 140ms;
  z-index: 60;
}
.user-menu.open .user-dropdown {
  opacity: 1;
  transform: scale(1);
  visibility: visible;
  transition: opacity 140ms var(--ease-out), transform 140ms var(--ease-out);
}
.dropdown-head {
  padding: 0.55rem 0.7rem 0.6rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 0.35rem;
  font-size: 0.8rem;
  color: var(--ink-2);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.dropdown-item {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  width: 100%;
  padding: 0.5rem 0.7rem;
  border: none;
  background: none;
  border-radius: 9px;
  font-size: 0.87rem;
  font-weight: 500;
  color: var(--ink);
  cursor: pointer;
  text-align: left;
  transition: background 140ms var(--ease-out);
}
@media (hover: hover) and (pointer: fine) {
  .dropdown-item:hover { background: var(--surface-2); }
}
.dropdown-item i { width: 16px; color: var(--ink-3); font-size: 0.8rem; }

/* ============ Toast ============ */
.toast-wrap {
  position: fixed;
  top: 76px;
  right: 16px;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.toast {
  background: var(--surface);
  border: 1px solid var(--accent-border);
  border-left: 3px solid var(--accent);
  border-radius: 10px;
  padding: 10px 15px;
  font-size: 0.85rem;
  box-shadow: var(--shadow-lg);
  max-width: 320px;
  opacity: 0;
  transform: translateY(-6px) scale(0.98);
  transition: transform 220ms var(--ease-out), opacity 220ms ease-out;
}
.toast.in { opacity: 1; transform: translateY(0) scale(1); }
.toast.err { border-color: var(--danger); border-left-color: var(--danger); }

/* ============ Modal ============ */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(16, 17, 21, 0.5);
  backdrop-filter: blur(3px);
  z-index: 90;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 200ms ease-out;
}
.modal-backdrop.open { opacity: 1; pointer-events: auto; }
.modal {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  padding: 1.4rem 1.5rem 1.5rem;
  transform: scale(0.95);
  transition: transform 220ms var(--ease-out);
}
.modal-backdrop.open .modal { transform: scale(1); }
.modal h3 { font-size: 1.05rem; letter-spacing: -0.01em; margin-bottom: 0.3rem; }
.modal .modal-sub { font-size: 0.82rem; color: var(--ink-2); margin-bottom: 1rem; }

/* ============ Forms ============ */
.field { display: flex; flex-direction: column; gap: 0.35rem; margin-bottom: 0.85rem; }
.field label { font-size: 0.78rem; font-weight: 600; color: var(--ink-2); }
.field input, .field select {
  padding: 0.55rem 0.8rem;
  border-radius: 10px;
  border: 1px solid var(--border-2);
  background: var(--surface);
  color: var(--ink);
  font-size: 0.9rem;
  font-family: inherit;
  min-width: 0;
  transition: border-color 160ms var(--ease-out), box-shadow 160ms var(--ease-out);
}
.field input:focus, .field select:focus {
  border-color: var(--accent);
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.field .hint { font-size: 0.74rem; color: var(--ink-3); }
.field .err { font-size: 0.76rem; color: var(--danger); min-height: 1em; }

/* ============ Chips & pills ============ */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.34rem 0.85rem;
  border-radius: 999px;
  border: 1px solid var(--border-2);
  background: var(--surface);
  color: var(--ink-2);
  font-size: 0.8rem;
  font-weight: 550;
  cursor: pointer;
  transition: transform 140ms var(--ease-out), background 160ms var(--ease-out),
    color 160ms var(--ease-out), border-color 160ms var(--ease-out);
}
.chip:active { transform: scale(0.96); }
.chip i.dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.chip .count { color: var(--ink-3); font-variant-numeric: tabular-nums; font-size: 0.74rem; }
@media (hover: hover) and (pointer: fine) {
  .chip:hover { border-color: var(--ink-3); color: var(--ink); }
}
.chip.on {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--bg);
}
.chip.on .count { color: inherit; opacity: 0.65; }

/* ============ Reveal on scroll ============ */
.reveal {
  opacity: 0;
  transform: translateY(22px);
  transition: opacity 0.65s var(--ease-out), transform 0.65s var(--ease-out);
}
.reveal.visible { opacity: 1; transform: translateY(0); }

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .reveal { opacity: 1 !important; transform: none !important; transition: none; }
  .toast, .user-dropdown, .modal, .modal-backdrop { transition: none; }
  .chip, .btn, .user-avatar { transition: none; }
}

/* ============ Footer ============ */
.site-footer {
  border-top: 1px solid var(--border);
  margin-top: auto;
  padding: 1.6rem 0;
}
.footer-inner {
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 1.25rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.8rem 2rem;
  align-items: center;
  justify-content: space-between;
  font-size: 0.82rem;
  color: var(--ink-3);
}
.footer-inner nav { display: flex; gap: 1.2rem; flex-wrap: wrap; }
.footer-inner a { color: var(--ink-3); text-decoration: none; transition: color 160ms var(--ease-out); }
@media (hover: hover) and (pointer: fine) {
  .footer-inner a:hover { color: var(--ink); }
}

/* noscript: reveal content without JS */
noscript .reveal { opacity: 1; transform: none; }

/* search inputs: hide the native browser clear ✕ so only the app's own
   clear button shows (Chromium/WebKit add one for type=search) */
input[type="search"]::-webkit-search-cancel-button,
input[type="search"]::-webkit-search-decoration {
  -webkit-appearance: none;
  appearance: none;
  display: none;
}
