:root {
  --bg: #f5f5f5; --card: #fff; --card2: #f8f9fa; --hover: #f0f0f0;
  --text: #333; --text2: #555; --muted: #999; --border: #ddd; --border2: #f0f0f0;
  --ok: #22c55e; --warn: #fbbf24; --bad: #ef4444; --info: #007bff; --shadow: rgba(0,0,0,.1); --overlay: rgba(0,0,0,.5);
}
[data-theme="dark"] {
  --bg: #1a1a1a; --card: #2d2d2d; --card2: #3a3a3a; --hover: #404040;
  --text: #e0e0e0; --text2: #c0c0c0; --muted: #808080; --border: #444; --border2: #3a3a3a; --shadow: rgba(0,0,0,.3); --overlay: rgba(0,0,0,.7);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.5 -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Ubuntu, sans-serif; }
[hidden] { display: none !important; }
.mono { font-family: Menlo, Monaco, 'Ubuntu Mono', monospace; }

.top-nav { height: 56px; background: var(--card); border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; padding: 0 20px; position: sticky; top: 0; z-index: 50; }
.top-nav .logo { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 16px; }
.logo-mark { width: 26px; height: 26px; border-radius: 6px; background: linear-gradient(135deg, #ff7a18, #af002d); }
.top-nav .right { display: flex; align-items: center; gap: 12px; }
.chip { font-size: 13px; color: var(--text2); border: 1px solid var(--border); border-radius: 4px; padding: 4px 10px; }
.icon-btn { background: none; border: 1px solid var(--border); color: var(--text); border-radius: 4px; padding: 4px 8px; cursor: pointer; }

main { max-width: 1360px; margin: 0 auto; padding: 24px 20px 60px; }   /* wide enough for a 1280 px stream at 1:1 */
@media (max-width: 600px) { main { padding: 16px; } }
h2 { margin: 0 0 14px; font-size: 22px; }
.section-header { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.server-line { font-size: 13px; color: var(--text2); }
.server-line b { color: var(--text); }
.card { background: var(--card); border: 1px solid var(--border); border-radius: 8px; padding: 20px; margin-bottom: 20px; }
.subhead { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0 0 12px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; }
.grid-5 { display: grid; grid-template-columns: repeat(5, 1fr); gap: 16px; }
@media (max-width: 900px) { .grid-3, .grid-5 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 520px) { .grid-3, .grid-5 { grid-template-columns: 1fr; } }
.form-group { margin-bottom: 12px; }
.form-group label { display: block; margin-bottom: 5px; color: var(--text2); font-weight: 500; }
.form-group select, .form-group input { width: 100%; padding: 8px 12px; border: 1px solid var(--border); border-radius: 4px; font-size: 14px; background: var(--card); color: var(--text); }
.form-group .hint, .hint { font-size: 12px; color: var(--muted); margin-top: 4px; }
.row2 { display: flex; gap: 6px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.btn { padding: 10px 18px; border: 0; border-radius: 4px; cursor: pointer; font-size: 14px; color: #fff; background: var(--info); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-danger { background: #dc3545; }
.btn-secondary { background: #6c757d; }
.btn-small { padding: 5px 10px; font-size: 12px; }
.error { color: var(--bad); font-size: 13px; }
.dev { border: 1px dashed var(--border); border-radius: 6px; padding: 12px 14px; margin-bottom: 14px; background: var(--card2); }
.dev input { font-family: Menlo, Monaco, 'Ubuntu Mono', monospace; font-size: 12px; }
.dev code { font-family: Menlo, Monaco, 'Ubuntu Mono', monospace; font-size: 12px; }

.banner { border-radius: 6px; padding: 12px 16px; margin-bottom: 16px; display: flex; gap: 12px; align-items: flex-start; border: 1px solid; }
.banner-warn { background: rgba(251,191,36,.12); border-color: var(--warn); }
.banner-bad { background: rgba(239,68,68,.12); border-color: var(--bad); }
.banner-ok { background: rgba(34,197,94,.12); border-color: var(--ok); }
.banner .close { margin-left: auto; background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 16px; }

.stage { background: #000; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
/* The surface takes the stream's own aspect ratio and, when the page is wide
   enough, its exact pixel width, so the web client renders 1:1. The iframe is
   always laid out at the stream's pixel size and scaled by app.js to fit the
   surface: the clients size their canvas from the width alone, so anything
   but a 1:1 or uniformly scaled frame squashes or clips the picture. */
.stage-surface { --stage-w: 1280px; --stage-ar: 16 / 9; width: min(100%, var(--stage-w)); aspect-ratio: var(--stage-ar); margin: 0 auto; position: relative; overflow: hidden; background: linear-gradient(135deg, #1a1a2e, #16213e 50%, #0f3460); color: #c0c0c0; display: flex; align-items: center; justify-content: center; }
.portrait .stage-surface { max-height: 75vh; }
.stage-surface iframe { position: absolute; top: 0; left: 0; border: 0; background: #000; transform-origin: top left; }
.stage-surface:fullscreen { width: 100%; aspect-ratio: auto; max-height: none; }
.stage-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 14px; background: #111; border-top: 1px solid #222; color: #9aa; font-size: 12px; }
.status { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: #c0c0c0; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: #6b7280; }
.st-starting .status-dot, .st-ready .status-dot, .st-booting .status-dot, .st-stopping .status-dot { background: var(--warn); animation: pulse 1.2s ease-in-out infinite; }
.st-live .status-dot { background: var(--ok); }
.st-failed .status-dot { background: var(--bad); }
@keyframes pulse { 50% { opacity: .3; } }
.stage-toolbar .icon-btn { border-color: #333; color: #ccc; }

.stats { margin-top: 20px; background: var(--card); border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.stats-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--border2); }
.stats-header h4 { margin: 0; font-size: 14px; }
.tbl-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
th, td { padding: 9px 14px; text-align: right; white-space: nowrap; border-bottom: 1px solid var(--border2); }
th:first-child, td:first-child { text-align: left; }
th { font-size: 12px; color: var(--muted); font-weight: 500; }
th .unit { font-weight: 400; color: var(--muted); font-size: 11px; }
tr.total td { font-weight: 600; border-top: 2px solid var(--border); }
.pid { color: var(--muted); font-size: 12px; }
.stats-extras { display: flex; flex-wrap: wrap; gap: 8px 22px; padding: 10px 16px; border-top: 1px solid var(--border2); font-size: 12px; color: var(--muted); }
.stats-extras b { color: var(--text); font-variant-numeric: tabular-nums; }

.logs-list { display: grid; gap: 10px; }
.log-item { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border: 1px solid var(--border2); border-radius: 6px; background: var(--card2); flex-wrap: wrap; }
.log-item .name { font-family: Menlo, Monaco, 'Ubuntu Mono', monospace; font-size: 12px; }
.log-item .who { font-size: 12px; color: var(--muted); }
.log-item .state { margin-left: auto; font-size: 12px; }
.state-ok { color: var(--ok); } .state-wait { color: var(--warn); } .state-bad { color: var(--bad); }
a { color: var(--info); }

.modal-overlay { position: fixed; inset: 0; background: var(--overlay); display: flex; align-items: center; justify-content: center; z-index: 200; padding: 16px; }
.modal { background: var(--card); border-radius: 8px; padding: 22px 24px; max-width: 460px; width: 100%; box-shadow: 0 10px 40px var(--shadow); }
.modal h3 { margin: 0 0 8px; font-size: 17px; }
.modal p { margin: 0 0 12px; color: var(--text2); }
.modal .who { background: var(--card2); border-radius: 6px; padding: 10px 12px; font-size: 13px; margin-bottom: 16px; }
.modal .who div { display: flex; justify-content: space-between; gap: 12px; }
.modal .who span:first-child { color: var(--muted); }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }

.login { max-width: 380px; margin: 60px auto; }
.login h2 { margin-bottom: 18px; }
