:root {
  --bg: #f3f5f8;
  --panel: #ffffff;
  --text: #17202b;
  --muted: #637083;
  --line: #dde3ea;
  --accent: #1f6feb;
  --accent-text: #ffffff;
  --danger: #c62828;
  --ok: #2e7d32;
  --warn: #b26a00;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0, 0, 0, .08);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f141a;
    --panel: #18202a;
    --text: #e6ebf1;
    --muted: #93a1b3;
    --line: #2a3542;
    --accent: #4b8df8;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }

/* layout */
header.top {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 8px;
  padding: 8px 16px; padding-top: max(8px, env(safe-area-inset-top));
  background: #0b2545; color: #fff;
}
header.top .brand { font-weight: 700; margin-right: auto; white-space: nowrap; }
nav.tabs { display: flex; gap: 4px; }
nav.tabs button { background: transparent; border: 0; color: #c9d6e6; padding: 8px 12px; border-radius: 8px; cursor: pointer; }
nav.tabs button.active { background: rgba(255, 255, 255, .14); color: #fff; }
header.top .icon-btn { background: transparent; border: 0; color: #c9d6e6; cursor: pointer; padding: 8px; border-radius: 8px; }
main { max-width: 1200px; margin: 0 auto; padding: 16px; }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 14px; }
.toolbar h1 { font-size: 20px; margin: 0 auto 0 0; }
.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.spacer { flex: 1; }
.empty { text-align: center; padding: 40px 16px; color: var(--muted); }

/* controls */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line); background: var(--panel); border-radius: 8px;
  padding: 8px 14px; cursor: pointer; min-height: 40px; white-space: nowrap;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.danger { color: var(--danger); }
.btn.small { min-height: 32px; padding: 4px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }
input[type=text], input[type=password], input[type=number], select, textarea {
  width: 100%; border: 1px solid var(--line); background: var(--bg); border-radius: 8px; padding: 8px 10px; min-height: 40px;
}
textarea { min-height: 90px; resize: vertical; }
input[type=color] { width: 44px; height: 36px; border: 1px solid var(--line); border-radius: 8px; padding: 2px; background: var(--bg); }
label.field { display: block; margin-bottom: 10px; }
label.field > span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 3px; }
.fields2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
.fields4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0 8px; }
.props .fields4 { grid-template-columns: 1fr 1fr; }

