/* Toolkit — fixed app chrome + one morphing panel. No page scroll. No layout jump. */

:root,
[data-theme="dark"] {
  /* ShadowRig studio tokens — match marketing site */
  --ink: #0a0a0a;
  --coral: #d4734a;
  --coral-soft: rgba(212, 115, 74, 0.14);
  --sky: #7eb8c4;
  --brass: #c4a35a;
  --accent-sage: #9bb5a6;
  --bg: #0a0a0a;
  --surface: #121214;
  --surface-2: #1a1a1e;
  --text: #f2f2f3;
  --muted: #8a8a90;
  --hairline: rgba(255, 255, 255, 0.1);
  --accent: #d4734a;
  --accent-fg: #0a0a0a;
  --danger: #ff6b6b;
  --font: "IBM Plex Sans", "Segoe UI", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
  --bar-h: 48px;
  --panel-w: min(560px, calc(100vw - 2rem));
  --panel-h: min(420px, calc(100dvh - var(--bar-h) - 3rem));
}

[data-theme="light"] {
  --bg: #f4f4f5;
  --surface: #ffffff;
  --surface-2: #ececef;
  --text: #121214;
  --muted: #5c5c64;
  --hairline: rgba(0, 0, 0, 0.09);
  --accent: #c45f38;
  --accent-fg: #ffffff;
  --danger: #c62828;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden !important;
  background-color: var(--bg);
  background-image:
    linear-gradient(to right, rgba(255, 255, 255, 0.03) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(255, 255, 255, 0.03) 1px, transparent 1px),
    radial-gradient(ellipse 48% 36% at 8% 12%, var(--coral-soft), transparent 55%);
  background-size: 24px 24px, 24px 24px, auto;
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
}

