@font-face {
  font-family: 'ABC Diatype';
  src: url('../fonts/ABCDiatype-Regular-Trial.otf') format('opentype');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'ABC Diatype';
  src: url('../fonts/ABCDiatype-Bold.otf') format('opentype');
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'ABC Diatype Mono';
  src: url('../fonts/ABCDiatypeMono-Regular-Trial.otf') format('opentype');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

:root {
  --paper: #f9f8f3; /* base tone; grain + vignette take ~5% off it on screen */
  --paper-seen: #ecebe6; /* paper after grain + vignette: what the eye sees, and what Safari paints under its bars */
  --ink: #141414;
  --ink-2: #6f6d68;
  --ink-3: #a3a19b;
  --accent: #e1251b;
  --line: rgba(20, 20, 20, 0.14);
  --mono: 'ABC Diatype Mono', 'SF Mono', Menlo, monospace;
  --sans: 'ABC Diatype', Helvetica, Arial, sans-serif;
  --shadow: rgba(20, 20, 20, 0.08);
}
:root.dark {
  --paper: #141412;
  --paper-seen: #151513;
  --ink: #ecebe6;
  --ink-2: #a3a19b;
  --ink-3: #6f6d68;
  --line: rgba(236, 235, 230, 0.14);
  --shadow: rgba(0, 0, 0, 0.45);
}
:root.dark .paper-grain { opacity: 0.09; box-shadow: inset 0 0 22vmax rgba(0, 0, 0, 0.35); }

* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

html, body {
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
  -webkit-text-size-adjust: 100%;
  background: var(--paper-seen);
  color: var(--ink);
  font-family: var(--mono);
  font-size: 11px;
  line-height: 1.5;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  -webkit-font-smoothing: antialiased;
}

canvas { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
#gl { z-index: 0; touch-action: none; cursor: grab; }
#gl.dragging { cursor: grabbing; }
#gl.over-track { cursor: pointer; }
#ink { z-index: 3; pointer-events: none; }


/* Paper: a faint drafting grid, a vignette and a whisper of grain. */
.paper-grain {
  position: fixed; inset: 0; z-index: 2; pointer-events: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.5 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  opacity: 0.16;
  box-shadow: inset 0 0 22vmax rgba(40, 36, 28, 0.16);
}

/* HUD corners */
.hud {
  position: fixed; z-index: 4; pointer-events: none;
  max-width: 34vw;
}
.hud a, .hud button, .hud input, .hud form { pointer-events: auto; }
.hud-tl { top: calc(22px + env(safe-area-inset-top)); left: calc(24px + env(safe-area-inset-left)); }
.hud-tr { top: calc(22px + env(safe-area-inset-top)); right: calc(24px + env(safe-area-inset-right)); text-align: right; }
.hud-br { bottom: calc(22px + env(safe-area-inset-bottom)); right: calc(24px + env(safe-area-inset-right)); text-align: right; }

/* Path bar: PLAYGROUND / PLAYLIST ATLAS. The parents are dim and clickable, the page itself is the bold one. */
.crumbs { font-family: var(--sans); font-weight: 700; font-size: 12px; letter-spacing: 0.08em; display: flex; flex-wrap: wrap; align-items: baseline; column-gap: 8px; }
.crumbs a { color: var(--ink-2); text-decoration: none; display: inline-flex; align-items: baseline; }
.crumbs a:hover { color: var(--ink); }
.crumbs .sep { color: var(--ink-3); font-weight: 400; }
.crumbs .here { color: var(--ink); }
.sub { margin-top: 8px; display: inline-block; } /* the playlist name sits a clear line under the path */
.sub.link { color: var(--ink-2); border-bottom-color: var(--ink-3); }
.sub.link:hover { color: var(--ink); }
.stats { margin-top: 10px; white-space: pre-line; }
.dim { color: var(--ink-2); }
/* the status line blinks while the page is reading, locating or loading something */
.busy { animation: busy-blink 1.1s steps(2, jump-none) infinite; }
@keyframes busy-blink { from { opacity: 1; } to { opacity: 0.3; } }
.code { font-size: 11px; margin-bottom: 6px; }
.sep { color: var(--ink-3); }
.faint { color: var(--ink-3); }
.faint .link { color: var(--ink-2); }

.link {
  font: inherit; letter-spacing: inherit; text-transform: inherit;
  color: var(--ink); background: none; border: 0; padding: 0; cursor: pointer;
  text-decoration: none; border-bottom: 1px solid currentColor;
}
.link:hover { color: var(--ink-2); }
#resetBtn { margin-right: 14px; }

/* Over-100 detour */
.detour {
  margin: 10px 0 8px; padding: 10px 12px; text-align: left; display: inline-block;
  border: 1px solid var(--ink); background: var(--paper); box-shadow: 6px 6px 0 var(--shadow);
}
.detour-title { font-family: var(--sans); font-weight: 700; margin-bottom: 4px; }
.detour div + div { margin-top: 2px; }
.detour .kbd { border: 1px solid var(--ink-3); padding: 0 4px; }
.detour-close { margin-top: 8px; color: var(--ink-2); }

/* Paste-a-link */
.linkform { display: inline-flex; align-items: center; gap: 10px; margin: 6px 0 2px; }
.linkform input {
  font: inherit; letter-spacing: inherit; text-transform: uppercase;
  color: var(--ink); background: transparent; border: 0; border-bottom: 1px solid var(--ink-3);
  --w: calc(29ch + 29 * 0.06em); /* exactly the placeholder: 29 chars + letter-spacing */
  padding: 2px 0; width: var(--w); outline: none;
}
.linkform input::placeholder { color: var(--ink-3); }
.linkform input:focus { border-bottom-color: var(--ink); }

/* Preview player: one bare line of type at the bottom, progress underneath */
.player {
  position: fixed; z-index: 6; left: 50%; bottom: calc(22px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  width: min(540px, 80vw);
  display: flex; flex-wrap: wrap; align-items: center; gap: 0 12px;
}
.player-btn {
  font: inherit; width: 20px; height: 20px; border: 1px solid var(--ink); background: transparent;
  color: var(--ink); cursor: pointer; border-radius: 50%; display: grid; place-items: center; font-size: 7px; padding: 0; flex: none;
}
.player-btn:hover { background: var(--ink); color: var(--paper); }
.player-title { flex: 1 1 0; min-width: 0; font-family: var(--sans); text-transform: none; letter-spacing: 0.02em; font-size: 11px; line-height: 20px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.player-time { white-space: nowrap; flex: none; }
.player-close { font: inherit; font-size: 13px; line-height: 1; border: 0; background: none; color: var(--ink-2); cursor: pointer; padding: 0 2px; flex: none; }
.player-close:hover { color: var(--ink); }
.player-track { flex-basis: 100%; height: 1px; background: var(--line); margin-top: 7px; position: relative; }
.player-bar { position: absolute; left: 0; top: -1px; height: 3px; width: 0; background: var(--accent); }
.player-cover, .player-artist, .player-meta { display: none; } /* desktop: the hover card carries these */

/* Top-right ladder: one column per 15° sector, the one facing you is tall. While a preview
   plays it is a spectrum: the bars follow the sound, and a peak mark hangs above each and drifts down. */
.ticks { display: inline-flex; align-items: flex-end; gap: 3px; height: 18px; margin-bottom: 4px; }
.ticks span { position: relative; display: block; width: 1.5px; height: 100%; }
.ticks span i { position: absolute; left: 0; right: 0; bottom: 0; display: block; height: 7px; background: var(--ink); opacity: 0.55; }
.ticks span i.peak { display: none; height: 1.5px; opacity: 1; }
.ticks span.on i.bar { height: 100%; opacity: 1; }
.ticks span.load i.bar { opacity: 0.18; }
.ticks.viz span i.peak { display: block; }

/* Bottom-left region bars */
.regions { display: grid; grid-template-columns: auto auto auto; column-gap: 10px; row-gap: 1px; align-items: center; }
.regions .cc { color: var(--ink); }
.regions .bar { height: 5px; background: var(--ink); min-width: 1px; }
.regions .n { color: var(--ink-2); text-align: right; }

/* Hover card */
.card {
  position: fixed; z-index: 5; pointer-events: none;
  width: 236px; background: var(--paper);
  border: 1px solid var(--ink);
  box-shadow: 6px 6px 0 var(--shadow);
}
.card-cover { display: block; width: 100%; aspect-ratio: 1; object-fit: cover; background: #d9d7d0; border-bottom: 1px solid var(--ink); }
.card-body { padding: 9px 10px 10px; }
.card-title { font-family: var(--sans); font-weight: 700; font-size: 12px; letter-spacing: 0.04em; text-transform: none; line-height: 1.25; }
.card-artist { margin-top: 2px; text-transform: none; font-family: var(--sans); font-size: 12px; letter-spacing: 0.02em; }
.card-meta { margin-top: 8px; }
.card-meta .from { color: var(--ink); }
.card-genres { margin-top: 2px; }

/* Drop overlay */
.drop {
  position: fixed; inset: 0; z-index: 8; background: rgba(236, 235, 230, 0.86);
  display: flex; align-items: center; justify-content: center; pointer-events: none;
}
.drop-frame { width: 60vmin; height: 60vmin; border: 1px dashed var(--ink); border-radius: 50%; display: flex; align-items: center; justify-content: center; }
.drop-text { font-family: var(--sans); font-weight: 700; font-size: 14px; letter-spacing: 0.1em; }

/* Feedback sits in the bottom-right stack, above the inputs, clear of the player */
.toast { display: block; margin-bottom: 8px; white-space: normal; }

@media (max-width: 900px) {
  .hud { max-width: 46vw; }
  .hud-tr { top: calc(14px + env(safe-area-inset-top)); }
  .hud-tl { top: calc(14px + env(safe-area-inset-top)); left: calc(14px + env(safe-area-inset-left)); }
  .hud-tr, .hud-br { right: calc(14px + env(safe-area-inset-right)); }
  .hud-br { bottom: calc(14px + env(safe-area-inset-bottom)); }
  .card { width: 190px; }
  .linkform input { width: min(var(--w), 56vw); }
}
@media (max-width: 600px) {
  body { font-size: 10px; }
  .hud-tl { max-width: 72vw; } /* room for the path; the stats are off on phones anyway */
  .hud-tr { display: none; } /* phones: no instrument readout */
  .hud-br { max-width: 90vw; left: 50%; right: auto; transform: translateX(-50%); text-align: center; } /* the link input sits centred under the player */
  .stats { display: none; } /* stats need the width; the title and the link carry the page */
  .card { display: none; } /* phones: the player carries the cover and the lines, so the globe stays in view */
  /* The player becomes a small record sleeve: cover on the left, four rows beside it
     (title, artist, one line of facts, the controls), progress underneath. */
  .player {
    width: calc(100vw - 28px); bottom: calc(72px + env(safe-area-inset-bottom)); /* clear of the link input */
    display: grid; grid-template-columns: 68px auto 1fr auto; grid-template-rows: 16px 16px 16px 20px auto;
    column-gap: 10px; row-gap: 0; align-items: center;
  }
  .player-cover { display: block; grid-area: 1 / 1 / 5 / 2; width: 68px; height: 68px; object-fit: cover; background: #d9d7d0; border: 1px solid var(--ink); }
  .player-title { grid-area: 1 / 2 / 2 / 4; font-weight: 700; line-height: 16px; }
  .player-close { grid-area: 1 / 4 / 2 / 5; justify-self: end; }
  .player-artist, .player-meta { display: block; min-width: 0; line-height: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .player-artist { grid-area: 2 / 2 / 3 / 5; font-family: var(--sans); text-transform: none; letter-spacing: 0.02em; font-size: 11px; }
  .player-meta { grid-area: 3 / 2 / 4 / 5; }
  .player-btn { grid-area: 4 / 2 / 5 / 3; }
  .player-time { grid-area: 4 / 3 / 5 / 4; line-height: 20px; }
  .player-link { grid-area: 4 / 4 / 5 / 5; justify-self: end; line-height: 20px; }
  .player-track { grid-area: 5 / 1 / 6 / 5; }
  .linkform input { width: min(var(--w), 86vw); }
  .detour { max-width: 78vw; }
}
