:root {
  color: #17211d;
  background: #f4f6f4;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
  letter-spacing: 0;
  --ink: #17211d;
  --muted: #66716c;
  --line: #d8dedb;
  --surface: #ffffff;
  --surface-soft: #edf1ef;
  --accent: #1f7354;
  --accent-hover: #175c43;
  --accent-soft: #deeee7;
  --warning: #b64d35;
}

* {
  box-sizing: border-box;
  letter-spacing: 0;
}

[hidden] {
  display: none !important;
}

html,
body {
  min-height: 100%;
  margin: 0;
}

body {
  min-height: 100vh;
  background: #f4f6f4;
}

button,
select,
input {
  font: inherit;
}

button,
select,
label {
  -webkit-tap-highlight-color: transparent;
}

button {
  border: 0;
  cursor: pointer;
}

button:focus-visible,
select:focus-visible,
input:focus-visible + span {
  outline: 3px solid rgba(31, 115, 84, 0.22);
  outline-offset: 2px;
}

button:disabled {
  cursor: not-allowed;
}

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

.topbar {
  min-height: 80px;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 0 0 auto;
}

.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 6px;
  background: var(--ink);
  color: #ffffff;
  font-size: 14px;
  font-weight: 750;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 17px;
  line-height: 1.2;
  font-weight: 720;
}

.service-status {
  margin-top: 5px;
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #a4aca8;
}

.service-status.online .status-dot {
  background: #2c956b;
}

.service-status.offline .status-dot {
  background: var(--warning);
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  min-width: 0;
}

.segmented {
  height: 40px;
  margin: 0;
  padding: 3px;
  display: flex;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-soft);
}

.segmented label {
  position: relative;
  cursor: pointer;
}

.segmented input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.segmented span {
  width: 48px;
  height: 32px;
  display: grid;
  place-items: center;
  border-radius: 4px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

.segmented input:checked + span {
  color: var(--ink);
  background: var(--surface);
  box-shadow: 0 1px 3px rgba(23, 33, 29, 0.12);
}

.select-control {
  height: 40px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--muted);
  font-size: 12px;
}

.select-control select {
  min-width: 68px;
  border: 0;
  outline: 0;
  color: var(--ink);
  background: transparent;
  font-weight: 650;
}

.prompt-control {
  width: min(360px, 32vw);
}

.token-control {
  width: min(240px, 22vw);
}

.prompt-control input,
.token-control input {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  color: var(--ink);
  background: transparent;
  font: inherit;
}

.toggle-control {
  height: 40px;
  padding: 0 11px;
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
}

.toggle-control input {
  position: absolute;
  opacity: 0;
}

.toggle-track {
  width: 30px;
  height: 18px;
  padding: 2px;
  display: block;
  border-radius: 10px;
  background: #b9c1bd;
}

.toggle-track span {
  width: 14px;
  height: 14px;
  display: block;
  border-radius: 50%;
  background: #ffffff;
  transition: transform 160ms ease;
}

.toggle-control input:checked + .toggle-track {
  background: var(--accent);
}

.toggle-control input:checked + .toggle-track span {
  transform: translateX(12px);
}

.primary-button,
.secondary-button,
.download-button,
.replace-button {
  min-height: 40px;
  padding: 0 16px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 680;
}

.primary-button {
  min-width: 104px;
  color: #ffffff;
  background: var(--accent);
}

.primary-button:hover:not(:disabled),
.download-button:hover:not(:disabled) {
  background: var(--accent-hover);
}

.primary-button:disabled {
  color: #8d9692;
  background: #dce1df;
}

.primary-button.loading {
  background: #355f50;
}

.secondary-button {
  color: var(--ink);
  border: 1px solid var(--line);
  background: var(--surface);
}

.docs-link {
  min-height: 40px;
  padding: 0 16px;
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  background: var(--surface);
  font-size: 13px;
  font-weight: 680;
  text-decoration: none;
  white-space: nowrap;
}

.docs-link:hover {
  background: var(--surface-soft);
}

.workspace {
  height: calc(100vh - 80px);
  min-height: 560px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
}

.image-pane {
  min-width: 0;
  display: grid;
  grid-template-rows: 56px minmax(0, 1fr);
  background: var(--surface-soft);
}

.input-pane {
  border-right: 1px solid var(--line);
}

