:root{
  --bg0:#07080b;
  --bg1:#0b0d12;
  --panel:#0f121a;
  --line:rgba(255,255,255,0.08);
  --text:rgba(255,255,255,0.92);
  --muted:rgba(255,255,255,0.62);
  --muted2:rgba(255,255,255,0.45);
  --accent:#8be9fd;
  --accent2:#ffd166;
  --good:#4ade80;
  --warn:#fbbf24;
  --bad:#fb7185;

  /* UI scaling hook (optional; you can remove if not using it) */
  --ui-scale: 1;
}

*{ box-sizing:border-box; }
html,body{ height:100%; }

body{
  margin:0;
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji","Segoe UI Emoji";
  background:
    radial-gradient(1200px 700px at 20% 10%, rgba(139,233,253,0.12), transparent 60%),
    radial-gradient(900px 600px at 80% 30%, rgba(255,209,102,0.09), transparent 55%),
    linear-gradient(180deg, var(--bg1), var(--bg0));
  color:var(--text);

  /* IMPORTANT: allow scroll on mobile; JS/canvas resizing handles layout */
  overflow-x:hidden;
  overflow-y:auto;
}

#app{
  height:100%;
  min-height:100svh;
  display:flex;
  flex-direction:column;
}

/* -------------------------
   Topbar
------------------------- */
.topbar{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap: 12px;
  padding:14px 16px;
  border-bottom: 1px solid var(--line);
  background: rgba(10,12,18,0.65);
  backdrop-filter: blur(10px);
}

.brand{
  display:flex;
  align-items:center;
  gap:12px;
  min-width: 220px;
}
.mark{
  width:14px; height:14px; border-radius:4px;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  box-shadow: 0 0 18px rgba(139,233,253,0.35);
}
.titleblock h1{
  margin:0;
  font-size:16px;
  font-weight:650;
  letter-spacing:0.2px;
}
.titleblock p{
  margin:2px 0 0;
  font-size:12px;
  color:var(--muted);
}

/* Prevent the “vertical pill stack” issue: no wrapping */
.actions{
  display:flex;
  align-items:center;
  justify-content:flex-end;
  gap:10px;
  flex-wrap: nowrap;
}

.btn{
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.04);
  color: var(--text);
  padding: 10px 12px;
  border-radius: 10px;
  font-weight: 600;
  font-size: 13px;
  cursor:pointer;
  transition: transform .06s ease, background .2s ease, border-color .2s ease;
  user-select:none;
  white-space: nowrap; /* keeps labels from forcing wrap */
}
.btn:hover{
  background: rgba(255,255,255,0.07);
  border-color: rgba(255,255,255,0.14);
}
.btn:active{ transform: translateY(1px); }
.btn.primary{
  border-color: rgba(139,233,253,0.35);
  background: rgba(139,233,253,0.10);
}

/* -------------------------
   Stage (canvas + panel)
------------------------- */
.stage{
  /* Fill remaining height after topbar */
  flex: 1 1 auto;
  min-height: 0; /* allows children to scroll correctly */
  display:grid;
  grid-template-columns: 1fr 340px;
}

#c{
  width:100%;
  height:100%;
  display:block;
}

/* Panel */
.panel{
  height:100%;
  border-left: 1px solid var(--line);
  background: rgba(15,18,26,0.75);
  backdrop-filter: blur(12px);
  padding: 14px 14px 10px;
  overflow:auto;
}

.panel-head{
  display:flex;
  align-items:flex-start;
  justify-content:space-between;
  gap:8px;
  margin-bottom: 10px;
}
.panel-head h2{
  margin:0;
  font-size:13px;
  letter-spacing:0.2px;
  font-weight: 700;
  color: rgba(255,255,255,0.86);
}
.status{
  display:flex;
  align-items:center;
  gap:8px;
  font-size:12px;
  color: var(--muted);
  margin-top: 2px;
}
.dot{
  width:10px; height:10px; border-radius:999px;
  background: rgba(255,255,255,0.2);
}
.dot.idle{ background: rgba(255,255,255,0.22); }
.dot.live{ background: rgba(74,222,128,0.9); box-shadow: 0 0 14px rgba(74,222,128,0.35); }
.dot.warn{ background: rgba(251,191,36,0.95); box-shadow: 0 0 14px rgba(251,191,36,0.25); }
.dot.bad{ background: rgba(251,113,133,0.95); box-shadow: 0 0 14px rgba(251,113,133,0.25); }

.group{
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
  margin: 10px 0;
  background: rgba(255,255,255,0.03);
}

.row{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:10px;
  font-size: 12px;
  color: var(--muted);
  margin: 8px 0 6px;
}
.value{
  color: rgba(255,255,255,0.78);
  font-variant-numeric: tabular-nums;
}
.value.small{ font-size:11px; color: var(--muted2); }

input[type="range"]{
  width:100%;
  margin: 0 0 6px;
  accent-color: var(--accent);
}

.note{
  font-size: 12px;
  color: var(--muted2);
  line-height: 1.35;
  margin-top: 8px;
}

.panel-foot{
  display:flex;
  align-items:center;
  justify-content:center;
  gap:10px;
  margin: 12px 0 6px;
  color: var(--muted2);
}
.panel-foot a{
  color: rgba(139,233,253,0.9);
  text-decoration:none;
  font-weight:700;
  font-size:12px;
}
.panel-foot a:hover{ text-decoration:underline; }
.sep{ opacity:0.5; }
.small{ font-size:12px; }

