:root {
  --bg: #101316;
  --surface: #191d21;
  --surface-raised: #21262b;
  --line: #2b3138;
  --text: #e6e3dd;
  --text-dim: #8b9199;
  --accent: #c8825a;
  --accent-soft: #3a2a20;
  --danger: #d4776b;

  --radius: 14px;
  --gap: 12px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
  box-sizing: border-box;
}

/* Any author `display` beats the browser's built-in [hidden] rule, so .gate,
   .app, and .panel would all render at once — including the panel's fixed
   full-screen scrim, greying out the page and eating every click. */
[hidden] {
  display: none !important;
}

html,
body {
  height: 100%;
  margin: 0;
  overscroll-behavior-y: none;
}

body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui,
    sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

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

/* --- passphrase gate --- */

.gate {
  display: grid;
  place-items: center;
  min-height: 100dvh;
  padding: 24px;
}

.gate__form {
  display: grid;
  gap: var(--gap);
  width: 100%;
  max-width: 320px;
}

.gate__title {
  margin: 0 0 8px;
  font: 500 30px/1.2 Georgia, "Times New Roman", serif;
  letter-spacing: -0.01em;
}

.gate__input,
.gate__button {
  border-radius: var(--radius);
  padding: 14px 16px;
  border: 1px solid var(--line);
}

.gate__input {
  background: var(--surface);
  outline: none;
}

.gate__input:focus {
  border-color: var(--accent);
}

.gate__button {
  background: var(--accent);
  border-color: var(--accent);
  color: #17110c;
  font-weight: 600;
  cursor: pointer;
}

.gate__error {
  min-height: 1.2em;
  margin: 0;
  color: var(--danger);
  font-size: 14px;
}

/* --- app shell --- */

.app {
  display: grid;
  grid-template-rows: auto 1fr auto;
  height: 100dvh;
}

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--gap);
  padding: calc(var(--safe-top) + 12px) 16px 12px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
}

.header__title {
  margin: 0;
  font: 500 20px/1 Georgia, "Times New Roman", serif;
  letter-spacing: -0.01em;
}

.header__actions {
  display: flex;
  gap: 8px;
}

.ghost {
  padding: 7px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--text-dim);
  font-size: 14px;
  cursor: pointer;
}

.ghost:active {
  background: var(--surface-raised);
}

.ghost[disabled] {
  opacity: 0.45;
  cursor: default;
}

/* --- thread --- */

.thread {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 16px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.msg {
  max-width: 82%;
  padding: 10px 14px;
  border-radius: var(--radius);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.msg--user {
  align-self: flex-end;
  background: var(--accent-soft);
  border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
  border-bottom-right-radius: 4px;
}

.msg--assistant {
  align-self: flex-start;
  background: var(--surface);
  border: 1px solid var(--line);
  border-bottom-left-radius: 4px;
}

.msg--error {
  align-self: flex-start;
  background: transparent;
  border: 1px dashed var(--danger);
  color: var(--danger);
  font-size: 14px;
}

.msg--pending {
  color: var(--text-dim);
  font-style: italic;
}

.load-more {
  align-self: center;
  padding: 6px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--text-dim);
  font-size: 13px;
  cursor: pointer;
}

/* --- composer --- */

.composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px calc(var(--safe-bottom) + 10px);
  border-top: 1px solid var(--line);
  background: var(--bg);
}

.composer__input {
  flex: 1;
  max-height: 40dvh;
  padding: 11px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  resize: none;
  outline: none;
}

.composer__input:focus {
  border-color: color-mix(in srgb, var(--accent) 55%, var(--line));
}

.composer__send {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  border: none;
  border-radius: 50%;
  background: var(--accent);
  color: #17110c;
  cursor: pointer;
}

.composer__send[disabled] {
  opacity: 0.4;
  cursor: default;
}

/* --- memory panel --- */

.panel {
  position: fixed;
  inset: 0;
  display: grid;
  align-items: end;
  background: rgba(0, 0, 0, 0.5);
}

.panel__sheet {
  max-height: 78dvh;
  padding: 16px 16px calc(var(--safe-bottom) + 16px);
  border-top: 1px solid var(--line);
  border-radius: 18px 18px 0 0;
  background: var(--surface);
  overflow-y: auto;
}

.panel__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.panel__title {
  margin: 0;
  font: 500 18px/1 Georgia, "Times New Roman", serif;
}

.panel__body h3 {
  margin: 18px 0 8px;
  color: var(--text-dim);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.panel__body ul {
  margin: 0;
  padding-left: 18px;
}

.panel__body li {
  margin-bottom: 6px;
}

.panel__body .cat {
  margin: 10px 0 4px;
  color: var(--accent);
  font-size: 13px;
}

.panel__body .cat + ul {
  margin-bottom: 4px;
}

.panel__body .empty {
  color: var(--text-dim);
  font-size: 14px;
}

.panel__body code {
  color: var(--accent);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 13px;
}
