:root {
  color-scheme: dark;
  --bg: #080d16;
  --panel: #101826;
  --panel-strong: #172233;
  --line: rgba(255, 255, 255, 0.1);
  --line-strong: rgba(255, 255, 255, 0.18);
  --text: #f7f8fb;
  --muted: #8e9aab;
  --orange: #ff5a14;
  --orange-soft: #ff7a26;
  --green: #35df6f;
  --red: #ff5563;
  --amber: #ffb84d;
  --radius: 16px;
  font-family: Inter, "SF Pro Display", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  background: var(--bg);
}

* { box-sizing: border-box; }

html, body { margin: 0; min-width: 320px; min-height: 100%; background: var(--bg); }

body {
  min-height: 100vh;
  color: var(--text);
  overflow-x: hidden;
  background:
    radial-gradient(circle at 18% -10%, rgba(255, 90, 20, 0.13), transparent 30%),
    radial-gradient(circle at 86% 0%, rgba(65, 92, 125, 0.15), transparent 30%),
    linear-gradient(145deg, #0b111d 0%, #070b12 72%);
}

button { font: inherit; }

.app-shell {
  width: 100%;
  min-height: 100vh;
  padding: max(18px, 1.5vw) max(24px, 2.2vw) max(12px, 1vw);
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 15px;
}

.topbar {
  min-height: 70px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  border-bottom: 1px solid var(--line);
  padding-bottom: 14px;
}

.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-mark { width: 46px; height: 46px; display: grid; place-items: center; overflow: hidden; padding: 3px; border-radius: 11px; background: #fff; box-shadow: 0 7px 20px rgba(0, 113, 207, .18); }
.brand-mark img { width: 100%; height: 100%; display: block; object-fit: contain; }
.brand-copy { display: flex; flex-direction: column; gap: 1px; }
.brand-copy strong { font-size: clamp(18px, 1.45vw, 28px); letter-spacing: 0.06em; }
.brand-copy small { color: #737f90; font-size: 10px; letter-spacing: 0.12em; }

.title-block { align-self: center; text-align: center; min-width: 240px; }
.title-block h1 { margin: 0; font-size: clamp(24px, 2.1vw, 40px); line-height: 1.05; letter-spacing: 0.16em; }
.title-rule { display: block; width: 72px; height: 3px; margin: 10px auto 0; border-radius: 4px; background: var(--orange); box-shadow: 0 0 14px rgba(255, 90, 20, 0.52); }

.system-meta { justify-self: end; display: flex; align-items: center; gap: 22px; }
.clock { display: grid; grid-template-columns: auto auto; align-items: baseline; gap: 12px; }
.clock strong { font-variant-numeric: tabular-nums; font-size: clamp(20px, 1.75vw, 34px); letter-spacing: 0.04em; }
.clock span { color: var(--muted); font-size: 14px; }
.environment-badge { padding: 6px 10px; border: 1px solid rgba(255, 184, 77, .35); border-radius: 7px; color: #ffc46d; background: rgba(255, 184, 77, .08); font-size: 12px; font-weight: 650; letter-spacing: .08em; white-space: nowrap; }
.environment-badge[hidden] { display: none; }
.connection-pill { display: inline-flex; align-items: center; gap: 8px; padding: 9px 13px; border-radius: 999px; border: 1px solid var(--line); background: rgba(255,255,255,.045); color: #c9d1dc; font-size: 14px; white-space: nowrap; }
.connection-pill i { width: 9px; height: 9px; border-radius: 50%; background: var(--amber); box-shadow: 0 0 10px currentColor; }
.connection-pill.is-live i { background: var(--green); }
.connection-pill.is-demo i { background: var(--amber); }
.connection-pill.is-error i { background: var(--red); }
.topbar-button { min-height: 40px; display: inline-flex; align-items: center; gap: 7px; padding: 0 12px; border: 1px solid var(--line); border-radius: 9px; color: #cbd2dc; background: rgba(255,255,255,.045); cursor: pointer; white-space: nowrap; }
.topbar-button svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.play-all-button { min-width: 128px; justify-content: center; color: white; border-color: rgba(255,90,20,.45); background: linear-gradient(135deg, #ff5712, #ff7a25); box-shadow: 0 7px 22px rgba(255,90,20,.17); }
.play-all-button .pause-icon { display: none; }
.play-all-button.is-playing .play-icon { display: none; }
.play-all-button.is-playing .pause-icon { display: inline; }

main { min-height: 0; display: grid; grid-template-rows: auto auto 1fr; gap: 12px; }

.control-deck { display: flex; align-items: center; justify-content: space-between; gap: 18px; min-width: 0; }
.region-strip { display: flex; gap: 9px; min-width: 0; overflow: hidden; padding: 3px; }
.region-tab, .tv-button { border: 1px solid transparent; color: #aab3c1; background: #121a27; border-radius: 10px; min-height: 44px; padding: 0 17px; cursor: pointer; transition: color .18s ease, background .18s ease, border-color .18s ease, transform .18s ease, box-shadow .18s ease; }
.region-tab { display: inline-flex; align-items: center; gap: 9px; flex: 0 0 auto; font-size: 16px; }
.region-tab small { min-width: 28px; padding: 3px 8px; border-radius: 999px; color: #8e99aa; background: rgba(255,255,255,.055); font-size: 12px; font-variant-numeric: tabular-nums; }
.region-tab.is-active, .tv-button.is-active { color: white; border-color: rgba(255, 90, 20, .42); background: linear-gradient(135deg, var(--orange), #ff7d24); box-shadow: 0 8px 24px rgba(255, 90, 20, .18); }
.region-tab.is-active small { background: rgba(255,255,255,.2); color: white; }

.deck-actions { display: flex; align-items: center; gap: 8px; flex: 0 0 auto; }
.tv-button { display: inline-flex; align-items: center; justify-content: center; gap: 8px; font-size: 14px; }
.tv-button svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon-button { width: 44px; padding: 0; }
.view-switcher { display: flex; padding: 4px; gap: 3px; border-radius: 12px; background: rgba(255,255,255,.035); }
.view-switcher .tv-button { min-height: 36px; padding: 0 13px; background: transparent; }
.view-switcher .tv-button.is-active { background: #303b4b; border-color: transparent; box-shadow: none; }
.page-indicator { min-width: 49px; text-align: center; color: #7f8a9a; font-size: 13px; font-variant-numeric: tabular-nums; }

.notice { min-height: 43px; display: flex; align-items: center; gap: 11px; padding: 8px 15px; color: #ffd2bc; background: rgba(255, 90, 20, .09); border: 1px solid rgba(255, 90, 20, .2); border-radius: 11px; font-size: 14px; }
.notice[hidden] { display: none; }
.notice-icon { width: 23px; height: 23px; display: grid; place-items: center; border-radius: 50%; background: var(--orange); color: white; font-weight: 800; }

.monitor-grid { min-height: 0; display: grid; gap: 13px; align-content: center; }
.monitor-grid.layout-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.monitor-grid.layout-6 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.monitor-grid.layout-9 { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }

.monitor-card {
  position: relative;
  min-width: 0;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,.13);
  border-radius: var(--radius);
  background: #121a25;
  box-shadow: 0 12px 32px rgba(0,0,0,.25);
  isolation: isolate;
  cursor: pointer;
  outline: 0;
  transform: translateZ(0);
  transition: border-color .18s ease, transform .18s ease, box-shadow .18s ease;
}
.monitor-card::after { content: ""; position: absolute; inset: 0; z-index: 3; pointer-events: none; background: linear-gradient(to bottom, rgba(4,7,12,.78) 0%, rgba(4,7,12,.03) 27%, rgba(4,7,12,.04) 60%, rgba(4,7,12,.88) 100%); }
.monitor-card:hover { border-color: rgba(255,255,255,.28); }
.monitor-card[data-focused="true"], [data-focus]:focus-visible { outline: 3px solid var(--orange); outline-offset: 3px; box-shadow: 0 0 0 1px rgba(255,255,255,.72), 0 0 28px rgba(255, 90, 20, .5); z-index: 5; }
.monitor-card[data-focused="true"] { transform: scale(1.012); }
.monitor-card video, .monitor-card .poster, .monitor-card .ez-player-host { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.monitor-card video { z-index: 2; background: #111720; }
.monitor-card .ez-player-host { z-index: 2; overflow: hidden; background: #111720; }
.monitor-card .ez-player-host > div, .monitor-card .ez-player-host canvas, .monitor-card .ez-player-host video { width: 100% !important; height: 100% !important; }
.monitor-card .poster { z-index: 1; filter: saturate(.84) contrast(1.04); }
.monitor-card.is-offline .poster { filter: grayscale(.75) brightness(.65); }
.monitor-card.is-paused .poster { filter: saturate(.55) brightness(.42); }

.card-head, .card-foot { position: absolute; left: 0; right: 0; z-index: 4; display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.card-head { top: 0; padding: clamp(11px, 1vw, 18px); }
.card-foot { bottom: 0; align-items: flex-end; padding: clamp(11px, 1vw, 18px); }
.camera-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: clamp(15px, 1.08vw, 21px); font-weight: 680; text-shadow: 0 2px 8px rgba(0,0,0,.72); }
.camera-region { display: block; margin-top: 4px; color: #c2c9d3; font-size: clamp(12px, .77vw, 14px); font-weight: 450; }
.status-chip { flex: 0 0 auto; display: inline-flex; align-items: center; gap: 7px; padding: 7px 10px; border-radius: 999px; background: rgba(4,8,13,.66); border: 1px solid rgba(255,255,255,.12); font-size: 13px; backdrop-filter: blur(8px); }
.status-chip i { width: 9px; height: 9px; border-radius: 50%; background: var(--green); box-shadow: 0 0 8px var(--green); }
.is-offline .status-chip i { background: var(--red); box-shadow: 0 0 8px var(--red); }
.is-pending .status-chip i { background: var(--amber); box-shadow: 0 0 8px var(--amber); }
.is-paused .status-chip i { background: var(--amber); box-shadow: 0 0 8px var(--amber); }
.is-token-missing .status-chip i { background: var(--red); box-shadow: 0 0 8px var(--red); }
.is-demo .status-chip i { background: var(--amber); box-shadow: 0 0 8px var(--amber); }
.timestamp { color: rgba(255,255,255,.78); font-size: clamp(11px, .72vw, 14px); font-variant-numeric: tabular-nums; text-shadow: 0 2px 8px #000; }
.card-tools { display: flex; gap: 7px; }
.card-tool { width: 35px; height: 35px; display: grid; place-items: center; border: 0; border-radius: 9px; color: white; background: rgba(3,6,10,.56); backdrop-filter: blur(8px); }
.card-tool svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.stream-state { position: absolute; inset: 0; z-index: 3; display: grid; place-items: center; pointer-events: none; }
.stream-state span { display: none; padding: 9px 14px; border-radius: 999px; color: #d9dee7; background: rgba(5,8,13,.62); backdrop-filter: blur(8px); font-size: 13px; }
.monitor-card.is-loading .stream-state span, .monitor-card.is-error .stream-state span, .monitor-card.is-paused .stream-state span { display: inline-flex; align-items: center; gap: 8px; }
.monitor-card.is-loading .stream-state span::before { content: ""; width: 13px; height: 13px; border: 2px solid rgba(255,255,255,.25); border-top-color: white; border-radius: 50%; animation: spin .8s linear infinite; }
.monitor-card.is-paused .stream-state span { color: #fff; background: rgba(5,8,13,.78); border: 1px solid rgba(255,255,255,.12); }

.empty-state { min-height: 420px; align-self: stretch; display: grid; place-content: center; justify-items: center; text-align: center; color: #8792a2; }
.empty-state[hidden] { display: none; }
.empty-state h2 { margin: 18px 0 6px; color: #d6dce5; font-size: 24px; }
.empty-state p { margin: 0; }
.empty-icon { width: 74px; height: 74px; display: grid; place-items: center; border-radius: 22px; background: #121b28; color: #687486; }
.empty-icon svg { width: 42px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.statusbar { min-height: 36px; display: flex; align-items: center; justify-content: space-between; gap: 24px; color: #788496; font-size: 13px; }
.status-summary { display: flex; align-items: center; gap: 22px; }
.status-summary span { display: inline-flex; align-items: center; gap: 7px; }
.status-summary strong { color: #d8dee7; font-variant-numeric: tabular-nums; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.dot.online { color: var(--green); }
.dot.offline { color: var(--red); }
.dot.demo { color: var(--orange); }
.remote-help { display: flex; align-items: center; gap: 7px; }
kbd { min-width: 27px; padding: 3px 7px; color: #aab3c0; text-align: center; border: 1px solid #313b49; border-bottom-width: 2px; border-radius: 5px; background: #121925; font-family: inherit; }

.toast { position: fixed; left: 50%; bottom: 62px; z-index: 200; max-width: min(520px, 85vw); padding: 12px 18px; border-radius: 11px; color: white; background: rgba(25,33,45,.94); border: 1px solid var(--line-strong); box-shadow: 0 14px 40px rgba(0,0,0,.35); opacity: 0; transform: translate(-50%, 12px); pointer-events: none; transition: opacity .2s ease, transform .2s ease; }
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }

.settings-backdrop { position: fixed; inset: 0; z-index: 300; display: grid; place-items: center; padding: 24px; background: rgba(3,6,11,.78); backdrop-filter: blur(9px); }
.settings-backdrop[hidden] { display: none; }
.settings-panel { width: min(520px, 92vw); padding: 26px; border: 1px solid rgba(255,255,255,.14); border-radius: 18px; background: linear-gradient(145deg, #182231, #0e1622); box-shadow: 0 30px 90px rgba(0,0,0,.55); }
.settings-heading { display: flex; justify-content: space-between; align-items: flex-start; gap: 18px; }
.settings-heading span { color: var(--orange); font-size: 11px; font-weight: 750; letter-spacing: .16em; }
.settings-heading h2 { margin: 4px 0 0; font-size: 26px; }
.settings-close { width: 38px; height: 38px; border: 1px solid var(--line); border-radius: 9px; color: #aeb8c5; background: rgba(255,255,255,.04); font-size: 24px; cursor: pointer; }
.settings-panel > p { margin: 18px 0 22px; color: #929eae; line-height: 1.65; font-size: 14px; }
.minutes-field { display: flex; align-items: center; justify-content: space-between; gap: 18px; padding: 16px; border: 1px solid var(--line); border-radius: 12px; background: rgba(255,255,255,.025); }
.minutes-field > span { color: #d8dee7; font-weight: 650; }
.minutes-field div { display: flex; align-items: center; gap: 9px; }
.minutes-field input { width: 106px; height: 42px; padding: 0 12px; border: 1px solid rgba(255,90,20,.36); border-radius: 8px; outline: 0; color: white; background: #0b121d; font: inherit; font-size: 18px; font-variant-numeric: tabular-nums; }
.minutes-field b { color: #8e99a9; font-size: 13px; }
.preset-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 12px; }
.preset-row button, .settings-actions button { min-height: 42px; border: 1px solid var(--line); border-radius: 9px; color: #aeb8c5; background: rgba(255,255,255,.035); cursor: pointer; }
.preset-row button:hover { color: white; border-color: rgba(255,90,20,.45); }
.settings-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 25px; }
.settings-actions button { min-width: 108px; padding: 0 18px; }
.settings-actions .primary-action { color: white; border-color: transparent; background: linear-gradient(135deg, var(--orange), #ff7a25); }

.monitor-card.is-zoomed { position: fixed; inset: 18px; z-index: 100; width: auto; height: auto; aspect-ratio: auto; border-color: rgba(255, 90, 20, .8); box-shadow: 0 0 0 200vmax rgba(0,0,0,.94), 0 20px 80px rgba(0,0,0,.65); }
.monitor-card.is-zoomed .camera-name { font-size: 26px; }

@keyframes spin { to { transform: rotate(360deg); } }

@media (max-aspect-ratio: 4/3) {
  .topbar { grid-template-columns: 1fr auto; }
  .title-block { order: -1; grid-column: 1 / -1; margin-bottom: 14px; }
  .clock span, .view-switcher, .remote-help { display: none; }
  .control-deck { align-items: flex-start; flex-direction: column; }
  .region-strip { width: 100%; overflow-x: auto; }
  .deck-actions { width: 100%; justify-content: flex-end; }
  .monitor-grid.layout-4, .monitor-grid.layout-6, .monitor-grid.layout-9 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 760px) {
  .app-shell { padding: 14px; }
  .brand-copy small, .clock, .page-indicator, .environment-badge, #playbackSettingsButton span { display: none; }
  .system-meta { gap: 8px; }
  .topbar-button { padding: 0 10px; }
  .play-all-button { min-width: 108px; }
  .connection-pill { padding: 8px 10px; }
  .refresh-button { font-size: 0; width: 44px; padding: 0; }
  .monitor-grid.layout-4, .monitor-grid.layout-6, .monitor-grid.layout-9 { grid-template-columns: 1fr; }
  .statusbar { justify-content: center; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
