:root {
  color-scheme: light;
  --paper: #f7f7f4;
  --surface: #ffffff;
  --ink: #343434;
  --muted: #77736f;
  --line: #c9c7c1;
  --line-dark: #565552;
  --accent: #dd6b60;
  --accent-soft: #faece9;
  --success: #55705b;
  --danger: #a44b43;
  --edge: clamp(20px, 3.35vw, 64px);
  --radius: 2px;
  font-family: Arial, "Malgun Gothic", sans-serif;
  color: var(--ink);
  background: var(--paper);
  font-synthesis: none;
}

* { box-sizing: border-box; }
html { min-width: 300px; scroll-behavior: smooth; }
body { margin: 0; min-height: 100vh; background: var(--paper); }
button, input, select, textarea { font: inherit; color: inherit; }
button, select { cursor: pointer; }
button, input, select, textarea { border-radius: 0; }
a { color: inherit; text-decoration: none; }
img { display: block; max-width: 100%; }
:focus-visible { outline: 1px solid var(--accent); outline-offset: 4px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; }
[hidden] { display: none !important; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  height: 92px;
  padding: 30px var(--edge) 20px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  background: color-mix(in srgb, var(--paper) 94%, transparent);
  border-bottom: 1px solid transparent;
  backdrop-filter: blur(12px);
}

.topbar.is-scrolled { border-bottom-color: var(--line); }
.brand { display: flex; align-items: center; gap: 13px; line-height: 1; letter-spacing: .045em; font-size: 20px; font-weight: 300; }
.brand strong { font-size: 10px; letter-spacing: .18em; font-weight: 500; }
.brand-divider { width: 28px; height: 1px; background: var(--line-dark); }
.topbar-actions { display: flex; align-items: center; gap: 22px; }
.status-button { display: flex; align-items: center; gap: 9px; padding: 0; border: 0; background: transparent; font-size: 11px; letter-spacing: .03em; }
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: #a9a6a0; }
.status-button.is-online .status-dot { background: var(--success); box-shadow: 0 0 0 4px rgba(85, 112, 91, .1); }
.status-button.is-error .status-dot { background: var(--accent); }
.brand-symbol { display: grid; grid-template-columns: repeat(2, 11px); grid-template-rows: repeat(2, 11px); gap: 3px; width: 25px; height: 25px; }
.brand-symbol::before, .brand-symbol i { content: ""; display: block; background: var(--ink); }
.brand-symbol i:nth-child(1) { grid-column: 1; grid-row: 1 / span 2; }
.brand-symbol i:nth-child(2) { grid-column: 2; grid-row: 1; }
.brand-symbol i:nth-child(3) { grid-column: 2; grid-row: 2; }

.page-shell { padding: 76px var(--edge) 48px; }
.intro-copy { display: grid; grid-template-columns: 1fr minmax(360px, 690px); column-gap: 9vw; align-items: end; margin-bottom: 76px; }
.intro-copy .eyebrow { align-self: start; }
.intro-copy h1 { grid-column: 1; margin: 80px 0 0; max-width: 700px; font-size: clamp(42px, 5.1vw, 82px); line-height: .98; letter-spacing: -.06em; font-weight: 300; }
.intro-copy > p:last-child { grid-column: 2; grid-row: 1 / span 2; margin: 0 0 5px; max-width: 540px; font-size: 14px; line-height: 1.8; color: var(--muted); }
.eyebrow { margin: 0; font-size: 10px; letter-spacing: .22em; color: var(--muted); }

.workspace { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); border-top: 1px solid var(--line-dark); }
.panel { min-width: 0; padding: 24px 0 34px; border-bottom: 1px solid var(--line); }
.provider-panel { grid-column: 1 / -1; display: grid; grid-template-columns: 4fr 7fr 1fr; gap: 24px; align-items: start; }
.source-panel { grid-column: 1 / span 7; padding-right: 3.2vw; border-right: 1px solid var(--line); }
.references-panel { grid-column: 8 / -1; padding-left: 3.2vw; }
.direction-panel { grid-column: 1 / span 7; padding-right: 3.2vw; border-right: 1px solid var(--line); }
.action-panel { grid-column: 8 / -1; padding-left: 3.2vw; display: flex; flex-direction: column; justify-content: flex-end; }

