/* Jotling design system.
   One hand-authored stylesheet: tokens, primitives, components. No framework,
   no CDN, no build step. See docs/design.md for the rationale behind each
   scale; change tokens here rather than hard-coding values in components. */

/* ---------------------------------------------------------------- tokens */

:root {
  color-scheme: light dark;

  /* Neutrals — light */
  --bg: #fbfbfd;
  --bg-sunken: #f4f4f7;
  --surface: #ffffff;
  --surface-hover: #f7f7fa;
  --border: #e6e6ec;
  --border-strong: #d3d3dd;
  --text: #16161d;
  --text-muted: #66667a;
  --text-faint: #90909f;

  /* Accent */
  --accent: #5b45e0;
  --accent-hover: #4c37c9;
  --accent-fg: #ffffff;
  --accent-text: #5237d6;
  --accent-soft: #efecfd;

  /* Status */
  --danger: #d92d3c;
  --danger-soft: #fdecee;
  --success: #0f8a5f;
  --success-soft: #e7f6ef;
  --warning-text: #8a5a00;
  --warning-soft: #fdf3e2;

  --ring: color-mix(in srgb, var(--accent) 45%, transparent);
  --overlay: rgb(20 20 28 / 42%);
  --shadow-overlay: 0 24px 60px -16px rgb(16 16 24 / 28%);

  /* Type */
  --font-sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
    "Liberation Mono", monospace;
  --text-xs: 0.75rem;
  --text-sm: 0.8125rem;
  --text-base: 0.9375rem;
  --text-lg: 1.0625rem;
  --text-xl: clamp(1.25rem, 0.9rem + 1.1vw, 1.5rem);
  --text-2xl: clamp(1.75rem, 1.1rem + 2.4vw, 2.75rem);

  /* Space */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.5rem;
  --space-6: 2rem;
  --space-7: 3rem;
  --space-8: 4.5rem;

  --radius-sm: 7px;
  --radius: 11px;
  --radius-lg: 16px;
  --radius-full: 999px;

  --measure: 68rem;
  --duration: 140ms;
  --ease: cubic-bezier(0.2, 0.6, 0.2, 1);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b0b0f;
    --bg-sunken: #08080b;
    --surface: #141419;
    --surface-hover: #1b1b22;
    --border: #26262f;
    --border-strong: #35353f;
    --text: #ededf2;
    --text-muted: #9a9aab;
    --text-faint: #6e6e80;

    --accent: #6d59f0;
    --accent-hover: #7d6bf5;
    --accent-fg: #ffffff;
    --accent-text: #a897ff;
    --accent-soft: #1d1936;

    --danger: #f2606e;
    --danger-soft: #2a1418;
    --success: #3ecf99;
    --success-soft: #0e2620;
    --warning-text: #f0c274;
    --warning-soft: #2a2013;

    --overlay: rgb(4 4 8 / 62%);
    --shadow-overlay: 0 24px 60px -16px rgb(0 0 0 / 70%);
  }
}

:root[data-theme="dark"] {
  --bg: #0b0b0f;
  --bg-sunken: #08080b;
  --surface: #141419;
  --surface-hover: #1b1b22;
  --border: #26262f;
  --border-strong: #35353f;
  --text: #ededf2;
  --text-muted: #9a9aab;
  --text-faint: #6e6e80;

  --accent: #6d59f0;
  --accent-hover: #7d6bf5;
  --accent-fg: #ffffff;
  --accent-text: #a897ff;
  --accent-soft: #1d1936;

  --danger: #f2606e;
  --danger-soft: #2a1418;
  --success: #3ecf99;
  --success-soft: #0e2620;
  --warning-text: #f0c274;
  --warning-soft: #2a2013;

  --overlay: rgb(4 4 8 / 62%);
  --shadow-overlay: 0 24px 60px -16px rgb(0 0 0 / 70%);
}

/* ------------------------------------------------------------- baseline */

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

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

body {
  margin: 0;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1,
h2,
h3 {
  margin: 0;
  font-weight: 600;
  letter-spacing: -0.021em;
  line-height: 1.2;
}

h1 { font-size: var(--text-xl); }
h2 { font-size: var(--text-lg); }

p { margin: 0; }

a {
  color: var(--accent-text);
  text-decoration: none;
  text-underline-offset: 0.18em;
}

a:hover { text-decoration: underline; }

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

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

svg {
  display: block;
  flex: none;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* --------------------------------------------------------------- layout */

.shell {
  width: 100%;
  max-width: var(--measure);
  margin-inline: auto;
  padding-inline: var(--space-5);
}

.main {
  flex: 1;
  width: 100%;
  padding-block: var(--space-7) var(--space-8);
}

.main--bare {
  padding: 0;
  display: flex;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.page-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-5);
}

.page-head__title { display: grid; gap: 2px; }

.page-head__sub {
  color: var(--text-muted);
  font-size: var(--text-sm);
}

.actions {
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
}

/* ------------------------------------------------------------------ nav */

.nav {
  position: sticky;
  top: 0;
  z-index: 20;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(1.4) blur(12px);
}

.nav__inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  height: 58px;
}