/* -------------------------
   Panel collapse
------------------------- */
.stage.panel-collapsed{
  grid-template-columns: 1fr !important;
}
.stage.panel-collapsed .panel{
  display:none !important;
}
.stage.panel-collapsed #c{
  outline: 1px solid rgba(255,255,255,0.06);
  outline-offset: -1px;
}

/* -------------------------
   Mobile / Tablet layout fixes
------------------------- */
@media (max-width: 980px){
  .stage{
    grid-template-columns: 1fr;
    grid-template-rows: 62svh auto;
  }
  .panel{
    border-left:none;
    border-top:1px solid var(--line);
  }
}

/* Very small screens: compact topbar and allow actions to scroll horizontally */
@media (max-width: 720px){
  .topbar{
    padding: 10px 12px;
  }

  /* Keep brand from forcing wrapping */
  .brand{
    min-width: 0;
  }
  .titleblock p{
    display:none;
  }

  /* Instead of wrapping into a big vertical stack, allow horizontal scroll */
  .actions{
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 2px;
    -webkit-overflow-scrolling: touch;
  }
  .actions::-webkit-scrollbar{ height: 6px; }
  .actions::-webkit-scrollbar-thumb{ background: rgba(255,255,255,0.10); border-radius: 10px; }

  .btn{
    padding: 8px 10px;
    border-radius: 12px;
    font-size: 13px;
  }

  /* When collapsed on mobile, give full height to canvas */
  .stage.panel-collapsed{
    grid-template-rows: 1fr !important;
  }
}

/* -------------------------
   Palette modal (Pick 2 Colors)
------------------------- */
.modal{
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  backdrop-filter: blur(10px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 14px;
}
.modal.open{
  display: flex;
}
.modal-card{
  width: min(980px, 100%);
  max-height: min(760px, 90vh);
  overflow: auto;
  border: 1px solid rgba(255,255,255,0.10);
  background: rgba(15,18,26,0.80);
  border-radius: 18px;
  box-shadow: 0 18px 60px rgba(0,0,0,0.55);
  padding: 12px;
}
.modal-head{
  display:flex;
  align-items:flex-start;
  justify-content:space-between;
  gap:12px;
  padding: 6px 6px 10px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}
.modal-title{
  font-weight: 800;
  letter-spacing: 0.2px;
}
.modal-sub{
  margin-top: 4px;
  color: rgba(255,255,255,0.62);
  font-size: 12px;
}
.modal-foot{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:10px;
  padding: 12px 6px 6px;
  border-top: 1px solid rgba(255,255,255,0.08);
}
.hint{
  color: rgba(255,255,255,0.65);
  font-size: 12px;
}

/* Swatches grid */
.swatch-grid{
  display:grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 10px;
  padding: 12px 6px;
}
@media (max-width: 900px){
  .swatch-grid{ grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
@media (max-width: 560px){
  .swatch-grid{ grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

.swatch{
  border-radius: 14px;
  border: 1px solid rgba(255,255,255,0.10);
  overflow:hidden;
  cursor:pointer;
  position: relative;
  min-height: 72px;
}
.swatch .label{
  position:absolute;
  left:10px;
  bottom:8px;
  font-weight: 800;
  font-size: 12px;
  letter-spacing: 0.2px;
  color: rgba(255,255,255,0.92);
  text-shadow: 0 2px 10px rgba(0,0,0,0.35);
}
.swatch.selected{
  outline: 3px solid rgba(139,233,253,0.75);
  outline-offset: 2px;
}
.swatch .check{
  position:absolute;
  top:8px;
  right:8px;
  width: 22px;
  height: 22px;
  border-radius: 999px;
  background: rgba(0,0,0,0.32);
  border: 1px solid rgba(255,255,255,0.18);
  display:flex;
  align-items:center;
  justify-content:center;
  font-size: 13px;
  opacity: 0;
}
.swatch.selected .check{ opacity: 1; }
/* =========================
   Drawer (Menu) — FIXED
   ========================= */

.drawer-overlay{
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  backdrop-filter: blur(8px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms ease;
  z-index: 9998;
}
.drawer-overlay.open{
  opacity: 1;
  pointer-events: auto;
}

.drawer{
  position: fixed;
  top: 72px;              /* sits under the topbar */
  right: 12px;
  width: min(420px, calc(100vw - 24px));
  max-height: calc(100vh - 84px);
  overflow: auto;

  background: rgba(15,18,26,0.92);
  border: 1px solid rgba(255,255,255,0.10);
  border-radius: 18px;
  box-shadow: 0 18px 60px rgba(0,0,0,0.55);

  transform: translateY(-8px);
  opacity: 0;
  pointer-events: none;

  transition: opacity 160ms ease, transform 160ms ease;
  z-index: 9999;
}

.drawer.open{
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

/* Drawer internals */
.drawer-head{
  display:flex;
  align-items:flex-start;
  justify-content:space-between;
  gap:12px;
  padding: 14px 14px 10px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}

.drawer-title{
  font-weight: 800;
  letter-spacing: 0.2px;
}

.drawer-sub{
  margin-top: 2px;
  color: rgba(255,255,255,0.62);
  font-size: 12px;
}

.drawer-body{
  padding: 12px 14px 16px;
}

.drawer-section{
  padding: 12px 0;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}
.drawer-section:last-child{
  border-bottom: none;
}

/* On small screens, make it full-width and full-height */
@media (max-width: 720px){
  .drawer{
    top: 0;
    right: 0;
    width: 100vw;
    max-height: 100vh;
    border-radius: 0;
    border-left: none;
    border-right: none;
    border-top: none;
  }
}
