/* CONTROL DESK (design 4a) - the browser side of the clock's PAPER
   language as a desk console: IBM Plex Mono, ink on warm grey paper, ink
   borders, inversion = state. Two screens: RADIO and SETUP. */

@font-face {
  font-family: "IBM Plex Mono";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("./fonts/plex-mono-400.woff2") format("woff2");
}
@font-face {
  font-family: "IBM Plex Mono";
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url("./fonts/plex-mono-500.woff2") format("woff2");
}
@font-face {
  font-family: "IBM Plex Mono";
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("./fonts/plex-mono-600.woff2") format("woff2");
}
@font-face {
  font-family: "IBM Plex Mono";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("./fonts/plex-mono-700.woff2") format("woff2");
}

:root {
  color-scheme: light dark;
  --paper: #e7e5df;
  --ink: #14131a;
  --focus-fill: #f6f4ee;
  font-family: "IBM Plex Mono", ui-monospace, "SF Mono", Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #14131a;
    --ink: #e7e5df;
    --focus-fill: #1d1c24;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-width: 0;
  min-height: 100vh;
  background: var(--paper);
  color: var(--ink);
  font-size: 12px;
  line-height: 1.5;
}
button, input, output, select { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .4; }
button[aria-busy="true"] { cursor: progress; }
:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
.muted, .empty, small { opacity: .72; }
.small-print { font-size: 10px; letter-spacing: .05em; text-transform: uppercase; }

/* ---- desk bar -------------------------------------------------------- */

.deskbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 11px 20px;
  border-bottom: 1px solid var(--ink);
}
.brand {
  color: var(--ink);
  text-decoration: none;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .18em;
  text-transform: uppercase;
  white-space: nowrap;
}
nav { display: flex; gap: 0; border: 1px solid var(--ink); }
.nav-button {
  border: 0;
  padding: 9px 22px;
  background: transparent;
  color: var(--ink);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .16em;
  text-transform: uppercase;
  white-space: nowrap;
}
.nav-button.active { background: var(--ink); color: var(--paper); }
.connection { display: flex; gap: 10px; align-items: center; }
.connection-dot { display: none; }
.connection-chip {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--ink);
  padding: 5px 13px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .14em;
  text-transform: uppercase;
  opacity: .72;
  text-align: right;
}
.connection-chip.online { background: var(--ink); color: var(--paper); opacity: 1; }
.connection-chip small { font-size: 9px; font-weight: 500; }
.connection-chip.online small { opacity: .7; }

/* ---- shared: cards, buttons, inputs ---------------------------------- */

main { padding: 20px 22px; }
.view[hidden] { display: none; }

.card { border: 1px solid var(--ink); min-width: 0; padding: 0; }
.card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-bottom: 1px solid var(--ink);
}
.card-head h1, .card-head h2 {
  margin: 0;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: .16em;
  text-transform: uppercase;
  white-space: nowrap;
}
.card-meta {
  display: flex;
  gap: 10px;
  align-items: center;
  min-width: 0;
  font-size: 10px;
  letter-spacing: .14em;
  text-transform: uppercase;
  opacity: .86;
}
.card-meta > span { opacity: 1; }
.card-body { padding: 12px 12px 14px; }

.primary, .quiet {
  border: 1px solid var(--ink);
  padding: 10px 16px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .14em;
  text-transform: uppercase;
  white-space: nowrap;
}
.primary { background: var(--ink); color: var(--paper); }
.primary:not(:disabled):hover { background: transparent; color: var(--ink); }
.quiet { background: transparent; color: var(--ink); }
.quiet:not(:disabled):hover { background: var(--ink); color: var(--paper); }
.compact { padding: 8px 13px; }
.mini { padding: 6px 10px; font-size: 9px; }
.danger::before { content: "!\00a0"; }

input:not([type="radio"]):not([type="checkbox"]):not([type="range"]), select {
  width: 100%;
  background: transparent;
  border: 1px solid var(--ink);
  padding: 9px 11px;
  font-size: 12px;
  color: var(--ink);
  outline: none;
}
input:focus:not([type="radio"]):not([type="checkbox"]):not([type="range"]) { background: var(--focus-fill); }
form label, .card-body label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin: 0 0 12px;
}
form label > span, .seg-field > span {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .14em;
  text-transform: uppercase;
  opacity: .72;
  white-space: nowrap;
}

