/* =========================================================================
   PlatCast デモ
   - .console  : コントロールパネル（放送卓をイメージした暗色）
   - .listener : リスナー画面（スマホ前提の明色）
   ========================================================================= */

:root {
  --font: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic UI", Meiryo, system-ui, sans-serif;
  --mono: "SF Mono", "Cascadia Mono", "Consolas", "Menlo", monospace;
  --radius: 10px;

  /* console */
  --c-bg: #0f1216;
  --c-panel: #171b21;
  --c-panel-2: #1e232b;
  --c-line: #2a313b;
  --c-text: #e7ebf0;
  --c-muted: #8a95a3;
  --c-accent: #3d8bfd;
  --c-green: #2fbf71;
  --c-amber: #f0a92c;
  --c-red: #e5484d;

  /* listener */
  --l-bg: #f6f4f0;
  --l-card: #ffffff;
  --l-text: #1d2025;
  --l-muted: #6a6f78;
  --l-accent: #1f6feb;
  --l-line: #e3e0da;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { font-family: var(--font); line-height: 1.6; -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; }
[hidden] { display: none !important; }

/* ------------------------------------------------------------- console 共通 */

body.console { background: var(--c-bg); color: var(--c-text); min-height: 100vh; }
.console a { color: #8cb8ff; }

.console-header {
  display: flex; align-items: center; gap: 24px;
  padding: 0 24px; height: 60px;
  background: #0b0d10; border-bottom: 1px solid var(--c-line);
  position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark {
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--c-red); box-shadow: 0 0 0 4px rgba(229, 72, 77, .18);
}
.brand-name { font-weight: 700; letter-spacing: .04em; }
.brand-sub { color: var(--c-muted); font-size: 13px; }
.tabs { display: flex; gap: 4px; height: 100%; }
.tabs a {
  display: flex; align-items: center; padding: 0 18px;
  color: var(--c-muted); text-decoration: none; font-weight: 600;
  border-bottom: 3px solid transparent;
}
.tabs a:hover { color: var(--c-text); }
.tabs a.active { color: var(--c-text); border-bottom-color: var(--c-accent); }
.logout { margin-left: auto; }
.link-button { background: none; border: 0; color: var(--c-muted); cursor: pointer; }
.link-button:hover { color: var(--c-text); }

.console-main { max-width: 1180px; margin: 0 auto; padding: 24px; display: grid; gap: 20px; }

.panel {
  background: var(--c-panel); border: 1px solid var(--c-line);
  border-radius: var(--radius); padding: 22px 24px;
}
.panel-title { margin: 0 0 6px; font-size: 18px; }
h1.panel-title { font-size: 20px; }
.panel-lead { margin: 0 0 18px; color: var(--c-muted); font-size: 14px; }
.panel-lead strong { color: var(--c-text); }

.flash {
  margin: 0; padding: 12px 16px; border-radius: var(--radius);
  background: rgba(61, 139, 253, .12); border: 1px solid rgba(61, 139, 253, .35);
}

/* ------------------------------------------------------------- フォーム */

.setup-form { display: grid; gap: 16px; }
.field { display: grid; gap: 6px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.field label, .input-row > label { font-weight: 600; font-size: 14px; }
.req {
  font-size: 11px; font-weight: 700; color: var(--c-red);
  border: 1px solid currentColor; border-radius: 4px; padding: 0 5px; margin-left: 6px;
}
.console input[type=text], .console input[type=password], .console input[type=datetime-local],
.console textarea, .console select {
  width: 100%; padding: 10px 12px;
  background: var(--c-panel-2); color: var(--c-text);
  border: 1px solid var(--c-line); border-radius: 8px;
  color-scheme: dark;
}
.console input:focus, .console textarea:focus, .console select:focus {
  outline: 2px solid var(--c-accent); outline-offset: 1px; border-color: transparent;
}
.console input.invalid { border-color: var(--c-red); }
.field-error { margin: 0; color: #ff8a8d; font-size: 13px; }
.field-hint { margin: 0; color: var(--c-muted); font-size: 13px; }
.actions { display: flex; justify-content: flex-end; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 18px; border-radius: 8px; border: 1px solid var(--c-line);
  background: var(--c-panel-2); color: var(--c-text); font-weight: 600;
  cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover:not(:disabled) { border-color: #3a4350; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--c-accent); border-color: var(--c-accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: #2f7bec; }
.btn-small { padding: 6px 12px; font-size: 13px; }
.btn-ghost { background: transparent; }
.btn-block { width: 100%; }

.event-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.event-table th, .event-table td { padding: 10px 8px; border-bottom: 1px solid var(--c-line); text-align: left; vertical-align: middle; }
.event-table th { color: var(--c-muted); font-weight: 600; font-size: 12px; }
.event-table tr.ended td { color: var(--c-muted); }
.event-table code { font-family: var(--mono); font-size: 12px; color: var(--c-muted); }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; }
.row-actions form { margin: 0; }

/* ------------------------------------------------------------- ログイン */

.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-panel { width: min(380px, 100%); display: grid; gap: 14px; }
.login-panel h1 { margin: 0; font-size: 18px; }
.login-panel label { display: grid; gap: 6px; font-size: 14px; font-weight: 600; }
.error-text { margin: 0; color: #ff8a8d; }
.notice-text { margin: 0; color: var(--c-muted); }

/* ------------------------------------------------------------- 配信タブ */

.event-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; }
.event-head h1 { margin: 2px 0 4px; font-size: 24px; }
.eyebrow { margin: 0; color: var(--c-muted); font-size: 12px; letter-spacing: .08em; }
.schedule { margin: 0; color: var(--c-muted); font-size: 14px; }
.schedule strong { color: var(--c-text); font-family: var(--mono); }
.schedule .sep { margin: 0 8px; }
.rehearsal {
  margin: 0; padding: 8px 12px; border-radius: 8px; font-size: 13px;
  color: var(--c-amber); background: rgba(240, 169, 44, .1); border: 1px solid rgba(240, 169, 44, .35);
}

.status-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
.status-card {
  background: var(--c-panel); border: 1px solid var(--c-line); border-radius: var(--radius);
  padding: 14px 18px;
}
.status-label { margin: 0; color: var(--c-muted); font-size: 12px; letter-spacing: .06em; }
.status-value { margin: 4px 0 0; font-size: 22px; font-weight: 700; display: flex; align-items: center; gap: 10px; }
.status-value small { font-size: 14px; color: var(--c-muted); font-weight: 600; margin-left: 2px; }
.status-value.mono { font-family: var(--mono); }
.status-sub { margin: 2px 0 0; color: var(--c-muted); font-size: 12px; }

.status-card .dot { width: 12px; height: 12px; border-radius: 50%; background: var(--c-muted); flex: none; }
#serverCard[data-state="PROVISIONING"] .dot { background: var(--c-amber); animation: pulse 1.2s ease-in-out infinite; }
#serverCard[data-state="READY"] { border-color: rgba(47, 191, 113, .5); }
#serverCard[data-state="READY"] .dot { background: var(--c-green); box-shadow: 0 0 0 4px rgba(47, 191, 113, .2); }
#serverCard[data-state="READY"] .status-value { color: #7ee2a8; }
#serverCard[data-state="FAILED"] .dot { background: var(--c-red); }

.onair-card[data-live="true"] { background: #2a1214; border-color: var(--c-red); }
.onair { letter-spacing: .08em; }
.onair-card[data-live="true"] .onair { color: #fff; }
.onair-card[data-live="true"] .onair::before {
  content: ""; width: 12px; height: 12px; border-radius: 50%;
  background: var(--c-red); box-shadow: 0 0 10px var(--c-red); animation: pulse 1s ease-in-out infinite;
}
#remainCard[data-warn="true"] { border-color: var(--c-amber); }
#remainCard[data-warn="true"] .status-value { color: var(--c-amber); }

@keyframes pulse { 50% { opacity: .35; } }

.broadcast-grid { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 20px; align-items: start; }
.side-col { display: grid; gap: 20px; }

.input-row { display: grid; gap: 6px; margin-top: 10px; }
.input-controls { display: flex; gap: 8px; }
.input-controls select { flex: 1; }
.option-row { display: flex; flex-wrap: wrap; gap: 8px 20px; margin: 12px 0 4px; }
.check { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--c-accent); }

/* レベルメータ */
.meter {
  margin: 18px 0; padding: 14px 16px; border-radius: 8px;
  background: #0b0d10; border: 1px solid var(--c-line);
}
.meter-row { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.meter-ch { width: 12px; font-family: var(--mono); font-size: 12px; color: var(--c-muted); }
.meter-bar {
  position: relative; flex: 1; height: 14px; border-radius: 3px; overflow: hidden;
  background: linear-gradient(90deg, #1e9e5a 0%, #2fbf71 66%, #d7c32c 83%, #f0a92c 90%, #e5484d 100%);
}
.meter-cover { position: absolute; top: 0; right: 0; bottom: 0; width: 100%; background: #1a1f26; }
.meter-peak { position: absolute; top: 0; bottom: 0; width: 2px; background: #fff; opacity: 0; left: 0; }
.meter-scale {
  display: flex; justify-content: space-between; margin-left: 22px;
  font-family: var(--mono); font-size: 10px; color: var(--c-muted);
}
.meter-readout { margin: 6px 0 0; display: flex; gap: 10px; align-items: center; font-family: var(--mono); font-size: 13px; }
.clip { color: #fff; background: var(--c-red); border-radius: 4px; padding: 0 6px; font-weight: 700; }

/* 配信開始／停止ボタン */
.main-btn {
  width: 100%; height: 84px; border-radius: 12px; cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 14px;
  font-size: 24px; font-weight: 800; letter-spacing: .06em; color: #fff;
  border: 0; background: var(--c-green);
  box-shadow: 0 4px 0 #1d8a50;
  transition: transform .06s, background .2s;
}
.main-btn:active:not(:disabled) { transform: translateY(2px); box-shadow: 0 2px 0 #1d8a50; }
.main-btn:disabled { background: #2a313b; box-shadow: none; color: var(--c-muted); cursor: not-allowed; }
.main-btn[data-mode="stop"] { background: var(--c-red); box-shadow: 0 4px 0 #a52f33; }
.main-btn-icon { width: 0; height: 0; border-left: 20px solid currentColor; border-top: 12px solid transparent; border-bottom: 12px solid transparent; }
.main-btn[data-mode="stop"] .main-btn-icon { width: 20px; height: 20px; border: 0; background: currentColor; border-radius: 3px; }
.main-btn.shake { animation: shake .35s; }
@keyframes shake { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }
.main-hint { margin: 10px 0 0; text-align: center; color: var(--c-muted); font-size: 13px; }

.extend-value { margin: 4px 0 0; font-size: 22px; font-weight: 700; }
.extend-sub { margin: 0 0 14px; color: var(--c-muted); font-size: 14px; }
.extend-sub strong { color: var(--c-text); font-family: var(--mono); }

.qr { background: #fff; border-radius: 8px; padding: 8px; width: 200px; margin: 8px auto; }
.qr svg { display: block; width: 100%; height: auto; }
.qr-small { width: 140px; }
.url-line { margin: 4px 0; text-align: center; font-family: var(--mono); font-size: 12px; word-break: break-all; }
.alt-url { margin-top: 10px; font-size: 13px; color: var(--c-muted); }
.alt-url summary { cursor: pointer; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  padding: 12px 18px; border-radius: 8px; max-width: 90vw;
  background: #222932; color: var(--c-text); border: 1px solid var(--c-line);
  box-shadow: 0 8px 24px rgba(0, 0, 0, .4); z-index: 50; font-size: 14px;
}
.toast[data-kind="error"] { border-color: var(--c-red); }
.toast[data-kind="warn"] { border-color: var(--c-amber); }

@media (max-width: 900px) {
  .status-grid { grid-template-columns: repeat(2, 1fr); }
  .broadcast-grid { grid-template-columns: 1fr; }
  .field-row { grid-template-columns: 1fr; }
  .brand-sub { display: none; }
  .event-table { font-size: 12px; }
}

/* ------------------------------------------------------------- リスナー */

body.listener { background: var(--l-bg); color: var(--l-text); min-height: 100vh; min-height: 100dvh; }
.listener-main {
  max-width: 520px; margin: 0 auto; padding: 28px 20px calc(28px + env(safe-area-inset-bottom));
  min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; gap: 28px;
}
.listener-head h1 { margin: 12px 0 8px; font-size: 24px; line-height: 1.35; }
.description { margin: 0; color: var(--l-muted); white-space: pre-wrap; font-size: 15px; }

.status-pill {
  display: inline-flex; align-items: center; gap: 8px; margin: 0;
  padding: 4px 12px; border-radius: 999px; font-size: 13px; font-weight: 600;
  background: #ebe8e2; color: var(--l-muted);
}
.status-pill .dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.status-pill[data-state="LIVE"] { background: #fde7e8; color: #c62a2f; }
.status-pill[data-state="LIVE"] .dot { animation: pulse 1s ease-in-out infinite; }
.status-pill[data-state="WAITING"] { background: #e3edfd; color: var(--l-accent); }
.status-pill[data-state="PAUSED"] { background: #fdf1dc; color: #9a6206; }

.player {
  background: var(--l-card); border: 1px solid var(--l-line); border-radius: 20px;
  padding: 32px 24px 28px; display: grid; justify-items: center; gap: 6px;
  box-shadow: 0 6px 24px rgba(30, 30, 30, .06);
}
.play-btn {
  width: 132px; height: 132px; border-radius: 50%; border: 0; cursor: pointer;
  background: var(--l-accent); color: #fff;
  display: grid; place-items: center;
  box-shadow: 0 10px 24px rgba(31, 111, 235, .35);
  transition: transform .08s, background .2s;
  -webkit-tap-highlight-color: transparent;
}
.play-btn:active:not(:disabled) { transform: scale(.96); }
.play-btn:disabled { background: #c9ccd2; box-shadow: none; cursor: not-allowed; }
.play-icon {
  width: 0; height: 0; margin-left: 10px;
  border-left: 42px solid currentColor; border-top: 26px solid transparent; border-bottom: 26px solid transparent;
}
.play-btn[data-mode="stop"] { background: #2b2f36; box-shadow: 0 10px 24px rgba(0, 0, 0, .25); }
.play-btn[data-mode="stop"] .play-icon { margin: 0; width: 40px; height: 40px; border: 0; background: currentColor; border-radius: 6px; }
.play-label { margin: 12px 0 0; font-size: 18px; font-weight: 700; }
.play-sub { margin: 0; color: var(--l-muted); font-size: 14px; text-align: center; min-height: 1.6em; }

.volume { width: 100%; display: flex; align-items: center; gap: 12px; margin-top: 22px; }
.volume input[type=range] { flex: 1; accent-color: var(--l-accent); height: 32px; }
.vol-value { width: 44px; text-align: right; font-variant-numeric: tabular-nums; color: var(--l-muted); font-size: 14px; }
.vol-icon { width: 18px; height: 18px; flex: none; background: var(--l-muted);
  -webkit-mask: var(--icon) center / contain no-repeat; mask: var(--icon) center / contain no-repeat; }
.vol-low { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M4 9h4l5-4v14l-5-4H4z'/%3E%3C/svg%3E"); }
.vol-high { --icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M3 9h4l5-4v14l-5-4H3z'/%3E%3Cpath d='M15.5 8.5a5 5 0 0 1 0 7M18 6a8.5 8.5 0 0 1 0 12' stroke='%23000' stroke-width='2' fill='none' stroke-linecap='round'/%3E%3C/svg%3E"); }

.listener-foot { margin-top: auto; text-align: center; }
.stats { margin: 0 0 6px; font-family: var(--mono); font-size: 12px; color: var(--l-muted); }
.hint { margin: 0; font-size: 12px; color: var(--l-muted); }

/* 入力ゲイン・リミッター */
.gain-box { margin: 12px 0 4px; padding: 12px 14px; border: 1px solid var(--c-border, #d9dee7); border-radius: 10px; display: flex; flex-direction: column; gap: 8px; }
.gain-row { display: flex; align-items: center; flex-wrap: wrap; gap: 8px 14px; }
.gain-row input[type=range] { flex: 1; min-width: 140px; accent-color: var(--c-accent); }
.gain-value { min-width: 48px; text-align: right; font-size: 14px; }
.gain-row:has(#gainChk:not(:checked)) input[type=range], .gain-row:has(#gainChk:not(:checked)) .gain-value { opacity: .4; }

/* 遅延測定 */
.latency-summary { margin: 12px 0 4px; font-size: 15px; font-weight: 600; }
.latency-list { list-style: none; margin: 4px 0 0; padding: 0; font-size: 13px; color: var(--c-muted); display: flex; flex-direction: column; gap: 2px; }
