:root {
  --bg: #ede8e0;
  --bg-2: #e5e0d7;
  --bg-3: #f4efe7;
  --fg: #1a1a1a;
  --fg-muted: #5a5a5a;
  --fg-dim: #8b8b8b;
  --border: #d4cfc7;
  --border-soft: #e2ddd4;
  --terminal-bg: #1a1a1a;
  --terminal-fg: #ede8e0;
  --green: #5a9a6b;
  --red: #9a4d42;
  --blue: #2e6f8e;
  --purple: #7a4d8e;
  --transition: 0.22s ease;
  --font-sans: 'Inter', ui-sans-serif, system-ui, -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  --page-pad: clamp(18px, 4vw, 48px);
  --nav-h: clamp(58px, 6vw, 68px);
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--fg); font-family: var(--font-sans); -webkit-font-smoothing: antialiased; }
body { min-height: 100dvh; }
button, input, textarea, select { font: inherit; }
button { border: 1px solid var(--fg); background: var(--fg); color: var(--bg); min-height: 42px; padding: 0 15px; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 8px; font-weight: 800; transition: transform var(--transition), background var(--transition), color var(--transition), border-color var(--transition); }
button:hover { transform: translateY(-1px); }
button.secondary, .link-button { background: transparent; color: var(--fg); border-color: var(--border); }
button.secondary:hover, .link-button:hover { background: var(--bg-2); }
button.danger { border-color: var(--red); color: var(--red); background: transparent; }
button.danger:hover { background: rgba(154, 77, 66, 0.1); }
button:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }
input, textarea, select { width: 100%; border: 1px solid var(--border); background: var(--bg-3); color: var(--fg); padding: 0 12px; outline: none; }
input, select { height: 42px; }
textarea { min-height: 108px; padding: 12px; resize: vertical; line-height: 1.55; }
input:focus, textarea:focus, select:focus, [contenteditable]:focus { border-color: var(--fg); box-shadow: 0 0 0 2px rgba(26,26,26,0.08); }
a { color: inherit; }
.muted { color: var(--fg-muted); line-height: 1.55; }
.kicker { font-family: var(--font-mono); font-size: 11px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--fg-dim); }
.stack { display: grid; gap: 12px; }

.auth-shell { min-height: 100dvh; display: grid; place-items: center; padding: var(--page-pad); }
.auth-panel { width: min(100%, 420px); border: 1px solid var(--border); padding: clamp(22px, 5vw, 34px); background: var(--bg); box-shadow: 0 28px 70px -48px rgba(0,0,0,0.42); }
.auth-panel h1 { margin: 0 0 10px; font-size: clamp(44px, 10vw, 72px); line-height: 0.95; letter-spacing: -0.04em; }
.auth-panel .muted { margin: 0 0 24px; }
.auth-panel .link-button { width: 100%; margin-top: 12px; }
.auth-notice { margin: 0 0 16px; border: 1px solid rgba(90, 154, 107, 0.35); background: rgba(90, 154, 107, 0.1); color: var(--green); padding: 10px 12px; font-weight: 800; line-height: 1.4; }

.site-head { height: var(--nav-h); padding: 0 var(--page-pad); display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 20px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: rgba(237,232,224,0.92); backdrop-filter: blur(14px); z-index: 10; }
.site-logo { display: inline-flex; align-items: center; gap: 10px; text-decoration: none; font-weight: 900; letter-spacing: -0.02em; }
.mark { width: 28px; height: 28px; display: block; background: var(--fg); object-fit: contain; padding: 3px; }
.nav-links { display: flex; justify-content: center; gap: 4px; }
.nav-links a { text-decoration: none; color: var(--fg-muted); font-weight: 800; font-size: 14px; padding: 10px 12px; border: 1px solid transparent; }
.nav-links a.active { color: var(--fg); border-color: var(--border); background: var(--bg-2); }
.user-chip { display: flex; align-items: center; gap: 10px; font-family: var(--font-mono); font-size: 12px; color: var(--fg-muted); min-width: 0; }
.user-chip button { width: 36px; min-height: 36px; padding: 0; background: transparent; color: var(--fg); border-color: var(--border); }

