:root {
  --ink: #07130f;
  --ink-soft: #12251e;
  --paper: #f0eee5;
  --surface: #fffef8;
  --lime: #b8ff48;
  --mint: #64dc9a;
  --violet: #b998ff;
  --red: #d94d4d;
  --line: rgba(7, 19, 15, .15);
  --muted: rgba(7, 19, 15, .62);
  --shadow: 0 28px 80px rgba(7, 19, 15, .14);
  --mono: "Cascadia Code", "SFMono-Regular", Consolas, monospace;
  --sans: Inter, Manrope, "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html { min-height: 100%; background: var(--paper); }

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(rgba(7, 19, 15, .035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(7, 19, 15, .035) 1px, transparent 1px),
    var(--paper);
  background-size: 32px 32px;
  font-family: var(--sans);
}

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

.skip-link {
  position: fixed;
  top: 10px;
  left: 10px;
  z-index: 100;
  padding: 10px 14px;
  color: var(--surface);
  background: var(--ink);
  transform: translateY(-160%);
}
.skip-link:focus { transform: translateY(0); }

.site-header {
  min-height: 88px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 16px clamp(20px, 5vw, 76px);
  color: var(--surface);
  background: var(--ink);
  border-bottom: 1px solid rgba(255, 255, 255, .12);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 13px;
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  color: var(--ink);
  background: var(--lime);
  border-radius: 13px;
  font: 800 17px/1 var(--mono);
}

.brand-copy { display: grid; gap: 4px; }
.brand-copy strong { font: 700 12px/1 var(--mono); letter-spacing: .08em; }
.brand-copy small { color: rgba(255,255,255,.6); font-size: 11px; }

.secure-chip, .audit-badge, .count-chip {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 0 11px;
  border: 1px solid rgba(255,255,255,.16);
  border-radius: 999px;
  font: 700 9px/1 var(--mono);
  letter-spacing: .08em;
}

.page-shell {
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: clamp(28px, 5vw, 72px) clamp(18px, 5vw, 72px) 70px;
}

.login-layout {
  min-height: calc(100vh - 240px);
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(320px, .8fr);
  align-items: stretch;
  gap: clamp(24px, 5vw, 80px);
}

.intro-panel {
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: clamp(20px, 4vw, 58px) 0;
}

.eyebrow, .card-index, .panel-index {
  margin: 0 0 18px;
  color: var(--muted);
  font: 700 10px/1 var(--mono);
  letter-spacing: .13em;
}

.intro-panel h1, .dashboard-topline h1 {
  max-width: 780px;
  margin: 0;
  font-size: clamp(48px, 7.4vw, 108px);
  line-height: .88;
  letter-spacing: -.075em;
}

.intro-panel > p:not(.eyebrow) {
  max-width: 640px;
  margin: 34px 0 0;
  color: var(--muted);
  font-size: clamp(16px, 2vw, 20px);
  line-height: 1.7;
}

.audit-note {
  max-width: 620px;
  display: flex;
  align-items: center;
  gap: 11px;
  margin-top: 34px;
  padding-top: 20px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font: 600 11px/1.5 var(--mono);
}

.audit-dot {
  width: 9px;
  height: 9px;
  flex: 0 0 auto;
  background: var(--mint);
  border-radius: 50%;
  box-shadow: 0 0 0 5px rgba(100,220,154,.17);
}

.login-card {
  align-self: center;
  padding: clamp(28px, 4vw, 52px);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 26px;
  box-shadow: var(--shadow);
}

.login-card h2, .panel-heading h2, .dialog-heading h2 {
  margin: 0;
  font-size: clamp(25px, 3vw, 38px);
  line-height: 1;
  letter-spacing: -.045em;
}

.muted, .panel-summary, .attempt-note { color: var(--muted); }
.login-card .muted { margin: 14px 0 28px; line-height: 1.6; }
.attempt-note { margin: 18px 0 0; font: 500 10px/1.55 var(--mono); }

form label {
  display: block;
  margin-bottom: 8px;
  font: 700 10px/1.3 var(--mono);
  letter-spacing: .06em;
  text-transform: uppercase;
}

input[type="password"], textarea {
  width: 100%;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 13px;
}

input[type="password"] { min-height: 52px; padding: 0 14px; }
textarea { resize: vertical; min-height: 150px; padding: 13px; line-height: 1.5; }

.primary-button, .ghost-button, .icon-button, .message-action {
  border-radius: 12px;
  cursor: pointer;
  transition: transform .16s ease, background .16s ease, opacity .16s ease;
}

.primary-button {
  min-height: 48px;
  padding: 0 18px;
  color: var(--ink);
  background: var(--lime);
  border: 1px solid rgba(7,19,15,.15);
  font-weight: 800;
}

.login-card .primary-button { width: 100%; margin-top: 13px; }
.primary-button:hover, .icon-button:hover, .message-action:hover { transform: translateY(-1px); }

.ghost-button {
  min-height: 40px;
  padding: 0 14px;
  background: transparent;
  border: 1px solid currentColor;
}

.icon-button {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  padding: 0;
  background: var(--paper);
  border: 1px solid var(--line);
  font-size: 22px;
}

button:disabled { cursor: not-allowed; opacity: .48; transform: none !important; }
button:focus-visible, input:focus-visible, textarea:focus-visible {
  outline: 3px solid var(--violet);
  outline-offset: 3px;
}

.form-message { min-height: 21px; margin: 14px 0 0; color: var(--red); font: 600 11px/1.5 var(--mono); }

.dashboard-topline {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 30px;
}
.dashboard-topline h1 { font-size: clamp(42px, 6vw, 84px); }
.top-actions { display: flex; align-items: center; gap: 10px; }
.audit-badge { color: var(--ink); border-color: var(--line); background: var(--mint); }

.privacy-gate {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 18px;
  padding: 20px 22px;
  color: var(--surface);
  background: var(--ink);
  border-radius: 18px;
}
.privacy-gate strong { display: block; margin-bottom: 5px; font-size: 17px; }
.privacy-gate p { margin: 0; color: rgba(255,255,255,.62); font-size: 12px; }

.toggle-control { display: flex; align-items: center; gap: 10px; cursor: pointer; font: 700 11px/1 var(--mono); }
.toggle-control input { position: absolute; opacity: 0; pointer-events: none; }
.toggle-track {
  width: 52px;
  height: 29px;
  display: flex;
  align-items: center;
  padding: 3px;
  background: rgba(255,255,255,.17);
  border: 1px solid rgba(255,255,255,.22);
  border-radius: 999px;
  transition: background .2s ease;
}
.toggle-track span { width: 21px; height: 21px; background: white; border-radius: 50%; transition: transform .2s ease; }
.toggle-control input:checked + .toggle-track { background: var(--lime); }
.toggle-control input:checked + .toggle-track span { transform: translateX(23px); background: var(--ink); }
.toggle-control input:focus-visible + .toggle-track { outline: 3px solid var(--violet); outline-offset: 3px; }

.workspace {
  display: grid;
  grid-template-columns: minmax(280px, .34fr) minmax(0, .66fr);
  min-height: 610px;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 22px;
  box-shadow: var(--shadow);
}

.rooms-panel, .messages-panel { min-width: 0; padding: 24px; }
.rooms-panel { background: #e8e5da; border-right: 1px solid var(--line); }
.messages-panel { display: flex; flex-direction: column; }
.panel-heading { display: flex; align-items: start; justify-content: space-between; gap: 14px; }
.panel-heading h2 { font-size: 28px; }
.panel-index { margin-bottom: 10px; }
.panel-summary { min-height: 20px; margin: 12px 0 18px; font-size: 12px; }
.count-chip { color: var(--ink); border-color: var(--line); white-space: nowrap; }

.room-list { display: grid; gap: 8px; max-height: 505px; overflow-y: auto; }
.room-card {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  padding: 14px;
  text-align: left;
  color: var(--ink);
  background: rgba(255,255,255,.58);
  border: 1px solid transparent;
  border-radius: 13px;
  cursor: pointer;
}
.room-card:hover { border-color: rgba(7,19,15,.25); }
.room-card[aria-current="true"] { background: var(--lime); border-color: rgba(7,19,15,.2); }
.room-key { font: 700 11px/1.3 var(--mono); overflow-wrap: anywhere; }
.room-meta { margin-top: 5px; color: var(--muted); font-size: 10px; }
.room-count { align-self: center; font: 800 11px/1 var(--mono); }

.message-list { flex: 1; min-height: 420px; max-height: 505px; overflow-y: auto; padding-right: 5px; }
.message-card { padding: 16px 0; border-top: 1px solid var(--line); }
.message-card:first-child { border-top: 0; }
.message-head { display: flex; align-items: start; justify-content: space-between; gap: 16px; }
.message-author { font-weight: 800; }
.message-device, .message-time { color: var(--muted); font: 500 9px/1.4 var(--mono); }
.message-text { margin: 10px 0 0; padding: 13px 14px; background: var(--paper); border-radius: 5px 15px 15px 15px; white-space: pre-wrap; overflow-wrap: anywhere; }
.message-actions { display: flex; gap: 7px; margin-top: 10px; }
.message-action { min-height: 34px; padding: 0 10px; background: transparent; border: 1px solid var(--line); font: 700 9px/1 var(--mono); }
.message-action.danger { color: #a92f2f; border-color: rgba(169,47,47,.32); }

.empty-state { min-height: 360px; display: grid; place-items: center; color: var(--muted); text-align: center; }
.dashboard-status { min-height: 22px; margin: 14px 2px 0; color: var(--muted); font: 600 11px/1.5 var(--mono); }
.dashboard-status.is-error { color: #a92f2f; }

.edit-dialog {
  width: min(560px, calc(100vw - 28px));
  padding: 0;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: 0 35px 100px rgba(0,0,0,.35);
}
.edit-dialog::backdrop { background: rgba(7,19,15,.74); backdrop-filter: blur(5px); }
.edit-dialog form { padding: 25px; }
.dialog-heading { display: flex; align-items: start; justify-content: space-between; margin-bottom: 24px; }
.dialog-heading h2 { font-size: 28px; }
.dialog-meta { display: flex; justify-content: space-between; gap: 12px; margin-top: 7px; color: var(--muted); font: 500 9px/1.4 var(--mono); }
.dialog-actions { display: flex; justify-content: end; gap: 9px; margin-top: 18px; }
.noscript { margin: 20px; padding: 15px; color: white; background: #a92f2f; }

@media (max-width: 900px) {
  .login-layout { grid-template-columns: 1fr; min-height: auto; }
  .intro-panel { padding-bottom: 0; }
  .login-card { width: 100%; max-width: 620px; }
  .dashboard-topline { align-items: start; flex-direction: column; }
  .workspace { grid-template-columns: 1fr; }
  .rooms-panel { border-right: 0; border-bottom: 1px solid var(--line); }
  .room-list { max-height: 320px; }
  .message-list { max-height: 620px; }
}

@media (max-width: 620px) {
  .site-header { min-height: 72px; padding: 12px 16px; }
  .secure-chip { display: none; }
  .page-shell { padding: 28px 12px 48px; }
  .intro-panel h1 { font-size: 47px; }
  .login-card { padding: 26px 20px; border-radius: 18px; }
  .dashboard-topline h1 { font-size: 45px; }
  .top-actions { width: 100%; justify-content: space-between; }
  .privacy-gate { align-items: stretch; flex-direction: column; }
  .toggle-control { justify-content: space-between; }
  .rooms-panel, .messages-panel { padding: 18px 14px; }
  .message-head { flex-direction: column; gap: 4px; }
  .dialog-meta { align-items: end; flex-direction: column; }
}

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

@media (forced-colors: active) {
  .login-card, .workspace, .privacy-gate, .room-card, .message-text { border: 1px solid CanvasText; }
}
