:root {
  color-scheme: light;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background: var(--background);
  --text: #233a35;
  --background: #f5f4ef;
  --panel: #fff;
  --subtle: #f3f5f0;
  --image-surface: #fafbf8;
  --muted: #65716c;
  --accent: #245b4d;
  --border: #e0e4dc;
  --accent-hover: #1b483d;
  --on-accent: #fff;
  --disabled-bg: #e6ebe3;
  --disabled-text: #818d7e;
  --disabled-muted: #a3aca6;
  --error: #a33627;
  --empty-border: #dce2d6;
  --empty-icon: #a8b6a2;
  --focus: #ba6b35;
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --text: #e3ece7;
  --background: #151b19;
  --panel: #202924;
  --subtle: #29342e;
  --image-surface: #18221d;
  --muted: #a2b3a9;
  --accent: #87c6ac;
  --border: #34423b;
  --accent-hover: #a0d8c1;
  --on-accent: #152b21;
  --disabled-bg: #303c35;
  --disabled-text: #7d9084;
  --disabled-muted: #7d9084;
  --error: #ef9d8e;
  --empty-border: #3b4c40;
  --empty-icon: #698672;
  --focus: #dfaa6c;
}
* { box-sizing: border-box; }
body { margin: 0; }
main { max-width: 1240px; margin: auto; padding: 30px 40px 24px; }
button, input { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; }
button, a, input { -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 4px; }
[hidden] { display: none !important; }
svg { fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.page-header { position: relative; display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.category-carousel { position: absolute; left: 50%; transform: translateX(-50%); width: 220px; max-width: calc(100% - 632px); height: 24px; text-align: center; color: var(--muted); font-size: 15px; line-height: 24px; text-transform: capitalize; }
.category-carousel span { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wordmark { display: flex; gap: 12px; align-items: center; color: inherit; text-decoration: none; font-size: 17px; font-weight: 650; letter-spacing: -.4px; }
.wordmark svg { width: 28px; height: 28px; color: var(--accent); }
.header-tools { display: flex; align-items: center; gap: 12px; width: 300px; max-width: 50%; }
.theme-toggle { display: grid; place-items: center; flex-shrink: 0; width: 36px; height: 36px; padding: 8px; border: 1px solid var(--border); border-radius: 50%; color: var(--accent); background: var(--panel); }
.theme-toggle:hover { background: var(--subtle); }
.theme-toggle svg { width: 18px; height: 18px; }
.sun-icon, [data-theme="dark"] .moon-icon { display: none; }
[data-theme="dark"] .sun-icon { display: block; }
.model-info { position: relative; display: flex; flex: 1; min-width: 0; flex-direction: column; justify-content: center; min-height: 48px; color: var(--muted); font-size: 10px; }
.model-name { display: block; color: var(--accent); font-size: 12px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.model-state-row { display: flex; justify-content: space-between; align-items: center; min-height: 20px; }
.model-retry { border: 0; background: none; color: var(--accent); font-size: 10px; padding: 2px 0 2px 8px; }
.model-info progress { position: absolute; bottom: 0; display: block; width: 100%; height: 5px; accent-color: var(--accent); }
.model-info.ready progress { visibility: hidden; }
.model-info.failed #model-state { color: var(--error); }
.workspace { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; align-items: stretch; margin-top: 32px; }
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: 16px; padding: 24px; box-shadow: 0 5px 16px #233a3504; }
.drawing-panel, .results-panel { display: flex; flex-direction: column; height: 620px; }
.drawing-panel .canvas-wrap { width: 100%; max-width: 440px; margin: auto; flex-shrink: 0; }
.toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; gap: 8px; }
.tool-group { display: flex; gap: 4px; padding: 4px; background: var(--subtle); border-radius: 9px; }
.tool { display: flex; align-items: center; gap: 7px; border: 0; border-radius: 6px; background: transparent; color: var(--muted); padding: 8px 12px; font-size: 12px; }
.tool svg { width: 16px; height: 16px; }
.tool.selected { background: var(--panel); color: var(--accent); box-shadow: 0 1px 4px #233a3515; }
.tool:hover:not(:disabled) { color: var(--accent); }
.clear-button { background: none; border: 0; color: var(--muted); padding: 10px 0 10px 10px; font-size: 12px; }
.clear-button:hover:not(:disabled) { text-decoration: underline; }
.clear-button:disabled { color: var(--disabled-muted); }
.canvas-wrap { position: relative; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; background: white; }
canvas { display: block; width: 100%; aspect-ratio: 1; height: auto; background: white; cursor: crosshair; touch-action: none; }
[data-theme="dark"] .canvas-wrap { background: black; }
[data-theme="dark"] canvas { filter: invert(1); }
canvas.erasing { cursor: cell; }
.canvas-placeholder { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; flex-direction: column; gap: 18px; pointer-events: none; color: #8a948c; font-size: 13px; }
.canvas-placeholder svg { width: 70px; color: #aebaaa; stroke-width: 2; }
.drawing-footer { display: flex; align-items: center; justify-content: flex-end; gap: 16px; padding-top: 20px; }
.search-button { display: flex; align-items: center; justify-content: center; gap: 15px; background: var(--accent); color: var(--on-accent); border: 0; border-radius: 8px; padding: 14px 18px; font-size: 13px; font-weight: 600; white-space: nowrap; }
.search-button svg { width: 18px; height: 18px; }
.search-button:hover:not(:disabled) { background: var(--accent-hover); }
.search-button:disabled { background: var(--disabled-bg); color: var(--disabled-text); }
.search-button.busy { background: var(--accent); color: var(--on-accent); }
.search-button.busy svg { animation: pulse 1s ease-in-out infinite alternate; }
.results-empty { flex: 1; min-height: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; background: var(--image-surface); border: 1px dashed var(--empty-border); border-radius: 10px; padding: 30px; }
.results-empty svg { width: 48px; height: 48px; color: var(--empty-icon); margin-bottom: 15px; }
h3 { font-family: Georgia, "Times New Roman", serif; font-size: 21px; font-weight: 400; letter-spacing: -.4px; margin: 10px 0; }
.results-empty p { color: var(--muted); font-size: 13px; line-height: 1.8; margin: 0; }
.result-view { align-self: flex-start; margin-bottom: 16px; }
.results { display: grid; grid-template-columns: repeat(var(--columns, 1), minmax(0, 1fr)); grid-template-rows: repeat(var(--rows, 1), minmax(0, 1fr)); gap: 12px; flex: 1; min-height: 0; }
.result { margin: 0; display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.result-image { width: 100%; height: 0; flex: 1; min-height: 0; display: block; object-fit: contain; background: var(--image-surface); border: 1px solid var(--border); border-radius: 10px; }
.result figcaption { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding-top: 10px; font-size: 12px; color: var(--muted); }
.result figcaption strong { font-weight: 600; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.result figcaption span { white-space: nowrap; }
.result-controls { margin-top: 25px; border-top: 1px solid var(--border); padding-top: 20px; height: 76px; flex-shrink: 0; }
.slider-label { display: flex; justify-content: space-between; font-size: 12px; margin-bottom: 12px; }
.slider-label output { color: var(--accent); font-variant-numeric: tabular-nums; }
input[type="range"] { accent-color: var(--accent); width: 100%; margin: 0; height: 24px; cursor: pointer; }
.status { display: flex; align-items: center; flex: 1; min-width: 0; color: var(--muted); font-size: 11px; line-height: 1.6; margin: 0; min-height: 54px; }
.status.error { color: var(--error); }
.noscript { color: var(--error); }
@keyframes pulse { to { opacity: .3; } }
@media (prefers-reduced-motion: reduce) { .search-button.busy svg { animation: none; } }
@media (max-width: 760px) {
  .page-header { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .wordmark { min-width: 0; }
  .header-tools { width: 100%; max-width: none; }
  .category-carousel { position: static; transform: none; order: 1; grid-column: 1 / -1; width: 100%; max-width: none; font-size: 13px; }
  main { padding: 24px 18px; }
  .workspace { grid-template-columns: 1fr; gap: 18px; }
  .panel { padding: 20px; }
  .drawing-panel, .results-panel { height: auto; }
  .results-panel:has(.results:not([hidden])) { height: 540px; }
  .drawing-panel .canvas-wrap { max-width: none; }
  .results-empty { min-height: 300px; }
}
@media (max-width: 380px) {
  main { padding-inline: 12px; }
  .panel { padding: 16px; }
  .drawing-footer { align-items: stretch; flex-direction: column; gap: 12px; }
}
