/* Filet Studio: colours, layout, light and dark mode. No outside fonts. */

:root {
  --bg: #f6f1e9;
  --surface: #fffcf7;
  --surface-2: #efe8dd;
  --line: #ddd3c4;
  --text: #2a2521;
  --muted: #6e655b;
  --accent: #b0532c;
  --accent-ink: #ffffff;
  --accent-soft: #f5dfd2;
  --highlight: #f0b443;
  --ink: #2d2a3a;
  --done: #3f7d4e;
  --danger: #b3261e;
  --shadow: 0 1px 2px rgba(60, 40, 20, .06), 0 4px 16px rgba(60, 40, 20, .06);
  --shadow-lg: 0 10px 40px rgba(40, 25, 10, .18);

  --chart-bg: #fffcf7;
  --chart-paper: #ffffff;
  --chart-ink: #2d2a3a;
  --chart-grid: #d3cabd;
  --chart-grid-strong: #857a6d;
  --chart-num: #6e655b;
  --chart-out: #f1ebe2;
  --chart-hatch: #ddd3c4;

  --radius: 12px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", system-ui, sans-serif;
  --font-display: ui-rounded, "SF Pro Rounded", -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  --topbar-h: 60px;
  --tabbar-h: 64px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1d1a17;
    --surface: #26221e;
    --surface-2: #302b26;
    --line: #3e3832;
    --text: #efe8dd;
    --muted: #a99f93;
    --accent: #e27e52;
    --accent-ink: #1d1a17;
    --accent-soft: #4a3024;
    --highlight: #e0a73c;
    --ink: #ece4d6;
    --done: #7fbf8e;
    --danger: #f2867c;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
    --shadow-lg: 0 10px 40px rgba(0, 0, 0, .5);
    --chart-bg: #26221e;
    --chart-paper: #2e2925;
    --chart-ink: #efe6d8;
    --chart-grid: #4a433c;
    --chart-grid-strong: #8d8275;
    --chart-num: #b3a99c;
    --chart-out: #211e1a;
    --chart-hatch: #38322c;
    --chart-row: #f6c65a; --chart-row-alpha: .5;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #1d1a17;
  --surface: #26221e;
  --surface-2: #302b26;
  --line: #3e3832;
  --text: #efe8dd;
  --muted: #a99f93;
  --accent: #e27e52;
  --accent-ink: #1d1a17;
  --accent-soft: #4a3024;
  --highlight: #e0a73c;
  --ink: #ece4d6;
  --done: #7fbf8e;
  --danger: #f2867c;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
  --shadow-lg: 0 10px 40px rgba(0, 0, 0, .5);
  --chart-bg: #26221e;
  --chart-paper: #2e2925;
  --chart-ink: #efe6d8;
  --chart-grid: #4a433c;
  --chart-grid-strong: #8d8275;
  --chart-num: #b3a99c;
  --chart-out: #211e1a;
  --chart-hatch: #38322c;
    --chart-row: #f6c65a; --chart-row-alpha: .5;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); font-weight: 400; }
.hint { color: var(--muted); font-size: 14px; margin: 8px 0; }

.ico { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.ico .f { fill: currentColor; }

.app {
  height: 100%;
  height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* Top bar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  flex: none;
  display: flex;
  align-items: center;
  gap: 16px;
  height: calc(var(--topbar-h) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) max(16px, env(safe-area-inset-right)) 0 max(16px, env(safe-area-inset-left));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  -webkit-backdrop-filter: saturate(1.4) blur(12px);
  backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--accent); min-width: 0; }
.brand-mark { width: 28px; height: 28px; flex: none; }
.brand-name { font: 650 19px/1 var(--font-display); letter-spacing: -.01em; color: var(--text); white-space: nowrap; }

/* Step tabs */
.steps { display: flex; gap: 4px; margin: 0 auto; padding: 4px; background: var(--surface-2); border-radius: 999px; }
.step {
  display: flex; align-items: center; gap: 8px;
  min-height: 40px; padding: 0 18px 0 12px;
  border: 0; border-radius: 999px; background: transparent;
  color: var(--muted); font-weight: 560; cursor: pointer;
  transition: background-color .18s ease, color .18s ease, box-shadow .18s ease;
}
.step svg { display: none; width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.step svg .fill { fill: currentColor; stroke: none; }
.step-num {
  display: inline-grid; place-items: center; width: 20px; height: 20px; border-radius: 50%;
  background: var(--line); color: var(--text); font-size: 12px; font-weight: 700;
}
.step:hover { color: var(--text); }
.step[aria-selected="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.step[aria-selected="true"] .step-num { background: var(--accent); color: var(--accent-ink); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.top-actions { display: flex; gap: 8px; }
.icon-btn {
  display: grid; place-items: center; width: 40px; height: 40px;
  border: 1px solid var(--line); border-radius: 50%; background: var(--surface);
  color: var(--muted); cursor: pointer;
}
.icon-btn.sm { width: 32px; height: 32px; }
.icon-btn:hover { color: var(--text); }
.icon-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.7; }
.icon-btn svg .fill, .icon-btn svg .f { fill: currentColor; stroke: none; }

/* Main area */
.main {
  flex: 1;
  min-height: 0;
  display: flex;
  padding: 16px max(16px, env(safe-area-inset-right)) 16px max(16px, env(safe-area-inset-left));
}
.panel { flex: 1; display: flex; min-width: 0; min-height: 0; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 42px; padding: 0 16px;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface); color: var(--text);
  font-weight: 560; cursor: pointer; white-space: nowrap;
  transition: background-color .15s ease, border-color .15s ease;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.05); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.sm { min-height: 34px; padding: 0 12px; font-size: 14px; border-radius: 8px; }
.btn .ico { width: 18px; height: 18px; }
.btn-row { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin-top: 18px; }
.btn-row.left { justify-content: flex-start; margin-top: 10px; }

/* Segmented controls */
.seg { display: inline-flex; padding: 3px; gap: 2px; background: var(--surface-2); border-radius: 10px; }
.seg button {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 36px; padding: 0 10px;
  border: 0; border-radius: 8px; background: transparent;
  color: var(--muted); font-size: 14px; font-weight: 560; cursor: pointer;
}
.seg button:hover { color: var(--text); }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.seg.sm button { min-height: 30px; padding: 0 10px; font-size: 13px; }
.seg.brush button { min-width: 32px; justify-content: center; font-variant-numeric: tabular-nums; }

/* Empty states */
.empty { margin: auto; max-width: 460px; padding: 32px 8px; text-align: center; }
.empty-art { width: 168px; margin: 0 auto 20px; padding: 18px; border-radius: 24px; background: var(--surface); box-shadow: var(--shadow); }
.empty-art svg { display: block; width: 100%; fill: none; stroke: var(--muted); stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; }
.empty-art svg .fill { fill: var(--ink); stroke: none; }
.empty-art svg .hl { fill: var(--highlight); stroke: none; opacity: .45; }
.empty h1 { margin: 0 0 8px; font: 650 26px/1.2 var(--font-display); letter-spacing: -.015em; text-wrap: balance; }
.empty p { margin: 0 0 12px; color: var(--muted); text-wrap: pretty; }
.empty .soon { display: inline-block; margin-top: 8px; padding: 6px 12px; border-radius: 999px; background: var(--accent-soft); color: var(--text); font-size: 14px; }

/* Workspace: main area + side panel */
.workspace { gap: 16px; }
.workspace.has-project { display: grid; grid-template-columns: minmax(0, 1fr) 340px; }
.workspace:not(.has-project) .with-project, .workspace.has-project .no-project { display: none; }
.ws-main {
  display: flex; flex-direction: column; min-width: 0; min-height: 0;
  background: var(--surface); border: 1px solid var(--line); border-radius: 16px; overflow: hidden;
}
.toolbar {
  position: relative; /* keeps hidden labels (.sr) inside, so the page never scrolls sideways */
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 8px; border-bottom: 1px solid var(--line);
}
.tb-sep { width: 1px; height: 26px; background: var(--line); margin: 0 2px; }
.tb-grow { flex: 1; }
.tb-btn {
  display: inline-grid; place-items: center; width: 38px; height: 38px;
  border: 0; border-radius: 9px; background: transparent; color: var(--text); cursor: pointer; list-style: none;
}
.tb-btn::-webkit-details-marker { display: none; }
.tb-btn:hover { background: var(--surface-2); }
.tb-btn:disabled { opacity: .35; cursor: default; background: transparent; }
.select select {
  min-height: 38px; padding: 0 30px 0 10px; border: 1px solid var(--line); border-radius: 9px;
  background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%236e655b' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E") no-repeat right 8px center / 16px;
  -webkit-appearance: none; appearance: none; font-size: 14px; cursor: pointer;
}

.menu { position: relative; }
.menu > summary { list-style: none; }
.menu-pop {
  position: absolute; z-index: 30; top: calc(100% + 6px); left: 0;
  min-width: 240px; padding: 6px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow-lg);
}
.menu-pop button {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 9px 10px; border: 0; border-radius: 8px; background: transparent; text-align: left; cursor: pointer;
}
.menu-pop button:hover { background: var(--surface-2); }
.menu-pop hr { border: 0; border-top: 1px solid var(--line); margin: 5px 4px; }