.page-shell { width: min(100%, 760px); margin: 0 auto; padding: clamp(24px, 5vw, 48px) var(--page-pad) 80px; }
.title-row { display: flex; align-items: flex-end; justify-content: space-between; gap: 18px; margin-bottom: 24px; }
h1 { margin: 0; font-size: clamp(44px, 11vw, 82px); letter-spacing: -0.055em; line-height: 0.95; }
h2 { margin: 34px 0 14px; font-size: 13px; letter-spacing: 0.14em; text-transform: uppercase; font-family: var(--font-mono); color: var(--fg-dim); }
.title-row p { margin: 10px 0 0; }
.toolbar { display: grid; grid-template-columns: 1fr auto; gap: 12px; margin: 24px 0 10px; }
.search-box { display: flex; align-items: center; gap: 10px; border: 1px solid var(--border); background: var(--bg-3); padding: 0 12px; }
.search-box:focus-within { border-color: var(--fg); }
.search-box input { border: 0; background: transparent; padding: 0; box-shadow: none; outline: 0; }
.search-box input:focus { border: 0; box-shadow: none; outline: 0; }
.search-box i { color: var(--fg-dim); }

.dope-list { display: grid; gap: 10px; }
.dope-card { width: 100%; text-align: left; background: var(--bg); color: var(--fg); border: 1px solid var(--border); padding: 16px 18px; display: grid; grid-template-columns: 1fr auto; gap: 14px; align-items: center; min-height: 72px; transition: border-color var(--transition), box-shadow var(--transition), transform var(--transition); }
.dope-card:hover { border-color: var(--fg); box-shadow: 0 18px 44px -34px rgba(0,0,0,0.5); }
.dope-card h3 { margin: 0 0 7px; font-size: clamp(17px, 3.4vw, 22px); letter-spacing: -0.02em; line-height: 1.2; }
.meta { display: flex; flex-wrap: wrap; gap: 7px; align-items: center; color: var(--fg-muted); font-size: 13px; line-height: 1.4; }
.pill { display: inline-flex; align-items: center; gap: 5px; border: 1px solid var(--border-soft); background: var(--bg-3); padding: 4px 8px; color: var(--fg-muted); font-family: var(--font-mono); font-size: 11px; white-space: nowrap; }
.compact .dope-card { background: var(--bg-2); }
.empty { border: 1px dashed var(--border); padding: 28px; text-align: center; color: var(--fg-muted); }

