:root {
  color-scheme: light;
  --bg: #f5f7fa;
  --panel: #ffffff;
  --panel-subtle: #f8fafc;
  --ink: #17202a;
  --muted: #657083;
  --line: #d9e0e8;
  --line-strong: #b8c3cf;
  --accent: #0f766e;
  --accent-strong: #0b5f59;
  --accent-soft: #e6f4f2;
  --blue: #2563eb;
  --danger: #b42318;
  --shadow: 0 18px 45px rgba(24, 34, 48, 0.08);
  --checker-a: #e8edf3;
  --checker-b: #cfd8e3;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #101418;
  --panel: #181e25;
  --panel-subtle: #202832;
  --ink: #edf2f7;
  --muted: #a5b1c2;
  --line: #313b47;
  --line-strong: #495565;
  --accent: #37b6a9;
  --accent-strong: #62d0c5;
  --accent-soft: #123330;
  --blue: #7aa2ff;
  --danger: #ff8a80;
  --shadow: 0 20px 55px rgba(0, 0, 0, 0.32);
  --checker-a: #27313c;
  --checker-b: #1d252e;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select {
  font: inherit;
}

button,
a,
input,
select,
.file-drop {
  transition:
    background-color 160ms ease,
    border-color 160ms ease,
    color 160ms ease,
    box-shadow 160ms ease;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
.file-drop:focus-within {
  outline: 3px solid color-mix(in srgb, var(--accent) 34%, transparent);
  outline-offset: 2px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 20px clamp(18px, 4vw, 48px);
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--panel) 88%, transparent);
  backdrop-filter: blur(16px);
}

.brand,
.section-heading,
.auth-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
}

.brand,
.section-heading {
  min-width: 0;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(1.85rem, 3vw, 2.5rem);
  line-height: 1;
}

h2 {
  overflow-wrap: anywhere;
  font-size: 1.2rem;
  line-height: 1.2;
}

.eyebrow {
  margin-bottom: 7px;
  color: var(--accent-strong);
  font-size: 0.74rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.layout {
  display: grid;
  grid-template-columns: minmax(320px, 470px) minmax(0, 1fr);
  gap: 24px;
  width: min(1220px, calc(100% - 36px));
  margin: 28px auto 40px;
  min-height: 0;
}

.tool,
.result-panel,
.auth-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.tool,
.result-panel {
  min-height: 0;
  padding: clamp(18px, 2.5vw, 26px);
}

.tool {
  overflow: hidden;
}

.result-panel {
  overflow: auto;
  overscroll-behavior: contain;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 18px;
  min-height: 0;
  height: 100%;
}

.field {
  display: grid;
  gap: 8px;
}

label,
legend {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

legend {
  display: grid;
  gap: 2px;
  width: 100%;
  padding: 0;
  color: var(--ink);
}

fieldset {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

input,
select {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--ink);
  padding: 10px 12px;
}

input::placeholder {
  color: color-mix(in srgb, var(--muted) 78%, transparent);
}

button,
.download {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 46px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: var(--accent);
  color: #ffffff;
  padding: 0 18px;
  font-weight: 800;
  text-decoration: none;
  cursor: pointer;
}

button:hover,
.download:hover {
  background: var(--accent-strong);
}

button.ghost {
  border-color: var(--line);
  background: var(--panel);
  color: var(--ink);
}

button.ghost:hover {
  border-color: var(--line-strong);
  background: var(--panel-subtle);
}

button.compact {
  min-height: 36px;
  padding: 0 12px;
  font-size: 0.88rem;
}

.theme-toggle {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 3px;
  min-height: 38px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-subtle);
}

.theme-option {
  min-height: 30px;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: var(--muted);
  padding: 0 11px;
  font-size: 0.84rem;
}

.theme-option:hover,
.theme-option.is-active {
  background: var(--panel);
  color: var(--ink);
  box-shadow: 0 1px 4px rgba(15, 23, 42, 0.12);
}

.file-drop {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) auto;
  align-items: center;
  gap: 14px;
  min-height: 112px;
  padding: 18px;
  border: 1.5px dashed var(--line-strong);
  border-radius: 8px;
  background: var(--panel-subtle);
  color: var(--ink);
  cursor: pointer;
}