.viewport { position: relative; flex: 1; min-height: 240px; background: var(--chart-bg); }
.viewport canvas {
  position: absolute; inset: 0; width: 100%; height: 100%;
  touch-action: none; cursor: crosshair; display: block;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
}
.viewport canvas.grab { cursor: grab; }
.viewport canvas.grabbing { cursor: grabbing; }
.statusline {
  min-height: 34px; padding: 7px 12px; border-top: 1px solid var(--line);
  color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* Side panel */
.side { display: flex; flex-direction: column; gap: 12px; min-height: 0; overflow: auto; padding-bottom: 8px; }
.card { padding: 14px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; }
.card h3 { margin: 0 0 10px; font-size: 15px; font-weight: 650; }
details.card > summary { list-style: none; cursor: pointer; display: flex; align-items: center; justify-content: space-between; }
details.card > summary::-webkit-details-marker { display: none; }
details.card > summary h3 { margin: 0; }
details.card > summary::after { content: ''; width: 9px; height: 9px; border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted); transform: rotate(45deg); margin: -4px 4px 0; transition: transform .15s; }
details.card[open] > summary::after { transform: rotate(-135deg); margin-top: 4px; }
details.card[open] > summary { margin-bottom: 10px; }
details.sub { margin-top: 12px; border-top: 1px solid var(--line); padding-top: 10px; }
details.sub > summary { cursor: pointer; font-weight: 560; font-size: 14px; }
details.sub[open] > summary { margin-bottom: 8px; }