.wordmark {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-lg);
  font-weight: 600;
  letter-spacing: -0.03em;
  color: var(--text);
}

.wordmark:hover { text-decoration: none; }

.wordmark__mark {
  width: 22px;
  height: 22px;
  border-radius: 7px;
  background: var(--accent);
  display: grid;
  place-items: center;
  color: var(--accent-fg);
}

.nav__links {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  list-style: none;
  margin: 0;
  padding: 0;
}

.nav__link {
  padding: var(--space-2) var(--space-3);
  white-space: nowrap;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: var(--text-sm);
  font-weight: 500;
  transition: color var(--duration) var(--ease),
    background-color var(--duration) var(--ease);
}

.nav__link:hover {
  color: var(--text);
  background: var(--surface-hover);
  text-decoration: none;
}

.nav__link[aria-current="page"] {
  color: var(--text);
  background: var(--surface-hover);
}

[hidden] { display: none !important; }

/* -------------------------------------------------------------- buttons */

.btn {
  --btn-bg: var(--surface);
  --btn-fg: var(--text);
  --btn-border: var(--border-strong);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: 0 var(--space-4);
  height: 36px;
  border: 1px solid var(--btn-border);
  border-radius: var(--radius-sm);
  background: var(--btn-bg);
  color: var(--btn-fg);
  font: inherit;
  font-size: var(--text-sm);
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color var(--duration) var(--ease),
    border-color var(--duration) var(--ease),
    color var(--duration) var(--ease), transform var(--duration) var(--ease);
}

.btn:hover { background: var(--surface-hover); }
.btn:active { transform: translateY(0.5px); }

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn--primary {
  --btn-bg: var(--accent);
  --btn-fg: var(--accent-fg);
  --btn-border: transparent;
}

.btn--primary:hover { background: var(--accent-hover); }

.btn--danger {
  --btn-bg: var(--danger);
  --btn-fg: #fff;
  --btn-border: transparent;
}

.btn--danger:hover {
  background: color-mix(in srgb, var(--danger) 86%, #000);
}

.btn--ghost {
  --btn-bg: transparent;
  --btn-border: transparent;
  color: var(--text-muted);
}

.btn--ghost:hover { color: var(--text); }

.btn--block { width: 100%; }

.btn--icon {
  width: 32px;
  height: 32px;
  padding: 0;
  border-color: transparent;
  background: transparent;
  color: var(--text-faint);
  border-radius: var(--radius-sm);
}

.btn--icon:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.btn--icon.is-danger:hover { color: var(--danger); }
.btn--icon.is-done { color: var(--success); }

/* ----------------------------------------------------------------- form */

.field { display: grid; gap: var(--space-2); }

.field__label {
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--text);
}

.field__hint {
  font-size: var(--text-xs);
  color: var(--text-faint);
}

.input {
  width: 100%;
  height: 40px;
  padding: 0 var(--space-3);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: var(--text-base);
  transition: border-color var(--duration) var(--ease),
    box-shadow var(--duration) var(--ease);
}

.input::placeholder { color: var(--text-faint); }

.input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--ring);
}

select.input {
  appearance: none;
  padding-right: var(--space-6);
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%),
    linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: right 18px center, right 13px center;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}

.input-group { position: relative; }

.input-group .input { padding-right: 44px; }

.input-group__action {
  position: absolute;
  top: 50%;
  right: 4px;
  transform: translateY(-50%);
}

/* ---------------------------------------------------------------- cards */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
}

.card--flush { padding: 0; overflow: hidden; }

.panel {
  width: 100%;
  max-width: 25rem;
  margin-inline: auto;
}

.hero {
  text-align: center;
  margin-bottom: var(--space-6);
}

.hero__title {
  font-size: var(--text-2xl);
  font-weight: 640;
  letter-spacing: -0.035em;
}

.hero__sub {
  margin-top: var(--space-2);
  color: var(--text-muted);
}

/* ---------------------------------------------------------------- table */

.table-wrap { overflow-x: auto; }

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
  /* Fixed layout: a long destination widens its ellipsis, never the table.
     Without it the content sizes the columns and the last one is pushed
     past the scroll container, hiding the row actions. */
  table-layout: fixed;
}

.col-code { width: 8rem; }
.col-link { width: 19rem; }
.col-note { width: 13rem; }
.col-key { width: 12rem; }
.col-status { width: 8rem; }
.col-actions { width: 5.5rem; }

.table th {
  padding: var(--space-3) var(--space-4);
  text-align: left;
  font-size: var(--text-xs);
  font-weight: 500;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-faint);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.table td {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  overflow: hidden;
}

.table tbody tr:last-child td { border-bottom: 0; }

.table tbody tr {
  transition: background-color var(--duration) var(--ease);
}

.table tbody tr:hover { background: var(--surface-hover); }

.table td:last-child,
.table th:last-child { text-align: right; }

.cell-actions {
  display: inline-flex;
  gap: var(--space-1);
  justify-content: flex-end;
}

