:root {
  color-scheme: dark;
  --bg: #0e0d0b;
  --text: #f4eee4;
  --muted: #cbbfae;
  --line: #2e2a22;
  --card: #17150f;
  --field: #100e0b;
  --accent: #e6ff63;
  --accent-fg: #17150f;
  --danger: #ffb4a8;
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.28);
  font-family: "Iowan Old Style", Palatino, "Palatino Linotype", Georgia, serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html[data-boot="public"] #studio { display: none; }
html, body { margin: 0; min-height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
}
body[data-view="studio"] {
  background:
    radial-gradient(880px 420px at 88% -12%, rgba(230, 255, 99, 0.09), transparent 58%),
    radial-gradient(640px 360px at -8% 8%, rgba(255, 176, 120, 0.06), transparent 52%),
    var(--bg);
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, p { margin: 0; }
:focus { outline: none; }
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.skip {
  position: absolute;
  left: 12px;
  top: -40px;
  background: var(--accent);
  color: var(--accent-fg);
  padding: 8px 12px;
  border-radius: 8px;
  z-index: 5;
}
.skip:focus { top: 12px; }

#studio { max-width: 1120px; margin: 0 auto; padding: 28px 28px 64px; }
.top {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 16px;
  margin-bottom: 18px;
}
.mark {
  font-size: 40px;
  line-height: 0.95;
  letter-spacing: -0.03em;
}
.mark span { font-style: italic; font-weight: 560; }
.tag { color: var(--muted); margin-top: 6px; font-family: ui-sans-serif, system-ui, sans-serif; font-size: 15px; }
.top-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }

.btn {
  appearance: none;
  border: 0;
  background: var(--accent);
  color: var(--accent-fg);
  border-radius: 999px;
  min-height: 44px;
  padding: 0 16px;
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: 14px;
  font-weight: 650;
  letter-spacing: 0.01em;
}
.btn.ghost {
  background: transparent;
  color: var(--text);
  box-shadow: inset 0 0 0 1px var(--line);
}
.btn.danger { color: var(--danger); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.status, .banner, .hint, .count, .row-error, .empty-links, .leave-url, .tag, .credit, legend, label, .voices, .handle, .bio, .link {
  font-family: ui-sans-serif, system-ui, sans-serif;
}
.status { min-height: 1.2em; color: var(--muted); font-size: 14px; margin-bottom: 10px; }
.banner {
  background: #2a1714;
  color: var(--danger);
  border-radius: 12px;
  padding: 10px 12px;
  margin-bottom: 12px;
  font-size: 14px;
}
.tabs { display: none; gap: 8px; margin-bottom: 14px; }
.tab {
  flex: 1;
  min-height: 44px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: transparent;
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: 14px;
}
.tab[aria-selected="true"] { background: var(--text); color: #17150f; border-color: var(--text); }

.layout { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 28px; align-items: start; }
#editor { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
h2 { font-size: 22px; font-weight: 560; letter-spacing: -0.02em; }
.pair, .add-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.add-row { grid-template-columns: minmax(0, 0.8fr) minmax(0, 1.2fr) auto; align-items: end; }
label, legend {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}
fieldset { border: 0; margin: 0; padding: 0; }
.lab { display: flex; gap: 8px; align-items: baseline; }
.opt { text-transform: none; letter-spacing: 0; font-size: 12px; }
input, textarea {
  text-transform: none;
  letter-spacing: 0;
  font-size: 16px;
  background: var(--field);
  border: 1px solid #3a342b;
  border-radius: 12px;
  padding: 10px 12px;
  width: 100%;
}
textarea { resize: vertical; min-height: 76px; }
.voices { display: flex; gap: 8px; flex-wrap: wrap; text-transform: none; letter-spacing: 0; }
.voices label {
  flex-direction: row;
  align-items: center;
  gap: 6px;
  text-transform: none;
  letter-spacing: 0;
  font-size: 14px;
  color: var(--text);
  background: var(--field);
  border: 1px solid #3a342b;
  border-radius: 999px;
  padding: 8px 12px;
  min-height: 44px;
}
.hint, .count, .empty-links, .row-error { font-size: 13px; color: var(--muted); }
.row-error:empty { display: none; }
.row-error { color: var(--danger); }
.count { text-align: right; margin-top: -6px; }
.footer-row { display: flex; justify-content: space-between; gap: 12px; align-items: center; }
.footer-row .hint { max-width: 46ch; }

.link-row {
  display: grid;
  grid-template-columns: minmax(0, 0.8fr) minmax(0, 1.2fr) auto;
  gap: 8px;
  align-items: end;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
}
.link-actions { display: flex; gap: 4px; }
.icon-btn {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: transparent;
  font-size: 16px;
}
.icon-btn:disabled { opacity: 0.35; cursor: not-allowed; }
.swatches { display: flex; gap: 12px; }
.swatch {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.2);
  padding: 0;
}
.swatch[data-theme="ink"] { background: radial-gradient(circle at 35% 30%, #3c362c, #14120e 62%); border-color: #6d6456; }
.swatch[data-theme="paper"] { background: #f3eee4; }
.swatch[data-theme="tide"] { background: #0c3237; }
.swatch[data-theme="dusk"] { background: #3a2248; }
.swatch[aria-checked="true"] { box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--accent); }

.stage {
  position: sticky;
  top: 16px;
  background: #090807;
  border: 1px solid #2a261f;
  border-radius: 36px;
  padding: 12px;
  box-shadow: var(--shadow);
}
.page {
  --bg: #14120e;
  --fg: #f6f0e6;
  --soft: #b7ad9e;
  --line: #3a342a;
  --chip: #1e1b16;
  --mark: #e6ff63;
  --mark-fg: #17150f;
  background: var(--bg);
  color: var(--fg);
  border-radius: 26px;
  min-height: 560px;
  padding: 32px 22px 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.page[data-theme="paper"] {
  --bg: #f3eee4; --fg: #1c1914; --soft: #5c554b; --line: #ddd4c6; --chip: #fffaf3; --mark: #c4532a; --mark-fg: #fffaf3;
}
.page[data-theme="tide"] {
  --bg: #062428; --fg: #e7f7f4; --soft: #a3cdc7; --line: #1c484e; --chip: #0c3237; --mark: #7ee0c8; --mark-fg: #062428;
}
.page[data-theme="dusk"] {
  --bg: #1a1028; --fg: #f7edff; --soft: #d0bce2; --line: #3d2c55; --chip: #27183a; --mark: #ffb0d9; --mark-fg: #1a1028;
}
.mono {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--mark);
  color: var(--mark-fg);
  font-size: 22px;
  letter-spacing: -0.03em;
  margin-bottom: 8px;
}
.page h1, .page .bio, .page .handle, .leave-host, .link-label { overflow-wrap: anywhere; }
.page h1 { font-size: 40px; line-height: 0.95; letter-spacing: -0.03em; }
.page .ghost { color: var(--soft); }
.handle { color: var(--soft); font-size: 14px; }
.bio { font-size: 16px; line-height: 1.45; margin: 8px 0 16px; }
.links { display: flex; flex-direction: column; gap: 10px; margin-top: 18px; }
.stage .links { margin-top: auto; }
.links-empty {
  border: 1px dashed var(--line);
  border-radius: 14px;
  color: var(--soft);
  padding: 18px 14px;
  text-align: center;
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: 14px;
}
a.link {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  color: var(--fg);
  background: var(--chip);
  border: 1px solid var(--line);
  border-radius: 14px;
  min-height: 52px;
  min-width: 0;
  padding: 12px 14px;
  font-size: 15px;
  font-weight: 620;
}
.link-label { min-width: 0; }
a.link:hover { border-color: var(--mark); }
.arrow { color: var(--mark); }

#public { min-height: 100dvh; }
#public .page {
  min-height: 100dvh;
  border-radius: 0;
  max-width: 440px;
  margin: 0 auto;
  padding-top: 48px;
}
body[data-view="public"][data-theme="ink"] { background: #14120e; }
body[data-view="public"][data-theme="paper"] { background: #f3eee4; color-scheme: light; }
body[data-view="public"][data-theme="tide"] { background: #062428; }
body[data-view="public"][data-theme="dusk"] { background: #1a1028; }
.credit { margin-top: 22px; text-align: center; }
.credit button {
  background: none;
  border: 0;
  color: var(--soft);
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: 13px;
  min-height: 44px;
  text-decoration: underline;
  text-underline-offset: 3px;
}

dialog {
  border: 0;
  border-radius: 20px;
  padding: 24px;
  background: #17150f;
  color: var(--text);
  width: min(440px, calc(100vw - 32px));
  box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(8, 7, 5, 0.72); }
.kicker {
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
.leave-host { font-size: 32px; letter-spacing: -0.03em; margin: 10px 0; word-break: break-word; }
.leave-url { color: var(--muted); font-size: 13px; word-break: break-all; margin-bottom: 18px; }
.leave-actions { display: flex; justify-content: flex-end; gap: 8px; }

@media (max-width: 860px) {
  #studio { padding: 20px 16px 48px; }
  .top { flex-direction: column; align-items: stretch; }
  .top-actions { justify-content: stretch; }
  .top-actions .btn { flex: 1; }
  .mark { font-size: 34px; }
  .tabs { display: flex; }
  .layout { grid-template-columns: 1fr; }
  body[data-pane="edit"] #stage { display: none; }
  body[data-pane="preview"] #editor { display: none; }
  .pair, .add-row, .link-row { grid-template-columns: 1fr; }
  .footer-row { flex-direction: column; align-items: stretch; }
  .stage { position: static; }
  .page { min-height: 70dvh; }
  .page h1 { font-size: 36px; }
}

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