/* screens */
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; background: #9aa5b1; }
.dot.on { background: #2ecc71; box-shadow: 0 0 0 3px rgba(46, 204, 113, .2); }
.screen h3 { margin: 0; font-size: 17px; }
.remote { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
.remote .btn { min-height: 64px; font-size: 22px; }
.status-line { font-size: 13px; color: var(--muted); margin: 6px 0 10px; }

/* slide rendering (shared by editor + previews) */
.stage-wrap { position: relative; width: 100%; aspect-ratio: 16 / 9; overflow: hidden; background: #000; border-radius: 6px; }
.stage { position: absolute; left: 0; top: 0; width: 1920px; height: 1080px; transform-origin: 0 0; overflow: hidden; font-family: "DejaVu Sans", Verdana, sans-serif; }
.el { position: absolute; }
.el.text { display: flex; align-items: center; white-space: pre-wrap; word-wrap: break-word; line-height: 1.17; overflow: hidden; }
.el img, .el .ph { width: 100%; height: 100%; display: block; }
.el .ph { display: flex; align-items: center; justify-content: center; background: repeating-linear-gradient(45deg, #2b3440, #2b3440 20px, #333d4a 20px, #333d4a 40px); color: #c9d2dc; font-size: 48px; }
.el .play { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 140px; color: rgba(255, 255, 255, .85); text-shadow: 0 0 20px rgba(0, 0, 0, .6); pointer-events: none; }
.el.rss { overflow: hidden; display: flex; align-items: center; white-space: nowrap; line-height: 1.17; }
.el.rss.list { flex-direction: column; align-items: stretch; justify-content: flex-start; white-space: normal; }
.el.rss.list > * { flex-shrink: 0; }
.el.rss .feed-item { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.el.rss .feed-summary { opacity: .75; padding-left: 1.6em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.el.rss .feed-title { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.el.rss .feed-msg { padding: 0 .5em; opacity: .8; white-space: normal; }
.el.rss .ticker { display: flex; animation: ticker linear infinite; }
.el.rss .ticker span { white-space: pre; }
@keyframes ticker { from { transform: translateX(0); } to { transform: translateX(-50%); } }
.el.weather img { width: 100%; height: 100%; display: block; }
.el.weather .wx { position: absolute; inset: 0; display: flex; flex-direction: column; }
.el.weather .wx-chart { flex: 1; display: flex; align-items: flex-end; gap: 3px; min-height: 0; }
.el.weather .wx-chart > div { flex: 1; border-radius: 2px; }
.el.weather .wx-axis { display: flex; justify-content: space-between; opacity: .7; padding-top: 4px; }
.el.weather .wx-days { display: flex; }
.el.weather .wx-days > div { flex: 1; text-align: center; }
.el.weather .wx-credit { position: absolute; right: .5em; bottom: .3em; opacity: .7; }
.editing .el { cursor: move; }
.editing .el.sel { outline: 4px solid #4b8df8; outline-offset: 0; }
.editing .el:not(.sel) .handle { display: none; }
.editing .el .handle { position: absolute; right: -14px; bottom: -14px; width: 28px; height: 28px; background: #4b8df8; border: 3px solid #fff; border-radius: 50%; cursor: nwse-resize; touch-action: none; }

/* shows list */
.show-card .stage-wrap { margin-bottom: 10px; cursor: pointer; }
.badge { display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 99px; background: var(--bg); border: 1px solid var(--line); color: var(--muted); }

/* editor */
.editor { display: grid; grid-template-columns: 170px 1fr 300px; gap: 14px; align-items: start; }
.slides-strip { display: flex; flex-direction: column; gap: 8px; max-height: calc(100vh - 170px); overflow: auto; padding: 2px; }
.slides-strip .thumb { position: relative; border: 2px solid transparent; border-radius: 8px; cursor: pointer; }
.slides-strip .thumb.cur { border-color: var(--accent); }
.slides-strip .thumb .num { position: absolute; left: 4px; top: 2px; font-size: 11px; color: #fff; text-shadow: 0 0 3px #000; z-index: 2; }
.props h4 { margin: 4px 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.props hr { border: 0; border-top: 1px solid var(--line); margin: 14px 0; }
.canvas-col .stage-wrap { touch-action: none; }
.canvas-tools { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
@media (max-width: 960px) {
  .editor { grid-template-columns: 1fr; }
  .slides-strip { flex-direction: row; max-height: none; overflow-x: auto; }
  .slides-strip .thumb { flex: 0 0 120px; }
}

/* media */
.media-card .thumbbox { aspect-ratio: 16 / 9; background: #111 center / contain no-repeat; border-radius: 6px; margin-bottom: 8px; display: flex; align-items: center; justify-content: center; color: #889; font-size: 30px; }
.warn { color: var(--warn); font-size: 13px; }
.progress { height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; margin-top: 6px; }
.progress > div { height: 100%; background: var(--accent); width: 0; transition: width .2s; }
.dropzone { border: 2px dashed var(--line); border-radius: var(--radius); padding: 18px; text-align: center; color: var(--muted); margin-bottom: 14px; }
.dropzone.over { border-color: var(--accent); color: var(--accent); }

/* modal + toast */
.modal-back { position: fixed; inset: 0; background: rgba(0, 0, 0, .5); z-index: 50; display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal { background: var(--panel); border-radius: 12px; width: 100%; max-width: 720px; max-height: 90vh; overflow: auto; padding: 18px; }
.modal h2 { margin: 0 0 12px; font-size: 18px; }
.picker { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.picker .item { cursor: pointer; border: 2px solid transparent; border-radius: 8px; padding: 4px; }
.picker .item:hover { border-color: var(--accent); }
.picker .thumbbox { aspect-ratio: 16 / 9; background: #111 center / cover no-repeat; border-radius: 6px; }
.toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); background: #17202b; color: #fff; padding: 10px 16px; border-radius: 8px; z-index: 60; box-shadow: 0 4px 16px rgba(0, 0, 0, .3); max-width: calc(100vw - 32px); }
.toast.err { background: var(--danger); }

/* login */
.login { max-width: 360px; margin: 12vh auto; }
.login h1 { font-size: 22px; margin: 0 0 16px; }

@media (max-width: 600px) {
  header.top { flex-wrap: wrap; }
  nav.tabs { order: 3; width: 100%; }
  nav.tabs button { flex: 1; }
  .fields4 { grid-template-columns: 1fr 1fr; }
}
