/* Latent — dark theme, amber/gold accent, red-outline Discard */
:root{
  --bg:#171310; --bg2:#211b16; --bg3:#2a231c; --panel:#1e1915;
  --text:#f2ead9; --muted:#a89a83; --border:#3a322a;
  --amber:#f5a623; --amber2:#ffc95e; --red:#e5534b;
  --radius:10px;
}
*{box-sizing:border-box; -webkit-tap-highlight-color:transparent;}
html,body{height:100%; margin:0;}
body{
  background:var(--bg); color:var(--text);
  font-family:-apple-system,"Segoe UI",Roboto,Helvetica,Arial,sans-serif;
  overflow:hidden;
}
button{font-family:inherit; cursor:pointer;}
.hidden{display:none !important;}

#app{display:grid; grid-template-rows:auto 1fr auto auto; height:100dvh;}

/* Desktop-only toolbar extras (dimensions, Reset edits) */
.desktop-only{display:none !important;}

/* Photo toolbar */
#photoToolbar{
  display:flex; align-items:center; gap:6px;
  padding:5px 10px; background:var(--bg2); border-bottom:1px solid var(--border);
}
.file-name{font-size:13px; color:var(--muted); white-space:nowrap; overflow:hidden; text-overflow:ellipsis; max-width:40vw;}
.spacer{flex:1;}
.tool-btn{
  min-width:36px; height:34px; padding:0 8px; border-radius:8px;
  border:1px solid transparent; background:transparent; color:var(--text); font-size:16px;
}
.tool-btn:hover{background:var(--bg3);}
.tool-btn.active{background:var(--bg3); border-color:var(--amber); color:var(--amber2);}
.tool-btn:disabled{opacity:.35; cursor:default;}
.tool-btn.danger{color:var(--red);}
.tool-btn.gold{color:var(--amber);}
#deleteBtn.confirm{
  background:var(--red); color:#fff; border-color:var(--red);
  font-size:12px; font-weight:700; white-space:nowrap;
}
#app.no-filmstrip #filmstripRow{display:none;}

/* Layout */
#layout{display:flex; min-height:0;}
#leftRail{
  width:250px; flex:0 0 250px; background:var(--panel); border-right:1px solid var(--border);
  padding:10px; overflow-y:auto; display:flex; flex-direction:column; gap:14px;
}
#rightRail{
  width:300px; flex:0 0 300px; background:var(--panel); border-left:1px solid var(--border);
  display:flex; flex-direction:column; min-height:0;
}
#centerCol{flex:1; display:flex; flex-direction:column; min-width:0; min-height:0; background:#100d0a;}
.rail-section h2, .panel h2{font-size:12px; text-transform:uppercase; letter-spacing:1px; color:var(--muted); margin:2px 0 8px;}
#navCanvas{width:100%; height:auto; display:block; background:#14100c; border-radius:6px;}
.rail-section.grow{flex:1; display:flex; flex-direction:column; min-height:0;}
.small-btn{
  background:var(--bg3); color:var(--text); border:1px solid var(--border);
  border-radius:8px; padding:6px 10px; font-size:12.5px; width:100%; margin-bottom:8px;
}
.small-btn:hover{border-color:var(--amber);}

.preset-list{display:flex; flex-direction:column; gap:6px;}
.preset-item{
  text-align:left; background:var(--bg3); border:1px solid var(--border); color:var(--text);
  border-radius:8px; padding:8px 10px; font-size:13px;
}
.preset-item:hover{border-color:var(--amber);}
.snapshot-list,.history-list{display:flex; flex-direction:column; gap:4px; overflow-y:auto;}
.snapshot-item,.history-item{
  text-align:left; background:transparent; border:1px solid var(--border); color:var(--muted);
  border-radius:7px; padding:6px 9px; font-size:12.5px;
}
.snapshot-item:hover,.history-item:hover{color:var(--text); border-color:var(--amber);}
.history-item.current{color:var(--amber2); border-color:var(--amber);}

/* Stage */
#stageWrap{
  flex:1; min-height:0; display:flex; align-items:center; justify-content:center;
  padding:10px; position:relative; overflow:hidden;
}
#photoBox{position:relative; line-height:0; box-shadow:0 6px 30px rgba(0,0,0,.55);}
.stage-pill{
  position:absolute; top:8px; left:8px; z-index:6; pointer-events:none;
  font-size:11.5px; line-height:1.25; color:#fff; background:rgba(0,0,0,.55);
  padding:3px 9px; border-radius:999px; max-width:62%; white-space:nowrap;
  overflow:hidden; text-overflow:ellipsis;
}
.stage-pill-right{left:auto; right:8px; color:var(--amber2);}
#photoBox canvas{display:block;}
#mainCanvas{position:relative; z-index:1;}
#beforeCanvas{position:absolute; left:0; top:0; z-index:2;}
#brushCanvas{position:absolute; left:0; top:0; z-index:4; touch-action:none; cursor:none;}
/* Brush cursor: outer ring = full brush size, inner ring = the soft
 * core (feather), Lightroom-style. Follows the pointer over the photo. */
