/* Livery editor (/liveries/paint.html). Builds on liveries.css.
   Laid out like Photoshop so painters find things where they expect them: menu bar, options bar, tools on
   the left, the document in the middle, panels on the right, status bar at the bottom. Two neutral layers:
   the chrome (--pt-chrome) and, darker, the document well behind the texture and the car. */

body.paint {
  --pt-chrome: var(--lv-panel);
  --pt-chrome-2: #101622;          /* panel headers, the options bar */
  --pt-well: #070a0f;              /* behind the document */
  --pt-hover: rgba(243, 245, 248, .07);
  --pt-active: rgba(26, 229, 102, .14);
  --pt-active-line: rgba(26, 229, 102, .5);
  height: 100vh; height: 100dvh; display: flex; flex-direction: column; overflow: hidden; font-size: 13px;
}
body.paint ::selection { background: rgba(26, 229, 102, .35); color: var(--lv-ink); }
body.paint input:not([type=checkbox]):not([type=range]):not([type=color]), body.paint select {
  min-height: 30px; padding: 4px 10px; font-size: 13px; border-radius: 8px; caret-color: var(--lv-green);
}
body.paint input[type=checkbox] { width: 15px; height: 15px; margin: 0; }
body.paint input[type=range] { accent-color: var(--lv-green); margin: 0; }
body.paint label { font-size: 12px; font-weight: 600; gap: 5px; }
body.paint label.check { font-size: 13px; font-weight: 500; gap: 8px; color: var(--lv-ink2); }
body.paint label.check:has(input:disabled) { opacity: .45; }
body.paint button:focus-visible { outline: 2px solid #5fc8ff; outline-offset: 1px; }
button.small { padding: 8px 18px; font-size: 13px; }
button.tiny { padding: 6px 11px; font-size: 12px; }

/* Thin dark scrollbars, as in an app. */
body.paint * { scrollbar-width: thin; scrollbar-color: rgba(243, 245, 248, .2) transparent; }

.center-msg { margin: 60px auto; max-width: 560px; text-align: center; padding: 0 16px; }

/* ── Menu bar ───────────────────────────────────────────────────────────────────────────────── */

.menubar {
  flex: none; display: flex; align-items: center; gap: 6px; height: 44px; padding: 0 10px 0 12px;
  background: var(--pt-chrome); border-bottom: 1px solid var(--lv-line);
}
.menubar .brand { gap: 8px; font-size: 14px; margin-right: 10px; white-space: nowrap; }
.menubar .brand img { border-radius: 4px; }
.menus { display: flex; align-items: center; gap: 2px; min-width: 0; overflow-x: auto; }
.menus button {
  height: 30px; padding: 0 11px; border: none; border-radius: 6px; background: transparent;
  color: var(--lv-ink2); font: 500 13px/1.3 var(--font-sans);
}
.menus button:hover, .menus button[aria-expanded=true] { background: var(--pt-hover); color: var(--lv-ink); }
.menubar-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.menubar-actions button.ghost { padding: 7px 14px; font-size: 13px; }

/* Saving: the Save button says whether the page can be closed. A ring fills while the image uploads
   (--p, 0..100) and spins while the server stores it and the layers follow; a tick when it is done. */
#save { gap: 8px; font-variant-numeric: tabular-nums; }
#save .save-ring, #save .save-done { display: none; flex: none; width: 16px; height: 16px; }
#save[data-state=saving] .save-ring, #save[data-state=done] .save-done { display: block; }
#save[data-state=saving]:disabled { opacity: 1; cursor: progress; }
#save .ring-track, #save .ring-bar { fill: none; stroke-width: 2.4; }
#save .ring-track { stroke: rgba(5, 7, 10, .16); }
#save .ring-bar {
  stroke: #05070a; stroke-linecap: round; stroke-dasharray: 100; stroke-dashoffset: calc(100 - var(--p, 0));
  transform: rotate(-90deg); transform-origin: 50% 50%; transition: stroke-dashoffset .2s ease-out;
}
#save.busy .ring-bar { stroke-dasharray: 26 100; stroke-dashoffset: 0; transition: none; animation: save-spin .8s linear infinite; }
#save .save-done path { fill: none; stroke: #0a7a3a; stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; }
@keyframes save-spin { from { transform: rotate(-90deg); } to { transform: rotate(270deg); } }
@media (prefers-reduced-motion: reduce) { #save.busy .ring-bar { animation-duration: 2.4s; } }

/* ── Workspace grid ─────────────────────────────────────────────────────────────────────────── */

.workspace {
  flex: 1; min-height: 0; display: grid;
  grid-template-columns: 48px minmax(0, 1fr) 288px;
  grid-template-rows: auto minmax(0, 1fr) auto;
  grid-template-areas: "opts opts opts" "tools doc dock" "status status status";
}
.optionsbar { grid-area: opts; }
.tools { grid-area: tools; }
.document { grid-area: doc; }
.dock { grid-area: dock; }
.statusbar { grid-area: status; }

/* ── Options bar ────────────────────────────────────────────────────────────────────────────── */

.optionsbar {
  /* A fixed height: the tools show different controls, and the canvas below must not jump. */
  display: flex; align-items: center; gap: 18px; height: 44px; padding: 0 14px;
  background: var(--pt-chrome-2); border-bottom: 1px solid var(--lv-line); overflow: auto hidden; white-space: nowrap;
}
.opt-tool { display: flex; align-items: center; gap: 8px; padding-right: 16px; border-right: 1px solid var(--lv-line); color: var(--lv-ink); font-weight: 600; }
.opt-tool svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.optionsbar .opt { display: flex; flex-direction: row; align-items: center; gap: 8px; color: var(--lv-ink2); font-weight: 500; }
.optionsbar .opt input[type=range] { width: 104px; }
.optionsbar output, .panel output { min-width: 36px; font: 600 12px/1.3 var(--font-mono); color: var(--lv-ink3); font-variant-numeric: tabular-nums; }
.opt-hint { margin: 0; color: var(--lv-ink3); }

/* ── Tools ──────────────────────────────────────────────────────────────────────────────────── */

.tools {
  display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 8px 0;
  background: var(--pt-chrome); border-right: 1px solid var(--lv-line); overflow-y: auto;
}
.tool {
  flex: none; width: 34px; height: 34px; border-radius: 7px; border: 1px solid transparent; background: transparent;
  color: var(--lv-ink2); display: flex; align-items: center; justify-content: center; padding: 0;
}
.tool svg, .icon svg, .swap svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tool:hover:not(:disabled) { background: var(--pt-hover); color: var(--lv-ink); }
.tool.active { background: var(--pt-active); border-color: var(--pt-active-line); color: var(--lv-green); }
.tool:disabled { opacity: .3; cursor: default; }
.tools .sep { flex: none; height: 1px; width: 26px; background: var(--lv-line); margin: 4px 0; }

/* The two colours overlap like Photoshop's foreground and background swatches. */
.swatches { position: relative; flex: none; width: 38px; height: 42px; margin: 4px 0 2px; }
.swatches input[type=color] {
  position: absolute; width: 26px; height: 26px; padding: 0; border: 2px solid var(--lv-ink); border-radius: 5px;
  background: none; cursor: pointer; box-shadow: 0 0 0 1px rgba(0, 0, 0, .6);
}
.swatches input[type=color]::-webkit-color-swatch-wrapper { padding: 0; }
.swatches input[type=color]::-webkit-color-swatch { border: none; border-radius: 2px; }
.swatches input[type=color]::-moz-color-swatch { border: none; border-radius: 2px; }
#color { left: 0; top: 0; z-index: 1; }
#color2 { right: 0; bottom: 0; border-color: var(--lv-ink3); }
.swatches .swap {
  position: absolute; right: -2px; top: -2px; width: 16px; height: 16px; padding: 0; border: none; border-radius: 4px;
  background: transparent; color: var(--lv-ink3);
}
.swatches .swap svg { width: 13px; height: 13px; }
.swatches .swap:hover { color: var(--lv-ink); }

/* ── Document ───────────────────────────────────────────────────────────────────────────────── */

.document { min-width: 0; min-height: 0; display: flex; flex-direction: column; background: var(--pt-well); }
.doc-tabs {
  flex: none; display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; padding: 6px 10px 0;
  background: var(--pt-chrome); border-bottom: 1px solid var(--lv-line);
}
.doc-tab {
  display: flex; align-items: center; gap: 8px; min-width: 0; max-width: 100%; height: 32px; padding: 0 12px;
  border: 1px solid var(--lv-line); border-bottom: none; border-radius: 8px 8px 0 0; margin-bottom: -1px;
  background: var(--pt-well); color: var(--lv-ink); font: 600 13px/1.3 var(--font-sans);
}
.doc-tab span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-tab svg { flex: none; width: 14px; height: 14px; fill: none; stroke: var(--lv-ink3); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.doc-tab:hover svg { stroke: var(--lv-ink); }
.layout-seg { margin-bottom: 5px; }

.views { flex: 1; min-height: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 1px; background: var(--lv-line); }
.views[data-layout="2d"], .views[data-layout="3d"] { grid-template-columns: 1fr; }
.views[data-layout="2d"] #view3d, .views[data-layout="3d"] #view2d { display: none; }
.view { position: relative; min-width: 0; min-height: 0; overflow: hidden; background: var(--pt-well); }
#view2d { background: repeating-conic-gradient(#0b0f15 0% 25%, #0e131b 0% 50%) 50% / 24px 24px; }
#screen { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; cursor: crosshair; }
#three { position: absolute; inset: 0; touch-action: none; }
#three canvas { display: block; }
.view-hint {
  position: absolute; left: 10px; bottom: 10px; pointer-events: none; padding: 6px 10px; border-radius: 7px;
  background: rgba(5, 7, 10, .78); color: var(--lv-ink2); font: 500 12px/1.2 var(--font-sans);
}
.view-bar {
  position: absolute; right: 10px; top: 10px; display: flex; gap: 10px; align-items: center;
  padding: 6px 10px; border-radius: 9px; background: rgba(5, 7, 10, .78); border: 1px solid var(--lv-line);
}

/* ── Panel dock ─────────────────────────────────────────────────────────────────────────────── */

.dock { min-height: 0; overflow-y: auto; background: var(--pt-chrome); border-left: 1px solid var(--lv-line); }
.panel { border-bottom: 1px solid var(--lv-line); }
.panel summary {
  display: flex; align-items: center; gap: 8px; height: 34px; padding: 0 12px; cursor: pointer; user-select: none;
  list-style: none; background: var(--pt-chrome-2); color: var(--lv-ink); font: 600 13px/1.3 var(--font-sans);
}
.panel summary::-webkit-details-marker { display: none; }
.panel summary::before {
  content: ''; width: 6px; height: 6px; margin: 0 2px; border: solid var(--lv-ink3); border-width: 0 1.5px 1.5px 0;
  transform: rotate(-45deg); transition: transform .15s ease-out;
}
.panel[open] summary::before { transform: rotate(45deg) translate(-1px, -1px); }
.panel summary:hover { background: #141b28; }
.panel summary:focus-visible { outline: 2px solid #5fc8ff; outline-offset: -2px; }
.panel-body { display: flex; flex-direction: column; gap: 10px; padding: 12px; }
#sel-props:not([hidden]), #text-props:not([hidden]) { display: flex; flex-direction: column; gap: 10px; }
.panel-empty, .panel-note { margin: 0; font-size: 12px; line-height: 1.45; color: var(--lv-ink3); }
.panel label.range { display: grid; grid-template-columns: 1fr auto; align-items: center; row-gap: 4px; column-gap: 8px; }
.panel label.range input { grid-column: 1 / -1; width: 100%; }
.panel label.range output { grid-row: 1; grid-column: 2; text-align: right; }
.panel .inline-color { flex-direction: row; align-items: center; justify-content: space-between; }
.panel input[type=color] { width: 44px; height: 26px; border: 1px solid var(--lv-line); border-radius: 6px; background: transparent; padding: 2px; cursor: pointer; }
.btn-row { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.btn-row label.check { margin-right: 10px; }
.sel-size { margin: 0; font: 600 12px/1.3 var(--font-mono); color: var(--lv-ink); font-variant-numeric: tabular-nums; }
.finish-tune { display: flex; flex-direction: column; gap: 10px; padding-top: 4px; }
.finish-tune[hidden] { display: none; }
.finish-tune button { align-self: flex-start; }

/* Layers panel: opacity on top, the list, then Photoshop's row of small buttons at the bottom. */
.layers { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; border: 1px solid var(--lv-line); border-radius: 8px; overflow-y: auto; max-height: 300px; min-height: 120px; background: var(--pt-well); }
.layers li {
  display: flex; align-items: center; gap: 8px; min-height: 38px; padding: 4px 10px 4px 4px; cursor: pointer;
  border-bottom: 1px solid var(--lv-line); color: var(--lv-ink2);
}
.layers li:last-child { border-bottom: none; }
.layers li:hover { background: var(--pt-hover); }
.layers li.active { background: var(--pt-active); color: var(--lv-ink); box-shadow: inset 2px 0 0 var(--lv-green); }
.layers li .eye { flex: none; width: 28px; height: 28px; padding: 0; border: none; border-radius: 6px; background: none; color: var(--lv-ink2); }
.layers li .eye:hover { background: var(--pt-hover); color: var(--lv-ink); }
.layers li .eye svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.layers li .eye.off { color: var(--lv-ink3); opacity: .55; }
.layers li .lname { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.layers li .lname-edit { flex: 1; min-width: 0; min-height: 26px !important; padding: 2px 6px !important; font: inherit; color: var(--lv-ink); background: rgba(5, 7, 10, .8); border: 1px solid var(--pt-active-line); border-radius: 5px; }
.layers li .kind { font: 500 11px/1.3 var(--font-sans); color: var(--lv-ink3); }
.layer-bar { display: flex; align-items: center; justify-content: flex-end; gap: 2px; }
.layer-bar .sep { width: 1px; height: 18px; background: var(--lv-line); margin: 0 4px; }
.icon { width: 30px; height: 30px; padding: 0; border: none; border-radius: 6px; background: transparent; color: var(--lv-ink2); }
.icon svg { width: 17px; height: 17px; }
.icon:hover:not(:disabled) { background: var(--pt-hover); color: var(--lv-ink); }
.icon.danger:hover:not(:disabled) { color: var(--lv-red); }
.icon:disabled { opacity: .3; cursor: default; }

/* ── Status bar ─────────────────────────────────────────────────────────────────────────────── */

.statusbar {
  display: flex; align-items: center; gap: 16px; height: 28px; padding: 0 12px; overflow: hidden; white-space: nowrap;
  background: var(--pt-chrome); border-top: 1px solid var(--lv-line); color: var(--lv-ink3); font: 500 12px/1.3 var(--font-sans);
}
.statusbar .zoom, .statusbar .cursor { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.statusbar .zoom { color: var(--lv-ink2); min-width: 40px; }
.statusbar .cursor { min-width: 92px; }
.statusbar .status { flex: 1; min-width: 0; min-height: 0; font-size: 12px; overflow: hidden; text-overflow: ellipsis; color: var(--lv-ink2); }
.statusbar .status.bad { color: var(--lv-red); }
.statusbar .status.good { color: var(--lv-green); }
.statusbar-hint { margin-left: auto; }

/* ── File > Open ────────────────────────────────────────────────────────────────────────────── */

.open-panel {
  position: fixed; inset: auto; margin: 0; width: 300px; padding: 14px; flex-direction: column; gap: 12px;
  background: #121924; color: var(--lv-ink2); border: 1px solid var(--lv-line); border-radius: 10px; box-shadow: 0 14px 40px rgba(0, 0, 0, .6);
}
.open-panel:popover-open { display: flex; }
.open-panel select { width: 100%; }
.open-panel button { align-self: flex-end; }

/* ── Small screens: everything stacks, the bars scroll sideways ─────────────────────────────── */

@media (max-width: 900px) {
  body.paint { height: auto; overflow: auto; }
  .menubar .brand span { display: none; }
  .menubar .brand { margin-right: 2px; }
  .menus { flex: 1; }
  #save-copy { display: none; }   /* still in File */
  .workspace { grid-template-columns: minmax(0, 1fr); grid-template-areas: "opts" "tools" "doc" "dock" "status"; }
  .tools { flex-direction: row; flex-wrap: wrap; justify-content: center; border-right: none; border-bottom: 1px solid var(--lv-line); }
  .tools .sep { width: 1px; height: 26px; margin: 0 4px; }
  .document { height: 110vh; }
  .views, .views[data-layout] { grid-template-columns: 1fr; grid-template-rows: 1fr 1fr; }
  .views[data-layout="2d"], .views[data-layout="3d"] { grid-template-rows: 1fr; }
  .dock { border-left: none; }
  .statusbar-hint, .statusbar .cursor { display: none; }
}

.seg { display: flex; border: 1px solid var(--lv-line); border-radius: 8px; overflow: hidden; }
.menubar button, .doc-tabs button { white-space: nowrap; }
.seg button { padding: 6px 11px; white-space: nowrap; border: none; border-radius: 0; background: transparent; color: var(--lv-ink2); font: 500 12px/1.3 var(--font-sans); }
.seg button + button { border-left: 1px solid var(--lv-line); }
.seg button:hover { background: var(--pt-hover); color: var(--lv-ink); }
.seg button.active { background: var(--pt-active); color: var(--lv-green); }
.optionsbar .opt:has(.seg) { gap: 10px; }

/* Dragging image files over the editor: both views outlined, the one under the cursor lit. */
body.dropping .view::after {
  content: ''; position: absolute; inset: 8px; z-index: 5; pointer-events: none;
  border: 2px dashed rgba(26, 229, 102, .3); border-radius: 12px;
}
body.dropping .view.drop-here::after {
  content: 'Drop to add the image here'; display: flex; align-items: center; justify-content: center;
  border-color: var(--lv-green); background: rgba(26, 229, 102, .08); color: var(--lv-green); font: 700 15px/1.2 var(--font-sans);
}

/* Menus: the menu bar's drop-downs and the right-click menu on the texture, the 3D car and the layers. */
.ctx-menu {
  position: fixed; z-index: 50; min-width: 240px; max-width: calc(100vw - 16px); max-height: calc(100vh - 16px); overflow-y: auto;
  padding: 5px; background: #121924; border: 1px solid var(--lv-line); border-radius: 10px; box-shadow: 0 14px 40px rgba(0, 0, 0, .6);
  outline: none;
}
.ctx-menu[hidden] { display: none; }
.ctx-menu button {
  display: flex; align-items: center; width: 100%; gap: 10px; padding: 7px 10px; border: none; border-radius: 6px;
  background: transparent; color: var(--lv-ink); font: 500 13px/1.2 var(--font-sans); text-align: left;
}
.ctx-menu button:hover:not(:disabled), .ctx-menu button:focus-visible { background: var(--pt-active); outline: none; }
.ctx-menu button:disabled { opacity: .35; cursor: default; }
.ctx-menu button.danger { color: var(--lv-red); }
.ctx-menu button.current { color: var(--lv-green); }
.ctx-menu .tick { flex: none; width: 14px; height: 14px; fill: none; stroke: var(--lv-green); stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.ctx-menu .tick.off { visibility: hidden; }
.ctx-menu .label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ctx-menu .key { flex: none; margin-left: 18px; font: 500 11px/1.3 var(--font-mono); color: var(--lv-ink3); }
.ctx-menu .swatch { flex: none; width: 14px; height: 14px; border-radius: 4px; border: 1px solid var(--lv-line); }
.ctx-menu .sep { height: 1px; margin: 5px 4px; background: var(--lv-line); }
.ctx-menu .head { padding: 8px 10px 4px; font: 600 12px/1.3 var(--font-sans); color: var(--lv-ink3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
