/* Radio Caroline Player v2: Caroline on a sea chart.
   Palette, type and chart details borrowed from blue-wave.net. */

@font-face {
  font-family: "Fraunces";
  src: url("fonts/fraunces-roman.woff2") format("woff2");
  font-weight: 100 900; font-style: normal; font-display: swap;
}
@font-face {
  font-family: "IBM Plex Mono";
  src: url("fonts/plexmono-400.woff2") format("woff2");
  font-weight: 400; font-style: normal; font-display: swap;
}
@font-face {
  font-family: "IBM Plex Mono";
  src: url("fonts/plexmono-500.woff2") format("woff2");
  font-weight: 500; font-style: normal; font-display: swap;
}

:root {
  --paper: #f2eee3;
  --paper-2: #ebe5d5;
  --shoal: #cfe2ea;
  --ink: #142235;
  --ink-soft: #3b4a5e;
  --sea: #1b4f86;
  --signal: #c8102e;      /* Caroline red: on air, active stream */
  --live: #1f7a4d;
  --rule: rgba(20, 34, 53, .16);
  --serif: "Fraunces", "Iowan Old Style", Georgia, "Times New Roman", serif;
  --mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  --gutter: clamp(1rem, 4vw, 2.25rem);
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

body {
  margin: 0;
  color: var(--ink);
  font-family: var(--serif);
  font-size: clamp(1rem, .96rem + .25vw, 1.125rem);
  line-height: 1.55;
  background-color: var(--paper-2);
  /* chart graticule over the faded ship (v1 had the faded ship alone) */
  background-image:
    linear-gradient(var(--rule) 1px, transparent 1px),
    linear-gradient(90deg, var(--rule) 1px, transparent 1px),
    url("img/bg-faded.jpg");
  background-size: 120px 120px, 120px 120px, cover;
  background-position: -1px -1px, -1px -1px, center;
  background-attachment: scroll, scroll, fixed;
}
@supports (background-image: image-set(url("x.webp") type("image/webp"))) {
  body {
    background-image:
      linear-gradient(var(--rule) 1px, transparent 1px),
      linear-gradient(90deg, var(--rule) 1px, transparent 1px),
      image-set(url("img/bg-faded.webp") type("image/webp"), url("img/bg-faded.jpg") type("image/jpeg"));
  }
}

img, svg { max-width: 100%; height: auto; }
a { color: var(--sea); text-decoration-thickness: 1px; text-underline-offset: .18em; }
a:hover { color: var(--signal); }
a:focus-visible, button:focus-visible, input:focus-visible {
  outline: 3px solid var(--signal);
  outline-offset: 3px;
}
[hidden] { display: none !important; }

.skip {
  position: absolute; left: -999px; top: 0; z-index: 10;
  background: var(--ink); color: var(--paper); padding: .6rem 1rem;
  font-family: var(--mono); font-size: .85rem;
}
.skip:focus { left: 1rem; top: 1rem; }

/* The sheet: a chart panel with a graduated neatline */
.sheet {
  --tick: 8px;
  position: relative;
  max-width: 44rem;
  margin: clamp(0px, min(3vw, 3vh), 2.5rem) auto;
  background: var(--paper);
  border: 1.5px solid var(--ink);
  outline: 1px solid var(--ink);
  outline-offset: calc(var(--tick) * -1 - 3px);
  padding: 0 calc(var(--tick) + var(--gutter));
}
.sheet::before, .sheet::after {
  content: "";
  position: absolute; top: 0; bottom: 0;
  width: var(--tick);
  background: repeating-linear-gradient(to bottom, var(--ink) 0 24px, var(--paper) 24px 48px);
}
.sheet::before { left: 0; border-right: 1px solid var(--ink); }
.sheet::after { right: 0; border-left: 1px solid var(--ink); }
@media (max-width: 640px) {
  .sheet { --tick: 5px; margin: 0; border-width: 0 0 1.5px; min-height: 100vh; }
}

/* Masthead */
.masthead {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: clamp(1rem, 3vw, 1.6rem) 0 .9rem;
  border-bottom: 1px solid var(--ink);
}
.brand { display: flex; align-items: center; gap: .8rem; }
.kicker {
  margin: 0; font-family: var(--mono); font-size: .7rem; letter-spacing: .16em;
  text-transform: uppercase; color: var(--ink-soft);
}
.title {
  margin: .1rem 0 0; font-weight: 640; font-size: clamp(1.6rem, 1.2rem + 2vw, 2.3rem);
  line-height: 1.05; letter-spacing: -.015em;
}
.title em { font-style: normal; font-weight: 380; color: var(--ink-soft); }
.onair {
  flex: none; width: .95rem; height: .95rem; border-radius: 50%;
  background: #9aa3ad; box-shadow: 0 0 0 3px var(--paper), 0 0 0 4.5px var(--ink);
}
/* Green: the chosen stream is playing. Red: North tab, North silent, main
   channel playing instead. Grey: tuning or paused. */
.onair.is-live {
  --glow: rgba(31, 122, 77, .28);
  background: var(--live);
  box-shadow: 0 0 0 3px var(--paper), 0 0 0 4.5px var(--ink), 0 0 0 7px var(--glow);
  animation: pulse 2.4s ease-in-out infinite;
}
.onair.is-fallback {
  --glow: rgba(200, 16, 46, .24);
  background: var(--signal);
  box-shadow: 0 0 0 3px var(--paper), 0 0 0 4.5px var(--ink), 0 0 0 7px var(--glow);
}
@keyframes pulse { 50% { box-shadow: 0 0 0 3px var(--paper), 0 0 0 4.5px var(--ink), 0 0 0 10px var(--glow); } }
.rose { width: clamp(2.6rem, 8vw, 3.6rem); color: var(--sea); flex: none; font-family: var(--mono); }

/* Stream picker: chart-style tabs */
.streams {
  display: flex; gap: 0; margin: 1.1rem 0 .9rem;
  border: 1.5px solid var(--ink);
  box-shadow: 4px 4px 0 var(--shoal);
}
.streams a {
  flex: 1; text-align: center; padding: .6rem .4rem;
  font-family: var(--mono); font-size: .82rem; font-weight: 500; letter-spacing: .1em; text-transform: uppercase;
  color: var(--ink); text-decoration: none; background: var(--paper);
}
.streams a + a { border-left: 1px solid var(--ink); }
.streams a:hover { background: var(--shoal); color: var(--ink); }
.streams a[aria-current="page"] { background: var(--ink); color: var(--paper); box-shadow: inset 0 -4px 0 var(--signal); }

/* Banner: a fixed frame, never taller than 40% of the screen. The picture
   fills it (cover), anchored a little below centre so the hull stays in view. */
.banner { margin: 0; border: 1.5px solid var(--ink); background: var(--ink); overflow: hidden; }
.banner img {
  display: block; width: 100%; height: auto;
  aspect-ratio: 2 / 1;
  max-height: 40vh; max-height: 40dvh;
  object-fit: cover; object-position: 50% 62%;
}
/* Flashback is a wide logo: keep its own shape so no letters are cut off. */
.player[data-stream="flashback"] .banner img { aspect-ratio: 750 / 305; object-position: 50% 50%; }

.logline {
  margin: .5rem 0 1rem; font-family: var(--mono); font-size: .78rem; letter-spacing: .12em;
  color: var(--ink-soft); text-transform: uppercase;
}
#logline-state { color: var(--signal); font-weight: 500; }

/* Deck: play button and station */
.deck { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; }
.deck__info { flex: 1 1 12rem; min-width: 0; }
.station { margin: 0; font-size: 1.35rem; font-weight: 600; line-height: 1.2; }
.player-title { margin: .15rem 0 0; font-size: .95rem; color: var(--ink-soft); }
.play {
  flex: none; width: 4.25rem; height: 4.25rem; border-radius: 50%;
  display: grid; place-items: center; cursor: pointer;
  color: var(--paper); background: var(--sea);
  border: 2px solid var(--ink); box-shadow: 3px 3px 0 var(--shoal);
}
.play:hover { background: var(--ink); }
.play svg { width: 1.9rem; height: 1.9rem; }
.play .i-pause, .play.is-playing .i-play { display: none; }
.play.is-playing .i-pause { display: block; }
.volume { display: flex; align-items: center; gap: .5rem; font-family: var(--mono); font-size: .75rem; letter-spacing: .08em; text-transform: uppercase; }
.volume input { width: 8rem; accent-color: var(--sea); }

/* Loading bar (kept from v1) and status lines */
.loading { margin: 1rem 0 0; font-family: var(--mono); font-size: .8rem; }
.loading__track {
  display: block; height: 8px; margin-top: .3rem; overflow: hidden;
  background: var(--paper-2); border: 1px solid var(--ink);
}
#stream-loading-bar {
  display: block; height: 100%; width: 35%; background: var(--sea);
  animation: stream-loading 1.1s ease-in-out infinite;
}
@keyframes stream-loading { 0% { transform: translateX(-120%); } 100% { transform: translateX(320%); } }
.reconnecting { margin: .8rem 0 0; font-family: var(--mono); font-size: .85rem; font-weight: 500; color: #9a4a00; }
.error { margin: .8rem 0 0; font-family: var(--mono); font-size: .85rem; color: var(--signal); }
.north-status { margin: .6rem 0 0; font-size: .95rem; }
.north-status:empty { display: none; }

/* Now playing */
.nowplaying {
  margin: 1.2rem 0 1rem; padding: .7rem .9rem;
  border: 1px solid var(--ink); background: var(--paper-2);
}
.label {
  margin: 0; font-family: var(--mono); font-size: .7rem; font-weight: 400; letter-spacing: .16em;
  text-transform: uppercase; color: var(--ink-soft);
}
#track { margin: .2rem 0 0; font-family: var(--mono); font-size: .95rem; font-weight: 500; overflow-wrap: anywhere; }

/* Native controls: only the <noscript> copy is shown (no JavaScript);
   with JavaScript the deck's button drives #rcp-audio. */
.native { display: block; width: 100%; margin: .5rem 0; }
#rcp-audio { display: none; }
html:not(.js) #stayAwakeBtn,
html:not(.js) .nowplaying,
html:not(.js) #logline-state,
html:not(.js) #logline-state + .sep { display: none; }

.button {
  font: 500 .85rem var(--mono); padding: .5rem .9rem; cursor: pointer;
  color: var(--ink); background: var(--paper); border: 1.5px solid var(--ink);
}
.hint { margin: .8rem 0; font-size: .9rem; color: var(--ink-soft); }
.clock { margin: .6rem 0; font-family: var(--mono); font-size: .9rem; }
.clock time { font-weight: 500; font-variant-numeric: tabular-nums; }
.official { margin: .8rem 0 1.4rem; }

.foot {
  border-top: 1px solid var(--ink); padding: .9rem 0 1.2rem;
  font-size: .9rem;
}
.foot p { margin: .15rem 0; }
.foot__live { color: var(--live); }
.foot__by { font-family: var(--mono); font-size: .8rem; font-weight: 500; letter-spacing: .06em; color: var(--sea); }
.foot__small { font-family: var(--mono); font-size: .72rem; color: var(--ink-soft); }

/* North test mode (?north=test only) */
.kicker--test { color: var(--signal); font-weight: 500; }
.ntest {
  margin: .4rem 0 1rem; padding: .7rem .9rem;
  border: 2px dashed var(--signal); background: #fbf3ef;
}
.ntest__title { margin: 0 0 .5rem; font-family: var(--mono); font-size: .8rem; font-weight: 500; letter-spacing: .08em; text-transform: uppercase; color: var(--signal); }
.ntest__buttons { display: flex; flex-wrap: wrap; gap: .4rem; }
.ntest .button[aria-pressed="true"] { background: var(--ink); color: var(--paper); }
.ntest__facts { display: grid; grid-template-columns: auto 1fr; gap: .15rem .7rem; margin: .6rem 0 .3rem; font-family: var(--mono); font-size: .78rem; }
.ntest__facts dt { color: var(--ink-soft); text-transform: uppercase; letter-spacing: .08em; }
.ntest__facts dd { margin: 0; overflow-wrap: anywhere; }
.ntest__result { margin: .3rem 0 0; font-size: .9rem; }
.ntest__note { margin: .3rem 0 0; font-size: .78rem; color: var(--ink-soft); }

/* Phones: tighter spacing so the tabs, play button and Now playing fit
   on one screen, even with the browser's own bars showing. */
@media (max-width: 640px) {
  .masthead { padding: .75rem 0 .6rem; }
  .title { font-size: 1.45rem; }
  .rose { width: 2.4rem; }
  .streams { margin: .7rem 0 .6rem; }
  .streams a { padding: .5rem .3rem; font-size: .78rem; }
  .logline { margin: .35rem 0 .55rem; font-size: .68rem; letter-spacing: .08em; }
  .deck { gap: .45rem .8rem; }
  .play { width: 3.5rem; height: 3.5rem; }
  .play svg { width: 1.6rem; height: 1.6rem; }
  .station { font-size: 1.15rem; }
  .player-title { font-size: .88rem; line-height: 1.35; }
  .volume input { width: 9rem; }
  .north-status { margin-top: .4rem; font-size: .85rem; line-height: 1.4; }
  .nowplaying { margin: .6rem 0 .8rem; padding: .5rem .75rem; }
  #track { font-size: .88rem; }
}

/* Laptops and wide screens: picture on the left, controls and Now playing
   on the right, so nothing needs scrolling. */
@media (min-width: 900px) and (orientation: landscape) {
  .sheet { max-width: 72rem; }
  .masthead { padding: .9rem 0 .7rem; }
  .player {
    display: grid;
    grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr);
    column-gap: clamp(1.25rem, 2.5vw, 2.25rem);
    align-items: start;
    padding-top: 1.1rem;
    container-type: inline-size;
    /* Row 8 (Now playing) takes any extra height when the picture is taller
       than the controls, so the controls never spread apart. */
    grid-template-rows: repeat(7, auto) 1fr;
  }
  .player > * { grid-column: 2; }
  /* Fixed rows: the picture spans exactly the controls (tabs to Now playing),
     whatever status lines are showing, so it matches their height. */
  .player > .streams { grid-row: 1; margin-top: 0; }
  .player > .logline { grid-row: 2; }
  .player > .deck { grid-row: 3; }
  .player > .loading { grid-row: 4; }
  .player > .reconnecting { grid-row: 5; }
  .player > .error { grid-row: 6; }
  .player > .north-status { grid-row: 7; }
  .player > .nowplaying, .player > noscript { grid-row: 8; }
  .player > .ntest { grid-row: 9; }
  .player > #stayAwakeBtn { grid-row: 10; justify-self: start; }
  .player > .hint { grid-row: 11; }
  .player > .clock { grid-row: 12; }
  .player > .official { grid-row: 13; }
  .player > .banner {
    grid-column: 1; grid-row: 1 / 9; align-self: stretch;
    position: relative; min-height: 13rem;
    /* never smaller than the picture's own shape (up to 40% of the screen) */
    min-height: min(40vh, calc(30.4cqw - .7rem));
    min-height: min(40dvh, calc(30.4cqw - .7rem));
    margin-bottom: 1rem;   /* line up with the bottom of Now playing */
  }
  .banner img {
    position: absolute; inset: 0; width: 100%; height: 100%;
    aspect-ratio: auto; max-height: none;
  }
  /* Flashback: show the whole logo; the sea gradient fills round it. */
  .player[data-stream="flashback"] .banner { background: linear-gradient(#1a4782, #2b88a4); }
  .player[data-stream="flashback"] .banner img { object-fit: contain; aspect-ratio: auto; }
  .logline { margin-top: 0; }
  .nowplaying { margin-top: .9rem; }
  .hint, .clock, .official { font-size: .88rem; }
}
/* Short laptop screens (768px and below): trim vertical space further. */
@media (min-width: 900px) and (max-height: 800px) {
  .title { font-size: 1.9rem; }
  .rose { width: 2.8rem; }
  .play { width: 3.8rem; height: 3.8rem; }
  .player { padding-top: .8rem; }
  .player > .streams { margin-bottom: .6rem; }
}

@media (prefers-reduced-motion: reduce) {
  .onair.is-live, .onair.is-fallback, #stream-loading-bar { animation: none; }
}