.truncate {
  display: block;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mono {
  font-family: var(--font-mono);
  font-size: 0.8125em;
}

.muted { color: var(--text-muted); }
.faint { color: var(--text-faint); }

/* Block-level, so the media links below always start their own line and
   every row in the table keeps the same height. */
.inline-copy {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  min-width: 0;
}

.media-links {
  display: flex;
  gap: var(--space-3);
  margin-top: 2px;
  font-size: var(--text-xs);
}

/* --------------------------------------------------------------- badges */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px var(--space-2);
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: 500;
  background: var(--bg-sunken);
  color: var(--text-muted);
}

.badge::before {
  content: "";
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: currentColor;
}

.badge--active { background: var(--success-soft); color: var(--success); }
.badge--inactive { background: var(--danger-soft); color: var(--danger); }

/* ------------------------------------------------------- states, notices */

.notice {
  display: flex;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius);
  font-size: var(--text-sm);
  background: var(--bg-sunken);
  color: var(--text-muted);
}

.notice--error {
  background: var(--danger-soft);
  color: var(--danger);
}

.notice--warn {
  background: var(--warning-soft);
  color: var(--warning-text);
}

.empty {
  padding: var(--space-7) var(--space-5);
  text-align: center;
  display: grid;
  gap: var(--space-2);
  justify-items: center;
}

.empty__title { font-weight: 550; }
.empty__body { color: var(--text-muted); font-size: var(--text-sm); }

.loading {
  padding: var(--space-7);
  text-align: center;
  color: var(--text-faint);
  font-size: var(--text-sm);
}

.spinner {
  width: 16px;
  height: 16px;
  margin: 0 auto var(--space-2);
  border: 2px solid var(--border-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 700ms linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* --------------------------------------------------------------- dialog */

dialog.modal {
  width: min(30rem, calc(100vw - 2rem));
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-overlay);
}

dialog.modal::backdrop {
  background: var(--overlay);
  backdrop-filter: blur(2px);
}

dialog.modal[open] { animation: pop var(--duration) var(--ease); }

@keyframes pop {
  from { opacity: 0; transform: translateY(6px) scale(0.99); }
}

.modal__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--border);
}

.modal__body {
  padding: var(--space-5);
  display: grid;
  gap: var(--space-4);
}

.modal__foot {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-2);
  padding: var(--space-4) var(--space-5);
  border-top: 1px solid var(--border);
  background: var(--bg-sunken);
}

/* ---------------------------------------------------------------- toast */

.toasts {
  position: fixed;
  inset-inline: 0;
  bottom: var(--space-5);
  z-index: 60;
  display: grid;
  gap: var(--space-2);
  justify-items: center;
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  background: var(--surface);
  color: var(--text);
  font-size: var(--text-sm);
  box-shadow: var(--shadow-overlay);
  animation: rise var(--duration) var(--ease);
}

.toast--error { color: var(--danger); }

@keyframes rise {
  from { opacity: 0; transform: translateY(8px); }
}

/* --------------------------------------------------------------- footer */

.footer {
  border-top: 1px solid var(--border);
  padding-block: var(--space-4);
  color: var(--text-faint);
  font-size: var(--text-xs);
}

.footer__inner {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  align-items: center;
  justify-content: space-between;
}

/* ------------------------------------------------------ media, coming soon */

.stage {
  flex: 1;
  display: grid;
  place-items: center;
  background: #000;
  min-height: 100dvh;
}

.stage video {
  width: 100%;
  height: 100dvh;
  object-fit: contain;
}

.audio-card { display: grid; gap: var(--space-4); justify-items: center; }
.audio-card audio { width: 100%; }

.centered {
  min-height: 60vh;
  display: grid;
  place-items: center;
  text-align: center;
}

.code-block {
  padding: var(--space-3);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--bg-sunken);
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  word-break: break-all;
  user-select: all;
}

/* ---------------------------------------------------------- narrow screens */

/* The nav has to survive a 320px viewport before the table layout changes. */
@media (max-width: 30rem) {
  .nav__inner { gap: var(--space-2); }
  .nav__links { gap: 0; }
  .nav__link { padding-inline: var(--space-2); }
  .wordmark { font-size: var(--text-base); }
  .btn--ghost { padding-inline: var(--space-2); }
}

@media (max-width: 40rem) {
  .shell { padding-inline: var(--space-4); }
  .main { padding-block: var(--space-5) var(--space-6); }

  /* Rows become stacked cards, so the column template no longer applies. */
  .table { table-layout: auto; }
  .table colgroup { display: none; }
  .table thead { display: none; }

  .table tr {
    display: grid;
    gap: var(--space-2);
    padding: var(--space-4);
    border-bottom: 1px solid var(--border);
  }

  .table td {
    display: grid;
    grid-template-columns: 7.5rem 1fr;
    align-items: baseline;
    gap: var(--space-2) var(--space-3);
    padding: 0;
    border: 0;
  }

  .table td::before {
    content: attr(data-label);
    font-size: var(--text-xs);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-faint);
  }

  /* The label owns column one; every value in the cell stacks in column two,
     so a second line (the media links) stays aligned under the first. */
  .table td > * {
    grid-column: 2;
  }

  .table td:last-child { text-align: left; }
  .table td { overflow: visible; }
  .cell-actions { justify-content: flex-start; }
}

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