.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; font-size: 13px; color: var(--muted); }
.field > span { font-weight: 560; }
.field input, .field select, .card textarea {
  width: 100%; min-height: 40px; padding: 8px 10px;
  border: 1px solid var(--line); border-radius: 9px; background: var(--bg); color: var(--text); font-size: 16px;
}
.card textarea { resize: vertical; min-height: 70px; line-height: 1.4; }
.field input:focus, .field select:focus, .card textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
.field-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 8px; font-size: 14px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
.check { display: flex; align-items: center; gap: 8px; margin-top: 10px; font-size: 14px; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }
.check input:disabled + * { opacity: .5; }

.facts { margin: 4px 0 0; display: grid; gap: 6px; font-size: 14px; }
.facts > div { display: grid; grid-template-columns: 74px 1fr; gap: 8px; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; font-variant-numeric: tabular-nums; }

/* Written rows */
.wr-found { font-weight: 600; font-size: 14px; margin: 8px 0; }
.wr-list { list-style: none; margin: 0 0 12px; padding: 0; max-height: 50vh; overflow: auto; border: 1px solid var(--line); border-radius: 10px; }
.wr-list li + li { border-top: 1px solid var(--line); }
.wr-list button {
  display: grid; grid-template-columns: 52px 1fr; gap: 6px; width: 100%;
  padding: 7px 10px; border: 0; background: transparent; text-align: left; font-size: 13px; cursor: pointer;
}
.wr-list button:hover { background: var(--surface-2); }
.wr-list button[aria-pressed="true"] { background: color-mix(in srgb, var(--highlight) 30%, transparent); }
.wr-n { color: var(--muted); font-variant-numeric: tabular-nums; }