.seg-pair { display: inline-flex; gap: 6px; }
.seg-pair button, .seg-radio span {
  display: inline-block;
  border: 1px solid var(--ink);
  padding: 9px 16px;
  background: transparent;
  color: var(--ink);
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: .12em;
  text-transform: uppercase;
  white-space: nowrap;
  cursor: pointer;
}
.seg-pair button.on { background: var(--ink); color: var(--paper); }

button.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 32px;
  padding: 0;
  border: 1px solid var(--ink);
  background: transparent;
  color: var(--ink);
  cursor: pointer;
}
button.icon-button svg { display: block; width: 12px; height: 12px; }
#like-button svg { width: 15px; height: 13px; }
button.icon-button.on { background: var(--ink); color: var(--paper); }
button.icon-button:not(:disabled):hover { background: var(--ink); color: var(--paper); }
.seg-radio input { position: absolute; opacity: 0; pointer-events: none; }
.seg-radio input:checked + span { background: var(--ink); color: var(--paper); }
.seg-radio input:focus-visible + span { outline: 2px solid var(--ink); outline-offset: 2px; }
.seg-field { display: flex; flex-direction: column; gap: 5px; margin: 0 0 12px; }

.notice {
  position: fixed;
  z-index: 20;
  top: calc(env(safe-area-inset-top, 0px) + 14px);
  left: 50%;
  transform: translateX(-50%);
  width: max-content;
  max-width: calc(100% - 32px);
  padding: 7px 14px;
  border: 1px solid var(--ink);
  background: var(--paper);
  color: var(--ink);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  text-align: center;
  pointer-events: none;
}
.notice.error {
  background: var(--ink);
  color: var(--paper);
}
.notice.error::before { content: "!\00a0"; }

/* ---- RADIO screen ---------------------------------------------------- */

/* The radio column yields below its natural 432px so the directory and
   the radio share a row down to ~640px windows. */
.desk-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) clamp(280px, 42vw, 432px);
  gap: 22px;
  align-items: start;
}
#station-count { white-space: nowrap; }