.output-pane {
  grid-template-rows: 56px minmax(0, 1fr) 88px;
}

.pane-header {
  padding: 0 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.pane-header h2 {
  font-size: 14px;
  font-weight: 720;
}

.image-meta {
  min-width: 0;
  color: var(--muted);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.viewer {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  display: grid;
  place-items: center;
  background-color: #e8ecea;
  background-image:
    linear-gradient(45deg, #dfe4e1 25%, transparent 25%),
    linear-gradient(-45deg, #dfe4e1 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #dfe4e1 75%),
    linear-gradient(-45deg, transparent 75%, #dfe4e1 75%);
  background-size: 20px 20px;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0;
}

.viewer.dragging {
  box-shadow: inset 0 0 0 3px var(--accent);
}

.viewer img {
  width: 100%;
  height: 100%;
  padding: 24px;
  object-fit: contain;
}

.empty-state {
  display: grid;
  justify-items: center;
  gap: 14px;
  color: var(--muted);
  font-size: 13px;
}

.empty-hint {
  font-size: 12px;
  opacity: 0.85;
}

.empty-symbol {
  width: 56px;
  height: 56px;
  display: grid;
  place-items: center;
  border: 1px dashed #9ca7a1;
  border-radius: 6px;
  color: var(--accent);
  background: rgba(255, 255, 255, 0.7);
  font-size: 30px;
  font-weight: 300;
}

.output-placeholder {
  width: 62px;
  height: 46px;
  border: 1px solid #aab3ae;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.55);
  box-shadow: inset 0 -14px 0 var(--accent-soft);
}

.output-placeholder.processing {
  border-color: var(--accent);
  animation: pulse 1.1s ease-in-out infinite;
}

@keyframes pulse {
  50% {
    opacity: 0.48;
  }
}

.replace-button {
  position: absolute;
  top: 14px;
  right: 14px;
  min-height: 34px;
  padding: 0 12px;
  color: var(--ink);
  border: 1px solid rgba(23, 33, 29, 0.16);
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(8px);
}

.result-bar {
  padding: 12px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  border-top: 1px solid var(--line);
  background: var(--surface);
}

.timing-grid {
  margin: 0;
  display: flex;
  align-items: center;
  gap: 26px;
}

.timing-grid div {
  min-width: 68px;
}

.timing-grid dt {
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 11px;
}

.timing-grid dd {
  margin: 0;
  color: var(--ink);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  font-weight: 680;
}

.timing-grid .primary-timing dd {
  color: var(--accent);
  font-size: 19px;
}

.download-button {
  flex: 0 0 auto;
  color: #ffffff;
  background: var(--ink);
}

.download-button:disabled {
  color: #929a96;
  background: #dce1df;
}

.toast {
  position: fixed;
  z-index: 10;
  left: 50%;
  bottom: 24px;
  max-width: min(480px, calc(100vw - 32px));
  padding: 11px 14px;
  transform: translateX(-50%);
  border-radius: 6px;
  color: #ffffff;
  background: #26332e;
  box-shadow: 0 8px 24px rgba(23, 33, 29, 0.2);
  font-size: 13px;
}

.toast.error {
  background: #8f3d2b;
}

@media (max-width: 980px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
    gap: 12px;
  }

  .toolbar {
    width: 100%;
    justify-content: flex-start;
    flex-wrap: wrap;
  }

  .workspace {
    height: auto;
    min-height: 0;
  }

  .image-pane {
    min-height: 560px;
  }
}

@media (max-width: 720px) {
  .topbar {
    padding: 12px 14px;
  }

  .toolbar {
    display: grid;
    grid-template-columns: auto minmax(100px, 1fr);
  }

  .prompt-control,
  .token-control {
    grid-column: 1 / -1;
    width: 100%;
  }

  .toggle-control,
  .primary-button {
    width: 100%;
  }

  .workspace {
    display: block;
  }

  .image-pane,
  .output-pane {
    min-height: 520px;
    grid-template-rows: 52px 380px;
  }

  .input-pane {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .output-pane {
    grid-template-rows: 52px 380px auto;
  }

  .viewer img {
    padding: 14px;
  }

  .result-bar {
    align-items: stretch;
    flex-direction: column;
  }

  .timing-grid {
    justify-content: space-between;
    gap: 12px;
  }

  .download-button {
    width: 100%;
  }
}
