/* High contrast, big targets: built for people who don't use computers much. */
:root {
  --bg: #000;
  --panel: #111;
  --btn: #1e1e1e;
  --text: #fff;
  --muted: #cfcfcf;
  --accent: #ffd400;
  --line: #5a5a5a;
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 18px/1.35 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
body { display: grid; grid-template-rows: auto minmax(0, 1fr) auto; height: 100dvh; overflow: hidden; }
button, select, input, textarea { font: inherit; color: inherit; }
button { background: var(--btn); border: 2px solid var(--line); border-radius: 12px; padding: 10px 14px; cursor: pointer; min-height: 56px; }
button:hover { border-color: var(--text); }
:focus-visible { outline: 4px solid var(--accent); outline-offset: 2px; }
.ico { font-size: 1.35em; line-height: 1; }

/* ---------- header ---------- */
#top { display: flex; align-items: center; gap: 16px; padding: 10px 16px; background: var(--bg); border-bottom: 2px solid #222; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: inherit; flex: none; }
.logo { font-size: 30px; font-weight: 800; letter-spacing: -0.5px; color: var(--accent); }
.definition { display: flex; flex-wrap: wrap; gap: 0 10px; font-size: 15px; color: var(--muted); min-width: 0; flex: 1; }
.definition .word { color: var(--text); font-weight: 700; }
.definition .pron, .definition .pos { font-style: italic; }
.definition .sense { flex-basis: 100%; }
.definition b { color: var(--text); font-weight: 700; margin-right: 4px; }
.modes { display: flex; gap: 8px; flex: none; }
.modes button { font-size: 20px; font-weight: 700; padding: 10px 18px; }
.modes .on { background: var(--accent); color: #000; border-color: var(--accent); }

/* ---------- picture ---------- */
#stage { position: relative; display: grid; place-items: center; background: #000; min-height: 0; overflow: hidden; touch-action: manipulation; }
#osd { position: absolute; top: 20px; right: 20px; z-index: 3; text-align: right; background: rgba(0, 0, 0, .8); border: 2px solid var(--accent); border-radius: 14px; padding: 12px 20px; pointer-events: none; max-width: 70%; }
#osd-num { font-size: 64px; font-weight: 900; color: var(--accent); letter-spacing: 4px; line-height: 1; }
#osd-name { font-size: 22px; font-weight: 700; margin-top: 6px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#osd-name:empty { display: none; }
.osd-hint { font-size: 15px; color: var(--muted); margin-top: 4px; }
/* The picture always fits inside the play area: whole picture, same shape, black bars where needed. */
#video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: #000; }
#video::cue { font-size: 1.4em; background: rgba(0, 0, 0, .85); }
#status { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); padding: 14px 22px; border-radius: 12px; background: rgba(0, 0, 0, .85); border: 2px solid var(--line); font-size: 22px; font-weight: 600; text-align: center; max-width: 90%; pointer-events: none; }
#status:empty { display: none; }
#sound-hint { position: absolute; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--accent); color: #000; border: 0; font-size: 22px; font-weight: 800; padding: 14px 26px; }
#ad-banner { position: absolute; top: 16px; left: 50%; transform: translateX(-50%); display: flex; gap: 14px; align-items: center; background: rgba(0, 0, 0, .9); border: 2px solid var(--accent); border-radius: 12px; padding: 10px 14px; font-weight: 700; }
#ad-banner button { background: var(--accent); color: #000; border: 0; font-weight: 800; }
#radio-card { position: absolute; display: grid; justify-items: center; gap: 12px; text-align: center; padding: 24px; }
#radio-logo { width: 180px; height: 180px; object-fit: contain; border-radius: 20px; background: #fff; }
#radio-logo:not([src]) { visibility: hidden; }
#radio-name { font-size: 34px; font-weight: 800; max-width: 85vw; }
#radio-tags { color: var(--muted); font-size: 20px; }
.eq { display: flex; gap: 6px; height: 44px; align-items: flex-end; }
.eq i { width: 10px; background: var(--accent); border-radius: 3px; animation: eq 1s ease-in-out infinite; }
.eq i:nth-child(2) { animation-delay: .2s } .eq i:nth-child(3) { animation-delay: .4s } .eq i:nth-child(4) { animation-delay: .1s } .eq i:nth-child(5) { animation-delay: .3s }
@keyframes eq { 0%, 100% { height: 8px } 50% { height: 44px } }
body.paused .eq i { animation-play-state: paused; }

/* ---------- control bar ---------- */
#bar { background: var(--panel); border-top: 2px solid #222; padding: 10px 16px max(10px, env(safe-area-inset-bottom)); display: grid; gap: 10px; }
.now { display: flex; align-items: center; gap: 12px; min-width: 0; }
.chnum { flex: none; min-width: 64px; text-align: center; background: var(--accent); color: #000; font-weight: 900; font-size: 26px; border-radius: 10px; padding: 4px 10px; }
.chnum:empty { display: none; }
#now-logo { width: 52px; height: 52px; object-fit: contain; border-radius: 8px; background: #fff; flex: none; }
#now-logo:not([src]) { display: none; }
.now-text { min-width: 0; }
#now-name { font-size: 24px; font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#now-meta { color: var(--muted); font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.controls { display: grid; grid-template-columns: repeat(auto-fit, minmax(100px, 1fr)); gap: 8px; }
.controls button { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; font-weight: 700; font-size: 16px; min-height: 72px; }
.controls .primary { background: var(--accent); color: #000; border-color: var(--accent); font-size: 18px; }
.controls .on { border-color: var(--accent); color: var(--accent); }

/* Full screen: hide header and controls after a few seconds of no activity; any touch brings them back. */
body.fs { display: block; }
body.fs #stage { position: fixed; inset: 0; }
body.fs #top { position: fixed; top: 0; left: 0; right: 0; z-index: 2; background: rgba(0, 0, 0, .8); }
body.fs #bar { position: fixed; bottom: 0; left: 0; right: 0; z-index: 2; background: rgba(17, 17, 17, .92); }
body.fs .chrome { transition: opacity .4s; }
body.fs.idle .chrome { opacity: 0; pointer-events: none; }
body.fs.idle { cursor: none; }

/* ---------- find channels (browse) ---------- */
#browse { position: fixed; inset: 0; z-index: 5; background: #0a0a0a; overflow-y: auto; padding: 16px 16px 40px; }
.browse-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.browse-head h1 { margin: 0; font-size: 28px; }
.close { font-weight: 800; font-size: 20px; }
#search { width: 100%; margin: 14px 0 6px; font-size: 24px; padding: 14px 16px; border-radius: 12px; border: 3px solid var(--line); background: #000; }
#search:focus { border-color: var(--accent); outline: none; }
.row-title { font-size: 24px; margin: 22px 0 10px; }
.tiles { display: flex; gap: 14px; overflow-x: auto; padding: 4px 4px 12px; }
.tiles.grid { flex-wrap: wrap; overflow: visible; }
.tile { flex: none; width: 190px; display: grid; gap: 8px; padding: 10px; text-align: left; background: var(--btn); position: relative; }
.tile .art { height: 104px; border-radius: 8px; background: #fff; display: grid; place-items: center; overflow: hidden; }
.tile .art img { max-width: 92%; max-height: 92%; object-fit: contain; }
.tile .art .initial { color: #111; font-size: 44px; font-weight: 900; }
.tile .num { position: absolute; top: 4px; left: 4px; background: var(--accent); color: #000; font-weight: 900; font-size: 16px; padding: 2px 8px; border-radius: 8px; }
.tile .name { font-weight: 700; font-size: 17px; line-height: 1.2; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.tile .sub { color: var(--muted); font-size: 14px; }
.tile.cur { border-color: var(--accent); }
.empty { color: var(--muted); font-size: 20px; }

/* ---------- dialogs ---------- */
dialog { background: #141414; color: var(--text); border: 3px solid var(--line); border-radius: 16px; max-width: min(520px, 94vw); padding: 22px; }
dialog::backdrop { background: rgba(0, 0, 0, .75); }
dialog h2 { margin: 0 0 12px; font-size: 26px; }
dialog label { display: block; padding: 8px 0; font-size: 19px; }
dialog input[type=radio] { width: 22px; height: 22px; vertical-align: middle; margin-right: 8px; }
dialog textarea { width: 100%; min-height: 80px; margin-top: 8px; background: #000; border: 2px solid var(--line); border-radius: 10px; padding: 10px; }
dialog .row { display: flex; justify-content: flex-end; gap: 10px; margin-top: 14px; }
.hint { color: var(--muted); font-size: 16px; }
.go { background: var(--accent); color: #000; border-color: var(--accent); font-weight: 800; }
.soft { background: #2a2a2a; }
#num-display { font-size: 56px; font-weight: 900; text-align: center; color: var(--accent); letter-spacing: 6px; min-height: 70px; }
#num-name { text-align: center; min-height: 1.4em; }
.keys { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.keys button { font-size: 32px; font-weight: 800; min-height: 72px; }
.more-list { display: grid; gap: 10px; }
.more-list button, .linkbtn { display: flex; align-items: center; gap: 12px; text-align: left; font-size: 19px; font-weight: 700; }
.linkbtn { background: var(--btn); border: 2px solid var(--line); border-radius: 12px; padding: 14px; color: inherit; text-decoration: none; min-height: 56px; }
.setting { background: var(--btn); border: 2px solid var(--line); border-radius: 12px; padding: 12px 14px !important; font-weight: 700; }
.setting select { display: block; width: 100%; margin-top: 8px; font-size: 19px; padding: 10px; border-radius: 10px; background: #000; border: 2px solid var(--line); }
#pair { text-align: center; }
#pair-qr { width: 230px; height: 230px; margin: 12px auto; background: #fff; border-radius: 12px; padding: 8px; }
#pair-qr svg { width: 100%; height: 100%; display: block; }
#pair-code { font-size: 44px; font-weight: 900; letter-spacing: 8px; color: var(--accent); margin: 4px 0 8px; }

/* ---------- phones ---------- */
@media (max-width: 760px), (orientation: portrait) and (max-width: 1000px) {
  body { display: block; height: auto; min-height: 100dvh; overflow-y: auto; }
  #top { flex-wrap: wrap; gap: 8px 12px; }
  .logo { font-size: 26px; }
  .definition { order: 3; flex-basis: 100%; font-size: 14px; }
  .definition .sense:last-child { display: none; }
  .modes { margin-left: auto; }
  .modes button { font-size: 18px; padding: 8px 14px; }
  #stage { aspect-ratio: 16 / 9; width: 100%; }
  #radio-logo { width: 110px; height: 110px; }
  #radio-name { font-size: 24px; }
  .controls { grid-template-columns: repeat(3, 1fr); }
  .tile { width: 150px; }
  .tile .art { height: 84px; }
}

/* Loading screen with the logo, until the first channel plays. */
#splash { position: fixed; inset: 0; z-index: 10; background: #fff; color: #111; display: grid; place-content: center; justify-items: center; gap: 8px; transition: opacity .6s; }
#splash img { width: min(440px, 80vw, 55vh); height: auto; border-radius: 20px; }
#splash .logo { color: #111; font-size: 40px; }
#splash p { margin: 0; font-size: 22px; font-weight: 600; }
#splash.gone { opacity: 0; pointer-events: none; }
.tiles { cursor: grab; }
.tiles.dragging { cursor: grabbing; user-select: none; }
.tiles.dragging .tile { pointer-events: none; }
.tiles img { -webkit-user-drag: none; user-select: none; }
#now-meta .np { color: var(--accent); }

#account input, #acct-code { width: 100%; font-size: 22px; padding: 12px 14px; border-radius: 10px; border: 3px solid var(--line); background: #000; margin: 6px 0 10px; }
#account form .go { width: 100%; }
#acct-code { letter-spacing: 6px; text-align: center; }
#keys-list { display: grid; gap: 8px; max-height: 60vh; overflow-y: auto; }
.keyrow { display: grid; grid-template-columns: 1fr auto; gap: 6px 10px; align-items: center; background: var(--btn); border: 2px solid var(--line); border-radius: 12px; padding: 10px 12px; }
.keyrow .act { font-weight: 800; }
.keyrow .cur { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 6px; }
.keyrow kbd { font: inherit; font-size: 15px; background: #000; border: 2px solid var(--line); border-radius: 8px; padding: 2px 8px; }
.keyrow button { min-height: 44px; padding: 6px 12px; font-size: 16px; }
.keyrow.listening { border-color: var(--accent); }
.tm { font-size: .45em; vertical-align: super; margin-left: 2px; color: var(--muted); }
.devrow { display: grid; grid-template-columns: 2fr 1fr; gap: 10px; margin-bottom: 8px; }
.devrow label { padding: 0; font-size: 16px; font-weight: 700; }
.devrow input, .devrow select, .copysel { display: block; width: 100%; margin-top: 4px; font-size: 18px; padding: 10px; border-radius: 10px; background: #000; border: 2px solid var(--line); }
.copysel { margin: 4px 0 10px; }

/* Phone turned sideways (short, wide screen): the picture fills the screen; scroll down for the buttons. */
@media (orientation: landscape) and (max-height: 500px) {
  body { display: flex; flex-direction: column; height: auto; min-height: 100dvh; overflow-y: auto; }
  #stage { order: -1; flex: none; height: 100dvh; width: 100%; }
  body.fs #stage { height: auto; }
}

/* Stories: progress through the chapter. Drag to move; time passed left, time left right, lengths top right. */
#story-progress { display: grid; gap: 2px; }
.sp-top, .sp-times { display: flex; justify-content: space-between; gap: 2px 12px; color: var(--muted); font-size: 16px; }
.sp-top { flex-wrap: wrap; }
.sp-top #sp-chap { flex: 1 1 14em; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sp-top #sp-total { margin-left: auto; }
.sp-times { font-size: 18px; font-weight: 700; color: var(--text); font-variant-numeric: tabular-nums; }
#sp-bar { width: 100%; height: 34px; margin: 0; accent-color: var(--accent); cursor: pointer; }
/* The cover shrinks to fit the play area (it got cut off when the progress bar took some height). */
#stage { container-type: size; }
body.mode-stories #radio-logo { width: min(180px, 42cqh); height: min(180px, 42cqh); }
body.mode-stories #radio-card { gap: 8px; padding: 12px; }
body.mode-stories #radio-card .eq { display: none; }
