:root {
  --bg: #f4efe8;
  --ink: #1c1612;
  --muted: #6e6258;
  --line: #e0d5c8;
  --surface: #fffdf9;
  --accent: #e23d1b;
  --accent-ink: #fff8f4;
  --focus: #9a3412;
  --chip: #f6e3d6;
  --chip-ink: #6d2e16;
  --good: #1f6b3a;
  --danger: #9f1239;
  --shadow: 0 18px 40px rgba(48, 24, 8, 0.08);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12100e;
    --ink: #f4efe6;
    --muted: #b3a496;
    --line: #3a332c;
    --surface: #1c1815;
    --accent: #ff6a45;
    --accent-ink: #2a0d06;
    --focus: #ffc7b0;
    --chip: #3a261c;
    --chip-ink: #ffc7b0;
    --good: #b6e3a8;
    --danger: #ffb4b4;
    --shadow: 0 18px 40px rgba(0, 0, 0, 0.35);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: 1rem;
  line-height: 1.5;
  color: var(--ink);
  background-color: var(--bg);
  background-image:
    radial-gradient(ellipse 80% 50% at 100% -10%, color-mix(in srgb, var(--accent) 22%, transparent), transparent),
    radial-gradient(ellipse 50% 40% at 0% 0%, color-mix(in srgb, var(--accent) 10%, transparent), transparent);
}

::selection {
  background: var(--accent);
  color: var(--accent-ink);
}

:focus { outline: none; }

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 3px;
}

.wrap {
  width: min(40rem, 100%);
  margin: 0 auto;
  padding:
    max(1.5rem, env(safe-area-inset-top))
    max(1rem, env(safe-area-inset-right))
    max(2.5rem, env(safe-area-inset-bottom))
    max(1rem, env(safe-area-inset-left));
}

.mast { margin-bottom: 1.25rem; }

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

.brand img { border-radius: 10px; flex: none; }

.eyebrow {
  margin: 0;
  color: var(--accent);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

h1, h2 {
  font-family: "Iowan Old Style", Palatino, "Palatino Linotype", Georgia, serif;
  font-weight: 600;
  letter-spacing: -0.03em;
}

h1 {
  margin: 0;
  font-size: clamp(2.5rem, 8vw, 3.5rem);
  line-height: 0.95;
}

h2 { margin: 0; font-size: 1.45rem; }

.lede {
  margin: 0.85rem 0 0;
  max-width: 38rem;
  font-size: 1.05rem;
}

.steps {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem 1rem;
  margin: 0.9rem 0 0;
  padding: 0;
  list-style: none;
  counter-reset: step;
  color: var(--muted);
  font-size: 0.92rem;
}

.steps li {
  display: flex;
  gap: 0.4rem;
  align-items: center;
}

.steps li::before {
  counter-increment: step;
  content: counter(step);
  display: grid;
  place-items: center;
  width: 1.35rem;
  height: 1.35rem;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--ink);
  font-size: 0.75rem;
  font-weight: 700;
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 1rem;
  margin-bottom: 0.9rem;
}

label {
  display: block;
  margin-bottom: 0.4rem;
  font-size: 0.85rem;
  font-weight: 650;
}

.row {
  display: flex;
  gap: 0.6rem;
  align-items: stretch;
}

input {
  flex: 1;
  min-width: 0;
  min-height: 44px;
  font: inherit;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.65rem 0.8rem;
}

#composer .row { align-items: flex-end; }

#url {
  display: block;
  flex: 1;
  width: 100%;
  min-width: 0;
  min-height: 44px;
  resize: none;
  field-sizing: content;
  max-height: 8.5rem;
  overflow: auto;
  line-height: 1.4;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font: inherit;
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  font-size: 0.92rem;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.65rem 0.8rem;
}

button {
  min-height: 44px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  border: 0;
  border-radius: 999px;
  padding: 0.65rem 1.05rem;
  background: var(--accent);
  color: var(--accent-ink);
}

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

button.texty {
  display: block;
  width: 100%;
  margin-top: 0.7rem;
  background: transparent;
  color: var(--ink);
  border: 1px dashed var(--line);
}

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

.shrink {
  margin: 0 0 0.35rem;
  color: var(--good);
  font-weight: 700;
  font-size: 0.92rem;
}

.host {
  margin: 0;
  font-weight: 700;
}

.url {
  margin: 0.25rem 0 0.7rem;
  overflow-wrap: anywhere;
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  font-size: 0.84rem;
  color: var(--muted);
}

.result {
  display: flex;
  gap: 0.6rem;
  align-items: flex-start;
  margin: 0.35rem 0 0.75rem;
}

#clean-url {
  flex: 1;
  margin: 0;
  color: var(--ink);
  background: var(--bg);
  border-radius: 12px;
  padding: 0.6rem 0.7rem;
}

.result button { flex: none; }

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

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-bottom: 0.85rem;
}

.chip, .quiet {
  font-size: 0.75rem;
  border-radius: 999px;
  padding: 0.15rem 0.5rem;
}

.chip {
  background: var(--chip);
  color: var(--chip-ink);
}

.quiet { color: var(--muted); padding-left: 0; }

.error {
  margin: 0.55rem 0 0;
  color: var(--danger);
  font-weight: 650;
}

.lib-head {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: baseline;
  margin: 0.4rem 0 0.7rem;
}

#stats {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.vibe {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 0.9rem 1rem;
  margin-bottom: 0.6rem;
}

.vibe-top {
  display: flex;
  justify-content: space-between;
  gap: 0.8rem;
  align-items: baseline;
}

.vibe h3 {
  margin: 0;
  font-size: 1.05rem;
  overflow-wrap: anywhere;
}

.meta {
  margin: 0.2rem 0 0.7rem;
  color: var(--muted);
  font-size: 0.85rem;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.actions button {
  min-height: 40px;
  padding: 0.4rem 0.8rem;
  font-size: 0.9rem;
}

.actions .danger {
  color: var(--danger);
}

.empty, .note {
  color: var(--muted);
}

.empty {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.75rem;
  margin: 0;
  border: 1px dashed var(--line);
  border-radius: 16px;
  padding: 1.1rem 1rem;
}

.empty p { margin: 0; }

.actions button.armed {
  background: var(--danger);
  color: var(--surface);
  border-color: transparent;
}

.note {
  margin: 1rem 0 0;
  font-size: 0.85rem;
}

dialog {
  width: min(32rem, calc(100vw - 2rem));
  max-height: min(36rem, calc(100vh - 2rem));
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 1.25rem 1.2rem 1.1rem;
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow);
}

#leave-title {
  margin: 0.2rem 0 0.7rem;
  font-size: clamp(1.45rem, 4vw, 1.9rem);
  line-height: 1.15;
  overflow-wrap: anywhere;
}

dialog::backdrop { background: rgba(16, 12, 8, 0.62); }

.hint {
  margin: 0 0 0.9rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.dialog-actions { margin-top: 0.2rem; }

.dialog-actions button { flex: 1; }

@media (max-width: 560px) {
  .row, #composer .row, .result, .lib-head, .vibe-top {
    flex-direction: column;
    align-items: stretch;
  }
  .steps { flex-direction: column; align-items: flex-start; gap: 0.35rem; }
  .row button, .result button, .dialog-actions button { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
