:root {
  --bg: #ecf2f5;
  --card: #ffffff;
  --text: #14213d;
  --muted: #4b5563;
  --primary: #0f766e;
  --danger: #b91c1c;
  --ok: #166534;
  --border: #cfd8df;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 8% 12%, #dbeafe 0%, transparent 24%),
    radial-gradient(circle at 90% 10%, #dcfce7 0%, transparent 22%),
    var(--bg);
  min-height: 100vh;
}

.container {
  width: min(1080px, 94%);
  margin: 24px auto;
}

h1, h2, h3 {
  margin-top: 0;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 18px;
  margin-bottom: 14px;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.05);
}

.grid {
  display: grid;
  gap: 10px;
}

.grid.two {
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
}

label {
  display: block;
  font-weight: 600;
  margin-bottom: 6px;
}

input, button, select {
  width: 100%;
  font-size: 15px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
}

button {
  border: none;
  background: var(--primary);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
}

button.secondary {
  background: #334155;
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.badge {
  display: inline-block;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  padding: 6px 10px;
}

.badge.ok {
  color: #fff;
  background: var(--ok);
}

.badge.warn {
  color: #fff;
  background: #9a3412;
}

.log {
  background: #0f172a;
  color: #e2e8f0;
  border-radius: 12px;
  padding: 10px;
  min-height: 110px;
  max-height: 300px;
  overflow: auto;
  font-family: Consolas, Monaco, monospace;
  font-size: 13px;
  white-space: pre-wrap;
}

.small {
  font-size: 13px;
  color: var(--muted);
}

.nav {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.live-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 280px;
  gap: 6px;
  align-items: start;
}

.live-main {
  min-width: 0;
}

.live-side {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #f8fafc;
  padding: 10px;
  display: grid;
  gap: 6px;
  position: sticky;
  top: 8px;
}

.live-side .nav {
  display: grid;
  gap: 8px;
}

.live-side .nav button {
  width: 100%;
}

.nav a {
  text-decoration: none;
  color: var(--primary);
  font-weight: 700;
}

.screen-wrap {
  position: relative;
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
  background: #0b1022;
  min-height: 180px;
  max-height: 72vh;
  display: flex;
  align-items: center;
  justify-content: center;
  outline: none;
}

.keymap-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 4;
}

.keymap-dot {
  position: absolute;
  width: auto;
  max-width: 96px;
  min-width: 42px;
  height: 42px;
  padding: 0 10px;
  border-radius: 999px;
  border: 2px solid #10b981;
  background: rgba(15, 118, 110, 0.78);
  color: #f8fafc;
  display: grid;
  place-items: center;
  font-weight: 700;
  user-select: none;
  touch-action: none;
  pointer-events: auto;
  cursor: grab;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.28);
  font-size: 13px;
  line-height: 1;
}

.keymap-dot.active {
  border-color: #f59e0b;
  background: rgba(180, 83, 9, 0.82);
}

.keymap-dot.dragging {
  cursor: grabbing;
}

.keymap-list {
  margin-top: 8px;
  display: grid;
  gap: 6px;
  max-height: 180px;
  overflow: auto;
}

.keymap-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px;
  align-items: center;
}

.keymap-name {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 8px;
  font-size: 12px;
  color: #334155;
  background: #f8fafc;
}

.keymap-name.active {
  border-color: #f59e0b;
  background: #fff7ed;
  color: #9a3412;
}

.keymap-remove {
  width: auto;
  padding: 6px 10px;
  font-size: 12px;
  border-radius: 8px;
  background: #334155;
}

.screen-wrap:focus {
  box-shadow: 0 0 0 2px #22c55e;
}

#screenCanvas,
#mobileCanvas {
  display: block;
  width: 100%;
  height: auto;
  max-width: 100%;
  max-height: 72vh;
  object-fit: contain;
  min-height: 0;
  background: #0b1022;
  cursor: default;
  touch-action: none;
}

#mobileCanvas {
  cursor: pointer;
}

@media (max-width: 768px) {
  .screen-wrap {
    max-height: 85vh;
  }

  #screenCanvas,
  #mobileCanvas {
    max-height: 85vh;
  }

  .live-layout {
    grid-template-columns: 1fr;
  }

  .live-side {
    position: static;
  }
}

.screen-hint {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: #dbeafe;
  font-weight: 600;
}

.auth-row {
  margin-top: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.auth-btn {
  width: auto;
  min-width: 100px;
}

.host-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 10px;
}

.host-tile {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 8px;
  text-align: left;
  transition: transform 120ms ease, box-shadow 120ms ease, border-color 120ms ease;
  pointer-events: auto;
  cursor: pointer;
}

.host-tile:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 18px rgba(2, 6, 23, 0.1);
}

.host-tile.active {
  border-color: #10b981;
  box-shadow: 0 0 0 2px #a7f3d0;
}

.host-label {
  color: #0f172a;
  font-size: 14px;
  font-weight: 700;
  margin-bottom: 2px;
}

.host-meta {
  color: #475569;
  font-size: 12px;
  margin-bottom: 6px;
}

.host-thumb {
  width: 100%;
  height: auto;
  aspect-ratio: 16 / 9;
  border-radius: 8px;
  border: 1px solid #cbd5e1;
  display: block;
  background: #0b1022;
  pointer-events: none;
}

.host-slot,
.host-label,
.host-meta {
  pointer-events: none;
}

.host-sync-btn {
  width: 100%;
  padding: 6px 8px;
  font-size: 12px;
  border-radius: 8px;
  background: #334155;
}

.host-sync-btn.on {
  background: #0f766e;
}