dialog { border: 0; padding: 0; background: var(--bg); width: min(calc(100% - 24px), 680px); }
dialog::backdrop { background: rgba(26,26,26,0.42); backdrop-filter: blur(4px); }
.modal { position: relative; isolation: isolate; background: var(--bg); border: 1px solid var(--border); padding: 0; max-height: min(88dvh, 820px); overflow: auto; box-shadow: 0 32px 100px -44px rgba(0,0,0,0.55); overscroll-behavior: contain; }
.modal::before { content: ""; position: sticky; top: 0; display: block; height: 0; background: var(--bg); z-index: -1; }
.modal.small { width: min(100%, 480px); }
#filter-dialog .modal { padding: clamp(20px, 5vw, 32px); }
#dope-dialog .modal > .icon-close { display: none; }
#dope-dialog #modal-title[hidden] { display: none; }
.modal h2 { margin-top: 0; color: var(--fg); font-family: var(--font-sans); font-size: clamp(26px, 6vw, 38px); letter-spacing: -0.04em; text-transform: none; }
.icon-close { position: sticky; top: 0; float: right; width: 36px; min-height: 36px; padding: 0; background: var(--bg); border-color: var(--border); color: var(--fg); z-index: 8; }
.modal label { display: grid; gap: 7px; font-weight: 800; font-size: 13px; color: var(--fg-muted); margin-bottom: 14px; }
.editor { min-height: 190px; border: 1px solid var(--border); background: var(--bg-3); padding: 13px; outline: none; line-height: 1.6; overflow-wrap: anywhere; }
.editor:empty::before { content: attr(data-placeholder); color: var(--fg-dim); }
.editor img, .description img { max-width: 100%; display: block; margin: 12px 0; border: 1px solid var(--border); }
.description { line-height: 1.7; color: var(--fg); overflow-wrap: anywhere; }
.description p { margin: 0 0 12px; }
.modal-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 18px; }
.modal-content { padding: clamp(20px, 5vw, 32px); }
.modal-headline { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; margin: 4px 0 14px; }
.modal-headline > div:first-child { display: flex; flex-wrap: wrap; gap: 7px; }
.version-control { flex: 0 0 auto; }
.version-button { min-height: 30px; padding: 0 10px; background: transparent; color: var(--fg); border-color: var(--border); font-family: var(--font-mono); font-size: 11px; }
.version-empty { display: inline-flex; min-height: 30px; align-items: center; color: var(--fg-dim); font-family: var(--font-mono); font-size: 11px; }
.version-picker { margin: 0 0 18px; }
.modal-topbar { position: sticky; top: 0; z-index: 7; width: 100%; padding: 12px clamp(20px, 5vw, 32px); min-height: 64px; display: flex; align-items: center; justify-content: space-between; gap: 16px; background: var(--bg); border-bottom: 1px solid transparent; }
.modal-topbar strong { opacity: 0; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; letter-spacing: -0.01em; }
.modal-topbar.is-visible { border-bottom-color: var(--border); }
.modal-topbar.is-visible strong { opacity: 1; }
.modal-topbar .icon-close { position: static; float: none; flex: 0 0 auto; }
.modal-action-bar { position: sticky; bottom: 0; z-index: 9; width: 100%; display: flex; align-items: center; gap: 10px; padding: 12px clamp(20px, 5vw, 32px); background: var(--bg); border-top: 1px solid var(--border); }
.icon-action { width: 42px; padding: 0; flex: 0 0 auto; }
.action-text { flex: 0 1 auto; white-space: nowrap; }
.primary-wide { min-width: 160px; flex: 1 1 auto; }
.non-cta { background: transparent; color: var(--fg); border-color: var(--border); white-space: nowrap; }
.grid-two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.history, .links { margin: 18px 0 0; padding: 0; list-style: none; display: grid; gap: 8px; color: var(--fg-muted); font-size: 14px; }
.links a { color: var(--blue); overflow-wrap: anywhere; }
.toast { position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%); z-index: 30; background: var(--fg); color: var(--bg); padding: 12px 14px; font-weight: 800; box-shadow: 0 18px 54px -28px rgba(0,0,0,0.6); max-width: calc(100% - 24px); }
.undo { margin-left: 10px; min-height: 30px; padding: 0 10px; border-color: var(--bg); color: var(--bg); background: transparent; }

@media (max-width: 720px) {
  .site-head { grid-template-columns: 1fr auto; height: auto; min-height: var(--nav-h); padding-top: 10px; padding-bottom: 10px; }
  .nav-links { grid-column: 1 / -1; order: 3; justify-content: flex-start; overflow-x: auto; padding-bottom: 2px; }
  .user-chip #user-name { display: none; }
  .title-row { align-items: stretch; flex-direction: column; }
  .title-row button { width: 100%; }
  .toolbar { grid-template-columns: 1fr; }
  .toolbar button { width: 100%; }
  .dope-card { grid-template-columns: 1fr; }
  .dope-card .pill { justify-self: start; }
  .grid-two { grid-template-columns: 1fr; }
  .modal-headline { flex-direction: column; }
  .modal-action-bar { justify-content: stretch; flex-wrap: wrap; }
  .action-text, .primary-wide { flex: 1 1 auto; }
  .non-cta { flex: 1 1 100%; }
}
