:root {
  color-scheme: light;
  --bg: #efeae1;
  --ink: #1d1a16;
  --muted: #5f584e;
  --card: #fffdf9;
  --line: #e3d9c8;
  --gold: #a7843f;
  --gold-soft: #f4e7c8;
  --button: #1c1b19;
  --button-text: #f7f1e4;
  --danger-bg: #f8ece8;
  --danger: #7a2e28;
  --ok: #1f6b45;
  --shadow: 0 16px 40px rgba(40, 32, 18, 0.06);
  --sans: "Avenir Next", "Segoe UI", sans-serif;
  --serif: "Iowan Old Style", Palatino, Georgia, serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #141311;
    --ink: #f3efe6;
    --muted: #b7ad9e;
    --card: #211f1b;
    --line: #3a342c;
    --gold: #d4b36a;
    --gold-soft: #3a3120;
    --button: #f3efe6;
    --button-text: #1c1b19;
    --danger-bg: #3a2422;
    --danger: #f0c2bb;
    --ok: #8dcea9;
    --shadow: 0 16px 40px rgba(0, 0, 0, 0.28);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at top left, rgba(167, 132, 63, 0.16), transparent 28rem),
    var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  line-height: 1.5;
}

button, input, textarea, select { font: inherit; color: inherit; }

.wrap {
  width: min(1120px, calc(100% - 2rem));
  margin-inline: auto;
}

.skip {
  position: absolute;
  left: 1rem;
  top: -4rem;
  background: var(--card);
  color: var(--ink);
  padding: 0.5rem 0.75rem;
  z-index: 3;
}

.skip:focus { top: 1rem; }

.site-header {
  background: #161513;
  color: #f7f1e4;
}

.header-inner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 1.25rem 0;
}

.brand { display: flex; align-items: center; gap: 0.9rem; }

.mark {
  margin: 0;
  width: 3.4rem;
  height: 3.4rem;
  display: grid;
  place-items: center;
  border: 1px solid #d4b36a;
  color: #d4b36a;
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  font-weight: 700;
}

.eyebrow {
  margin: 0;
  color: #d4b36a;
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1, h2, legend { font-family: var(--serif); font-weight: 600; }

h1 { margin: 0; font-size: clamp(1.7rem, 3vw, 2.35rem); line-height: 1.1; }
h2 { margin: 0; font-size: 1.35rem; }

.connection {
  border: 1px solid rgba(247, 241, 228, 0.28);
  background: transparent;
  color: inherit;
  border-radius: 999px;
  padding: 0.45rem 0.8rem;
  cursor: pointer;
  max-width: 18rem;
  text-align: left;
}

.connection[data-state="up"] { border-color: #8dcea9; color: #cfeedd; }
.connection[data-state="down"] { border-color: #e7b1aa; color: #ffd7d1; }

.notice, .review-line {
  background: var(--gold-soft);
  border: 1px solid color-mix(in srgb, var(--gold) 45%, var(--line));
  border-radius: 16px;
}

.notice {
  margin: 1rem 0 0;
  padding: 0.85rem 1rem;
}

.notice strong { margin-right: 0.35rem; }

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 1.25rem;
  align-items: start;
  padding: 1.25rem 0 2rem;
}

.panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 22px;
  box-shadow: var(--shadow);
  padding: 1.1rem;
}

.panel-head, .label-row, .actions, .sample-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.sample-row { justify-content: flex-start; margin: 0.9rem 0 0.2rem; flex-wrap: wrap; }

fieldset {
  border: 0;
  margin: 1rem 0 0;
  padding: 0;
}

legend { padding: 0; margin-bottom: 0.45rem; }

.segment {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.35rem;
  background: color-mix(in srgb, var(--bg) 75%, var(--card));
  padding: 0.3rem;
  border-radius: 14px;
}

.segment label { position: relative; }

.segment input {
  position: absolute;
  opacity: 0;
  inset: 0;
  margin: 0;
}

.segment span {
  display: block;
  text-align: center;
  border-radius: 11px;
  padding: 0.6rem 0.45rem;
  cursor: pointer;
  color: var(--muted);
}

.segment label:has(input:checked) span {
  background: var(--button);
  color: var(--button-text);
}

.segment label:has(input:focus-visible) span {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

.field { margin-top: 1rem; }

label { font-weight: 600; }

textarea, select {
  width: 100%;
  margin-top: 0.35rem;
  border: 1px solid var(--line);
  background: transparent;
  border-radius: 14px;
  padding: 0.75rem 0.8rem;
}

textarea { resize: vertical; min-height: 9rem; line-height: 1.45; }

textarea:focus, select:focus, button:focus-visible, .output:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

.hint, .count, .meta, .site-footer, .review-line { color: var(--muted); }

.hint, .count, .meta { margin: 0.35rem 0 0; font-size: 0.92rem; }

.actions { align-items: center; margin-top: 1rem; flex-wrap: wrap; justify-content: flex-start; }

button {
  border-radius: 999px;
  padding: 0.72rem 1rem;
  cursor: pointer;
}

button:disabled { cursor: not-allowed; opacity: 0.55; }

.primary {
  background: var(--button);
  color: var(--button-text);
  border: 0;
  font-weight: 700;
}

.secondary, .ghost {
  background: transparent;
  border: 1px solid var(--line);
}

.ghost { padding: 0.4rem 0.75rem; }

.output {
  min-height: 18rem;
  margin-top: 0.9rem;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.output[data-empty="true"] { color: var(--muted); }
.output[data-empty="false"] { font-family: var(--serif); font-size: 1.08rem; line-height: 1.55; }

.output.is-streaming::after {
  content: "▍";
  color: var(--gold);
  margin-left: 0.15rem;
}

.error {
  margin-top: 0.9rem;
  background: var(--danger-bg);
  color: var(--danger);
  border-radius: 14px;
  padding: 0.75rem 0.85rem;
}

.review-line { margin: 0.9rem 0 0; padding: 0.7rem 0.85rem; }

.site-footer { padding-bottom: 2rem; font-size: 0.92rem; }

.copy-fallback {
  position: fixed;
  left: -9999px;
  top: 0;
}

[hidden] { display: none !important; }

@media (max-width: 860px) {
  .layout, .segment { grid-template-columns: 1fr; }
  .header-inner { align-items: flex-start; flex-direction: column; }
  .connection { max-width: none; }
}

@media (prefers-reduced-motion: reduce) {
  .output.is-streaming::after { content: ""; }
}

@media print {
  body { background: white; color: black; }
  .site-header, form, .connection, .site-footer, #copy, .notice { display: none; }
  .layout { display: block; }
  .panel { box-shadow: none; border: 0; padding: 0; }
  .output { min-height: 0; }
}
