body { margin:0; font-family: system-ui, sans-serif; background:#111; color:#eee; }
#top {
  padding: 10px;
  position: relative;
  display:flex; align-items:center; justify-content:flex-start; gap:10px;
  background:#0f0f0f; border-bottom:1px solid #222;
  flex-wrap: wrap;
  overflow-x: hidden;
}
.top-left, .top-right {
  display:flex;
  align-items:center;
  gap:8px;
  min-width: 0;
  flex: 0 0 auto;
}
.top-center {
  position: static;
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}
input, select { padding: 6px; }
button { padding: 6px 10px; cursor:pointer; }
label { display:flex; gap:6px; align-items:center; }
#wrap { position: relative; width: 100vw; height: calc(100vh - 64px); }
canvas { display:block; width:100%; height:100%; background:#222; }
#log {
  position:absolute; left:10px; bottom:10px;
  width:min(560px, calc(100vw - 20px));
  max-height: 200px;
  background: rgba(0,0,0,0.6);
  border: 1px solid rgba(255,255,255,0.12);
  display: flex;
  flex-direction: column;
  font-family: ui-monospace, monospace;
  font-size: 12px;
  z-index: 2;
}
#logHeader {
  display:flex;
  align-items:center;
  justify-content:space-between;
  padding: 6px 8px;
  border-bottom: 1px solid rgba(255,255,255,0.10);
  font-size: 11px;
  opacity: 0.9;
  user-select: none;
}
#logText {
  padding: 8px;
  overflow: auto;
  white-space: pre-wrap;
  max-height: 150px;
}
#log.collapsed #logText { display: none; }
#log.collapsed { max-height: none; width: 230px; }
#logToggle {
  padding: 2px 8px;
  font-size: 11px;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,0.2);
  background: rgba(255,255,255,0.06);
  color: #ddd;
}
#hint {
  position:absolute; right:10px; bottom:10px;
  background: rgba(0,0,0,0.5);
  border: 1px solid rgba(255,255,255,0.12);
  padding: 8px;
  font-size: 12px;
  max-width: 420px;
  line-height: 1.35;
  z-index: 2;
}
.pill { display:inline-block; padding:2px 6px; border-radius:999px; border:1px solid rgba(255,255,255,0.18); }
.drawer-toggle { padding: 6px 10px; font-size: 18px; }
.drawer {
  position: fixed;
  top: 64px;
  left: 0;
  width: 320px;
  height: calc(100% - 64px);
  background: #1e1e1e;
  color: #eee;
  box-shadow: 2px 0 10px rgba(0,0,0,0.4);
  z-index: 999;
  display: flex;
  flex-direction: column;
  transform: translateX(0);
  transition: transform 0.2s ease;
}
.drawer.hidden {
  transform: translateX(-100%);
  display: block;
}
.drawer-header {
  display: flex;
  justify-content: space-between;
  padding: 10px;
  background: #2a2a2a;
  font-weight: bold;
}
.drawer-tabs {
  display: flex;
  flex-wrap: wrap;
  border-bottom: 1px solid #444;
}
.drawer-tabs button {
  flex: 1;
  padding: 6px;
  background: #2a2a2a;
  border: none;
  color: #ccc;
  cursor: pointer;
}
.drawer-tabs button.active {
  background: #444;
  color: white;
}
.drawer-content {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}
.drawer-panel {
  display: none;
}
.drawer-panel.active {
  display: block;
}
.ctx {
  position: fixed;
  z-index: 2000;
  min-width: 220px;
  background: #1f1f1f;
  color: #eee;
  border: 1px solid rgba(255,255,255,0.10);
  border-radius: 10px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.45);
  padding: 6px;
  font-family: system-ui, sans-serif;
  user-select: none;
}
.ctx.hidden { display: none; }
.ctx-title {
  font-size: 12px;
  opacity: 0.75;
  padding: 6px 8px;
}
.ctx-item {
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  line-height: 1.1;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.ctx-item:hover { background: rgba(255,255,255,0.10); }
.ctx-item.danger:hover { background: rgba(255,0,0,0.15); }
.ctx-sep {
  height: 1px;
  margin: 6px 6px;
  background: rgba(255,255,255,0.10);
}
.ctx-sub { min-width: 240px; }
.tool-strip {
  display: inline-flex;
  gap: 4px;
  align-items: center;
  padding: 2px 4px;
  border: 1px solid rgba(255,255,255,0.14);
  border-radius: 999px;
  background: rgba(255,255,255,0.04);
}
.tool-btn {
  padding: 5px 8px;
  font-size: 13px;
  border: 1px solid transparent;
  border-radius: 999px;
  background: rgba(255,255,255,0.03);
  color: #ddd;
}
.tool-btn.active {
  background: rgba(0,209,255,0.16);
  border-color: rgba(0,209,255,0.55);
  color: #fff;
}
.top-action-btn {
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid transparent;
  background: rgba(255,255,255,0.03);
  color: #ddd;
}
.top-action-btn:hover {
  background: rgba(255,255,255,0.10);
}
.top-action-btn.active {
  background: rgba(0,209,255,0.16);
  border-color: rgba(0,209,255,0.55);
  color: #fff;
}
.tool-activate {
  animation: toolPulse 120ms ease;
}
@keyframes toolPulse {
  0% { transform: scale(1); }
  50% { transform: scale(1.06); }
  100% { transform: scale(1); }
}
.ui-tooltip {
  position: fixed;
  z-index: 3500;
  padding: 6px 8px;
  border-radius: 8px;
  background: rgba(16,16,16,0.96);
  border: 1px solid rgba(255,255,255,0.12);
  color: #eee;
  font-size: 12px;
  pointer-events: none;
  white-space: nowrap;
}
.size-strip {
  display: inline-flex;
  gap: 4px;
  align-items: center;
  padding: 2px 4px;
  border: 1px solid rgba(255,255,255,0.14);
  border-radius: 999px;
  background: rgba(255,255,255,0.04);
  font-size: 12px;
}
.session-pill{
  display:inline-flex;
  gap:8px;
  align-items:center;
  padding:6px 10px;
  border-radius:999px;
  border:1px solid rgba(255,255,255,0.12);
  background:#151515;
  cursor:pointer;
  font-size:13px;
}
.session-pill.ok{ border-color: rgba(0,255,120,0.25); }
.session-pill.bad{ border-color: rgba(255,80,80,0.25); }
.session-resync {
  font-size: 11px;
  opacity: 0.85;
  padding: 2px 6px;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,0.18);
  background: rgba(255,255,255,0.06);
}
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 3000;
}
.modal {
  position: fixed;
  top: 70px;
  left: 12px;
  width: 320px;
  background: #1f1f1f;
  color: #eee;
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 14px;
  box-shadow: 0 18px 50px rgba(0,0,0,0.55);
  z-index: 3001;
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 12px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}
.modal-title { font-weight: 700; }
.modal-close {
  border: none;
  background: transparent;
  color: #bbb;
  font-size: 16px;
  cursor: pointer;
}
.modal-body { padding: 12px; }
.field { margin-bottom: 10px; }
.field label {
  display: block;
  font-size: 12px;
  opacity: 0.8;
  margin-bottom: 4px;
}
.field input {
  width: 100%;
  box-sizing: border-box;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,0.12);
  background: #141414;
  color: #eee;
}
.hint { font-size: 12px; opacity: 0.65; margin-top: 4px; }
.modal-actions { display: flex; gap: 8px; margin-top: 12px; }
button.primary {
  padding: 8px 10px;
  border-radius: 10px;
  border: none;
  cursor: pointer;
}
button.ghost {
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,0.14);
  background: transparent;
  color: #ddd;
  cursor: pointer;
}
.hidden { display: none !important; }