.host-main-btn {
  width: 100%;
  padding: 6px 8px;
  font-size: 12px;
  border-radius: 8px;
  background: #334155;
}

.host-main-btn.on {
  background: #1d4ed8;
}

.host-sync-controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-bottom: 8px;
}


.top-mini {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

body.wall-mode {
  background: #d2d8de;
}

body.wall-mode .container {
  width: calc(100vw - 16px);
  max-width: none;
  margin: 8px;
}

body.wall-mode .card {
  border-radius: 10px;
  box-shadow: none;
  border: 1px solid #bfc7cf;
  margin-bottom: 10px;
  padding: 6px;
}

body.wall-mode .card.compact,
body.wall-mode .grid.two,
body.wall-mode .wall-phones,
body.wall-mode .card:has(#activeTitle) {
  width: 100%;
}

body.wall-mode .card.compact h1 {
  margin-bottom: 6px;
  font-size: 24px;
}

body.wall-mode .grid.two {
  grid-template-columns: 170px 170px 1fr 1fr;
  align-items: end;
}

body.wall-mode .wall-phones h2 {
  margin-bottom: 4px;
}

body.wall-mode .host-grid {
  display: flex;
  flex-wrap: nowrap;
  gap: 10px;
  overflow-x: auto;
  padding-bottom: 6px;
}

body.wall-mode .host-tile {
  width: 220px;
  min-width: 220px;
  border: 3px solid #545a61;
  border-radius: 12px;
  background: #dce2d3;
  padding: 6px;
  position: relative;
}

body.wall-mode .host-tile.active {
  border-color: #2c9f70;
  box-shadow: none;
}

body.wall-mode .host-slot {
  position: absolute;
  top: 4px;
  left: 8px;
  color: #d8dde3;
  font-weight: 800;
  font-size: 30px;
  line-height: 1;
  text-shadow: 0 1px 0 #646b73;
}

body.wall-mode .host-label {
  margin-top: 30px;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

body.wall-mode .host-meta {
  margin-bottom: 6px;
  font-size: 8px;
}

body.wall-mode .host-thumb {
  aspect-ratio: 16 / 9;
  border: 1px solid #5e646b;
  border-radius: 8px;
}

@media (max-width: 980px) {
  body.wall-mode .grid.two {
    grid-template-columns: 1fr 1fr;
  }
}
.screen-wrap.css-fullscreen {
  position: fixed !important;
  top: 0 !important;
  left: 0 !important;
  width: 100vw !important;
  height: 100dvh !important;
  max-width: none !important;
  max-height: none !important;
  z-index: 99999 !important;
  border-radius: 0 !important;
  background: #000 !important;
  margin: 0 !important;
  padding: 0 48px 0 0 !important;
  box-sizing: border-box !important;
  display: flex !important;
  flex-direction: column !important;
}

.screen-wrap.css-fullscreen canvas,
.screen-wrap:fullscreen canvas,
.screen-wrap:-webkit-full-screen canvas {
  width: 100% !important;
  height: 100% !important;
  max-height: 100dvh !important;
  max-width: 100vw !important;
  object-fit: contain !important;
}

.screen-wrap:fullscreen {
  padding-right: 48px !important;
  background: #000 !important;
  box-sizing: border-box !important;
}
.screen-wrap:-webkit-full-screen {
  padding-right: 48px !important;
  background: #000 !important;
  box-sizing: border-box !important;
}

.exit-fs-btn {
  display: none;
}

.fs-toolbar {
  display: flex;
  position: absolute;
  top: 50%;
  right: 4px;
  transform: translateY(-50%);
  flex-direction: column;
  gap: 4px;
  z-index: 100000;
  background: rgba(0, 0, 0, 0.5);
  padding: 4px;
  border-radius: 10px;
  backdrop-filter: blur(8px);
}

#exitFsBtn {
  display: none;
}

.screen-wrap:fullscreen #exitFsBtn,
.screen-wrap:-webkit-full-screen #exitFsBtn,
.screen-wrap.css-fullscreen #exitFsBtn {
  display: flex;
}

.screen-wrap:fullscreen #fsEnterFsBtn,
.screen-wrap:-webkit-full-screen #fsEnterFsBtn,
.screen-wrap.css-fullscreen #fsEnterFsBtn {
  display: none;
}

.fs-btn {
  background: rgba(255, 255, 255, 0.15);
  border: 1px solid rgba(255, 255, 255, 0.3);
  color: #fff;
  border-radius: 6px;
  width: 32px;
  height: 32px;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
}

.fs-btn:active {
  background: rgba(255, 255, 255, 0.3);
}

.fs-btn.danger {
  background: rgba(220, 38, 38, 0.4);
  border-color: rgba(248, 113, 113, 0.5);
}

.hidden-input {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.mumu-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  gap: 12px;
}

.mumu-item .info {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.mumu-item .name {
  font-weight: 700;
  color: #1e293b;
  font-size: 14px;
}

.mumu-item .status {
  font-size: 11px;
  color: #64748b;
}

.mumu-item .status.running {
  color: #16a34a;
  font-weight: 700;
}

.mumu-actions {
  display: flex;
  gap: 6px;
}

.mumu-actions button {
  padding: 4px 10px;
  font-size: 12px;
  width: auto;
}

.transparent-overlay-input {
  position: absolute;
  opacity: 0;
  background: transparent;
  border: none;
  color: transparent;
  outline: none;
  z-index: 10;
  caret-color: transparent;
  pointer-events: auto;
}

@media (max-width: 768px) {
  body.wall-mode .host-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    overflow-x: hidden;
    padding-bottom: 0;
  }
  
  body.wall-mode .host-tile {
    width: 100%;
    min-width: 0;
  }
}