button,
input {
  font: inherit;
  color: inherit;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.tk {
  height: 100dvh;
  height: 100svh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.tk-bar {
  flex: 0 0 var(--bar-h);
  height: var(--bar-h);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0 1rem;
  border-bottom: 1px solid var(--hairline);
  background: var(--bg);
  z-index: 20;
  min-width: 0;
}

.tk-brand {
  display: flex;
  align-items: baseline;
  gap: 0.35rem;
  flex-shrink: 0;
}

.tk-site {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.85rem;
}

.tk-site:hover {
  color: var(--text);
}

.tk-sep {
  color: var(--hairline);
}

.tk-title {
  margin: 0;
  font-size: 0.9rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.tk-nav {
  display: flex;
  gap: 0.1rem;
  margin-left: auto;
  overflow-x: auto;
  scrollbar-width: none;
}

.tk-nav::-webkit-scrollbar {
  display: none;
}

.tk-nav-btn,
.tk-ghost {
  background: transparent;
  border: none;
  color: var(--muted);
  padding: 0.35rem 0.55rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.8rem;
  white-space: nowrap;
}

.tk-nav-btn:hover,
.tk-ghost:hover:not(:disabled) {
  color: var(--text);
  background: var(--surface-2);
}

.tk-nav-btn.is-active {
  color: var(--text);
  background: var(--surface-2);
}

.tk-ghost:disabled {
  opacity: 0.35;
  cursor: default;
}

.tk-bar-actions {
  display: flex;
  gap: 0.25rem;
  flex-shrink: 0;
}

/* Stage centers one fixed-size panel — never expands document height */
.tk-stage {
  flex: 1;
  min-height: 0;
  display: grid;
  place-items: center;
  padding: 1rem;
  overflow: hidden;
}

.panel {
  width: var(--panel-w);
  height: var(--panel-h);
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: 4px;
  position: relative;
  overflow: hidden;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
  transition: border-color 160ms ease;
}

.panel[data-mode="empty"] {
  border-style: solid;
  border-color: color-mix(in srgb, var(--coral) 28%, transparent);
}

.panel[data-mode="loading"],
.panel[data-mode="file"],
.panel[data-mode="panel"] {
  border-style: solid;
}

.panel-empty,
.panel-loading,
.panel-file,
.panel-aux {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  opacity: 1;
  transform: none;
  transition: opacity 140ms ease;
}

.panel-empty[hidden],
.panel-loading[hidden],
.panel-file[hidden],
.panel-aux[hidden] {
  display: none !important;
}

/* Empty / drop — same quiet language as the tool view */
.panel-empty {
  align-items: center;
  justify-content: center;
  gap: 1.1rem;
  padding: 1.4rem 1.25rem 1.15rem;
  overflow: hidden;
}

.drop-zone {
  position: relative;
  z-index: 1;
  width: 100%;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.55rem;
  cursor: pointer;
  border-radius: 12px;
}

.drop-zone.is-drag {
  background: var(--surface-2);
}

.drop-title {
  margin: 0;
  font-size: 1.45rem;
  font-weight: 600;
  letter-spacing: -0.04em;
  text-align: center;
}

.drop-kinds {
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
  text-align: center;
}

.drop-tools {
  flex: 0 0 auto;
  width: 100%;
  max-width: 26rem;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.drop-tools-label {
  margin: 0;
  font-size: 0.68rem;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  font-family: var(--mono);
}

.job-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.45rem;
}

.job-card {
  appearance: none;
  text-align: left;
  border: 1px solid color-mix(in srgb, var(--coral) 35%, transparent);
  background: color-mix(in srgb, var(--coral) 6%, var(--surface));
  color: var(--text);
  border-radius: 2px;
  padding: 0.7rem 0.75rem;
  cursor: pointer;
  min-height: 4.4rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  transition: border-color 0.12s, background 0.12s;
}

.job-card:hover,
.job-card.is-active {
  border-color: var(--coral);
  background: color-mix(in srgb, var(--coral) 14%, var(--surface));
}

.job-card-name {
  font-size: 0.86rem;
  font-weight: 650;
  letter-spacing: -0.02em;
}

.job-card-blurb {
  font-size: 0.7rem;
  line-height: 1.35;
  color: var(--muted);
}

.job-more {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
}

.job-chip {
  appearance: none;
  border: 1px solid var(--hairline);
  background: var(--bg);
  color: var(--muted);
  border-radius: 2px;
  padding: 0.28rem 0.5rem;
  font-size: 0.7rem;
  cursor: pointer;
}

.job-chip:hover,
.job-chip.is-active {
  color: var(--text);
  border-color: color-mix(in srgb, var(--coral) 45%, transparent);
}

.job-panel {
  width: 100%;
  max-width: 26rem;
  border: 1px solid color-mix(in srgb, var(--coral) 35%, transparent);
  background: var(--surface);
  padding: 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.job-panel[hidden] {
  display: none !important;
}

.job-panel-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
}

.job-panel-title {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 650;
}

.job-panel-hint {
  margin: 0;
  font-size: 0.75rem;
  color: var(--muted);
  line-height: 1.4;
}

.job-file-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  max-height: 7rem;
  overflow: auto;
}

.job-file-list li {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  font-size: 0.75rem;
  padding: 0.35rem 0.45rem;
  border: 1px solid var(--hairline);
  background: var(--bg);
}

.job-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.drop-zone--job .drop-title {
  font-size: 1.15rem;
}

.tk-trust {
  flex: 0 0 auto;
  margin: 0;
  color: var(--muted);
  font-size: 0.72rem;
  text-align: center;
}

body.tk-job-focus .drop-zone {
  border-color: color-mix(in srgb, var(--coral) 45%, transparent);
  background: color-mix(in srgb, var(--coral) 6%, var(--surface));
}

body.tk-job-focus .panel[data-mode="empty"] {
  border-color: color-mix(in srgb, var(--coral) 40%, transparent);
}

.panel-loading {
  align-items: center;
  justify-content: center;
}

.loading-text {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
}

/* File mode — same panel bounds */
.panel-file {
  padding: 0.7rem 0.8rem;
  gap: 0.45rem;
  overflow: hidden;
}

/* Options open — only file + options + status (no scroll) */
.panel-file:has(#wsOptions:not([hidden])) .ask-row,
.panel-file:has(#wsOptions:not([hidden])) .action-row,
.panel-file:has(#wsOptions:not([hidden])) .action-more,
.panel-file:has(#wsOptions:not([hidden])) .trail,
.panel-file:has(#wsOptions:not([hidden])) .result {
  display: none !important;
}

.file-row {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 0.7rem;
  min-width: 0;
}

.file-thumb {
  width: 96px;
  height: 96px;
  flex: 0 0 96px;
  border-radius: 10px;
  border: 1px solid var(--hairline);
  background: var(--surface-2);
  overflow: hidden;
  display: grid;
  place-items: center;
}

.file-thumb img,
.file-thumb video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.file-thumb audio {
  width: 28px;
  height: 28px;
}

.file-thumb .ws-preview-fallback {
  font-size: 0.55rem;
  letter-spacing: 0.06em;
  color: var(--muted);
  text-transform: uppercase;
  text-align: center;
  padding: 0.2rem;
}

.file-thumb .ws-preview-name {
  display: none;
}

.file-id {
  flex: 1;
  min-width: 0;
}

.file-name {
  margin: 0;
  font-size: 0.92rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.file-meta {
  margin: 0.1rem 0 0;
  color: var(--muted);
  font-size: 0.72rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.file-row-actions {
  display: flex;
  gap: 0.1rem;
  flex-shrink: 0;
}

.ask-row {
  flex: 0 0 auto;
  display: flex;
  gap: 0.4rem;
}

.ask-input {
  flex: 1;
  min-width: 0;
  background: var(--bg);
  border: 1px solid var(--hairline);
  border-radius: 10px;
  padding: 0.65rem 0.8rem;
  outline: none;
  font-size: 0.92rem;
}

.ask-input:focus {
  border-color: color-mix(in srgb, var(--text) 28%, transparent);
}

.action-row,
.action-more .ws-actions--more {
  flex: 0 0 auto;
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.ws-action {
  text-align: left;
  background: var(--bg);
  border: 1px solid var(--hairline);
  border-radius: 2px;
  padding: 0.55rem 0.7rem;
  cursor: pointer;
  min-height: 2.6rem;
}

.ws-action:hover {
  background: color-mix(in srgb, var(--coral) 10%, var(--surface));
  border-color: var(--coral);
}

.ws-action.is-active {
  border-color: var(--coral);
  background: color-mix(in srgb, var(--coral) 14%, var(--surface));
}

.options {
  flex: 0 0 auto;
  overflow: hidden;
  border: 1px solid var(--hairline);
  border-radius: 10px;
  background: var(--bg);
  padding: 0.45rem 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.options[hidden] {
  display: none !important;
}

.opt-head {
  display: flex;
  align-items: baseline;
  gap: 0.45rem;
  min-width: 0;
}

.opt-title {
  margin: 0;
  font-size: 0.8rem;
  font-weight: 600;
}

.opt-notice,
.opt-hint {
  margin: 0;
  font-size: 0.68rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.opt-fields {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.opt-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.35rem;
}

.opt-size {
  display: flex;
  align-items: baseline;
  gap: 0.35rem;
  font-size: 0.78rem;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

.opt-size-arrow {
  color: var(--muted);
  font-weight: 400;
}

.opt-size-est {
  color: var(--text);
}

.opt-size-pct {
  margin-left: auto;
  font-size: 0.68rem;
  font-weight: 500;
  color: var(--muted);
}

.opt-actions {
  display: flex;
  gap: 0.3rem;
  align-items: center;
}

.opt-actions .btn {
  padding: 0.35rem 0.7rem;
  font-size: 0.78rem;
}

.opt-field {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  font-size: 0.68rem;
  color: var(--muted);
}

.opt-field input[type="number"],
.opt-field input[type="text"],
.opt-field select {
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: 7px;
  padding: 0.35rem 0.45rem;
  color: var(--text);
  font-size: 0.78rem;
}

.opt-field--slider .opt-slider-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.68rem;
  color: var(--muted);
}

.opt-slider-val {
  color: var(--text);
  font-weight: 600;
}

.opt-field--slider input[type="range"] {
  width: 100%;
  height: 1.1rem;
  accent-color: var(--text);
}

.opt-slider-ends {
  display: flex;
  justify-content: space-between;
  gap: 0.4rem;
  font-size: 0.62rem;
  color: var(--muted);
  opacity: 0.8;
}

.opt-field--slider[data-off="1"] {
  opacity: 0.4;
}

.opt-check {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.74rem;
  color: var(--text);
  cursor: pointer;
}

.opt-check input[type="checkbox"] {
  width: 0.95rem;
  height: 0.95rem;
  accent-color: var(--text);
  cursor: pointer;
}

.ws-action-title {
  font-weight: 600;
  font-size: 0.8rem;
}

.ws-action-desc {
  display: block;
  margin-top: 0.15rem;
  font-size: 0.7rem;
  font-weight: 400;
  color: var(--muted);
  line-height: 1.3;
}

.ws-actions--more .ws-action-desc {
  display: none;
}

.ws-more summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 0.78rem;
}

.action-more {
  flex: 0 0 auto;
}

.progress {
  flex: 0 0 auto;
  height: 2px;
  background: var(--hairline);
  border-radius: 99px;
  overflow: hidden;
}

.progress[hidden] {
  display: none !important;
}

#wsProgressFill {
  display: block;
  height: 100%;
  width: 0;
  background: var(--text);
  transition: width 140ms ease;
}

.status {
  flex: 0 0 auto;
  margin: 0;
  min-height: 1rem;
  font-size: 0.75rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.status.is-err {
  color: var(--danger);
}

.result {
  flex: 1;
  min-height: 0;
  border: 1px solid var(--hairline);
  border-radius: 10px;
  background: var(--bg);
  padding: 0.55rem 0.6rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  overflow: hidden;
}

.result:not(:has(.ws-output-text)) {
  flex: 0 0 auto;
}

.result[hidden] {
  display: none !important;
}

.ws-output-head {
  flex: 0 0 auto;
  display: flex;
  gap: 0.5rem;
  align-items: center;
  justify-content: space-between;
  min-width: 0;
}

.ws-output-meta {
  min-width: 0;
  flex: 1;
}

.ws-output-msg {
  margin: 0;
  font-size: 0.8rem;
  font-weight: 600;
}

.ws-output-file {
  margin: 0.1rem 0 0;
  font-size: 0.7rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ws-output-btns {
  display: flex;
  gap: 0.3rem;
  flex-shrink: 0;
}

.ws-output-btns .btn {
  padding: 0.4rem 0.75rem;
  font-size: 0.78rem;
}

.ws-output-text {
  flex: 1;
  min-height: 0;
  margin: 0;
  overflow: auto;
  white-space: pre-wrap;
  font-family: var(--mono);
  font-size: 0.74rem;
  line-height: 1.4;
}

/* Keep room for Download — hide history chips when result is up */
.panel-file:has(#wsOutput:not([hidden])) .trail {
  display: none !important;
}

.trail {
  flex: 0 0 auto;
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  max-height: 1.6rem;
  overflow: hidden;
}

.trail li {
  font-size: 0.65rem;
  color: var(--muted);
  background: var(--surface-2);
  border-radius: 99px;
  padding: 0.15rem 0.45rem;
}

.trail li.is-current {
  color: var(--text);
}

.panel-aux {
  padding: 1rem 1.1rem;
  overflow: auto;
}

.tk-panel-title {
  margin: 0 0 0.75rem;
  font-size: 1.05rem;
  letter-spacing: -0.02em;
}

.tk-sub {
  margin: 1rem 0 0.5rem;
  font-size: 0.75rem;
  color: var(--muted);
  font-weight: 600;
}

.tk-empty,
.tk-hint {
  color: var(--muted);
  font-size: 0.82rem;
}

.tk-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.tk-list li {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.55rem 0;
  border-bottom: 1px solid var(--hairline);
  font-size: 0.82rem;
}

.tk-list-meta {
  color: var(--muted);
  font-size: 0.72rem;
  white-space: nowrap;
}

.btn {
  appearance: none;
  border: 1px solid var(--hairline);
  background: var(--surface-2);
  color: var(--text);
  border-radius: 8px;
  padding: 0.5rem 0.85rem;
  cursor: pointer;
  font-size: 0.82rem;
}

.btn-primary {
  background: var(--accent);
  color: var(--accent-fg);
  border-color: transparent;
  font-weight: 600;
}

.btn-install {
  appearance: none;
  border: 1px solid var(--hairline);
  background: var(--surface-2);
  color: var(--text);
  border-radius: 8px;
  padding: 0.35rem 0.7rem;
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 600;
}

.btn-install[hidden],
html[data-display="standalone"] .btn-install,
body.is-standalone .btn-install {
  display: none !important;
}

html.can-install .btn-install:not([hidden]) {
  display: inline-block;
}

.format-sheet,
.install-sheet {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: end center;
}

.format-sheet[hidden],
.install-sheet[hidden] {
  display: none !important;
}

.format-sheet-backdrop,
.install-sheet-backdrop {
  position: absolute;
  inset: 0;
  border: none;
  background: rgba(0, 0, 0, 0.45);
  cursor: pointer;
}

.format-sheet-panel,
.install-sheet-panel {
  position: relative;
  width: min(420px, 100%);
  max-height: 70dvh;
  overflow: auto;
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: 14px 14px 0 0;
  padding: 1.15rem;
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  z-index: 1;
}

.format-sheet-title,
.install-sheet-title {
  margin: 0;
  font-size: 1.05rem;
}

.install-sheet-steps {
  margin: 0;
  padding-left: 1.15rem;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.5;
}

.format-sheet-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: 0.35rem;
}

.format-pick {
  background: var(--surface-2);
  border: 1px solid var(--hairline);
  border-radius: 8px;
  padding: 0.6rem;
  cursor: pointer;
}

@media (max-width: 640px) {
  .tk-nav {
    display: none;
  }

  body.has-panel .tk-nav,
  body.has-file .tk-nav {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    margin: 0;
    padding: 0.35rem 0.45rem calc(0.35rem + env(safe-area-inset-bottom));
    background: var(--bg);
    border-top: 1px solid var(--hairline);
    justify-content: space-around;
    z-index: 30;
  }

  body.has-panel .tk-stage,
  body.has-file .tk-stage {
    padding-bottom: calc(52px + env(safe-area-inset-bottom));
  }

  :root {
    --panel-h: min(460px, calc(100dvh - var(--bar-h) - 4.5rem));
  }
}
