:root {
  --color-bg: #fff;
  --color-bg-subtle: #f5f5f5;
  --color-text: #333;
  --color-text-muted: #555;
  --color-text-subtle: #666;
  --color-text-faint: #888;
  --color-border: #ccc;
  --color-btn-bg: #333;
  --color-btn-text: #fff;
  --color-btn-hover: #555;
  --color-btn-disabled: #999;
  --color-cancel-bg: #fff;
  --color-error: #c00;
  --color-success: #2a7a2a;
}

@media (prefers-color-scheme: dark) {
  :root {
    --color-bg: #1a1a1a;
    --color-bg-subtle: #2a2a2a;
    --color-text: #e0e0e0;
    --color-text-muted: #aaa;
    --color-text-subtle: #a9a9a9;
    --color-text-faint: #666;
    --color-border: #444;
    --color-btn-bg: #e0e0e0;
    --color-btn-text: #1a1a1a;
    --color-btn-hover: #bbb;
    --color-btn-disabled: #555;
    --color-cancel-bg: #1a1a1a;
    --color-error: #f66;
    --color-success: #4caf50;
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  color-scheme: light dark;
  background: var(--color-bg);
  color: var(--color-text);
  font-size: 1rem;
  font-family:
    Inter, Roboto, "Helvetica Neue", "Arial Nova", "Nimbus Sans", Arial,
    sans-serif;
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 1.5rem;
  height: 100vh;
  margin: 0;
  padding: 1.5rem;
}

p {
  line-height: 1.6;
}

aside h1 {
  font-size: 1.25rem;
  margin: 0;
}

aside {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

main {
  display: grid;
  grid-template-rows: minmax(0, 1fr) 6em auto;
  gap: 0.75rem;
  min-height: 0;
  overflow: hidden;
}

label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 1rem;
}

label small {
  color: var(--color-text-faint);
}

details {
  font-size: 1rem;
}
details summary {
  cursor: pointer;
  color: var(--color-text-muted);
}
details label {
  margin-top: 0.5rem;
}

aside p {
  font-size: 0.875rem;
  color: var(--color-text-subtle);
  margin: 0;
}
label small.hint {
  color: var(--color-success);
}

input,
button {
  width: 100%;
  padding: 0.5rem;
  font-size: 1rem;
  border: 1px solid var(--color-border);
  border-radius: 4px;
}

.input-wrap {
  position: relative;
  display: flex;
}

.input-wrap input {
  flex: 1;
  padding-right: 2.25rem;
}

#toggle-key {
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  width: 2.25rem;
  padding: 0;
  background: none;
  border: none;
  color: var(--color-text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

#toggle-key:hover { color: var(--color-text); }

#toggle-key .icon-eye-off { display: none; }
#toggle-key.showing .icon-eye { display: none; }
#toggle-key.showing .icon-eye-off { display: block; }

button {
  background: var(--color-btn-bg);
  color: var(--color-btn-text);
  border-color: var(--color-btn-bg);
  cursor: pointer;
}

#cancel {
  background: var(--color-cancel-bg);
  color: var(--color-error);
  border-color: var(--color-error);
}

button:hover {
  background: var(--color-btn-hover);
}
button:disabled {
  background: var(--color-btn-disabled);
  border-color: var(--color-btn-disabled);
  cursor: default;
}

#status {
  font-size: 0.875rem;
  color: var(--color-text-muted);
}
#status.error {
  color: var(--color-error);
  font-weight: bold;
}

#status.captioning::before {
  content: "";
  display: inline-block;
  width: 0.7em;
  height: 0.7em;
  border: 2px solid var(--color-border);
  border-top-color: var(--color-text);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin-right: 0.4em;
  vertical-align: middle;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

#drop-zone {
  position: relative;
  border: 2px dashed var(--color-border);
  border-radius: 4px;
  min-height: 0;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

#drop-zone.drag-over {
  border-color: var(--color-text);
  background: var(--color-bg-subtle);
}

#drop-zone.has-image {
  border-color: transparent;
}

#drop-zone.has-image.drag-over {
  border-color: var(--color-text);
}

#drop-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  color: var(--color-text-faint);
  pointer-events: none;
  user-select: none;
}

#drop-placeholder p {
  margin: 0;
  font-size: 0.875rem;
}

#drop-placeholder small {
  font-size: 0.75rem;
  color: var(--color-text-faint);
}

#drop-zone.has-image #drop-placeholder {
  display: none;
}

#drop-zone.has-image.drag-over #drop-placeholder {
  display: flex;
  position: relative;
  z-index: 1;
}

img#preview {
  position: absolute;
  inset: 0;
  display: none;
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: top left;
  border-radius: 4px;
}

img#preview[src]:not([src=""]) {
  display: block;
}

#drop-zone.drag-over img#preview {
  opacity: 0.25;
}

pre#out {
  white-space: pre-wrap;
  background: var(--color-bg-subtle);
  padding: 0.75rem;
  border-radius: 4px;
  margin: 0;
  font-size: 1rem;
  overflow-y: auto;
  min-height: 0;
}

#actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

#copy {
  width: auto;
  padding: 0.25rem 0.75rem;
  font-size: 0.875rem;
}

a#dl:not([href]) { display: none; }

.label-row {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

#model-help {
  width: auto;
  align-self: flex-start;
  padding: 0 0.4em;
  font-size: 0.75rem;
  line-height: 1.4;
  background: none;
  color: var(--color-text-muted);
  border-color: var(--color-border);
}

#model-help:hover { background: var(--color-bg-subtle); }

dialog {
  background: var(--color-bg);
  color: var(--color-text);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  padding: 1.5rem;
  max-width: 480px;
  width: 90%;
}

dialog::backdrop { background: rgba(0 0 0 / 0.4); }

dialog h3 { margin: 0 0 0.75rem; }

dialog p { font-size: 1rem; margin: 0.5rem 0; }

dialog table {
  width: 100%;
  border-collapse: collapse;
  font-size: 1rem;
  margin: 0.75rem 0;
}

dialog th, dialog td {
  text-align: left;
  padding: 0.35rem 0.5rem;
  border-bottom: 1px solid var(--color-border);
}

dialog th { color: var(--color-text-muted); font-weight: 600; }

dialog code {
  font-size: 0.9em;
  background: var(--color-bg-subtle);
  padding: 0.1em 0.3em;
  border-radius: 3px;
}

dialog button {
  margin-top: 1rem;
  width: auto;
  padding: 0.4rem 1rem;
}
