/* ── Workspace: fullscreen canvas with floating panels ── */

.app { max-width: none; margin: 0 auto; padding: 0; }

.worksplit { position: relative; width: 100%; }
.workctl { min-width: 0; }
.workstage { min-width: 0; }

/* desktop: canvas fills workspace, panels float above */
@media (min-width: 901px) {
  #appView .worksplit { height: var(--wsh, 100vh); overflow: hidden; }

  #appView .workstage {
    position: absolute; inset: 0; z-index: 0;
    display: flex; flex-direction: column;
  }

  #appView .picker {
    display: flex; flex-direction: column; flex: 1; min-height: 0;
  }
  #appView .pickstage { height: auto; flex: 1; min-height: 180px; }
  #appView .pickframe { max-height: none; }
  #appView .pickstage img { max-height: none; }

  /* left panel: floating controls */
  #appView .workctl {
    position: absolute; left: 20px; top: 10px; bottom: 10px;
    width: 240px; z-index: 5;
    overflow-y: auto; overflow-x: hidden;
    scrollbar-width: thin; scrollbar-color: var(--dim) transparent;
    background: rgba(20, 20, 25, .92); backdrop-filter: blur(16px);
    border: 1px solid var(--line); border-radius: var(--r-card);
    padding: 18px 18px 22px;

    &::-webkit-scrollbar { width: 6px; }
    &::-webkit-scrollbar-thumb { background: var(--dim); }
    &::-webkit-scrollbar-track { background: transparent; }
  }

  /* right panel: floating settings */
  #appView .workright {
    position: absolute; right: 20px; top: 10px; bottom: 10px;
    width: 260px; z-index: 5; overflow: hidden;
    background: rgba(20, 20, 25, .92); backdrop-filter: blur(16px);
    border: 1px solid var(--line); border-radius: var(--r-card);
    padding: 18px 18px 22px;
    display: flex; flex-direction: column;
  }

  #appView.app { padding-bottom: 0; }
}

@media (max-width: 900px) {
  .worksplit { display: flex; flex-direction: column; gap: 24px; }
  .workright { margin-top: 24px; }
}

/* ── right panel scroll/pinned ── */

@media (min-width: 901px) {
  .wr-scroll {
    flex: 1; overflow-y: auto; overflow-x: hidden; min-height: 0;
    scrollbar-width: none; -ms-overflow-style: none;
    &::-webkit-scrollbar { display: none; }
  }

  .wr-pinned {
    flex: none; padding-top: 12px; position: relative;
    &::before {
      content: ""; position: absolute; top: -20px; left: 0; right: 0; height: 20px;
      background: linear-gradient(to top, rgba(20, 20, 25, .95), transparent);
      pointer-events: none;
    }
  }
}

/* right panel: hide verbose hints, keep count syntax hint */
.workright .hint { display: none; }
.workright .field:first-of-type .hint { display: block; }
.workright .field { margin-top: 14px; }

/* ── tooltips ── */

[data-tip] {
  position: relative; cursor: help;

  &:hover::after {
    content: attr(data-tip);
    position: absolute; left: 0; top: calc(100% + 8px); z-index: 40;
    width: 34ch; background: var(--panel2); border: 1px solid var(--line);
    border-radius: var(--r-ctl); box-shadow: var(--shadow);
    padding: 10px 12px; font-size: 10.5px; line-height: 1.7; color: var(--muted);
    text-transform: none; letter-spacing: 0; font-weight: 400;
    white-space: normal; pointer-events: none;
  }
}

/* ── drop zone ── */

.drop {
  padding: 14px 0 16px; color: var(--faint);
  cursor: pointer; transition: color .12s;
  &:hover, &.hot { color: var(--text); }
}
.drop-icon { display: none; }
.drop-main { margin: 0; font-size: 12.5px; &::before { content: "+ "; color: var(--dim); } }
.drop b { font-weight: 400; color: var(--text); }
.drop.hot .drop-main::before { color: var(--text); }

.filerow {
  display: flex; align-items: baseline; gap: 14px;
  margin-top: 6px; font-size: 11.5px; color: var(--muted); padding: 0;
  & .cost { color: var(--text); margin-left: auto; }
}

/* ── primary stage drop target (checkerboard) ── */