/* Dialogs */
.dlg {
  width: min(440px, calc(100vw - 32px)); padding: 0;
  border: 1px solid var(--line); border-radius: 18px;
  background: var(--surface); color: var(--text); box-shadow: var(--shadow-lg);
}
.dlg::backdrop { background: rgba(30, 20, 10, .35); }
.dlg-form { padding: 18px; }
.dlg-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.dlg-head h2 { margin: 0; font: 650 19px/1.2 var(--font-display); }
.dlg-body p { margin: 0 0 10px; color: var(--muted); }
.dlg-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px; }
.anchors { display: grid; grid-template-columns: repeat(3, 34px); gap: 4px; margin-top: 4px; }
.anchor input { position: absolute; opacity: 0; }
.anchor span { display: block; width: 34px; height: 34px; border: 1px solid var(--line); border-radius: 7px; background: var(--bg); cursor: pointer; }
.anchor input:checked + span { background: var(--ink); border-color: var(--ink); }
.anchor input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); z-index: 100;
  max-width: calc(100vw - 32px); padding: 10px 16px; border-radius: 12px;
  background: var(--text); color: var(--bg); font-size: 14px; box-shadow: var(--shadow-lg);
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* Smaller laptops: tool names as tooltips only */
@media (max-width: 1240px) {
  .tools button span { display: none; }
}
/* Tablet: narrower side panel */
@media (max-width: 1000px) {
  .workspace.has-project { grid-template-columns: minmax(0, 1fr) 290px; }
}

/* Phone */
@media (max-width: 720px) {
  .app { height: auto; min-height: 100%; }
  /* A blur on the header would trap the fixed tab bar inside it, so the header is solid here. */
  .topbar { gap: 12px; background: var(--bg); -webkit-backdrop-filter: none; backdrop-filter: none; }
  .steps {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; margin: 0;
    padding: 6px max(8px, env(safe-area-inset-right)) calc(6px + env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
    gap: 0; border-radius: 0;
    background: color-mix(in srgb, var(--surface) 92%, transparent);
    -webkit-backdrop-filter: saturate(1.4) blur(12px);
    backdrop-filter: saturate(1.4) blur(12px);
    border-top: 1px solid var(--line);
  }
  .step { flex: 1; flex-direction: column; justify-content: center; gap: 2px; min-height: var(--tabbar-h); padding: 4px 0; border-radius: 12px; font-size: 12px; }
  .step svg { display: block; width: 26px; height: 26px; }
  .step-num { display: none; }
  .step[aria-selected="true"] { background: transparent; box-shadow: none; color: var(--accent); }
  .top-actions { margin-left: auto; }
  .main { padding: 10px 10px calc(var(--tabbar-h) + 22px + env(safe-area-inset-bottom)); }
  .empty h1 { font-size: 23px; }

  .workspace.has-project { display: flex; flex-direction: column; gap: 12px; }
  .ws-main { height: calc(100dvh - var(--topbar-h) - var(--tabbar-h) - 56px - env(safe-area-inset-top) - env(safe-area-inset-bottom)); min-height: 360px; border-radius: 14px; }
  .toolbar { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; gap: 6px; padding: 6px; }
  .toolbar::-webkit-scrollbar { display: none; }
  .toolbar > * { flex: none; }
  .tools button span { display: none; }
  .tools button { padding: 0 9px; }
  .tb-grow { display: none; }
  .menu-pop { position: fixed; left: 10px; right: 10px; top: auto; bottom: calc(var(--tabbar-h) + 16px + env(safe-area-inset-bottom)); min-width: 0; }
  .side { overflow: visible; }
  .statusline { font-size: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
