:root {
  --bg: white;
  --compose-box-bg: hsl(0, 0%, 100%, 0.7);
  --fg: black;
  --my-message-bg: hsl(215, 90%, 50%);
  --my-message-fg: white;
  --response-bg: hsl(0, 0%, 91%);
  --link: hsl(215, 100%, 45%);
  --input-border: hsla(0, 0%, 0%, 20%);
  --input-border-strong: hsla(0, 0%, 0%, 35%);
  --info: hsl(120, 50%, 80%);
  --info-link: hsl(210, 100%, 30%);
  --error-fg: hsl(5, 70%, 50%);
  --code-bg: hsla(0, 0%, 100%, 0.7);
  --code-border: hsla(0, 0%, 0%, 0.15);
  --my-message-code-bg: hsla(0, 0%, 0%, 0.2);
  --my-message-code-border: hsla(0, 0%, 0%, 0.15);
  --file-item-bg: hsla(215, 100%, 97%, 1);
  --file-item-border: hsla(215, 90%, 80%, 1);
  --file-processed-bg: hsla(120, 70%, 90%, 1);

  --chat-max-width: 50em;
  --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.05), 0 2px 12px rgba(0, 0, 0, 0.06);
  --shadow-2: 0 2px 6px rgba(0, 0, 0, 0.08), 0 12px 24px rgba(0, 0, 0, 0.06);

  /* New theme tokens */
  --brand-1: hsl(215, 88%, 56%);
  --brand-2: hsl(265, 85%, 62%);
  --brand-3: hsl(195, 90%, 55%);
  --surface: hsla(0, 0%, 100%, 0.65);
  --surface-strong: hsla(0, 0%, 100%, 0.75);
  --surface-border: hsla(210, 18%, 10%, 0.08);
  --radius: 16px;

  /* Page background (overridable in dark mode) */
  --page-bg: linear-gradient(180deg, hsl(210, 100%, 99%), hsl(210, 100%, 97%));
}

html {
  -webkit-text-size-adjust: 100%; /* Prevent font scaling in landscape while allowing user zoom */
}

body {
  margin: 0;
  font-family: sans-serif;
  line-height: 135%;
  /* Background uses theme variable; dark mode overrides it below */
  background: var(--page-bg);
  color: var(--fg);
  margin-bottom: calc(4em + env(safe-area-inset-bottom));
  max-width: 820px;
  margin: 0 auto;
  padding: 1.2em 1.2em 3em;
}

.container {
  #output {
    white-space: pre-wrap;
    background: var(--compose-box-bg);
    border: 1px solid var(--input-border);
    border-radius: 12px;
    padding: 1em;
    min-height: 120px;
  }

  .app-header {
    margin-top: 0.6em;
    margin-bottom: 1em;
    text-align: center;
  }

  .app-header h1 {
    margin: 0.2em 0 0.1em;
    font-size: 2.1rem;
    line-height: 1.1;
    background: linear-gradient(90deg, var(--brand-1), var(--brand-2));
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
  }

  .subtitle {
    margin: 0;
    opacity: 0.7;
  }

  .card {
    background: var(--surface);
    border: 1px solid var(--surface-border);
    border-radius: var(--radius);
    padding: 1rem;
    box-shadow: var(--shadow-1);
    backdrop-filter: saturate(110%) blur(10px);
    -webkit-backdrop-filter: saturate(110%) blur(10px);
    transition: transform 0.08s ease, box-shadow 0.2s ease;
  }

  .card:hover {
    box-shadow: var(--shadow-2);
  }

  .card + .card {
    margin-top: 1rem;
  }

  .section-title {
    margin: 0 0 0.6rem;
    font-size: 1.05rem;
  }

  max-width: 44em;
  margin: 0 auto;
  padding: 0.7em 1em;
}

#start-view {
  background-color: var(--info);
  padding: 1em;
  border-radius: 1em;
  display: inline-block;
  margin: 1em 0;
  font-size: 1.1em;
}

#start-view a {
  color: var(--info-link);
  text-decoration: underline;
}

#upload-form {
  margin: 0.4em 0 0;
}

input {
  font-size: 16px;
}

br {
  line-height: 200%;
}

a,
a:visited {
  text-decoration: none;
  color: var(--link);
}

a:hover {
  text-decoration: underline;
}

.disclaimer {
  font-size: 0.7em;
  line-height: 130%;
  margin: 0.35em 0;
}

footer {
  margin-top: 10px;
  font-size: 0.7em;
  opacity: 70%;
}

input[type="text"],
textarea {
  font-family: -apple-system, sans-serif;
  line-height: 120%;
  background-color: var(--surface-strong);
  color: var(--fg);
  border: 1px solid var(--surface-border);
  padding: 0.2em 0.5em;
  border-radius: 1em;
  backdrop-filter: blur(6px) saturate(110%);
  -webkit-backdrop-filter: blur(6px) saturate(110%);
}

textarea {
  resize: none;
  height: auto;
}

button {
  background-color: var(--my-message-bg);
  color: var(--my-message-fg);
  border: none;
  padding: 0.5em 0.8em;
  border-radius: 19px;
  font-size: 1em;
  cursor: pointer;
  box-shadow: var(--shadow-1);
}

label.button {
  display: inline-block;
  background-image: linear-gradient(90deg, var(--brand-1), var(--brand-2));
  color: white;
  border: none;
  padding: 0.5em 0.8em;
  border-radius: 19px;
  font-size: 1em;
  cursor: pointer;
  transition: transform 0.04s ease, box-shadow 0.2s ease,
    background-color 0.2s ease;
  box-shadow: var(--shadow-1);
}

label.button.primary {
  background-image: linear-gradient(90deg, var(--brand-3), var(--brand-1));
}