.stagedrop {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 6px; text-align: center;
  height: 100%; min-height: 280px; border: none;
  background: var(--chk-a);
  background-image:
    linear-gradient(45deg, var(--chk-b) 25%, transparent 25%),
    linear-gradient(-45deg, var(--chk-b) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, var(--chk-b) 75%),
    linear-gradient(-45deg, transparent 75%, var(--chk-b) 75%);
  background-size: 18px 18px;
  background-position: 0 0, 0 9px, 9px -9px, -9px 0;
  border-radius: var(--r-card);
  transition: border-color .12s;

  &[hidden] { display: none !important; }
  &.hot { border: 1px dashed var(--acc); }

  & .sd-main { margin: 2px 0 0; font-size: 19px; letter-spacing: .02em; }
  & .sd-sub { margin: 0; color: var(--faint); font-size: 14px; }
  & .hint { margin-top: 10px; }
}
.drop-icon.big { width: 52px; height: 52px; opacity: .5; }

/* ── prompt input ── */

.prompt-wrap {
  position: relative; display: flex; align-items: center;

  & input {
    flex: 1;
    &:not(:placeholder-shown) { border-color: var(--acc); }
  }
}

.prompt-ok {
  position: absolute; right: 8px; color: var(--acc); font-size: 13px;
  pointer-events: none; opacity: 0; transition: opacity .2s ease;
  &.show { opacity: 1; }
}

/* ── fields ── */

.field {
  margin-top: 22px; font-size: 11px; color: var(--faint); gap: 4px;

  &.checkrow {
    gap: 2px;
    & span:first-child {
      display: flex; align-items: center; gap: 8px;
      font-size: 11.5px; color: var(--muted);
      text-transform: none; letter-spacing: 0;
    }
    & input[type=checkbox] { accent-color: var(--acc); margin: 0; }
  }
}

.field-label {
  display: flex; align-items: baseline; justify-content: space-between;
  font-size: 10.5px; color: var(--faint);
  text-transform: uppercase; letter-spacing: .14em;
  & .mono { color: var(--text); letter-spacing: 0; }
}

.scale {
  display: flex; justify-content: space-between;
  font-size: 9.5px; color: var(--dim);
  letter-spacing: .1em; text-transform: uppercase;
}

.opt { color: var(--dim); text-transform: none; letter-spacing: 0; }

.actions {
  display: flex; gap: 20px; margin-top: 26px; align-items: baseline;
  & .primary { margin-left: auto; }
}

.tier-left { margin-top: 8px; & span:first-child { font-size: 10.5px; } }
#tierRow .hint { margin: 2px 0 0 24px; }

/* ── run FAB ── */

.run-fab { display: flex; flex-direction: column; gap: 8px; }
.run-hint {
  font-size: 10px; color: var(--dim);
  text-align: center; letter-spacing: .06em;
}

/* ── point picker ── */

.picker { margin-top: 0; }
.pickcount { color: var(--faint); letter-spacing: .06em; }

.pickstage {
  position: relative; overflow: hidden; display: grid; place-items: center;
  min-height: 260px; height: 100%; border-radius: var(--r-card);
  background-size: 18px 18px;
  background-position: 0 0, 0 9px, 9px -9px, -9px 0;

  &.panning, &.panning .pickframe { cursor: grabbing; }
}

.pickframe {
  position: relative; display: inline-block; line-height: 0;
  cursor: crosshair; max-width: 100%; max-height: 100%;
  transform-origin: 0 0; will-change: transform;

  &.pixel img { image-rendering: pixelated; }
}

.pickstage img {
  display: block; max-width: 100%; max-height: 100%;
  object-fit: contain; user-select: none; -webkit-user-drag: none;
}