.section-heading { display: grid; grid-template-columns: 36px 1fr; gap: 2px; margin-bottom: 24px; }
.section-heading > span { padding-top: 3px; font-size: 10px; color: var(--accent); }
.section-heading h2 { margin: 0; font-size: 16px; line-height: 1.3; font-weight: 500; }
.section-heading p { margin: 7px 0 0; font-size: 12px; line-height: 1.5; color: var(--muted); }

.provider-switch { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); border-left: 1px solid var(--line); }
.provider-option { position: relative; min-height: 78px; padding: 10px 20px 11px; display: grid; grid-template-columns: 1fr auto; align-content: center; gap: 7px 18px; border-right: 1px solid var(--line); transition: background .2s ease; cursor: pointer; }
.provider-option input { position: absolute; opacity: 0; pointer-events: none; }
.provider-option.is-selected { background: var(--surface); box-shadow: inset 0 -2px 0 var(--accent); }
.provider-name { font-size: 18px; letter-spacing: .04em; font-weight: 400; }
.provider-desc, .provider-state { font-size: 10px; color: var(--muted); }
.provider-state { grid-column: 2; grid-row: 1 / span 2; align-self: center; color: var(--ink); }
.provider-state.is-connected { color: var(--success); }
.text-button { justify-self: end; border: 0; border-bottom: 1px solid var(--line-dark); background: transparent; padding: 7px 0 5px; font-size: 11px; }

