/* ---- Themes (palettes as custom properties) ---- */
:root[data-theme="dark"] {
  --bg: #0d0e12; --panel: #16171d; --panel-2: #1b1d25; --line: #23252e;
  --text: #f2f3f5; --muted: #8b8f99; --muted-strong: #b9bdc7; --accent: #16d67a; --accent-ink: #04240f;
  --now: #16d67a; --now-glow: 0 0 6px #16d67a; --ring: #16d67a; --live-bg: #10351f;
}
:root[data-theme="light"] {
  --bg: #f4f1ea; --panel: #ffffff; --panel-2: #faf7f0; --line: #ddd6c7;
  --text: #1d1b16; --muted: #6b7280; --muted-strong: #4b5563; --accent: #2b4a8b; --accent-ink: #ffffff;
  --now: #d83b3b; --now-glow: none; --ring: #2b4a8b; --live-bg: #eef2fb;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font-family: system-ui, -apple-system, "Hiragino Kaku Gothic ProN", "Noto Sans JP", sans-serif;
  line-height: 1.4;
}
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* ---- App shell (full viewport) ---- */
.app { height: 100vh; display: grid; grid-template-rows: 1fr auto minmax(0, 42vh) auto; }
.app.guide-hidden { grid-template-rows: 1fr auto 0 auto; }
.app.guide-hidden .top { grid-template-columns: 1fr; }  /* video goes full width */
.app.guide-hidden .info { display: none; }

.top { display: grid; grid-template-columns: 1.9fr 1fr; min-height: 0; }
.video { background: #000; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.player-frame { position: relative; width: 100%; max-height: 100%; aspect-ratio: 16 / 9; background: #000; }
.player-frame iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }

.info { background: var(--panel); padding: 18px 20px; overflow: auto; border-left: 1px solid var(--line);
  display: flex; flex-direction: column; position: relative; }
.share-wrap { position: absolute; top: 14px; right: 16px; z-index: 6; }
.share-btn { background: var(--accent); color: var(--accent-ink); border: 0; border-radius: 999px;
  padding: 6px 14px; font-size: .8rem; font-weight: 700; cursor: pointer; }
.share-btn:hover { filter: brightness(1.08); }
.share-menu { position: absolute; right: 0; top: 116%; min-width: 160px; background: var(--panel);
  border: 1px solid var(--line); border-radius: 10px; padding: 6px; box-shadow: 0 14px 34px rgba(0,0,0,.4);
  display: flex; flex-direction: column; gap: 2px; }
.share-menu[hidden] { display: none; }
.share-menu a, .share-menu button { display: block; text-align: left; background: transparent; border: 0;
  color: var(--text); padding: 8px 10px; border-radius: 7px; font-size: .86rem; cursor: pointer; text-decoration: none; font-family: inherit; }