.pickmarks {
  position: absolute; inset: 0; pointer-events: none; line-height: 1;

  & i {
    position: absolute; transform: translate(-50%, -50%) scale(var(--iz, 1));
    font-style: normal; font-size: 12px; line-height: 1;
    width: 15px; height: 15px; display: grid; place-items: center;
    text-shadow: 0 0 2px #000, 0 0 2px #000, 0 0 3px #000;

    &.pos { color: var(--lc, #fff); }
    &.neg { color: var(--lc, #fff); opacity: .9; }

    &.pos::after, &.neg::after {
      content: ""; position: absolute; inset: 0;
      border: 1px solid var(--lc, #fff); border-radius: 50%;
      box-shadow: 0 0 0 1px rgba(0, 0, 0, .7);
    }
    &.neg::after { border-style: dashed; }
    &.other { opacity: .35; }
  }
}

/* ── zoom tag ── */

.zoomtag {
  position: absolute; right: 290px; top: 14px; z-index: 6;
  font-size: 11px; color: var(--faint); letter-spacing: .08em;
  pointer-events: none; text-shadow: 0 0 3px #000, 0 0 3px #000;
  background: rgba(11, 11, 15, .6); padding: 2px 8px; border-radius: 6px;
}
@media (max-width: 900px) { .zoomtag { right: 14px; top: 14px; } }

/* ── matte overlay ── */

.ovmatte {
  position: absolute; inset: 0; pointer-events: none; opacity: 0;
  transition: opacity .12s;
  -webkit-mask-size: 100% 100%; mask-size: 100% 100%;
  -webkit-mask-repeat: no-repeat; mask-repeat: no-repeat;
}

.ovctl { display: flex; flex-direction: column; gap: 8px; margin-top: 22px; }
.ovrow { display: flex; align-items: center; justify-content: space-between; gap: 12px; }

.ovlabel {
  display: flex; flex-direction: row; align-items: center; gap: 10px;
  font-size: 10.5px; color: var(--faint);

  & .frameno { flex: none; min-width: 34px; text-align: right; }
  & input[type=range] { flex: 1; margin: 0; accent-color: var(--acc); height: 2px; }
  &.swatch { flex: none; min-width: 0; }
  & input[type=color] {
    width: 26px; height: 16px; padding: 0; border: 1px solid var(--dim);
    background: none; cursor: pointer;
  }
}

.preview { margin-top: 26px; }
.preview-label {
  font-size: 10px; letter-spacing: .18em; text-transform: uppercase;
  color: var(--faint); margin-bottom: 8px;
}

.checker {
  overflow: hidden; min-height: 100px; border-radius: var(--r-ctl);
  background-size: 16px 16px;
  background-position: 0 0, 0 8px, 8px -8px, -8px 0;
  & img { display: block; max-width: 100%; margin: 0 auto; }
}

/* ── detection overlay ── */

.ovseg {
  position: absolute; inset: 0; pointer-events: none; z-index: 3;
  background: var(--acc); opacity: 0; transition: opacity .12s;
  -webkit-mask-size: 100% 100%; mask-size: 100% 100%;
  -webkit-mask-repeat: no-repeat; mask-repeat: no-repeat;
  mask-mode: luminance; -webkit-mask-source-type: luminance;
  mix-blend-mode: screen;
}

.segbusy {
  position: absolute; left: 50%; bottom: 90px; transform: translateX(-50%);
  z-index: 11; font-size: 11px; letter-spacing: .12em; text-transform: uppercase;
  color: var(--acc); background: rgba(0, 0, 0, .7); backdrop-filter: blur(8px);
  padding: 5px 14px; border-radius: 8px; white-space: nowrap;
}

.segnote {
  position: absolute; left: 50%; bottom: 90px; transform: translateX(-50%);
  z-index: 11; font-size: 10.5px; letter-spacing: .1em; text-transform: uppercase;
  color: var(--faint); background: rgba(0, 0, 0, .65); backdrop-filter: blur(8px);
  padding: 5px 14px; border-radius: 8px; white-space: nowrap;
}

/* ── selection box ── */

.pkbox, .pkrubber { position: absolute; pointer-events: none; z-index: 4; }
.pkbox {
  border: 1px solid var(--acc); box-shadow: 0 0 0 1px rgba(0, 0, 0, .55);
  &::after { content: ""; position: absolute; inset: 0; background: var(--acc); opacity: .08; }
}
.pkrubber { border: 1px dashed var(--acc); background: rgba(88, 192, 138, .10); }

/* ── floating timeline bar ── */

.float-timeline {
  position: absolute; bottom: 10px; left: 274px; right: 292px;
  background: rgba(11, 11, 15, .85); backdrop-filter: blur(12px);
  border: 1px solid var(--line); border-radius: 12px;
  padding: 8px 16px 10px; z-index: 10;
  display: flex; flex-direction: column; gap: 4px;

  & .frameno { font-size: 11px; }
}
@media (max-width: 900px) { .float-timeline { left: 16px; right: 16px; } }

.tl-meta {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; padding: 0 2px;
}

.tl-controls {
  display: flex; align-items: center; gap: 12px;
  & .timeline { flex: 1; }
}

.tl-btn {
  background: none; border: 0; color: var(--faint); font-size: 14px;
  padding: 0 2px; cursor: pointer; line-height: 1; flex: none;
  &:hover { color: var(--text); }
  &.tl-play { font-size: 12px; width: 20px; text-align: center; }
}

/* ── timeline ── */

.timeline {
  position: relative; flex: 1; min-width: 60px; height: 22px;
  cursor: pointer; touch-action: none;
  display: flex; align-items: center;

  &:focus { outline: none; }
  &:focus .tl-line { background: var(--muted); }
}

.tl-line { position: absolute; left: 0; right: 0; height: 1px; background: var(--dim); }

.tl-keys {
  position: absolute; inset: 0; pointer-events: none;

  & b {
    position: absolute; top: 4px; width: 1px; height: 14px;
    margin-left: -.5px; background: var(--muted);

    &.pos { background: var(--acc); }
    &.neg { background: var(--faint); }
    &.both { background: var(--text); box-shadow: 0 6px 0 -1px var(--faint); }
    &.on { background: var(--text); width: 2px; margin-left: -1px; }
  }
}

.tl-head {
  position: absolute; top: 1px; width: 1px; height: 20px;
  margin-left: -.5px; background: var(--acc);

  &::before {
    content: ""; position: absolute; top: -1px; left: -2px;
    border-left: 2.5px solid transparent; border-right: 2.5px solid transparent;
    border-top: 4px solid var(--acc);
  }
}

/* ── stage action bar ── */

.stagebar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 14px; margin-top: 10px;
}
.stagebar-right { display: inline-flex; align-items: center; gap: 12px; }

/* ── stage meta ── */

.stage-meta {
  font-size: 10px; color: var(--faint); letter-spacing: .06em;
}

/* ── canvas hints table ── */

table.canvas-hints {
  width: 100%; font-size: 11px; color: var(--faint);
  border-collapse: collapse; margin-top: 6px;

  & td { padding: 2px 0; }
  & td:first-child { color: var(--muted); padding-right: 14px; white-space: nowrap; }
}
.canvas-note { font-size: 10.5px; color: var(--dim); margin: 10px 0 0; }

/* ── subject layers (dropdown) ── */

.layer-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 6px;
  & .preview-label { margin: 0; }
}

.layer-row { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }

.layer-select-wrap { position: relative; flex: 1; }

.layer-select {
  width: 100%; appearance: none; -webkit-appearance: none;
  background: var(--bg); border: 1px solid var(--line); border-radius: var(--r-ctl);
  padding: 7px 32px 7px 10px; color: var(--text); font: inherit;
  font-size: 11px; letter-spacing: .08em; text-transform: uppercase;
  cursor: pointer; outline: none;

  &:focus { border-color: rgba(70, 211, 146, .5); }
  & option { background: var(--panel); color: var(--text); }
}

.layer-chevron {
  position: absolute; right: 10px; top: 50%; transform: translateY(-50%);
  pointer-events: none; color: var(--faint);
}

.layer-add {
  font-size: 10px; letter-spacing: .08em; text-transform: uppercase;
  color: var(--faint); cursor: pointer; padding: 0;
  background: none; border: 0; white-space: nowrap;
  &:hover { color: var(--text); }
}

/* legacy chip styles kept for JS compat */
.layers { display: none; }
.lchip { display: none; }

/* ── help accordion ── */

.help {
  margin-top: 30px;

  & summary {
    cursor: pointer; list-style: none;
    font-size: 10px; letter-spacing: .16em;
    text-transform: uppercase; color: var(--dim); user-select: none;

    &::-webkit-details-marker { display: none; }
    &::before { content: "[ + ] "; }
    &:hover { color: var(--text); }
  }

  &[open] summary::before { content: "[ − ] "; }
}

.help-body {
  margin-top: 12px; font-size: 11px; line-height: 1.75;
  color: var(--muted); max-width: 48ch;

  & p { margin: 0 0 11px; }
  & b { font-weight: 400; color: var(--text); }
  & code {
    color: var(--text); border: 1px solid var(--line);
    border-radius: 5px; padding: 0 4px;
  }
}

/* ── responsive ── */

@media (max-width: 560px) {
  .app, .farm { padding: 6px 14px 50px; }
  .gallery { grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); }
  .actions { flex-wrap: wrap; gap: 14px; }
  .actions .primary { margin-left: 0; }
}
