:root {
  --bg: #10141c;
  --panel: #171d28;
  --line: #2a3344;
  --fg: #e7edf7;
  --muted: #8b97a8;
  --accent: #2f8f6b;
  --accent2: #3d7ecf;
  --danger: #c44c4c;
  --live: #2f8f6b;
  --ready: #3d7ecf;
  --idle: #6b7585;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--fg);
  background:
    linear-gradient(160deg, #152033 0%, var(--bg) 42%, #0d1118 100%);
  font-family: "IBM Plex Sans", "Segoe UI", sans-serif;
}
.wrap { max-width: 1100px; margin: 0 auto; padding: 1.5rem 1.25rem 3rem; }
.wrap.setup-wrap { max-width: 1480px; }
.top {
  display: flex;
  justify-content: space-between;
  gap: 1.25rem;
  align-items: flex-start;
  flex-wrap: wrap;
  margin-bottom: 1.5rem;
}
.brand {
  margin: 0 0 0.2rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-size: 0.72rem;
  color: var(--muted);
}
h1 { margin: 0; font-size: 1.6rem; font-weight: 600; }
.num-btns {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  margin-top: 15px;
}
.num-btn {
  min-width: calc(2.25rem + 5px);
  min-height: calc(2.25rem + 5px);
  padding: 0.4rem 0.7rem;
  font-size: 0.95rem;
  background: var(--panel);
  color: var(--fg);
  border: 1px solid var(--line);
  font-weight: 600;
  white-space: nowrap;
}
.num-btn:hover { border-color: var(--accent2); }
.num-btn.active {
  background: var(--accent2);
  border-color: var(--accent2);
  color: #fff;
}
.muted { color: var(--muted); }
.mono { font-family: "IBM Plex Mono", ui-monospace, monospace; font-size: 0.8rem; }
.small { font-size: 0.85rem; }
.create { display: flex; gap: 0.5rem; align-items: center; }
.header-actions {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 0.85rem;
}
.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  max-width: none;
}
.login-card {
  width: min(100%, 420px);
  padding: 1.75rem 1.5rem;
  background: color-mix(in srgb, var(--panel) 92%, transparent);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.login-card h1 { margin-bottom: 0.65rem; }
.login-card .muted { margin: 0 0 1.15rem; line-height: 1.45; }
.btn-tg {
  width: 100%;
  background: #2aabee;
}
.btn-tg:hover { filter: brightness(1.05); }
.create-row {
  display: flex;
  flex-wrap: nowrap;
  gap: 0.5rem;
  align-items: center;
  justify-content: flex-end;
}
input {
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--fg);
  padding: 0.55rem 0.7rem;
  border-radius: 4px;
  min-width: 220px;
}
button, .secondary {
  background: var(--accent);
  color: #fff;
  border: 0;
  border-radius: 4px;
  padding: 0.55rem 0.9rem;
  cursor: pointer;
  font-weight: 600;
}
button.secondary, .secondary { background: var(--accent2); }
button:disabled { opacity: 0.45; cursor: not-allowed; }
button.danger { background: var(--danger); }
.table {
  width: 100%;
  border-collapse: collapse;
  background: color-mix(in srgb, var(--panel) 88%, transparent);
  border: 1px solid var(--line);
}
.table th, .table td {
  text-align: left;
  padding: 0.85rem 0.9rem;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
.table th { color: var(--muted); font-weight: 500; font-size: 0.8rem; }
.pill {
  display: inline-block;
  padding: 0.15rem 0.45rem;
  border-radius: 3px;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #fff;
}
.pill.live { background: var(--live); }
.pill.ready { background: var(--ready); }
.pill.idle { background: var(--idle); }
.links { display: flex; gap: 0.75rem; }
.links a, .back, a { color: #9ec5ff; }
.empty, .err { color: var(--muted); }
.err { color: #ff8e8e; }
.actions { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.setup-grid {
  display: grid;
  grid-template-columns: minmax(0, 2.4fr) minmax(320px, 0.95fr);
  gap: 1.1rem;
  align-items: start;
}
@media (max-width: 900px) {
  .setup-grid { grid-template-columns: 1fr; }
}
.panel {
  background: color-mix(in srgb, var(--panel) 90%, transparent);
  border: 1px solid var(--line);
  padding: 0.75rem;
}
.panel-head {
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 0.5rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.canvas-box { position: relative; background: #000; user-select: none; }
#source, #preview {
  width: 100%;
  display: block;
  background: #000;
  max-height: 60vh;
}
.setup-wrap #source {
  max-height: 78vh;
}
.setup-wrap #preview {
  max-height: 36vh;
}
.caption-cell {
  min-width: 220px;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
.caption-input {
  width: 100%;
  min-width: 180px;
  resize: vertical;
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--fg);
  padding: 0.45rem 0.55rem;
  border-radius: 4px;
  font-family: inherit;
  font-size: 0.85rem;
}
.crop-overlay {
  position: absolute;
  border: 2px solid #3dffb0;
  background: rgba(61, 255, 176, 0.12);
  box-sizing: border-box;
  cursor: move;
  z-index: 3;
  pointer-events: auto;
}
.crop-size-badge {
  position: absolute;
  left: 0;
  top: -1.55rem;
  padding: 0.15rem 0.4rem;
  background: #111;
  color: #9effc8;
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: 0.78rem;
  border-radius: 3px;
  white-space: nowrap;
  pointer-events: none;
  z-index: 4;
}
.crop-size-line {
  margin: 0.45rem 0 0;
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: 0.85rem;
}
.crop-handle {
  position: absolute;
  width: 10px;
  height: 10px;
  background: #fff;
  border: 2px solid #3dffb0;
  border-radius: 2px;
  box-sizing: border-box;
  z-index: 5;
}
.crop-handle[data-handle="nw"] { left: -6px; top: -6px; cursor: nwse-resize; }
.crop-handle[data-handle="n"]  { left: 50%; top: -6px; transform: translateX(-50%); cursor: ns-resize; }
.crop-handle[data-handle="ne"] { right: -6px; top: -6px; cursor: nesw-resize; }
.crop-handle[data-handle="e"]  { right: -6px; top: 50%; transform: translateY(-50%); cursor: ew-resize; }
.crop-handle[data-handle="se"] { right: -6px; bottom: -6px; cursor: nwse-resize; }
.crop-handle[data-handle="s"]  { left: 50%; bottom: -6px; transform: translateX(-50%); cursor: ns-resize; }
.crop-handle[data-handle="sw"] { left: -6px; bottom: -6px; cursor: nesw-resize; }
.crop-handle[data-handle="w"]  { left: -6px; top: 50%; transform: translateY(-50%); cursor: ew-resize; }
.caption-box {
  margin-top: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  width: 100%;
}
.caption-lines {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}
.caption-line-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 0.4rem;
  align-items: center;
}
.caption-line-row input[type="text"] {
  width: 100%;
  min-width: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--fg);
  padding: 0.55rem 0.65rem;
  border-radius: 4px;
  font-size: 0.95rem;
}
.caption-line-row select {
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--fg);
  padding: 0.5rem 0.4rem;
  border-radius: 4px;
  min-width: 88px;
}
.caption-line-row .btn-del-line {
  background: var(--danger);
  color: #fff;
  border: 0;
  border-radius: 4px;
  padding: 0.45rem 0.55rem;
  cursor: pointer;
  font-weight: 600;
}
.caption-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}