#brushCursor{
  position:absolute; z-index:5; pointer-events:none; border-radius:50%;
  border:1.5px solid rgba(255,255,255,.92); box-shadow:0 0 0 1px rgba(0,0,0,.45), inset 0 0 0 1px rgba(0,0,0,.25);
  transform:translate(-50%,-50%);
  display:flex; align-items:center; justify-content:center;
}
#brushCursor .bc-inner{
  width:55%; height:55%; border-radius:50%;
  border:1px solid rgba(255,255,255,.55); box-shadow:inset 0 0 0 1px rgba(0,0,0,.2);
}
#emptyState{text-align:center; color:var(--muted);}
#emptyState .empty-title{font-size:30px; color:var(--text); margin:0 0 4px; letter-spacing:1px;}
#emptyState .empty-sub{font-size:12px;}
#stageWrap.dragover{outline:2px dashed var(--amber); outline-offset:-8px;}

/* Before / After split */
#splitDivider{position:absolute; top:0; bottom:0; z-index:3; width:0;}
#splitDivider::before{
  content:""; position:absolute; top:0; bottom:0; left:-1px; width:2px; background:#fff;
  box-shadow:0 0 6px rgba(0,0,0,.7);
}
#splitHandle{
  position:absolute; top:50%; left:0; transform:translate(-50%,-50%);
  width:34px; height:34px; border-radius:50%; background:rgba(20,16,12,.85);
  border:2px solid #fff; color:#fff; display:flex; align-items:center; justify-content:center;
  font-size:15px; cursor:ew-resize; touch-action:none; user-select:none;
}
.ba-label{
  position:absolute; top:8px; font-size:11.5px; color:#fff; background:rgba(0,0,0,.55);
  padding:3px 8px; border-radius:6px; line-height:1.2; pointer-events:none; white-space:nowrap;
}
.ba-before{right:10px;}
.ba-after{left:10px;}

/* Crop overlay */
#cropOverlay{position:absolute; inset:0; z-index:5; touch-action:none;}
#cropOverlay::before{content:""; position:absolute; inset:0; background:rgba(0,0,0,.45);}
.crop-frame{
  position:absolute; border:3px solid var(--amber); box-shadow:0 0 0 1px rgba(0,0,0,.5);
  cursor:move; touch-action:none;
}
.crop-grid{
  position:absolute; inset:0; pointer-events:none;
  background:
    linear-gradient(to right, transparent calc(33.33% - .5px), rgba(255,255,255,.35) 33.33%, transparent calc(33.33% + .5px)),
    linear-gradient(to right, transparent calc(66.66% - .5px), rgba(255,255,255,.35) 66.66%, transparent calc(66.66% + .5px)),
    linear-gradient(to bottom, transparent calc(33.33% - .5px), rgba(255,255,255,.35) 33.33%, transparent calc(33.33% + .5px)),
    linear-gradient(to bottom, transparent calc(66.66% - .5px), rgba(255,255,255,.35) 66.66%, transparent calc(66.66% + .5px));
}
.handle{
  position:absolute; width:18px; height:18px; background:var(--amber);
  border:2px solid #fff2d8; border-radius:3px; z-index:2; touch-action:none;
}
.handle[data-h="nw"]{left:-11px; top:-11px; cursor:nwse-resize;}
.handle[data-h="n"]{left:calc(50% - 9px); top:-11px; cursor:ns-resize;}
.handle[data-h="ne"]{right:-11px; top:-11px; cursor:nesw-resize;}
.handle[data-h="e"]{right:-11px; top:calc(50% - 9px); cursor:ew-resize;}
.handle[data-h="se"]{right:-11px; bottom:-11px; cursor:nwse-resize;}
.handle[data-h="s"]{left:calc(50% - 9px); bottom:-11px; cursor:ns-resize;}
.handle[data-h="sw"]{left:-11px; bottom:-11px; cursor:nesw-resize;}
.handle[data-h="w"]{left:-11px; top:calc(50% - 9px); cursor:ew-resize;}

