:root {
  color-scheme: light;
  --paper: #f3efe6;
  --paper-deep: #e7dfd0;
  --ink: #201d19;
  --muted: #716a61;
  --line: #cfc4b2;
  --wine: #5d1f2d;
  --wine-dark: #321018;
  --gold: #aa7b34;
  --white: #fffdf8;
  --success: #285f43;
  --danger: #a2323a;
  font-family: Georgia, "Times New Roman", serif;
}

* { box-sizing: border-box; }
html { background: var(--paper); }
body { margin: 0; min-height: 100vh; color: var(--ink); background: var(--paper); }
a { color: inherit; }
button, input, select, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 3px solid #277da1; outline-offset: 3px; }
[hidden] { display: none !important; }

.skip-link { position: fixed; left: 1rem; top: -5rem; z-index: 100; padding: .8rem 1rem; background: var(--white); }
.skip-link:focus { top: 1rem; }
.eyebrow { margin: 0 0 .7rem; color: var(--wine); font: 700 .72rem/1.2 Arial, sans-serif; letter-spacing: .16em; text-transform: uppercase; }

.entry-shell { background: var(--wine-dark); }
.entry-main { min-height: 100vh; display: grid; place-items: center; padding: 1.25rem; background: radial-gradient(circle at 20% 15%, #763348 0, transparent 34%), linear-gradient(135deg, var(--wine-dark), #160c0e 72%); }
.entry-card { width: min(100%, 31rem); padding: clamp(1.5rem, 5vw, 3.4rem); background: var(--paper); box-shadow: 0 2rem 6rem #0008; border-top: .35rem solid var(--gold); }
.entry-card-wide { width: min(100%, 46rem); }
.entry-card h1 { margin: 0; font-size: clamp(2rem, 6vw, 3.7rem); font-weight: 500; line-height: .96; letter-spacing: -.045em; }
.entry-card > p:not(.eyebrow) { color: var(--muted); line-height: 1.55; }
.entry-brand { display: flex; align-items: center; gap: .7rem; margin-bottom: 3rem; font: 700 1rem Arial, sans-serif; }
.brand-seal { display: grid; place-items: center; width: 2.5rem; aspect-ratio: 1; border-radius: 50%; color: var(--paper); background: var(--wine); font: 700 .72rem Arial, sans-serif; letter-spacing: .08em; }
.entry-footnote { display: block; margin-top: 2rem; color: var(--muted); line-height: 1.5; }

.stack-form { display: grid; gap: 1rem; margin-top: 2rem; }
.compact-form { grid-template-columns: 1fr auto; align-items: end; }
label { display: grid; gap: .45rem; color: var(--muted); font: 700 .75rem/1.3 Arial, sans-serif; letter-spacing: .06em; text-transform: uppercase; }
input, select, textarea { width: 100%; border: 1px solid var(--line); border-radius: 0; padding: .82rem .9rem; color: var(--ink); background: var(--white); font: 400 1rem/1.3 Arial, sans-serif; }
textarea { min-height: 6.5rem; resize: vertical; }
input:disabled { color: var(--muted); background: var(--paper-deep); }
.code-input { font: 700 1.2rem/1 monospace; letter-spacing: .12em; }
.primary-button, .secondary-button, .danger-button, .inline-search button, .search-results button, .install-button, .preview-link { display: inline-flex; align-items: center; justify-content: center; min-height: 2.8rem; border: 0; padding: .78rem 1.1rem; text-decoration: none; cursor: pointer; font: 700 .78rem Arial, sans-serif; letter-spacing: .04em; }
.primary-button { color: #fff; background: var(--wine); }
.secondary-button { color: var(--wine); border: 1px solid var(--wine); background: transparent; }
.danger-button { color: #fff; background: var(--danger); }
.secret-panel { display: grid; grid-template-columns: 7rem 1fr; gap: .8rem; margin: 2rem 0; padding: 1.2rem; background: var(--white); border-left: .3rem solid var(--gold); }
.secret-panel > span { color: var(--muted); font: 700 .72rem Arial, sans-serif; text-transform: uppercase; }
.secret-panel details { grid-column: 1 / -1; }
.break-code { display: block; margin-top: .8rem; overflow-wrap: anywhere; }
.recovery-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: .7rem 2rem; margin: 2rem 0; padding-left: 2rem; }
.workspace-list { display: grid; gap: .7rem; margin-top: 2rem; }
.workspace-list button { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 1rem; border: 1px solid var(--line); text-align: left; background: var(--white); cursor: pointer; }
.workspace-list span { display: grid; gap: .2rem; }
.workspace-list small { color: var(--muted); }
.workspace-list em { color: var(--wine); font: 700 .7rem Arial, sans-serif; text-transform: uppercase; }

.workbench-shell { display: grid; grid-template-columns: 18rem 1fr; }
.ledger-rail { position: fixed; inset: 0 auto 0 0; width: 18rem; display: flex; flex-direction: column; padding: 1.4rem; color: var(--paper); background: var(--wine-dark); z-index: 20; }
.brand { display: flex; align-items: center; gap: .75rem; text-decoration: none; }
.brand .brand-seal { color: var(--wine-dark); background: var(--gold); }
.brand > span:last-child, .tenant-marker, .account-link { display: grid; }
.brand small, .tenant-marker span, .tenant-marker small, .account-link small { color: #d7c9bc; font: .7rem Arial, sans-serif; }
.tenant-marker { gap: .25rem; margin: 2.5rem -.2rem 1rem; padding: 1.2rem; border: 1px solid #ffffff24; }
.tenant-marker span { text-transform: uppercase; letter-spacing: .12em; }
.ledger-nav { display: grid; }
.ledger-nav a { display: flex; gap: 1rem; padding: .9rem .5rem; border-bottom: 1px solid #ffffff1c; text-decoration: none; font: .9rem Arial, sans-serif; }
.ledger-nav a span { color: var(--gold); font-size: .7rem; }
.ledger-nav a[aria-current="page"] { color: #fff; background: #ffffff0d; }
.account-link { gap: .2rem; margin-top: auto; padding: 1rem 0 0; border-top: 1px solid #ffffff24; text-decoration: none; }
.workbench-main { grid-column: 2; min-width: 0; min-height: 100vh; }
.topbar { height: 5.2rem; display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 0 clamp(1rem, 4vw, 3rem); border-bottom: 1px solid var(--line); background: #f3efe6e8; backdrop-filter: blur(12px); }
.topbar > div:first-of-type { display: grid; }
.topbar > div:first-of-type span { color: var(--muted); font: .68rem Arial, sans-serif; text-transform: uppercase; letter-spacing: .12em; }
.topbar-actions { display: flex; gap: .5rem; }
.install-button { border: 1px solid var(--line); color: var(--ink); background: transparent; }
.preview-link { color: #fff; background: var(--wine); }
.rail-toggle { display: none; border: 0; background: transparent; }
.rail-toggle span { display: block; width: 1.5rem; height: 2px; margin: .3rem; background: var(--ink); }

.page-intro { display: flex; justify-content: space-between; align-items: end; gap: 2rem; padding: clamp(2rem, 6vw, 5rem) clamp(1rem, 5vw, 4.5rem) 2.5rem; }
.page-intro h1 { margin: 0; font-size: clamp(2.7rem, 7vw, 5.5rem); font-weight: 500; line-height: .9; letter-spacing: -.055em; }
.page-intro p:last-child { max-width: 43rem; color: var(--muted); line-height: 1.55; }
.role-chip, .status-pill { padding: .45rem .65rem; border: 1px solid var(--line); color: var(--wine); font: 700 .67rem Arial, sans-serif; text-transform: uppercase; white-space: nowrap; }
.metric-grid { display: grid; grid-template-columns: repeat(4, 1fr); margin: 0 clamp(1rem, 5vw, 4.5rem); border: 1px solid var(--line); }
.metric-grid article { display: grid; gap: .6rem; padding: 1.3rem; border-right: 1px solid var(--line); }
.metric-grid article:last-child { border: 0; }
.metric-grid span { color: var(--muted); font: .7rem Arial, sans-serif; text-transform: uppercase; }
.metric-grid strong { font-size: 3rem; font-weight: 500; }
.metric-grid a { color: var(--wine); font: 700 .75rem Arial, sans-serif; }
.workbench-note { display: grid; grid-template-columns: 7rem 1fr; gap: 1.5rem; margin: 3rem clamp(1rem, 5vw, 4.5rem); padding: 2rem 0; border-top: 1px solid var(--ink); border-bottom: 1px solid var(--line); }
.note-number { color: var(--wine); font: 700 .7rem Arial, sans-serif; text-transform: uppercase; }
.workbench-note h2 { margin-top: 0; }

.notice, .editor-sheet, .catalog-search, .record-list, .creation-panel, .account-card { margin-left: clamp(1rem, 5vw, 4.5rem); margin-right: clamp(1rem, 5vw, 4.5rem); }
.notice { margin-bottom: 1rem; padding: 1rem; border-left: .3rem solid; background: var(--white); }
.notice p { margin: 0; }
.notice-error { border-color: var(--danger); }
.notice-success { border-color: var(--success); }
.editor-sheet, .account-card { padding: clamp(1rem, 4vw, 2.5rem); border: 1px solid var(--line); background: var(--white); }
.editor-sheet fieldset { margin: 0 0 2rem; padding: 0; border: 0; }
.editor-sheet legend { margin-bottom: 1rem; font-size: 1.4rem; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
.wide-field { grid-column: 1 / -1; }
.theme-options { display: grid; grid-template-columns: repeat(3, 1fr); gap: .7rem; }
.theme-options label { cursor: pointer; }
.theme-options input { position: absolute; opacity: 0; pointer-events: none; }
.theme-options span { display: grid; gap: .3rem; padding: 1rem; border: 1px solid var(--line); color: var(--ink); text-transform: none; }
.theme-options input:checked + span { border-color: var(--wine); box-shadow: inset 0 0 0 2px var(--wine); }
.theme-options small { color: var(--muted); }
.permission-note, .empty-note { padding: 1rem; color: var(--muted); background: var(--paper-deep); }

.catalog-search { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; margin-bottom: 2rem; padding: 1.4rem; border-top: .25rem solid var(--gold); background: var(--white); }
.catalog-search h2 { margin: 0; }
.catalog-search p { color: var(--muted); }
.inline-search { display: flex; align-items: end; gap: .5rem; }
.inline-search label { flex: 1; }
.inline-search button, .search-results button { color: #fff; background: var(--wine); }
.search-results { grid-column: 1 / -1; display: grid; }
.search-results form { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: .8rem 0; border-top: 1px solid var(--line); }
.search-results span { display: grid; }
.search-results small { color: var(--muted); }
.record-list { display: grid; gap: .7rem; padding-bottom: 4rem; }
.record-card, .creation-panel { border: 1px solid var(--line); background: var(--white); }
.record-card > summary, .creation-panel > summary { display: flex; align-items: center; gap: 1rem; padding: 1rem; cursor: pointer; list-style: none; }
.record-card > summary::-webkit-details-marker, .creation-panel > summary::-webkit-details-marker { display: none; }
.record-card > summary::after, .creation-panel > summary::after { content: "+"; margin-left: auto; color: var(--wine); font-size: 1.5rem; }
.record-card[open] > summary::after, .creation-panel[open] > summary::after { content: "−"; }
.record-index { color: var(--gold); font: .75rem monospace; }
.record-heading { display: grid; flex: 1; }
.record-heading small { color: var(--muted); }
.status-live { color: var(--success); }
.status-archived { color: var(--muted); }
.record-form { padding: 1.2rem; border-top: 1px solid var(--line); background: #faf7f0; }
.record-form .primary-button { margin-top: 1rem; }
.creation-panel { margin-bottom: .8rem; }
.split-editor { display: grid; grid-template-columns: minmax(0, 2fr) minmax(16rem, 1fr); border-top: 1px solid var(--line); }
.split-editor .record-form { border: 0; }
.pairing-form { padding: 1.2rem; border-left: 1px solid var(--line); }
.pairing-form h3 { margin-top: 0; }
.pairing-form p { color: var(--muted); }
.check-list { display: grid; max-height: 22rem; overflow: auto; margin-bottom: 1rem; border: 1px solid var(--line); }
.check-list label { display: flex; align-items: center; gap: .7rem; padding: .65rem; border-bottom: 1px solid var(--line); color: var(--ink); text-transform: none; }
.check-list input { width: auto; }
.account-card { max-width: 48rem; }
.account-card dl { margin: 0 0 2rem; }
.account-card dl div { display: grid; grid-template-columns: 10rem 1fr; padding: .8rem 0; border-bottom: 1px solid var(--line); }
.account-card dt { color: var(--muted); font: .7rem Arial, sans-serif; text-transform: uppercase; }
.account-card dd { margin: 0; }
.error-stage { display: grid; justify-items: start; gap: 1rem; max-width: 42rem; padding: 8vw; }
.error-stage > strong { color: var(--wine); font-size: clamp(5rem, 16vw, 12rem); font-weight: 500; line-height: .7; }
.error-stage h1 { margin: 0; font-size: 2rem; }

@media (max-width: 980px) {
  .workbench-shell { display: block; }
  .ledger-rail { transform: translateX(-100%); transition: transform .22s ease; box-shadow: 1rem 0 3rem #0004; }
  .rail-open .ledger-rail { transform: translateX(0); }
  .workbench-main { min-height: 100vh; }
  .rail-toggle { display: block; }
  .metric-grid { grid-template-columns: repeat(2, 1fr); }
  .metric-grid article:nth-child(2) { border-right: 0; }
  .metric-grid article:nth-child(-n+2) { border-bottom: 1px solid var(--line); }
  .split-editor { grid-template-columns: 1fr; }
  .pairing-form { border-left: 0; border-top: 1px solid var(--line); }
}

@media (max-width: 620px) {
  .topbar { height: auto; min-height: 4.6rem; padding: .7rem 1rem; }
  .topbar > div:first-of-type span { display: none; }
  .install-button { display: none !important; }
  .preview-link { padding: .6rem .7rem; font-size: .68rem; }
  .page-intro { align-items: start; flex-direction: column; }
  .form-grid, .theme-options, .catalog-search, .recovery-grid { grid-template-columns: 1fr; }
  .inline-search { align-items: stretch; flex-direction: column; }
  .metric-grid { grid-template-columns: 1fr; }
  .metric-grid article { border-right: 0; border-bottom: 1px solid var(--line); }
  .metric-grid article:nth-child(3) { border-bottom: 1px solid var(--line); }
  .workbench-note { grid-template-columns: 1fr; }
  .record-card > summary { align-items: start; flex-wrap: wrap; }
  .status-pill { margin-left: 2rem; }
  .compact-form { grid-template-columns: 1fr; }
  .secret-panel { grid-template-columns: 1fr; }
  .account-card dl div { grid-template-columns: 1fr; gap: .3rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}
