/* ESP32-KVM web UI - dark, compact, no external assets. */
* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0; height: 100%; overflow: hidden;
  background: #0b0d10; color: #dfe4ea;
  font: 12px/1.35 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  overscroll-behavior: none; -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}
body {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  touch-action: none; user-select: none; -webkit-user-select: none;
}
button {
  font: inherit; color: #cfd7e0; background: #171c22; border: 1px solid #2a313a;
  border-radius: 5px; padding: 3px 8px; cursor: pointer; white-space: nowrap;
}
button:hover { background: #1f262e; }
button:active { background: #2b6cb0; border-color: #3b82d0; color: #fff; }
button.on { background: #2b6cb0; border-color: #3b82d0; color: #fff; }
button[hidden] { display: none; }
input, textarea, select {
  font: inherit; color: #dfe4ea; background: #0e1216; border: 1px solid #2a313a;
  border-radius: 5px; padding: 5px 7px; width: 100%;
}
input[type=range] {
  width: auto; flex: 0 1 78px; min-width: 54px; padding: 0;
  background: none; border: 0; accent-color: #3b82d0;
}
.dim { color: #8b95a1; }
b { font-weight: 600; }

/* --- screen ------------------------------------------------------------- */
#stage {
  position: relative; flex: none; background: #000; overflow: hidden;
  box-shadow: 0 0 0 1px #1b2026;
}
#scr {
  display: block; width: 100%; height: 100%; image-rendering: auto;
  touch-action: none; cursor: crosshair;
}
#ret {
  position: absolute; left: 50%; top: 50%; width: 18px; height: 18px;
  margin: -9px 0 0 -9px; pointer-events: none; border-radius: 50%;
  border: 1px solid rgba(255, 70, 70, .85);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .45);
}
#ret::before, #ret::after { content: ""; position: absolute; background: rgba(255, 70, 70, .75); }
#ret::before { left: 8px; top: -7px; width: 1px; height: 30px; }
#ret::after { top: 8px; left: -7px; height: 1px; width: 30px; }
#hint {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  padding: 14px; text-align: center; pointer-events: none;
}
#hint[hidden] { display: none; }
#hint span {
  max-width: 460px; padding: 10px 14px; border-radius: 8px; font-size: 13px; line-height: 1.45;
  background: rgba(0, 0, 0, .74); border: 1px solid #39414b;
}

/* --- top status bar ----------------------------------------------------- */
#bar {
  position: absolute; top: 0; left: 0; right: 0; z-index: 6;
  display: flex; align-items: center; gap: 7px; font-size: 11px;
  padding: calc(3px + env(safe-area-inset-top)) calc(7px + env(safe-area-inset-right)) 3px calc(7px + env(safe-area-inset-left));
  background: rgba(9, 11, 14, .62); white-space: nowrap; overflow: hidden;
}
#bar .dot {
  flex: none; width: 7px; height: 7px; border-radius: 50%;
  background: #c0392b; box-shadow: 0 0 6px #c0392b;
}
#bar .dot.on { background: #2ecc71; box-shadow: 0 0 6px #2ecc71; }
#st { overflow: hidden; text-overflow: ellipsis; }
#bar .tag { flex: none; padding: 0 5px; border-radius: 4px; border: 1px solid #39414b; color: #9fb0c2; }
#bar .tag.relay { color: #f0b400; border-color: #6b5300; }

/* --- bottom toolbar ----------------------------------------------------- */
#tools {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 6;
  display: flex; align-items: center; gap: 5px;
  padding: 4px calc(6px + env(safe-area-inset-right)) calc(4px + env(safe-area-inset-bottom)) calc(6px + env(safe-area-inset-left));
  background: rgba(9, 11, 14, .62);
  overflow-x: auto; overflow-y: hidden; white-space: nowrap;
  scrollbar-width: none;
}
#tools::-webkit-scrollbar { display: none; }
#tools .rng { display: flex; align-items: center; gap: 4px; color: #8b95a1; flex: none; }
#tools select { width: auto; flex: none; padding: 2px 4px; }

/* --- sticky keys row ---------------------------------------------------- */
#keys {
  position: absolute; left: 0; right: 0; z-index: 5;
  bottom: calc(32px + env(safe-area-inset-bottom));
  display: flex; gap: 6px; align-items: center;
  padding: 4px calc(6px + env(safe-area-inset-right)) 4px calc(6px + env(safe-area-inset-left));
  background: rgba(9, 11, 14, .78); overflow-x: auto; scrollbar-width: none;
}
#keys[hidden] { display: none; }
#keys::-webkit-scrollbar { display: none; }
#keys .grp { display: flex; gap: 3px; flex: none; }

/* --- panels ------------------------------------------------------------- */
#panels {
  position: absolute; inset: 0; z-index: 20; display: none;
  align-items: center; justify-content: center; padding: 10px;
  background: rgba(0, 0, 0, .55);
}
#panels.open { display: flex; }
.pnl {
  display: none; flex-direction: column; width: min(540px, 100%);
  max-height: min(80vh, 620px); overflow: hidden;
  background: #14181d; border: 1px solid #2a313a; border-radius: 8px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .5);
}
.pnl.on { display: flex; }
.pnl > header {
  display: flex; align-items: center; gap: 8px; padding: 7px 10px;
  border-bottom: 1px solid #22282f; font-weight: 600;
}
.pnl > header .x { margin-left: auto; padding: 0 7px; }
.pnl .body { display: flex; flex-direction: column; gap: 7px; padding: 9px; overflow: auto; }
.pnl .body.row { flex-direction: row; flex-wrap: wrap; }
.pnl .list { display: flex; flex-direction: column; gap: 2px; overflow: auto; max-height: 54vh; }
.pnl .list button { text-align: left; overflow: hidden; text-overflow: ellipsis; }
.pnl .row { display: flex; align-items: center; gap: 7px; }
.pnl .row > span { flex: none; width: 42px; color: #8b95a1; }
.pnl .row > b { flex: none; width: 26px; text-align: right; }
#clip-ta { min-height: 64px; resize: vertical; }

/* --- hidden typing input ------------------------------------------------ */
#ta {
  position: fixed; left: 0; bottom: 0; width: 1px; height: 1px;
  padding: 0; border: 0; opacity: .01; font-size: 16px; z-index: 1;
}

/* --- toast -------------------------------------------------------------- */
#toast {
  position: absolute; left: 50%; z-index: 40;
  bottom: calc(44px + env(safe-area-inset-bottom));
  transform: translateX(-50%); max-width: 84vw;
  padding: 6px 11px; border-radius: 6px; font-size: 12px;
  background: #232b34; border: 1px solid #3a4450;
  opacity: 0; transition: opacity .15s; pointer-events: none;
}
#toast.on { opacity: 1; }

@media (max-width: 520px) {
  #bar { font-size: 10px; gap: 5px; }
  #tools button, #tools select { padding: 2px 6px; }
  #keys button { padding: 2px 6px; }
}