/* Mode strip (below the photo) */
#modeStrip{
  display:flex; align-items:center; gap:8px; margin:0 10px 8px;
  padding:8px 10px; background:var(--bg2); border:1px solid var(--border); border-radius:var(--radius);
}
#modeHint{font-size:12.5px; color:var(--muted);}
.discard-btn{
  background:transparent; color:#ff8a80; border:1.5px solid var(--red);
  border-radius:999px; padding:7px 16px; font-size:13.5px; font-weight:600;
}
.done-btn{
  background:var(--amber); color:#241a05; border:none;
  border-radius:999px; padding:8px 18px; font-size:13.5px; font-weight:700;
}
.done-btn:hover{background:var(--amber2);}

/* Rating bar */
#ratingBar{
  display:flex; align-items:center; gap:12px; flex-wrap:wrap;
  padding:7px 12px; background:var(--bg2); border-top:1px solid var(--border);
}
#stars{display:flex; gap:2px;}
#stars button{background:none; border:none; font-size:21px; color:#5c5344; padding:0 1px; line-height:1;}
#stars button.on{color:var(--amber);}
#colorLabels{display:flex; gap:6px;}
.pill{width:20px; height:26px; border-radius:6px; border:2px solid transparent; padding:0;}
.pill-red{background:#e5484d;} .pill-yellow{background:#f5c542;}
.pill-green{background:#46a758;} .pill-blue{background:#3e7bfa;}
.pill.on{border-color:#fff; box-shadow:0 0 0 2px var(--amber);}
.flag-btn{
  background:var(--bg3); color:var(--muted); border:1px solid var(--border);
  border-radius:999px; padding:6px 14px; font-size:12.5px;
}
.flag-btn.on-pick{background:#2f5233; color:#b7e4c7; border-color:#46a758;}
.flag-btn.on-reject{background:#5a2b28; color:#ffc9c4; border-color:var(--red);}

/* Filmstrip */
#filmstripRow{
  display:flex; align-items:center; gap:8px; padding:7px 10px;
  background:var(--bg2); border-top:1px solid var(--border);
}
#filmstrip{display:flex; gap:7px; overflow-x:auto; flex:1; padding:2px; min-height:56px;}
.thumb{
  flex:0 0 auto; width:74px; height:54px; border-radius:7px; overflow:hidden;
  border:2.5px solid transparent; padding:0; background:var(--bg3); position:relative;
}
.thumb img{width:100%; height:100%; object-fit:cover; display:block;}
.thumb.active{border-color:var(--amber);}
.thumb .thumb-flag{position:absolute; left:3px; bottom:3px; font-size:10px; line-height:1;}
#addTile{
  flex:0 0 auto; width:52px; height:54px; border-radius:7px; font-size:22px;
  background:transparent; color:var(--muted); border:1.5px dashed var(--border);
}
#addTile:hover{color:var(--amber2); border-color:var(--amber);}
#filterSelect{
  background:var(--bg3); color:var(--text); border:1px solid var(--border);
  border-radius:8px; padding:8px 6px; font-size:12.5px; max-width:118px;
}
.chip{
  font-size:11.5px; color:var(--muted); border:1px solid var(--border);
  padding:6px 10px; border-radius:999px; white-space:nowrap;
}

/* Right rail / panels */
#histogramBox{padding:10px 10px 4px; border-bottom:1px solid var(--border);}
#histogram{width:100%; height:72px; display:block; background:#14100c; border-radius:6px;}
#panelContainer{flex:1; overflow-y:auto; padding:12px; min-height:0; --pc-pad:12px;}
.panel{display:none; flex-direction:column; gap:14px;}
.panel.active{display:flex;}
.panel-head{display:flex; align-items:center; gap:8px;}
.panel-head h2{flex:1; margin:0;}
/* Sticky sheet header: tool title (+ Discard/Done pair on editing sheets) */
.sheet-head{
  position:sticky; top:calc(-1 * var(--pc-pad)); z-index:3; background:var(--panel);
  display:flex; align-items:center; gap:8px; padding:8px 0 6px; margin:-4px 0 0;
}
.sheet-head h2{flex:1; margin:0;}
.panel-head.sticky{
  position:sticky; top:calc(-1 * var(--pc-pad)); z-index:3; background:var(--panel);
  padding:8px 0 6px; margin:-4px 0 0;
}
.panel-note{font-size:12px; color:var(--muted); line-height:1.45;}
.panel-note b{color:var(--amber2);}

.slider-row{display:grid; grid-template-columns:86px 1fr 40px 22px; align-items:center; gap:7px; margin:5px 0;}
.slider-row label{font-size:12.5px; color:var(--text); white-space:nowrap; overflow:hidden; text-overflow:ellipsis;}
.slider-row .val{font-size:11.5px; color:var(--muted); text-align:right;}
.slider-row input[type="range"]{-webkit-appearance:none; appearance:none; width:100%; height:26px; background:transparent; touch-action:pan-y;}
.slider-row input[type="range"]::-webkit-slider-runnable-track{height:4px; background:#4a4036; border-radius:2px;}
.slider-row input[type="range"]::-webkit-slider-thumb{
  -webkit-appearance:none; width:17px; height:17px; border-radius:50%;
  background:var(--amber); margin-top:-6.5px; border:2px solid #fff2d8;
}
.slider-row input[type="range"]::-moz-range-track{height:4px; background:#4a4036; border-radius:2px;}
.slider-row input[type="range"]::-moz-range-thumb{width:15px; height:15px; border-radius:50%; background:var(--amber); border:2px solid #fff2d8;}
.reset-pill{
  width:20px; height:20px; border-radius:50%; border:1px solid var(--amber); color:var(--amber2);
  background:transparent; font-size:12px; line-height:1; padding:0; visibility:hidden;
}
.reset-pill.show{visibility:visible;}

.chip-row{display:flex; flex-wrap:wrap; gap:6px;}
.chip-btn{
  background:var(--bg3); color:var(--muted); border:1px solid var(--border);
  border-radius:999px; padding:6px 12px; font-size:12.5px;
}
.chip-btn.active{background:var(--amber); color:#241a05; border-color:var(--amber); font-weight:700;}
.chip-btn:hover{border-color:var(--amber);}
.btn-row{display:flex; gap:8px; flex-wrap:wrap;}
.action-btn{
  flex:1; background:var(--bg3); color:var(--text); border:1px solid var(--border);
  border-radius:9px; padding:9px 10px; font-size:13px; white-space:nowrap;
}
.action-btn:hover{border-color:var(--amber);}
.action-btn.active{border-color:var(--amber); color:var(--amber2);}

/* In-context tips (complicated tools only): small ⓘ next to a heading */
.title-row{display:flex; align-items:center; gap:6px;}
.title-row h2{margin:2px 0 8px;}
.tip-btn{
  width:19px; height:19px; border-radius:50%; flex:0 0 auto;
  border:1px solid var(--muted); color:var(--muted); background:transparent;
  font-size:11.5px; line-height:1; padding:0; margin-bottom:6px;
}
.tip-btn.on{border-color:var(--amber); color:var(--amber2);}
.tip-note{margin:-2px 0 6px;}
.sheet-head .tip-btn{margin-bottom:0;}
/* Colour grading picker */
.grade-row{display:flex; align-items:center; gap:8px; margin:5px 0;}
.grade-row label{font-size:12.5px; flex:1;}
.grade-swatch{
  width:34px; height:24px; border-radius:7px; padding:0;
  border:2px solid var(--border); background:#3a3a3a;
}
.grade-swatch.active{border-color:var(--amber);}
#gradePicker{margin:6px 0 2px;}
#gradeWheel{display:block; margin:0 auto; border-radius:50%; touch-action:none; cursor:crosshair;}
.grade-swatches{display:flex; gap:6px; flex-wrap:wrap; margin-top:8px;}
.grade-swatches .grade-swatch{width:26px; height:26px; border-radius:50%;}
#gradeReadout{text-align:center; margin-top:6px;}

/* Tone curve */
#curveCanvas{
  width:100%; aspect-ratio:1/0.6; background:#14100c; border:1px solid var(--border);
  border-radius:8px; touch-action:pan-y; display:block;
}
.curve-tabs{display:flex; gap:6px;}
.curve-tabs .chip-btn[data-ch="r"].active{background:#e5484d; border-color:#e5484d; color:#fff;}
.curve-tabs .chip-btn[data-ch="g"].active{background:#46a758; border-color:#46a758; color:#fff;}
.curve-tabs .chip-btn[data-ch="b"].active{background:#3e7bfa; border-color:#3e7bfa; color:#fff;}

/* AI inbox */
.ai-list{display:flex; flex-direction:column; gap:6px;}
.ai-req{
  border:1px solid var(--border); border-radius:8px; padding:8px 10px; font-size:12.5px;
  background:var(--bg2);
}
.ai-req .st{color:var(--amber2); font-weight:600;}
.ai-req .meta{color:var(--muted); font-size:11.5px;}
select.ai-select, textarea.ai-note, input.msg-input{
  width:100%; background:var(--bg3); color:var(--text); border:1px solid var(--border);
  border-radius:8px; padding:9px; font-size:13px; font-family:inherit;
}
textarea.ai-note{resize:vertical; min-height:52px;}
.msg-thread{display:flex; flex-direction:column; gap:6px; max-height:220px; overflow-y:auto;}
.msg{border-radius:10px; padding:7px 10px; font-size:12.5px; max-width:92%; line-height:1.4;}
.msg.me{align-self:flex-end; background:#3a2c12; border:1px solid #6b5518;}
.msg.them{align-self:flex-start; background:var(--bg3); border:1px solid var(--border);}
.msg .who{font-size:10.5px; color:var(--muted); display:block; margin-bottom:2px;}
.msg-row{display:flex; gap:6px;}
.msg-row .msg-input{flex:1;}
.swatch{
  display:inline-block; width:22px; height:22px; border-radius:5px; border:1px solid var(--border);
  vertical-align:middle; margin-right:6px;
}

/* Tool bar */
#toolBar{
  display:flex; background:var(--bg2); border-top:1px solid var(--border);
  padding:4px 2px calc(4px + env(safe-area-inset-bottom)); overflow-x:auto;
}
#toolBar button{
  flex:1 0 auto; background:none; border:none; color:var(--muted); position:relative;
  font-size:11px; display:flex; flex-direction:column; align-items:center; gap:2px; padding:5px 8px;
}
#toolBar button .tb-icon{font-size:19px; line-height:1;}
#toolBar button.active{color:var(--amber2);}
.tb-badge{
  position:absolute; top:1px; right:6px; min-width:17px; height:17px; border-radius:999px;
  background:var(--amber); color:#241a05; font-size:10.5px; font-weight:700; line-height:17px;
  text-align:center; padding:0 4px;
}

/* ---------- Desktop (>1200px): all panels stacked in right rail, no tool bar ---------- */
@media (min-width:1201px){
  #toolBar{display:none;}
  .panel{display:flex; padding-bottom:14px; border-bottom:1px solid var(--border); margin-bottom:14px;}
  .panel:last-child{border-bottom:none;}
  .desktop-only{display:flex !important;}
  span.desktop-only{display:inline !important;}
  .sheet-head{position:static;}
  .panel-head.sticky{position:static;}
  /* Right-column section order approximating the artifact's desktop
   * nesting (Basic → Curve → HSL/Grading → Detail → Lens → Crop &
   * Transform → Effects → Heal → Masks → Export → AI → Mark → Inbox →
   * From Muse → Message); panels are the granularity available. */
  #panelContainer{display:flex; flex-direction:column;}
  #panel-colour{order:1;} #panel-light{order:2;} #panel-effects{order:3;}
  #panel-detail{order:4;} #panel-lens{order:5;} #panel-crop{order:6;}
  #panel-geometry{order:7;} #panel-heal{order:8;} #panel-masks{order:9;}
  #panel-export{order:10;} #panel-aitools{order:11;} #panel-mark{order:12;}
  #panel-inbox{order:13;} #panel-frommuse{order:14;} #panel-message{order:15;}
  #panel-presets{order:16;}
}
/* ---------- Tablet (768–1200px): slim left rail, compact right panel ---------- */
@media (min-width:768px) and (max-width:1200px){
  #leftRail{width:64px; flex-basis:64px; padding:8px 6px; overflow:hidden;}
  #leftRail h2{font-size:9.5px; text-align:center;}
  #leftRail .preset-item, #leftRail .snapshot-item, #leftRail .history-item{font-size:10.5px; padding:5px 4px; text-align:center;}
  #leftRail .small-btn{font-size:10.5px; padding:5px 2px;}
  #rightRail{width:272px; flex-basis:272px;}
}
/* ---------- Mobile (<768px) ---------- */
@media (max-width:767px){
  #leftRail{display:none;}
  #rightRail{
    position:static; width:auto; flex:none; border-left:none; background:transparent;
  }
  #layout{flex-direction:column;}
  #centerCol{order:1;}
  #rightRail{order:2;}
  #histogramBox{display:none;}
  #rightRail{min-height:0;}
  #panelContainer{overflow-y:auto; max-height:42dvh; padding:10px 12px; --pc-pad:10px;}
  #app.panel-open #ratingBar, #app.panel-open #filmstripRow{display:none;}
  .file-name{max-width:26vw;}
  #stageWrap{padding:6px;}
}