.dropzone { position: relative; min-height: 390px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; overflow: hidden; border: 1px dashed #aaa8a2; background: rgba(255, 255, 255, .44); text-align: center; transition: border-color .2s ease, background .2s ease; cursor: pointer; }
.dropzone:hover, .dropzone.is-dragging { border-color: var(--accent); background: var(--accent-soft); }
.dropzone.has-image { border-style: solid; background: #ecece8; }
.dropzone-plus { position: relative; width: 32px; height: 32px; margin-bottom: 7px; }
.dropzone-plus::before, .dropzone-plus::after { content: ""; position: absolute; left: 50%; top: 50%; background: var(--line-dark); transform: translate(-50%, -50%); }
.dropzone-plus::before { width: 32px; height: 1px; }
.dropzone-plus::after { width: 1px; height: 32px; }
.dropzone strong { font-size: 14px; font-weight: 500; }
.dropzone small { font-size: 10px; color: var(--muted); }
.dropzone img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: #e9e9e6; }
.remove-image { position: absolute; top: 12px; right: 12px; z-index: 2; width: 30px; height: 30px; padding: 0; border: 1px solid rgba(255,255,255,.65); background: rgba(42,42,42,.72); color: #fff; font-size: 20px; line-height: 28px; }
.lock-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.lock-row span { padding: 5px 8px; border: 1px solid var(--line); background: rgba(255,255,255,.55); font-size: 9px; letter-spacing: .03em; color: var(--muted); }
.lock-row span::before { content: "✓"; margin-right: 5px; color: var(--success); }

.reference-columns { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.mini-dropzone { min-height: 150px; display: flex; flex-direction: column; justify-content: flex-end; gap: 6px; padding: 17px; border: 1px dashed #aaa8a2; background: rgba(255,255,255,.44); cursor: pointer; transition: border-color .2s ease, background .2s ease; }
.mini-dropzone:hover, .mini-dropzone.is-dragging { border-color: var(--accent); background: var(--accent-soft); }
.mini-dropzone > span { margin-bottom: auto; font-size: 9px; letter-spacing: .18em; color: var(--accent); }
.mini-dropzone strong { font-size: 13px; font-weight: 500; }
.mini-dropzone small { font-size: 10px; color: var(--muted); }
.reference-list { margin-top: 14px; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.reference-item { position: relative; aspect-ratio: 1; overflow: hidden; background: #e8e8e5; }
.reference-item img { width: 100%; height: 100%; object-fit: cover; }
.reference-item em { position: absolute; left: 6px; bottom: 6px; padding: 3px 5px; background: rgba(247,247,244,.88); font-style: normal; font-size: 8px; letter-spacing: .08em; }
.reference-item button { position: absolute; top: 5px; right: 5px; width: 22px; height: 22px; border: 0; background: rgba(42,42,42,.74); color: #fff; line-height: 1; }

.prompt-field { position: relative; display: block; }
.prompt-field textarea { width: 100%; min-height: 166px; resize: vertical; padding: 20px 20px 34px; border: 1px solid var(--line); background: var(--surface); font-size: 14px; line-height: 1.75; }
.prompt-field textarea::placeholder { color: #aaa6a0; }
.prompt-counter { position: absolute; right: 12px; bottom: 11px; font-size: 9px; color: var(--muted); }
.prompt-counter b { font-weight: 400; }
.render-options { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); border: 1px solid var(--line); border-top: 0; }
.render-options label { display: grid; grid-template-columns: 1fr auto; align-items: center; padding: 12px 14px; font-size: 10px; color: var(--muted); }
.render-options label + label { border-left: 1px solid var(--line); }
.render-options select { min-width: 92px; padding: 5px 26px 5px 8px; border: 0; background-color: transparent; text-align: right; font-size: 12px; color: var(--ink); }
.automation-note { margin-top: 12px; padding: 13px 0; border-bottom: 1px solid var(--line); font-size: 10px; color: var(--muted); }
.automation-note summary { cursor: pointer; color: var(--ink); }
.automation-note p { margin: 12px 0 0; line-height: 1.7; }

.privacy-line { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 28px; }
.privacy-mark { width: 13px; height: 17px; flex: 0 0 auto; border: 1px solid var(--success); border-radius: 8px 8px 2px 2px; }
.privacy-mark::before { content: ""; display: block; width: 7px; height: 6px; margin: -6px auto 0; border: 1px solid var(--success); border-bottom: 0; border-radius: 7px 7px 0 0; }
.privacy-line p { margin: 0; font-size: 11px; line-height: 1.6; color: var(--muted); }
.privacy-line strong { color: var(--success); letter-spacing: .09em; font-size: 9px; }
.form-message { min-height: 20px; margin: 0 0 8px; font-size: 11px; color: var(--danger); }
.render-button { width: 100%; min-height: 118px; display: flex; align-items: center; justify-content: space-between; padding: 20px 24px; border: 1px solid var(--line-dark); background: var(--ink); color: #fff; font-size: 20px; font-weight: 400; transition: background .2s ease, color .2s ease; }
.render-button:hover { background: var(--accent); border-color: var(--accent); }
.render-button:disabled { cursor: wait; opacity: .48; }
.render-arrow { font-size: 28px; font-weight: 200; }

.results-section { margin-top: 92px; padding-top: 23px; border-top: 1px solid var(--line-dark); }
.results-heading { display: flex; justify-content: space-between; align-items: end; gap: 24px; margin-bottom: 26px; }
.results-heading h2 { margin: 10px 0 0; font-size: clamp(28px, 3vw, 48px); font-weight: 300; letter-spacing: -.04em; }
.results-actions { display: flex; align-items: center; gap: 18px; font-size: 10px; color: var(--muted); }
.line-button { padding: 8px 0 6px; border: 0; border-bottom: 1px solid var(--line-dark); background: transparent; font-size: 11px; }
.job-progress { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 18px; margin: 20px 0 18px; font-size: 10px; color: var(--muted); }
.progress-bar { display: block; height: 1px; background: var(--line); overflow: hidden; }
.progress-bar i { display: block; width: 0; height: 100%; background: var(--accent); transition: width .4s ease; }
.results-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.result-card { position: relative; min-height: 340px; display: grid; place-items: center; overflow: hidden; background: #e9e9e5; }
.result-card.is-loading::after { content: ""; width: 28px; height: 28px; border: 1px solid #aaa; border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
.result-card img { width: 100%; height: 100%; min-height: 340px; object-fit: contain; }
.result-meta { position: absolute; inset: auto 0 0; display: flex; justify-content: space-between; align-items: center; padding: 11px 13px; background: linear-gradient(transparent, rgba(25,25,25,.68)); color: #fff; font-size: 10px; }
.result-meta button { padding: 5px 0; border: 0; border-bottom: 1px solid rgba(255,255,255,.7); background: transparent; color: #fff; font-size: 10px; }
.result-error { padding: 30px; max-width: 420px; text-align: center; font-size: 12px; line-height: 1.7; color: var(--danger); }
@keyframes spin { to { transform: rotate(360deg); } }

.truth-note { max-width: 650px; margin: 78px 0 58px auto; display: grid; grid-template-columns: 76px 1fr; padding-top: 14px; border-top: 1px solid var(--line); }
.truth-note span { font-size: 9px; letter-spacing: .18em; color: var(--accent); }
.truth-note p { margin: 0; font-size: 11px; line-height: 1.7; color: var(--muted); }
footer { min-height: 86px; padding: 22px var(--edge); display: flex; align-items: center; justify-content: space-between; gap: 24px; border-top: 1px solid var(--line-dark); font-size: 9px; letter-spacing: .12em; color: var(--muted); }

.connection-dialog { width: min(560px, calc(100vw - 32px)); padding: 0; border: 1px solid var(--line-dark); background: var(--paper); color: var(--ink); }
.connection-dialog::backdrop { background: rgba(32,32,30,.36); backdrop-filter: blur(3px); }
.dialog-card { padding: 27px; }
.dialog-head { display: flex; justify-content: space-between; gap: 24px; padding-bottom: 24px; border-bottom: 1px solid var(--line); }
.dialog-head h2 { margin: 9px 0 0; font-size: 27px; font-weight: 300; letter-spacing: -.03em; }
.dialog-close { width: 32px; height: 32px; border: 0; background: transparent; font-size: 24px; }
.connect-panel { padding: 24px 0 4px; }
.connect-panel > p { margin: 0 0 22px; font-size: 12px; line-height: 1.7; color: var(--muted); }
.connection-state-row { display: flex; align-items: center; justify-content: space-between; gap: 20px; font-size: 11px; }
.connection-state-row a { border-bottom: 1px solid var(--line); padding-bottom: 5px; }
.key-field { display: block; margin: 18px 0; }
.key-field span { display: block; margin-bottom: 8px; font-size: 9px; letter-spacing: .16em; color: var(--muted); }
.key-field input { width: 100%; padding: 13px 12px; border: 1px solid var(--line); background: var(--surface); }
.connect-panel > small { display: block; margin-top: 18px; font-size: 9px; line-height: 1.5; color: var(--danger); }
.bridge-install { margin-top: 24px; padding: 20px; border: 1px solid var(--accent); background: var(--accent-soft); }
.bridge-install strong { font-size: 13px; }
.bridge-install p { margin: 8px 0 18px; font-size: 11px; line-height: 1.6; color: var(--muted); }
.bridge-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; }
.download-button { display: inline-block; padding: 10px 13px; background: var(--ink); color: #fff; font-size: 11px; }

@media (max-width: 900px) {
  .page-shell { padding-top: 44px; }
  .intro-copy { grid-template-columns: 1fr; margin-bottom: 56px; }
  .intro-copy h1 { margin-top: 50px; }
  .intro-copy > p:last-child { grid-column: 1; grid-row: auto; margin-top: 28px; }
  .provider-panel { grid-template-columns: 1fr; }
  .provider-switch { border-top: 1px solid var(--line); }
  .text-button { justify-self: start; }
  .source-panel, .references-panel, .direction-panel, .action-panel { grid-column: 1 / -1; padding-left: 0; padding-right: 0; border-right: 0; }
  .dropzone { min-height: 52vw; }
}

@media (max-width: 600px) {
  .topbar { height: 76px; padding-top: 24px; }
  .brand { font-size: 17px; gap: 9px; }
  .brand-divider { width: 17px; }
  .brand strong { font-size: 8px; }
  .status-button span:last-child { display: none; }
  .topbar-actions { gap: 14px; }
  .brand-symbol { transform: scale(.82); transform-origin: right top; }
  .page-shell { padding-top: 35px; }
  .intro-copy h1 { margin-top: 42px; font-size: 40px; }
  .intro-copy > p:last-child { font-size: 12px; }
  .provider-switch { grid-template-columns: 1fr; border-left: 0; }
  .provider-option { border-left: 1px solid var(--line); }
  .provider-option + .provider-option { border-top: 1px solid var(--line); }
  .dropzone { min-height: 74vw; }
  .reference-columns { gap: 8px; }
  .mini-dropzone { min-height: 132px; padding: 13px; }
  .reference-list { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .render-options { grid-template-columns: 1fr; }
  .render-options label + label { border-left: 0; border-top: 1px solid var(--line); }
  .render-button { min-height: 96px; }
  .results-heading { align-items: start; flex-direction: column; }
  .results-actions { width: 100%; justify-content: space-between; }
  .results-grid { grid-template-columns: 1fr; }
  .result-card, .result-card img { min-height: 250px; }
  .truth-note { grid-template-columns: 52px 1fr; margin-top: 56px; }
  footer { align-items: flex-start; flex-direction: column; min-height: 100px; }
  .connection-state-row { align-items: flex-start; flex-direction: column; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