.file-drop:hover,
.file-drop.is-dragging {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.file-drop input {
  display: none;
}

.file-drop-icon {
  position: relative;
  display: block;
  width: 44px;
  aspect-ratio: 1;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.file-drop-icon::before,
.file-drop-icon::after {
  position: absolute;
  content: "";
  left: 50%;
  top: 50%;
  width: 19px;
  height: 2px;
  border-radius: 999px;
  background: var(--accent);
  transform: translate(-50%, -50%);
}

.file-drop-icon::after {
  width: 2px;
  height: 19px;
}

.file-drop-copy {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.file-drop-copy strong,
.preview-details strong {
  overflow: hidden;
  color: var(--ink);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-drop-copy span:last-child {
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.35;
}

.file-drop-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--ink);
  padding: 0 12px;
  font-size: 0.88rem;
  font-weight: 800;
}

.upload-preview {
  display: grid;
  gap: 12px;
}

.upload-preview[hidden] {
  display: none;
}

.preview-frame,
.preview {
  background-color: var(--checker-a);
  background-image:
    linear-gradient(45deg, var(--checker-b) 25%, transparent 25%),
    linear-gradient(-45deg, var(--checker-b) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, var(--checker-b) 75%),
    linear-gradient(-45deg, transparent 75%, var(--checker-b) 75%);
  background-position: 0 0, 0 10px, 10px -10px, -10px 0;
  background-size: 20px 20px;
}

.preview-frame {
  display: grid;
  place-items: center;
  min-height: 220px;
  max-height: 360px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.preview-frame img {
  display: block;
  width: 100%;
  max-height: 360px;
  object-fit: contain;
}

.preview-details {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-width: 0;
}

.divider {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--muted);
  font-size: 0.85rem;
}

.divider::before,
.divider::after {
  content: "";
  height: 1px;
  flex: 1;
  background: var(--line);
}

.hint {
  color: var(--muted);
  font-size: 0.93rem;
  line-height: 1.45;
}

.error {
  color: var(--danger);
  line-height: 1.45;
}

.model-choice {
  display: grid;
  gap: 12px;
  min-height: 0;
}

.model-selected-card {
  display: grid;
  gap: 7px;
  padding: 15px;
  border: 1px solid var(--accent);
  border-radius: 8px;
  background: var(--accent-soft);
  box-shadow: inset 3px 0 0 var(--accent);
}

.model-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.model-card-head strong {
  color: var(--ink);
  line-height: 1.2;
}

.model-tag {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border: 1px solid color-mix(in srgb, var(--blue) 35%, var(--line));
  border-radius: 999px;
  color: var(--blue);
  padding: 0 9px;
  font-size: 0.76rem;
  font-weight: 800;
  white-space: nowrap;
}

.model-name {
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 0.78rem;
  overflow-wrap: anywhere;
}

.model-summary,
.model-best {
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.38;
}

.model-best {
  color: var(--ink);
}

.empty-state,
.job-card {
  display: grid;
  gap: 18px;
}

.empty-state {
  min-height: 100%;
  place-items: center;
  color: var(--muted);
  text-align: center;
}

.preview {
  width: min(100%, 760px);
  max-height: 62vh;
  border: 1px solid var(--line);
  border-radius: 8px;
  object-fit: contain;
}

.status-card {
  display: grid;
  gap: 14px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-subtle);
}

.status-card.is-working {
  border-color: color-mix(in srgb, var(--accent) 42%, var(--line));
  background: color-mix(in srgb, var(--panel-subtle) 82%, var(--accent-soft));
}

.status-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 28px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  color: var(--muted);
  padding: 0 10px;
  font-size: 0.8rem;
  font-weight: 800;
  white-space: nowrap;
}

.status-steps {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.status-step {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 800;
}

.status-step span:last-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-dot {
  width: 12px;
  aspect-ratio: 1;
  border: 2px solid var(--line-strong);
  border-radius: 50%;
  background: var(--panel);
  flex: 0 0 auto;
}

.status-step.complete,
.status-step.active {
  color: var(--ink);
}

.status-step.complete .status-dot {
  border-color: var(--accent);
  background: var(--accent);
}

.status-step.active .status-dot {
  border-color: var(--accent);
  background: var(--panel);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 18%, transparent);
}

.status-step.failed {
  color: var(--danger);
}

.status-step.failed .status-dot {
  border-color: var(--danger);
  background: var(--danger);
}

.activity-bar {
  position: relative;
  height: 12px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  contain: paint;
}

.activity-bar::before {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 44%;
  content: "";
  background:
    linear-gradient(
      90deg,
      transparent 0%,
      color-mix(in srgb, var(--accent) 34%, transparent) 28%,
      color-mix(in srgb, var(--accent) 82%, transparent) 50%,
      color-mix(in srgb, var(--accent) 34%, transparent) 72%,
      transparent 100%
    );
  transform: translate3d(-120%, 0, 0);
  will-change: transform;
  animation: activity-sweep 1.55s linear infinite;
  animation-delay: var(--activity-delay, 0s);
}

.activity-bar.active::before {
  animation-duration: 1.1s;
}

@keyframes activity-sweep {
  to {
    transform: translate3d(240%, 0, 0);
  }
}

.auth-page {
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-shell {
  width: min(100%, 460px);
}

.auth-panel {
  padding: 28px;
}

.auth-head {
  margin-bottom: 22px;
}

@media (max-width: 920px) {
  body {
    display: block;
    height: auto;
    overflow: auto;
  }

  .layout {
    grid-template-columns: 1fr;
    margin-top: 20px;
    min-height: auto;
  }

  .tool,
  .result-panel {
    min-height: auto;
    overflow: visible;
  }

  .stack {
    height: auto;
  }

  .model-choice {
    flex: initial;
  }

  .result-panel {
    min-height: 320px;
  }

  .empty-state {
    min-height: 260px;
  }
}

@media (max-width: 620px) {
  .topbar,
  .auth-head {
    align-items: stretch;
    flex-direction: column;
  }

  .brand {
    flex-direction: column;
    gap: 2px;
  }

  .topbar-actions {
    justify-content: flex-start;
  }

  .section-heading {
    display: grid;
  }

  .file-drop {
    grid-template-columns: 44px minmax(0, 1fr);
  }

  .file-drop-action {
    grid-column: 1 / -1;
  }

  .preview-details {
    align-items: stretch;
    flex-direction: column;
  }

  button.compact {
    width: 100%;
  }
}