.station-list { max-height: 496px; overflow: auto; }
.station {
  display: grid;
  grid-template-columns: 32px 1fr auto;
  gap: 12px;
  align-items: center;
  width: 100%;
  padding: 10px 12px;
  border: 0;
  border-bottom: 1px solid var(--ink);
  background: transparent;
  color: var(--ink);
  text-align: left;
}
.station:last-child { border-bottom: 0; }
.station:not(:disabled):hover, .station.selected {
  background: var(--ink);
  color: var(--paper);
}
.station .num { font-size: 10.5px; font-weight: 600; opacity: .72; }
.station .id { min-width: 0; }
.station .id strong {
  display: block;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.station .id small {
  display: block;
  font-size: 10px;
  opacity: .72;
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.station .chip {
  border: 1px solid currentColor;
  padding: 3px 7px;
  font-size: 8.5px;
  font-weight: 700;
  letter-spacing: .16em;
  text-transform: uppercase;
  white-space: nowrap;
}
.empty { padding: 22px; text-align: center; font-size: 10.5px; letter-spacing: .1em; text-transform: uppercase; }

#stations-form { border-bottom: 1px solid var(--ink); padding: 11px 12px; }
.station-editor { display: grid; gap: 8px; margin-bottom: 10px; }
.station-edit {
  display: grid;
  grid-template-columns: 24px .45fr 1fr auto;
  gap: 8px;
  align-items: center;
}
.station-edit > span { font-size: 10.5px; font-weight: 600; opacity: .72; }
.editor-actions { display: flex; gap: 8px; }

.deskmain, .deskside { display: flex; flex-direction: column; gap: 14px; }

.likes-list { max-height: 320px; overflow: auto; }
.like-row {
  display: grid;
  grid-template-columns: 32px 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 10px 12px;
  border-bottom: 1px solid var(--ink);
}
.like-row:last-child { border-bottom: 0; }
.like-row .num { font-size: 10.5px; font-weight: 600; opacity: .72; }
.like-row .id { min-width: 0; }
.like-row .id strong {
  display: block;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.like-row .id small {
  display: block;
  font-size: 10px;
  opacity: .72;
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.mirror { margin: 0; }
.bezel {
  background: #26262a;
  border-radius: 14px;
  padding: 16px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .06);
  width: 100%;
}
#mirror-canvas {
  display: block;
  width: 100%;
  max-width: 400px;
  height: auto;
  aspect-ratio: 4 / 3;
  margin: 0 auto;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}
.volume-control {
  margin: 12px auto 0;
  max-width: 400px;
  color: #e7e5df;
}
.volume-control label {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .14em;
  text-transform: uppercase;
}
.volume-control output {
  font-variant-numeric: tabular-nums;
}
#volume-range {
  display: block;
  width: 100%;
  height: 28px;
  margin: 1px 0 0;
  accent-color: #e7e5df;
  cursor: pointer;
}
#volume-range:disabled { cursor: not-allowed; opacity: .42; }
.mirror figcaption {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px 10px;
  font-size: 10px;
  letter-spacing: .14em;
  text-transform: uppercase;
  margin-top: 8px;
}
.mirror figcaption #state-source { opacity: .72; }
.live-chip {
  background: var(--ink);
  color: var(--paper);
  padding: 3px 7px;
  font-size: 8.5px;
  font-weight: 700;
  letter-spacing: .16em;
  text-transform: uppercase;
  white-space: nowrap;
}
/* The key deck sits inside the bezel, under the screen, like the radio's
   own front-panel buttons. The chassis is dark in both themes, so the keys
   use fixed chassis colors rather than the paper/ink tokens. */
.deck {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-top: 14px;
}
.deck .icon-button {
  border-color: #6f6e74;
  color: #d9d7d1;
}
.deck .icon-button.on {
  background: #e7e5df;
  color: #26262a;
  border-color: #e7e5df;
}
.deck .icon-button:not(:disabled):hover {
  background: #e7e5df;
  color: #26262a;
  border-color: #e7e5df;
}

/* The clock drops a recognized song from its screen after ten seconds;
   the browser keeps it here so you can still read and like it. */
.last-song {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin: 8px 0 0;
  font-size: 11px;
  letter-spacing: .04em;
  text-transform: uppercase;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.last-song b { font-weight: 700; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.last-song span {
  font-size: 8.5px;
  font-weight: 700;
  letter-spacing: .16em;
  border: 1px solid var(--ink);
  padding: 2px 6px;
  opacity: .72;
  flex: none;
}

/* Recognition takes about 25 s on the clock: the key blinks while it
   listens so the wait reads as progress rather than a dead control. */
#recognize-button[aria-busy="true"] { animation: listening 1.4s steps(2) infinite; }
@keyframes listening {
  0% { background: transparent; color: #d9d7d1; }
  50% { background: #e7e5df; color: #26262a; }
}
@media (prefers-reduced-motion: reduce) {
  #recognize-button[aria-busy="true"] { animation: none; opacity: .6; }
}

/* ---- SETUP screen ---------------------------------------------------- */

.setup-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 22px;
  align-items: start;
}
.setup-col { display: flex; flex-direction: column; gap: 22px; min-width: 0; }
.setup-paths { display: grid; gap: 12px; }
.setup-path {
  padding: 12px;
  border: 1px solid var(--ink);
}
.setup-path h2 {
  margin: 0 0 8px;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: .16em;
  text-transform: uppercase;
}
.path-intro { margin: 0 0 6px; opacity: .72; }
.steps { margin: 0 0 14px; padding-left: 18px; }
.steps li { margin: 8px 0; font-size: 11px; line-height: 1.6; }
.setup-path .steps { margin-bottom: 0; }
.setup-path form { margin-top: 14px; }
.pairing-code {
  text-transform: uppercase;
  font-weight: 700 !important;
  font-size: 18px !important;
  letter-spacing: .3em !important;
}
.pairing-verification {
  margin: 14px 0;
  padding: 14px;
  border: 1px solid var(--ink);
  text-align: center;
}
.compare-label {
  margin: 0;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .14em;
  text-transform: uppercase;
  opacity: .72;
}
.pairing-verification output {
  display: block;
  margin: 6px 0;
  font-size: clamp(28px, 6vw, 44px);
  font-weight: 700;
  letter-spacing: .18em;
}
.pairing-verification button { margin: 6px 4px 0; }
.status-line { font-size: 11px; letter-spacing: .04em; opacity: .82; margin: 12px 0 0; }
.status-line.failed::before { content: "!\00a0"; }
.locked-state {
  margin: 0 0 12px;
  padding: 11px 12px;
  border: 1px dashed var(--ink);
  font-size: 11px;
  opacity: .82;
}
.locked-state[hidden] { display: none; }
#admin-controls {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}
#admin-controls:disabled { opacity: .62; }
.scan-heading { display: grid; grid-template-columns: 1fr auto; align-items: end; gap: 8px; }
.scan-heading button { margin-bottom: 12px; }
.grant-list { display: grid; gap: 8px; margin: 10px 0 12px; }
.grant {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--ink);
}
.grant span { display: flex; flex-direction: column; min-width: 0; }
.grant strong { font-size: 11px; letter-spacing: .04em; text-transform: uppercase; }
.grant small { font-size: 10px; }

#share-invite-button { margin-bottom: 12px; }
.invite-panel {
  margin: 0 0 14px;
  padding: 12px;
  border: 1px solid var(--ink);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
/* Author-origin CSS beats the user-agent [hidden] rule regardless of
   specificity, so an unconditional `display: flex` above would otherwise
   keep the panel visibly rendered even while the `hidden` attribute is
   set (matches the existing `.view[hidden]` idiom above). */
.invite-panel[hidden] { display: none; }
.invite-panel label { margin: 0; }
.invite-actions { display: flex; align-items: center; gap: 10px; }
.invite-countdown {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .1em;
  font-variant-numeric: tabular-nums;
  opacity: .75;
}
.invite-qr {
  display: block;
  width: 160px;
  height: 160px;
  margin: 0 auto;
  background: #fff;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

dl { margin: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 0 22px; }
dl div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 7px 0;
  border-bottom: 1px solid var(--ink);
}
dt {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .14em;
  text-transform: uppercase;
  opacity: .72;
  align-self: center;
}
dd { margin: 0; font-size: 11px; text-align: right; }

footer {
  border-top: 1px solid var(--ink);
  padding: 10px;
  text-align: center;
  font-size: 10px;
  letter-spacing: .18em;
  text-transform: uppercase;
  opacity: .72;
  overflow-wrap: anywhere;
}

/* ---- responsive ------------------------------------------------------ */

@media (max-width: 980px) {
  .setup-grid { grid-template-columns: 1fr; }
  dl { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
  .desk-grid { grid-template-columns: 1fr; }
  .deskside { order: -1; }
  /* The mirror is a 1:1 view of a 400x300 screen: never scale it up,
     only down when the viewport is narrower than the chassis. */
  .mirror { width: fit-content; max-width: 100%; margin: 0 auto; }
  .bezel { width: fit-content; max-width: 100%; }
  #mirror-canvas { max-width: 100%; }
}

@media (max-width: 620px) {
  .deskbar { flex-wrap: wrap; }
  .connection { margin-left: auto; }
  .connection-chip small { display: none; }
  main { padding: 14px; }
}

@media (max-width: 400px) {
  .deskbar { gap: 10px; padding: 10px 12px; }
  .nav-button { padding: 9px 18px; }
  main { padding: 12px 10px; }
  .card-head { flex-wrap: wrap; }
  .card-head h1, .card-head h2 { white-space: normal; }
  .deskmain .card-head .card-meta {
    flex: 1 0 100%;
    justify-content: space-between;
    flex-wrap: wrap;
  }
  .station-edit {
    grid-template-columns: 24px minmax(0, 1fr) auto;
  }
  .station-edit [data-field="url"] { grid-column: 2 / 4; }
  .editor-actions, .invite-actions, .pairing-verification { flex-wrap: wrap; }
  #forget-browser-button { width: 100%; white-space: normal; }
  .grant { align-items: flex-start; flex-wrap: wrap; }
  .grant button { margin-left: auto; }
  .last-song { white-space: normal; }
  dl div { min-width: 0; }
  dd { min-width: 0; overflow-wrap: anywhere; }
}
