/* Layout: one full-bleed grayscale bedroom stage, letterboxed to 16:9. The reset bulb hangs
   from the top-left corner. Single light grayscale look, kept from all four studies. */
:root {
  --bulbH: clamp(195px, 39vh, 480px);
  --ground: #d6d6d6;
  --ink: #222222;
  --room: #ececec;
  color-scheme: light;
}

html, body { height: 100%; margin: 0; }
body {
  background: var(--ground);
  color: var(--ink);
  overflow: hidden;
  font-family: ui-sans-serif, system-ui, -apple-system, sans-serif;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

#room { position: fixed; inset: 0; display: grid; place-items: center; }
#stage {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
}
#stage image { pointer-events: none; }

#display {
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-weight: 700;
  font-size: 52px;
  letter-spacing: 2px;
  fill: #cfcfcf;
}
#fx text, #windowFx text { font-family: ui-monospace, Menlo, Consolas, monospace; font-weight: 700; }

/* blackout used by the reset bulb */
#dark {
  position: fixed; inset: 0;
  background: #0b0b0b;
  opacity: 0;
  pointer-events: none;
  z-index: 5;
}

/* reset: pull-chain bulb, top-left corner, above the blackout so the firefly can flash in the dark */
#bulb {
  position: fixed;
  top: 0;
  left: max(12px, env(safe-area-inset-left, 0px));
  /* scales with the screen like the room does (about 281 px tall on a 720 px-high window) */
  /* --bulbS / --bulbK come from the Reset light sliders (size, and extra height for a longer chain) */
  height: calc(var(--bulbH) * var(--bulbK, 1));
  width: calc(var(--bulbH) * var(--bulbS, 1) * 120 / 230);
  padding: 0;
  border: 0;
  background: none;
  cursor: grab;
  z-index: 6;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
}
#bulb:active { cursor: grabbing; }
#bulb svg { width: 100%; height: 100%; overflow: visible; display: block; }
#bulb:focus-visible { outline: 3px solid var(--ink); outline-offset: 2px; border-radius: 8px; }

.sr {
  position: absolute !important;
  width: 1px; height: 1px;
  margin: -1px; padding: 0; border: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}
#kbd:focus-visible + #hint { outline: none; }

@media (max-width: 600px) {
  :root { --bulbH: clamp(165px, 36vh, 285px); }
}