label.button:hover {
  filter: brightness(1.02);
  box-shadow: var(--shadow-2);
}
label.button:active {
  transform: translateY(1px);
}

select {
  font-family: -apple-system, sans-serif;
  line-height: 120%;
  background-color: var(--surface-strong);
  color: var(--fg);
  border: 1px solid var(--surface-border);
  padding: 0.2em 0.5em;
  border-radius: 1em;
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 7'><path fill='%23666666' d='M5 6.8s-.1 0 0 0c-.1 0-.1 0 0 0L1 2.8 2.2 1.6 5 4.4 7.8 1.6 9 2.8z'/></svg>");
  background-repeat: no-repeat;
  background-position: right 0.5em center;
  background-size: 14px;
  padding-right: 2em;
  margin-top: 0.4em;
  font-size: 1em;
}

select:focus {
  outline: none;
  box-shadow: 0 0 0 3px rgba(36, 99, 235, 0.15);
}

.hidden {
  display: none !important;
}

.parallel-control {
  margin: 0.4em 0 0.2em;
}

.slider {
  width: 100%;
  margin-top: 0.5em;
  appearance: none;
  height: 6px;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--brand-1), var(--brand-2));
}

.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: white;
  border: 2px solid hsl(215, 88%, 46%);
  box-shadow: var(--shadow-2);
}

.slider::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: white;
  border: 2px solid hsl(215, 88%, 46%);
}

.segment {
  margin: 1em 0;
}

.file-list {
  margin: 1.5em 0;
  max-height: 300px;
  overflow-y: auto;
  border: 1px solid var(--input-border);
  border-radius: 0.75em;
  padding: 0.6em;
  background: var(--compose-box-bg);
}

.processed-file {
  padding: 0.5em;
  margin: 0.3em 0;
  background-color: var(--file-item-bg);
  border: 1px solid var(--file-item-border);
  border-radius: 0.4em;
  font-size: 0.9em;
  position: relative;
  word-break: break-all;
  transition: background-color 0.2s ease, transform 0.08s ease,
    box-shadow 0.2s ease;
}

.processed-file.done {
  background-color: var(--file-processed-bg);
}

.processed-file.error {
  background-color: hsla(0, 70%, 95%, 1);
  border-color: hsla(0, 70%, 80%, 1);
}

.processed-file:hover {
  box-shadow: var(--shadow-1);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: hsl(215, 20%, 9%);
    --compose-box-bg: hsl(215, 20%, 9%, 0.7);
    --fg: hsl(0, 0%, 95%);
    --my-message-bg: hsl(215, 75%, 48%);
    --my-message-fg: white;
    --response-bg: hsl(215, 15%, 20%);
    --link: hsl(215, 100%, 65%);
    --input-border: hsla(0, 0%, 90%, 40%);
    --info: hsl(130, 30%, 25%);
    --info-link: hsl(220, 100%, 85%);
    --error-fg: hsl(5, 70%, 60%);
    --code-bg: hsla(0, 0%, 0%, 0.25);
    --code-border: hsla(0, 0%, 0%, 0.15);
    --my-message-code-bg: hsla(0, 0%, 0%, 0.25);
    --my-message-code-border: hsla(0, 0%, 0%, 0.15);
    --file-item-bg: hsla(215, 30%, 25%, 1);
    --file-item-border: hsla(215, 30%, 35%, 1);
    --file-processed-bg: hsla(120, 30%, 25%, 1);
    --file-error-bg: hsla(0, 30%, 25%, 1);
    --file-error-border: hsla(0, 50%, 35%, 1);

    /* Dark surfaces and accents */
    --surface: hsla(215, 30%, 18%, 0.55);
    --surface-strong: hsla(215, 30%, 18%, 0.75);
    --surface-border: hsla(0, 0%, 100%, 0.08);
    --brand-1: hsl(215, 85%, 70%);
    --brand-2: hsl(265, 80%, 75%);
    --brand-3: hsl(195, 85%, 70%);

    /* Subtle dark background without light blobs at the bottom */
    --page-bg: radial-gradient(
        800px 420px at 100% -10%,
        hsla(265, 70%, 25%, 0.22),
        transparent 60%
      ),
      linear-gradient(180deg, hsl(215, 22%, 12%), hsl(215, 20%, 9%));
  }

  * {
    color-scheme: dark;
  }

  :root {
    --input-border-strong: hsla(0, 0%, 90%, 40%);
  }

  .processed-file.error {
    background-color: var(--file-error-bg);
    border-color: var(--file-error-border);
  }
}

/* New layout helpers */
.form {
  display: grid;
  gap: 0.8rem;
}
.form-row {
  display: grid;
  gap: 0.35rem;
}
.form-label {
  font-size: 0.9rem;
  opacity: 0.8;
}
.buttons-row {
  align-items: center;
  grid-template-columns: auto auto auto;
  gap: 0.6rem;
  text-align: center;
}
.or-text {
  opacity: 0.6;
  font-size: 0.9rem;
}
.label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.badge {
  display: inline-block;
  padding: 0.15em 0.6em;
  border-radius: 999px;
  background: linear-gradient(90deg, hsl(215, 15%, 92%), hsl(215, 15%, 86%));
  color: hsl(215, 30%, 20%);
  font-weight: 600;
  font-size: 0.85rem;
}

@media (prefers-color-scheme: dark) {
  .badge {
    background: linear-gradient(90deg, hsl(215, 15%, 26%), hsl(215, 15%, 30%));
    color: hsl(0, 0%, 98%);
  }
}

.output-card #output {
  margin-top: 0.4rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, "Courier New",
    monospace;
  background: var(--surface-strong);
  border: 1px solid var(--surface-border);
  border-radius: calc(var(--radius) - 4px);
  min-height: 140px;
}
