* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: 'Space Grotesk', 'Segoe UI', system-ui, sans-serif;
  background: #0a0e12;
  color: #e6edf3;
  min-height: 100vh;
}
.hidden { display: none !important; }

/* ---- Login ---- */
#login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at 50% 20%, #0f1720 0%, #05070a 80%);
}
.login-box {
  background: #10161d;
  border: 1px solid #1e2a35;
  border-radius: 10px;
  padding: 40px;
  width: 320px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.login-box h1 {
  font-size: 22px;
  letter-spacing: 2px;
  color: #22d3ee;
  margin: 0;
}
.login-box .sub { margin: 0 0 10px; color: #7d8b98; font-size: 13px; }
.login-box input {
  background: #0a0e12;
  border: 1px solid #253340;
  border-radius: 6px;
  color: #e6edf3;
  padding: 10px 12px;
  font-size: 14px;
}
.login-box button {
  background: #22d3ee;
  border: none;
  color: #05141a;
  font-weight: 700;
  padding: 11px;
  border-radius: 6px;
  cursor: pointer;
  letter-spacing: 0.5px;
}
.error { color: #f87171; font-size: 13px; min-height: 16px; }

/* ---- App shell ---- */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 24px;
  background: #0d1218;
  border-bottom: 1px solid #1a232c;
}
.brand { font-weight: 700; letter-spacing: 2px; color: #22d3ee; }
.topbar-right { display: flex; align-items: center; gap: 14px; font-size: 13px; color: #9fb0bd; }

.grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 18px;
  padding: 22px;
  max-width: 1200px;
  margin: 0 auto;
}
.card {
  background: #10161d;
  border: 1px solid #1e2a35;
  border-radius: 10px;
  padding: 20px;
}
.card.wide { grid-column: 1 / -1; }
.card h2 { margin: 0 0 14px; font-size: 15px; color: #22d3ee; letter-spacing: 0.5px; }
.card h3 { margin: 16px 0 8px; font-size: 13px; color: #9fb0bd; }

input[type=text], input[type=number], textarea {
  width: 100%;
  background: #0a0e12;
  border: 1px solid #253340;
  border-radius: 6px;
  color: #e6edf3;
  padding: 9px 10px;
  font-size: 13px;
  font-family: inherit;
  margin-bottom: 6px;
}
textarea { resize: vertical; }

label { font-size: 12px; color: #9fb0bd; display: block; margin-bottom: 4px; }

button {
  cursor: pointer;
  border: none;
  border-radius: 6px;
  font-weight: 600;
  font-size: 13px;
  padding: 9px 16px;
}
button.primary { background: #22d3ee; color: #05141a; }
button.ghost { background: transparent; border: 1px solid #2c3d4a; color: #cfe3ec; }
button.ghost.small { padding: 6px 12px; font-size: 12px; }
button.warn { background: #f59e0b; color: #221a05; }
button.danger { background: #ef4444; color: #2b0505; }

.btn-row { display: flex; gap: 10px; margin-top: 12px; flex-wrap: wrap; }

.badge {
  display: inline-block;
  padding: 6px 14px;
  border-radius: 20px;
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 1px;
}
.badge.idle { background: #1e2a35; color: #9fb0bd; }
.badge.running { background: #052e1c; color: #34d399; border: 1px solid #34d399; }

.status-details { margin-top: 12px; font-size: 13px; color: #b7c4cf; line-height: 1.7; white-space: pre-line; }

.upload-row { margin-bottom: 14px; }
.upload-status { font-size: 12px; color: #7d8b98; margin-left: 8px; }
.upload-status.ok { color: #34d399; }
.upload-status.err { color: #f87171; }

.settings-row { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.settings-row label { margin: 0; width: 170px; flex-shrink: 0; }
.settings-row input { margin-bottom: 0; }

.hint { font-size: 11.5px; color: #64707a; margin-top: 4px; }

#tiers-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; }
.tier-row {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #0a0e12;
  border: 1px solid #253340;
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 12.5px;
  flex-wrap: wrap;
}
.tier-row span { color: #9fb0bd; }
.tier-row input { width: 70px; margin-bottom: 0; text-align: center; }
.tier-row button { background: #2c1416; color: #f87171; padding: 5px 10px; font-size: 11px; }

.preview-wrap {
  width: 640px;
  height: 360px;
  overflow: hidden;
  position: relative;
  border-radius: 8px;
  border: 1px solid #253340;
  background-image:
    linear-gradient(45deg, #1c2530 25%, transparent 25%),
    linear-gradient(-45deg, #1c2530 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #1c2530 75%),
    linear-gradient(-45deg, transparent 75%, #1c2530 75%);
  background-size: 24px 24px;
  background-position: 0 0, 0 12px, 12px -12px, -12px 0px;
  background-color: #0a0e12;
}
.preview-wrap iframe {
  width: 1920px;
  height: 1080px;
  border: none;
  transform: scale(0.3333); /* 640/1920 */
  transform-origin: top left;
  pointer-events: none;
}

#pos-box {
  position: absolute;
  border: 2px dashed #22d3ee;
  background: rgba(34, 211, 238, 0.12);
  cursor: move;
  box-sizing: border-box;
  min-width: 20px;
  min-height: 14px;
}
.pos-handle {
  position: absolute;
  width: 12px;
  height: 12px;
  background: #22d3ee;
  border: 2px solid #0a0e12;
  border-radius: 50%;
  z-index: 10;
}
.pos-handle[data-handle="tl"] { top: -7px; left: -7px; cursor: nwse-resize; }
.pos-handle[data-handle="tr"] { top: -7px; right: -7px; cursor: nesw-resize; }
.pos-handle[data-handle="bl"] { bottom: -7px; left: -7px; cursor: nesw-resize; }
.pos-handle[data-handle="br"] { bottom: -7px; right: -7px; cursor: nwse-resize; }

#logs-table { font-size: 12px; max-height: 320px; overflow-y: auto; }
.log-row {
  display: grid;
  grid-template-columns: 150px 110px 90px 1fr;
  gap: 10px;
  padding: 6px 4px;
  border-bottom: 1px solid #1a232c;
  color: #b7c4cf;
}
.log-row .ev { color: #22d3ee; font-weight: 600; }

@media (max-width: 850px) {
  .grid { grid-template-columns: 1fr; }
}
