/* 3dtoolbox.uk shared editing kit: menus, handles, flat design editor, studio preview */
:root {
  --tbx-bg: #17191c; --tbx-raised: #1f2226; --tbx-line: #33373e; --tbx-ink: #eceae6; --tbx-soft: #a3a6ab; --tbx-faint: #6f737a;
  --tbx-select: #4f9cf0; --tbx-red: #c8262f; --tbx-studio: #cbc9c4; --tbx-studio-2: #b9b7b1;
  --tbx-mono: "JetBrains Mono", ui-monospace, Menlo, Consolas, monospace;
}

/* studio backdrop behind a three.js preview */
.tbx-studio { background: radial-gradient(130% 100% at 50% 25%, #d6d4cf 0%, var(--tbx-studio) 55%, var(--tbx-studio-2) 100%) !important; }
.tbx-studio .hint, .tbx-studio .orbit-hint { color: #4a4c50 !important; }

/* right-click menu */
.tbx-menu { position: fixed; z-index: 1000; min-width: 220px; max-width: calc(100vw - 16px); background: #1d2024; border: 1px solid #3a3f46; border-radius: 8px; padding: 5px; box-shadow: 0 18px 40px -12px rgba(0,0,0,.8); font: 14px/1.3 "Public Sans", "Segoe UI", system-ui, sans-serif; color: var(--tbx-ink); }
.tbx-menu button { width: 100%; display: flex; justify-content: space-between; gap: 18px; background: none; border: 0; color: inherit; font: inherit; padding: 7px 10px; border-radius: 5px; cursor: pointer; text-align: left; }
.tbx-menu button:hover:not(:disabled), .tbx-menu button:focus-visible { background: #2a2e34; outline: none; }
.tbx-menu button:disabled { color: var(--tbx-faint); cursor: default; }
.tbx-menu .sc { color: var(--tbx-faint); font: 12px var(--tbx-mono); white-space: nowrap; }
.tbx-menu hr { border: 0; border-top: 1px solid #33373e; margin: 4px 2px; }
.tbx-menu .danger { color: #ff8a8f; }
.tbx-menu-note { margin: 4px 10px 4px; font-size: 12px; color: #ffb0b4; max-width: 230px; }

.tbx-toast { position: fixed; left: 50%; bottom: calc(18px + env(safe-area-inset-bottom, 0px)); transform: translate(-50%, 12px); opacity: 0; pointer-events: none; z-index: 1001; background: #0b0c0e; color: #fff; border: 1px solid #3a3f46; border-radius: 6px; padding: 7px 14px; font: 500 13px "Public Sans", system-ui, sans-serif; transition: opacity .18s ease, transform .18s ease; }
.tbx-toast.on { opacity: 1; transform: translate(-50%, 0); }

/* 3D handles: size labels and first-use hint */
.tbx-dims { position: absolute; inset: 0; pointer-events: none; z-index: 3; }
.tbx-dim { position: absolute; transform: translate(-50%, -50%); font: 500 12px var(--tbx-mono); color: #fff; background: rgba(11,12,14,.84); border: 1px solid #3a3f46; padding: 2px 7px; border-radius: 4px; white-space: nowrap; }
.tbx-dim.live { border-color: var(--tbx-select); }
.tbx-hint { position: absolute; left: 50%; top: 12px; transform: translateX(-50%); z-index: 3; pointer-events: none; font: 500 12.5px "Public Sans", system-ui, sans-serif; color: #1a1b1d; background: rgba(255,255,255,.82); border-radius: 999px; padding: 5px 12px; white-space: nowrap; max-width: calc(100% - 24px); overflow: hidden; text-overflow: ellipsis; }

/* flat design editor */
.tbx-ed { display: grid; gap: 10px; }
.tbx-ed-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.tbx-btn { appearance: none; border: 1px solid var(--line, var(--tbx-line)); background: var(--field, var(--tbx-raised)); color: var(--ink, var(--tbx-ink)); font: 500 13px/1 inherit; padding: 7px 10px; border-radius: 6px; cursor: pointer; }
.tbx-btn:hover:not(:disabled) { border-color: #4a5058; }
.tbx-btn:disabled { opacity: .4; cursor: default; }
.tbx-sep { width: 1px; height: 22px; background: var(--line, var(--tbx-line)); margin: 0 2px; }
.tbx-ed-tip { margin-left: auto; font-size: 12px; color: var(--ink-soft, var(--tbx-soft)); }
.tbx-ed-stage { position: relative; border-radius: 8px; overflow: hidden; background: #22252a; touch-action: none; user-select: none; -webkit-user-select: none; }
.tbx-ed-svg { display: block; width: 100%; height: auto; }
.tbx-ed-cap { position: absolute; left: 8px; bottom: 6px; font: 11px var(--tbx-mono); color: rgba(255,255,255,.55); pointer-events: none; }
.tbx-item { cursor: move; }
.tbx-centre { stroke: rgba(255,255,255,.22); stroke-dasharray: 2 2; stroke-width: .3; vector-effect: non-scaling-stroke; }
.tbx-guide { stroke: #e5484d; }
.tbx-box { fill: none; stroke: var(--tbx-select); pointer-events: none; }
.tbx-h { fill: var(--tbx-select); stroke: var(--tbx-select); }
.tbx-h.corner { fill: #fff; }
.tbx-readout { position: absolute; pointer-events: none; font: 500 12px var(--tbx-mono); background: #0b0c0e; color: #fff; padding: 3px 7px; border-radius: 4px; border: 1px solid #3a3f46; white-space: nowrap; transform: translate(14px, 14px); z-index: 2; }
.tbx-ed-fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 8px; }
.tbx-field { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 6px; font-size: 13px; color: var(--ink-soft, var(--tbx-soft)); }
.tbx-field input { width: 100%; min-width: 0; background: var(--field, #0f1012); border: 1px solid var(--line, var(--tbx-line)); color: var(--ink, var(--tbx-ink)); border-radius: 5px; padding: 5px 6px; font: 12.5px var(--tbx-mono); }
.tbx-field .u { font-size: 12px; color: var(--tbx-faint); }
.tbx-ed-note { margin: 0; font-size: 12.5px; color: var(--ink-soft, var(--tbx-soft)); }
.tbx-ed-note:empty { display: none; }
.tbx-ed-note.warn { color: #ffb0b4; }
@media (max-width: 520px) { .tbx-ed-tip { display: none; } .tbx-ed-fields { grid-template-columns: minmax(0, 1fr); } }
@media (prefers-reduced-motion: reduce) { .tbx-toast { transition: none; } }

/* "Controls" reminder in the corner of each 3D view */
.tbx-help { position: absolute; right: 10px; bottom: 10px; z-index: 4; appearance: none; border: 1px solid rgba(0,0,0,.18); background: rgba(255,255,255,.86); color: #1a1b1d; font: 600 12px/1 "Public Sans", system-ui, sans-serif; padding: 7px 10px; border-radius: 999px; cursor: pointer; }
.tbx-help:hover { background: #fff; }
.tbx-helpbox { position: absolute; right: 10px; bottom: 44px; z-index: 5; width: min(320px, calc(100% - 20px)); max-height: calc(100% - 60px); overflow: auto; background: rgba(22,24,27,.96); color: #eceae6; border: 1px solid #3d4249; border-radius: 10px; padding: 12px 14px; font: 400 12.5px/1.4 "Public Sans", system-ui, sans-serif; box-shadow: 0 12px 30px -12px rgba(0,0,0,.7); }
.tbx-helpbox[hidden] { display: none; }
.tbx-helpbox strong { display: block; font: 600 13px/1.2 "Archivo", system-ui, sans-serif; margin-bottom: 8px; }
.tbx-helpbox dl { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); gap: 5px 12px; margin: 0; }
.tbx-helpbox dt { font-weight: 600; color: #fff; }
.tbx-helpbox dd { margin: 0; color: #a3a6ab; }

/* ---------- keep the preview on screen while you scroll the options ---------- */
/* Stacked layouts (phones, tablets): the 3D view sticks to the top of the screen at a smaller size. */
@media (max-width: 960px) {
  .layout > .stage:has(> #viewport) { display: contents; }
  .layout > .stage > #viewport { position: sticky; top: env(safe-area-inset-top, 0px); z-index: 20; aspect-ratio: auto; height: clamp(200px, 40svh, 440px); min-height: 0; max-height: none; box-shadow: 0 8px 16px -10px rgba(0,0,0,.55); }
}
/* Cozies: the 3D view and the flat design both fit on screen together on laptops. */
@media (min-width: 901px) and (min-height: 561px) {
  .layout > .viewcol.cz-flat { position: sticky; top: 12px; display: flex; flex-direction: column; height: calc(100svh - 24px); }
  .viewcol.cz-flat > * { flex: none; }
  .viewcol.cz-flat > .viewer-wrap { flex: 1 1 0; height: auto; min-height: 150px; max-height: 680px; }
  .viewcol.cz-flat .tbx-ed-stage { max-height: 30svh; }
}
@media (max-width: 900px) {
  .layout > .viewcol:not(.cz-flat) { position: sticky; top: env(safe-area-inset-top, 0px); z-index: 20; background: var(--paper); padding: 6px 0 8px; box-shadow: 0 10px 14px -12px rgba(0,0,0,.5); }
  .layout > .viewcol:not(.cz-flat) .viewer-wrap { height: clamp(190px, 32svh, 420px); min-height: 0; }
  .layout > .viewcol:not(.cz-flat) .vinfo { margin-top: 6px; font-size: .8rem; }
  .layout > .viewcol.cz-flat { display: contents; }
  .layout > .viewcol.cz-flat > * { order: -1; }
  .layout > .viewcol.cz-flat > .viewer-wrap { position: sticky; top: env(safe-area-inset-top, 0px); z-index: 20; height: clamp(190px, 32svh, 420px); min-height: 0; box-shadow: 0 8px 16px -10px rgba(0,0,0,.55); }
}

/* align row in the flat design editor */
.tbx-ed-align { gap: 4px; }
.tbx-ed-lab { font-size: 12.5px; font-weight: 600; color: var(--ink-soft, var(--tbx-soft)); margin-right: 2px; }
.tbx-btn.tbx-ico { padding: 4px 6px; line-height: 0; }
.tbx-btn.tbx-ico svg { width: 20px; height: 20px; }
.tbx-marquee { fill: rgba(79,156,240,.12); stroke: var(--tbx-select); }
.tbx-group { opacity: .8; }
.tbx-ed-svg { margin: 0 auto; }
@media (max-width: 520px) { .tbx-ed-align { gap: 2px; } .tbx-btn.tbx-ico { padding: 3px 4px; } .tbx-ed-align .tbx-sep { margin: 0; } }

/* wide screens: use more of the width so the preview and options are bigger (Owen, 4 Nov) */
@media (min-width: 1500px) {
  .wrap, .layout, body > .top, body > footer { max-width: min(1760px, calc(100vw - 48px)); }
  .layout:has(> .viewcol) { grid-template-columns: minmax(0, 480px) minmax(0, 1fr); }
  .viewer-wrap { height: min(76vh, 900px); }
  #viewport { max-height: 78vh; }
}