/* ---------- Tools window: at the top, just right of the reset bulb ---------- */
#dock {
  position: fixed;
  left: calc(max(12px, env(safe-area-inset-left, 0px)) + var(--bulbH) * var(--bulbS, 1) * 120 / 230 + 8px);
  top: 12px;
  z-index: 4;
  width: min(calc(290px * var(--ui, 1)), calc(100vw - 24px));
  max-height: calc(100dvh - 24px);
  overflow-y: auto;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 10px;
  pointer-events: none;
}
.tpanel {
  pointer-events: auto;
  flex: none;
  width: 100%;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  background: rgba(246, 246, 246, .94);
  border: 2px solid var(--ink);
  border-radius: 12px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .18);
  font: 13px/1.35 ui-sans-serif, system-ui, -apple-system, sans-serif;
  color: var(--ink);
  -webkit-user-select: text;
  user-select: text;
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
}
/* scaled as a whole with the screen (--ui is set in js/panel.js) */
#tools { width: 290px; zoom: var(--ui, 1); }
#tools.closed { width: auto; }
.tpanel.closed { width: auto; }
.tpanel.closed .panelBody { display: none; }
.panelToggle {
  display: flex; align-items: center; gap: 8px;
  min-height: 40px;
  padding: 8px 14px;
  border: 0; background: none;
  font: 700 13px/1 ui-monospace, Menlo, Consolas, monospace;
  letter-spacing: .06em; text-transform: uppercase;
  color: var(--ink); cursor: pointer; text-align: left;
}
.panelToggle .chev { display: inline-block; font-size: 18px; transition: transform .2s; }
.tpanel.closed .panelToggle .chev { transform: rotate(180deg); }
.panelToggle:focus-visible, .tpanel button:focus-visible, .tpanel select:focus-visible, .tpanel input:focus-visible, .tpanel summary:focus-visible {
  outline: 2px solid var(--ink); outline-offset: 2px;
}
.panelBody { padding: 0 12px 12px; border-top: 1.5px solid #bdbdbd; overscroll-behavior: contain; }
/* one Tools window: a row of tabs (sticks to the top while the window scrolls), then the selected panel */
.tpanel .toolTabs {
  position: sticky; top: 0; z-index: 1;
  display: flex; gap: 4px; margin: 0 -12px 6px; padding: 8px 12px;
  background: rgba(246, 246, 246, .97); border-bottom: 1.5px solid #d0d0d0;
}
.tpanel .toolTabs button {
  flex: 1 1 0; min-width: 0; min-height: 32px; padding: 4px 2px;
  border: 1.5px solid var(--ink); border-radius: 8px; background: #fff; color: var(--ink);
  font: 600 11.5px ui-sans-serif, system-ui, sans-serif; cursor: pointer;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.tpanel .toolTabs button:hover { background: #e4e4e4; }
.tpanel .toolTabs button.on { background: var(--ink); color: #fff; }
.tpanel .tpane[hidden] { display: none; }
.tpanel .actions { display: flex; gap: 8px; margin-top: 10px; }
.tpanel button.act, .tpanel .jump button {
  flex: 1;
  min-height: 34px;
  border: 1.5px solid var(--ink); border-radius: 999px;
  background: #fff; color: var(--ink);
  font: 600 12px/1 ui-sans-serif, system-ui, sans-serif;
  cursor: pointer; padding: 6px 10px;
}
.tpanel button.act.primary { background: var(--ink); color: #fff; }
.tpanel button.act:hover, .tpanel .jump button:hover { background: #e4e4e4; }
.tpanel button.act.primary:hover { background: #444; }
.tpanel .status { min-height: 1.35em; margin: 6px 2px 0; font-size: 12px; color: #444; }
.tpanel .jump { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 4px 0 6px; }
.tpanel .jumpLabel { width: 100%; font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: #555; }
.tpanel .jump button { flex: 1 1 0; min-width: 0; min-height: 30px; padding: 4px 2px; font-size: 11.5px; }
.tpanel details { border-top: 1px solid #d0d0d0; padding: 2px 0; }
.tpanel summary {
  cursor: pointer; padding: 8px 2px; list-style-position: inside;
  font: 700 12px/1.2 ui-monospace, Menlo, Consolas, monospace; letter-spacing: .04em;
}
.tpanel .row { display: grid; gap: 3px; padding: 6px 2px 8px; }
.tpanel .row label { display: flex; justify-content: space-between; gap: 8px; font-weight: 600; }
.tpanel .row output { font: 600 12px/1.35 ui-monospace, Menlo, Consolas, monospace; white-space: nowrap; }
.tpanel .row small { color: #666; font-size: 11px; }
.tpanel input[type=range] { width: 100%; accent-color: #333; margin: 2px 0; }
.tpanel .easeRow { display: flex; align-items: center; gap: 8px; }
.tpanel select {
  flex: 1; min-height: 32px;
  border: 1.5px solid var(--ink); border-radius: 8px; background: #fff; color: var(--ink);
  font: 13px ui-sans-serif, system-ui, sans-serif; padding: 4px 6px;
}
.tpanel svg.curve { width: 60px; height: 36px; flex: none; background: #fff; border: 1px solid #c8c8c8; border-radius: 6px; }
.tpanel svg.curve path { fill: none; stroke: var(--ink); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.tpanel svg.curve path.guide { stroke: #d6d6d6; stroke-width: 1; stroke-dasharray: 2 2; }
.tpanel .note { margin: 10px 2px 0; font-size: 11.5px; color: #555; }
.tpanel .copyBox { width: 100%; height: 120px; margin-top: 8px; font: 11px ui-monospace, Menlo, monospace; box-sizing: border-box; }

/* narrow screens: no room beside the bulb, so the window sits below it */
@media (max-width: 700px) {
  #dock {
    left: max(12px, env(safe-area-inset-left, 0px));
    top: calc(var(--bulbH) * var(--bulbK, 1) + 12px);
    max-height: calc(100dvh - var(--bulbH) * var(--bulbK, 1) - 24px);
  }
}
.tpanel .check { display: flex; align-items: center; gap: 8px; margin: 2px 2px 8px; font-weight: 600; cursor: pointer; }
.tpanel .check input { width: 18px; height: 18px; accent-color: #333; }
.tpanel .colorRow { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 5px 2px; }
.tpanel .colorRow label { flex: 1; font-weight: 600; }
.tpanel .colorRow output { font: 600 12px ui-monospace, Menlo, Consolas, monospace; }
.tpanel input[type=color] { width: 44px; height: 30px; padding: 2px; border: 1.5px solid var(--ink); border-radius: 8px; background: #fff; cursor: pointer; }

/* ---------- component colors (values come from js/config.js; tuned live by the color panel) ---------- */
body { background: var(--colPage, #d6d6d6); }
#stage .col-wall { fill: var(--colWall); }
#stage .col-sideWall { fill: var(--colSideWall); }
#stage .col-floor { fill: var(--colFloor); }
#stage .col-floorLine { stroke: var(--colFloorLine); }
#stage .col-baseboard { fill: var(--colBaseboard); }
#stage .col-windowFrame { fill: var(--colWindowFrame); }
#stage [stroke="#222"], #stage [stroke="#222222"] { stroke: var(--colInk); }
#stage text[fill="#222"], #stage text[fill="#1c1c1c"] { fill: var(--colInk); }
#stage .col-headboard { fill: var(--colHeadboard); }
#stage .col-bedBase { fill: var(--colBedBase); }
#stage .col-sheet { fill: var(--colSheet); }
#stage .col-pillow { fill: var(--colPillow); }
#stage .col-blanket { fill: var(--colBlanket); }
#stage .col-blanketCheck { fill: var(--colBlanketCheck); }
#stage .col-legs { fill: var(--colLegs); }
#stage .col-hair { fill: var(--colHair); }
#stage .col-sleeve { fill: var(--colSleeve); }
#stage .col-skin { fill: var(--colSkin); }
#stage .col-cuff { fill: var(--colCuff); }
#stage .col-standTop { fill: var(--colStandTop); }
#stage .col-standBody { fill: var(--colStandBody); }
#stage .col-drawer { fill: var(--colDrawer); }
#stage .col-knob { fill: var(--colKnob); }
#stage .col-clockBody { fill: var(--colClockBody); }
#stage .col-clockFeet { fill: var(--colClockFeet); }
#stage .col-screen { fill: var(--colScreen); }
#stage #display { fill: var(--colDigits); }
#stage .col-bell { fill: var(--colBell); }
#stage .col-snooze { fill: var(--colSnooze); }
#stage .col-catRim { flood-color: var(--colCatRim); }

/* ---------- color panel: item menu + full-spectrum picker ---------- */
.tpanel .itemRow { display: flex; gap: 6px; align-items: center; margin: 8px 0; }
.tpanel .itemRow select { flex: 1; min-width: 0; }
.tpanel button.step {
  width: 32px; height: 32px; flex: none; padding: 0;
  border: 1.5px solid var(--ink); border-radius: 8px; background: #fff; color: var(--ink);
  font: 700 18px/1 ui-sans-serif, system-ui, sans-serif; cursor: pointer;
}
.tpanel button.step:hover { background: #e4e4e4; }
.tpanel .pickRow { display: flex; gap: 6px; align-items: center; margin-bottom: 8px; }
.tpanel .itemSwatch { width: 30px; height: 30px; flex: none; border: 1.5px solid var(--ink); border-radius: 8px; }
.tpanel .hexIn {
  width: 78px; min-height: 30px; box-sizing: border-box; padding: 4px 6px;
  border: 1.5px solid var(--ink); border-radius: 8px; background: #fff; color: var(--ink);
  font: 600 12px ui-monospace, Menlo, Consolas, monospace;
}
.tpanel .nativePick { width: 34px; height: 30px; flex: none; padding: 2px; border: 1.5px solid var(--ink); border-radius: 8px; background: #fff; cursor: pointer; }
.tpanel button.act.small { flex: 1; min-height: 30px; font-size: 11px; padding: 4px 6px; }
.tpanel .svBox, .tpanel .hueBar { position: relative; border: 1.5px solid var(--ink); border-radius: 8px; cursor: crosshair; touch-action: none; }
.tpanel .svBox { height: 130px; margin-bottom: 8px; }
.tpanel .hueBar {
  height: 18px; margin-bottom: 10px; cursor: ew-resize;
  background: linear-gradient(to right, #f00 0%, #ff0 16.66%, #0f0 33.33%, #0ff 50%, #00f 66.66%, #f0f 83.33%, #f00 100%);
}
.tpanel .svBox .knob, .tpanel .hueBar .knob {
  position: absolute; width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid #fff; box-shadow: 0 0 0 1.5px #222; transform: translate(-50%, -50%); pointer-events: none;
}
.tpanel .hueBar .knob { top: 50%; background: transparent; }
.tpanel .svBox:focus-visible, .tpanel .hueBar:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
.tpanel .swatches { display: grid; grid-template-columns: repeat(9, 1fr); gap: 5px; margin-bottom: 4px; }
.tpanel .sw { aspect-ratio: 1; min-height: 22px; padding: 0; border: 1.5px solid var(--ink); border-radius: 6px; cursor: pointer; }
.tpanel .sw:hover { transform: scale(1.12); }

/* ---------- window panel ---------- */
.tpanel .todTabs { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; margin: 4px 0 8px; }
.tpanel .todTabs button {
  min-height: 32px; border: 1.5px solid var(--ink); border-radius: 8px; background: #fff; color: var(--ink);
  font: 600 12px ui-sans-serif, system-ui, sans-serif; cursor: pointer;
}
.tpanel .todTabs button.on { background: var(--ink); color: #fff; }
.tpanel .row select { width: 100%; min-height: 32px; }
.tpanel p.jumpLabel { margin: 10px 0 4px; }

/* window sky extras: a comet now and then, a few twinkling stars */
#window .comet { animation: cometFly 9s linear infinite; }
@keyframes cometFly {
  0% { transform: translate(-60px, 24px); opacity: 0; }
  4% { opacity: 1; }
  40% { transform: translate(380px, 150px); opacity: 1; }
  44%, 100% { transform: translate(380px, 150px); opacity: 0; }
}
#window .twk { animation: twinkle 2.4s ease-in-out infinite alternate; }
@keyframes twinkle { from { opacity: 1; } to { opacity: .25; } }
@media (prefers-reduced-motion: reduce) {
  #window .comet { animation-duration: 18s; }
  #window .twk { animation: none; }
}

/* ---------- versions panel ---------- */
.tpanel .verSave { display: flex; gap: 6px; margin: 4px 0 2px; }
.tpanel .verName {
  flex: 1; min-width: 0; min-height: 32px; box-sizing: border-box; padding: 4px 8px;
  border: 1.5px solid var(--ink); border-radius: 8px; background: #fff; color: var(--ink); font: 13px ui-sans-serif, system-ui, sans-serif;
}
.tpanel .verSave .act { flex: none; }
.tpanel .verList { list-style: none; margin: 4px 0 0; padding: 0; max-height: 220px; overflow-y: auto; }
.tpanel .verList li { display: flex; align-items: center; gap: 6px; padding: 6px 2px; border-top: 1px solid #d6d6d6; }
.tpanel .verList li.empty { color: #666; font-size: 12px; border: 0; }
.tpanel .verInfo { flex: 1; min-width: 0; display: grid; }
.tpanel .verInfo strong { font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tpanel .verInfo small { color: #666; font-size: 11px; }
.tpanel .verList li.auto strong { font-weight: 500; color: #444; }
.tpanel .verList .act.small { flex: none; }
.tpanel button.step.del { width: 28px; height: 28px; font-size: 16px; }
.tpanel button.act.copyAll { width: 100%; margin-top: 8px; }

/* ---------- soft 3D look (toggle: "Soft 3D shading" in the Window tab) ---------- */
/* finer, softer outlines: the ink still takes its color from the Colors tab */
#stage.soft [stroke-width="3"], #bulb [stroke-width="3"] { stroke-width: 2px; }
#stage.soft [stroke="#222"]:not([stroke-opacity]), #stage.soft [stroke="#222222"]:not([stroke-opacity]) { stroke-opacity: .62; }
#stage.flat .look3d, body.flat #bulb .look3d { display: none; }