.share-menu a:hover, .share-menu button:hover { background: var(--panel-2); }
.info-learn { margin-top: auto; padding-top: 14px; border-top: 1px solid var(--line); }
.info-learn-h { color: var(--muted); font-size: .72rem; letter-spacing: .03em; margin: 6px 0 5px; }
.info-learn a { color: var(--accent); font-weight: 700; text-decoration: none; font-size: .9rem; }
.info-learn a:hover { text-decoration: underline; }
.info-head { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.info-avatar { width: 44px; height: 44px; border-radius: 50%; object-fit: cover; background: var(--panel-2); flex: none; }
.info-mode { font-size: .72rem; padding: 2px 8px; border-radius: 999px; background: var(--panel-2); color: var(--muted); }
.info-name { font-weight: 700; font-size: 1.05rem; }
.info-title { color: var(--accent); font-size: 1rem; margin: 6px 0 10px; }
.info-meta { color: var(--muted); font-size: .85rem; }
.info-next { color: var(--muted); font-size: .8rem; margin-top: 14px; border-top: 1px solid var(--line); padding-top: 10px; }

.guidebar { width: 100%; border: 0; background: var(--panel-2); color: var(--muted);
  font-size: 11px; letter-spacing: .05em; padding: 5px; cursor: pointer;
  border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.guide { overflow: auto; background: var(--bg); }
.app.guide-hidden .guide { display: none; }

.statusbar { display: flex; justify-content: space-between; align-items: center; gap: 12px;
  background: var(--panel); border-top: 1px solid var(--line); padding: 6px 12px;
  font-size: 11px; color: var(--muted); }
.sb-hint { color: var(--muted); }
.sb-right { display: flex; gap: 8px; align-items: center; }
.sb-btn { background: transparent; border: 1px solid var(--line); color: var(--text);
  border-radius: 8px; padding: 4px 9px; cursor: pointer; font-size: 12px; }
.sb-btn:hover { border-color: var(--accent); }
.tv-search { max-width: 240px; padding: 5px 12px; border: 1px solid var(--line);
  background: var(--bg); color: var(--text); border-radius: 999px; font-size: 12px; }
.tv-search::placeholder { color: var(--muted); }

/* ---- EPG / 番組表 (vertical time, channels as columns) ---- */
.epg-inner { display: flex; align-items: flex-start; width: max-content; position: relative; }
.epg-gutter { flex: none; position: sticky; left: 0; z-index: 4; background: var(--bg); }
.epg-corner { position: sticky; top: 0; z-index: 5; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 1px; font-size: 8px; color: var(--now);
  background: var(--panel); border-bottom: 1px solid var(--line); border-right: 1px solid var(--line); }
.epg-times { position: relative; border-right: 1px solid var(--line); }
.epg-time { position: absolute; right: 4px; font-size: 10px; color: var(--muted-strong); transform: translateY(-50%); white-space: nowrap; }
.epg-region-sep { flex: none; position: sticky; top: 0; z-index: 3; width: 20px; writing-mode: vertical-rl;
  background: var(--panel-2); color: var(--muted); font-size: 9px; padding: 76px 3px 0;
  border-right: 1px solid var(--line); white-space: nowrap; }
.epg-col { flex: none; border-right: 1px solid var(--line); }
.epg-col.on .epg-colhead { box-shadow: inset 0 -3px 0 var(--ring); }
.epg-col.on .epg-chicon { box-shadow: 0 0 0 2px var(--panel), 0 0 0 4px var(--ring); }
.epg-col.region-off, .epg-col.search-off { display: none; }
.epg-colhead { position: sticky; top: 0; z-index: 3; height: 72px; /* must match HEAD_H in epg.js */
  display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 1px; padding: 2px; text-align: center;
  background: var(--panel); border-bottom: 1px solid var(--line); cursor: pointer; }
.epg-colhead:hover { background: var(--panel-2); }
.epg-colhead:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.epg-chno { font-weight: 700; font-size: 11px; }
.epg-chicon { width: 22px; height: 22px; border-radius: 50%; object-fit: cover; background: var(--panel-2); flex: none; }
.epg-chicon.initials { display: flex; align-items: center; justify-content: center; color: #fff; font-size: 8px; font-weight: 700; background: hsl(var(--hue, 210), 45%, 40%); }
.epg-colname { font-size: 10px; max-width: 130px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.epg-colgenre { font-size: 8px; color: var(--muted); }
.epg-track { position: relative; background: repeating-linear-gradient(to bottom,
  transparent 0, transparent calc(var(--half, 300px) - 1px), var(--line) calc(var(--half, 300px) - 1px), var(--line) var(--half, 300px)); }
.epg-prog { position: absolute; left: 2px; right: 2px; overflow: hidden; cursor: pointer;
  text-align: left; border: 0; border-radius: 5px; padding: 3px 6px; margin: 0;
  background: var(--panel-2); color: var(--text); font-size: 11px; line-height: 1.2; }
.epg-prog:hover { outline: 1px solid var(--accent); }
.epg-prog.live { background: var(--live-bg); box-shadow: inset 0 0 0 1px var(--accent); }
.epg-prog.match { box-shadow: inset 0 0 0 2px #4f7cff; }
.epg-progtitle { overflow: hidden; }
.epg-now { position: absolute; height: 2px; background: var(--now); box-shadow: var(--now-glow); z-index: 2; pointer-events: none; }
.no-match { color: var(--muted); padding: 16px; font-size: 13px; }

/* ---- CRT start screen (power-on) ---- */
.start-screen { position: fixed; inset: 0; z-index: 100; cursor: pointer;
  background: radial-gradient(ellipse at center, #15110a 0%, #050402 82%);
  display: flex; align-items: center; justify-content: center;
  font-family: "Hiragino Mincho ProN", "Yu Mincho", serif; transition: opacity .55s ease; }
.start-screen[hidden] { display: none; }                 /* [hidden] must beat display:flex */
.start-screen.hide { opacity: 0; }
.start-screen::after { content: ""; position: absolute; inset: 0; pointer-events: none;
  background: repeating-linear-gradient(to bottom, rgba(0,0,0,0) 0, rgba(0,0,0,0) 2px, rgba(0,0,0,.32) 3px); }
.start-screen::before { content: ""; position: absolute; inset: 0; pointer-events: none;
  box-shadow: inset 0 0 120px 34px rgba(0,0,0,.85); border-radius: 50% / 12%; }
.start-inner { position: relative; text-align: center; color: #f0d9a8; animation: crtOn .55s ease-out both; }
.start-brand { font-size: clamp(18px, 3vw, 30px); letter-spacing: .2em; color: #e8c87a; text-shadow: 0 0 12px rgba(240,200,120,.5); }
.start-pow { width: 70px; height: 70px; margin: 22px auto; border-radius: 50%; border: 2px solid #e0673c; color: #e0673c;
  display: flex; align-items: center; justify-content: center; font-size: 32px; animation: powPulse 2s ease-in-out infinite; }
.start-cta { font-size: clamp(14px, 2vw, 18px); color: #efe6d6; }
.start-hint { font-size: 12px; color: #a99a82; margin-top: 8px; letter-spacing: .05em; }
@keyframes crtOn { 0% { transform: scaleY(.003); filter: brightness(4); opacity: 0; }
  45% { transform: scaleY(.003); filter: brightness(4); opacity: 1; } 100% { transform: scaleY(1); filter: brightness(1); opacity: 1; } }
@keyframes powPulse { 0%, 100% { box-shadow: 0 0 16px rgba(224,103,60,.5); } 50% { box-shadow: 0 0 28px rgba(224,103,60,.9); } }
@media (prefers-reduced-motion: reduce) { .start-inner { animation: none; } .start-pow { animation: none; } }

/* ---- Settings modal ---- */
.modal { position: fixed; inset: 0; display: flex; align-items: flex-start; justify-content: center;
  background: rgba(0, 0, 0, .55); z-index: 50; }
.modal[hidden] { display: none; }
.modal-card { margin-top: 6vh; width: 380px; max-width: 92vw; background: var(--panel);
  border: 1px solid var(--line); border-radius: 14px; color: var(--text); box-shadow: 0 20px 50px rgba(0, 0, 0, .5); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.modal-body { padding: 14px 18px 18px; }
.set-label { color: var(--muted); font-size: 10px; letter-spacing: .08em; margin: 16px 0 8px; }
.set-label:first-child { margin-top: 0; }
.set-row { font-size: 13px; margin-bottom: 6px; }
.seg { display: flex; gap: 8px; }
.seg-btn { flex: 1; padding: 8px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); color: var(--text); cursor: pointer; font-size: 12px; }
.seg-btn.on { border-color: var(--accent); background: var(--live-bg); }
.set-note { color: var(--muted); font-size: 10px; margin: 6px 0 4px; }
.set-check { display: flex; align-items: center; gap: 10px; font-size: 13px; margin: 10px 0; cursor: pointer; }
.set-check input { width: 16px; height: 16px; accent-color: var(--accent); }

/* ---- Mobile: stack info under a full-width video, smaller text, trim status bar ---- */
@media (max-width: 760px) {
  .app { grid-template-rows: auto auto minmax(0, 1fr) auto; }
  .app.guide-hidden { grid-template-rows: 1fr auto 0 auto; }
  .top { grid-template-columns: 1fr; }              /* video on top, info below */
  /* Size to content (no scroll); single-line rows below keep it bounded & compact. */
  .info { border-left: 0; border-top: 1px solid var(--line); padding: 10px 14px; max-height: none; overflow: hidden; }
  .info-head { margin-bottom: 6px; }
  .info-avatar { width: 32px; height: 32px; }
  .info-name { font-size: .9rem; }
  .info-title { font-size: .82rem; margin: 4px 0 6px; }
  .info-meta { font-size: .72rem; }
  .info-next { font-size: .7rem; margin-top: 6px; padding-top: 6px; }
  /* Trim each line so the panel never grows past one line per row (no wrap, no scroll). */
  .info-name, .info-title, .info-meta, .info-next {
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  }
  .info-learn { padding-top: 7px; }
  .info-learn-h { display: none; }                  /* compact: just the link on mobile */
  .info-learn a { font-size: .78rem; }
  .share-btn { padding: 5px 11px; font-size: .74rem; }
  .statusbar { justify-content: flex-end; }
  .sb-left { display: none; }                       /* drop the jumbled left side */
  .tv-search { max-width: 150px; }
}

.error { margin: 16px; padding: 14px 16px; border: 1px solid #5a2b2b;
  background: #2a1414; border-radius: 10px; color: #ffb4b4; }
.error a { color: #ffd; }
