:root {
  color-scheme: dark;
  --ink: #e9e2d3;
  --muted: #9c968a;
  --faint: #69655e;
  --paper: #171612;
  --paper-raised: #201e19;
  --line: #38352d;
  --gold: #bca265;
  --red: #7c3f35;
  --serif: "Libre Caslon Text", Georgia, serif;
  --mono: "DM Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }

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

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 50% -20%, rgba(188, 162, 101, .08), transparent 42rem),
    linear-gradient(145deg, #1a1814, var(--paper) 55%);
  font-family: var(--serif);
}

button, textarea, select, input { font: inherit; }
button, select { color: inherit; }
button { cursor: pointer; }

.grain {
  position: fixed;
  inset: 0;
  z-index: 10;
  pointer-events: none;
  opacity: .035;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 180 180' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.8'/%3E%3C/svg%3E");
}

.shell {
  width: min(980px, calc(100% - 40px));
  margin: 0 auto;
  padding: 28px 0 56px;
}

.masthead {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--line);
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: .14em;
}

.wordmark {
  display: inline-flex;
  width: fit-content;
  align-items: center;
  gap: 11px;
  color: var(--ink);
  text-decoration: none;
  font-weight: 500;
}

.zero-mark {
  display: grid;
  width: 28px;
  height: 28px;
  place-items: center;
  border: 1px solid var(--gold);
  border-radius: 50%;
  color: var(--gold);
  font-family: var(--serif);
  font-size: 15px;
  letter-spacing: 0;
}

.status {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  letter-spacing: .04em;
}

.status-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--gold);
  box-shadow: 0 0 0 4px rgba(188, 162, 101, .08);
  animation: pulse 1.7s ease-in-out infinite;
}

.status.ready .status-dot { background: #78856c; animation: none; }
.status.error .status-dot { background: var(--red); animation: none; }

.about-button,
.tune-button,
#clearButton {
  justify-self: end;
  padding: 0;
  border: 0;
  color: var(--muted);
  background: transparent;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: .12em;
}

.masthead-links { justify-self: end; display: flex; align-items: center; gap: 18px; }
.masthead-links a { color: var(--muted); text-decoration: none; }
.masthead-links a:hover { color: var(--ink); }

.about-button:hover,
.tune-button:hover,
#clearButton:hover { color: var(--ink); }

.intro { padding: 82px 6% 72px; text-align: center; }

.eyebrow {
  margin: 0 0 22px;
  color: var(--gold);
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: .18em;
}

h1 {
  margin: 0;
  font-size: clamp(38px, 6vw, 68px);
  font-weight: 400;
  letter-spacing: -.045em;
  line-height: 1.08;
}

h1 em { color: #c7beac; font-weight: 400; }

.dek {
  max-width: 650px;
  margin: 28px auto 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.75;
}

.chat {
  min-height: 265px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.empty-state {
  display: flex;
  min-height: 265px;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  text-align: center;
}

.empty-state[hidden] { display: none; }

.ornament { color: var(--faint); font-size: 28px; }
.empty-state p { max-width: 530px; color: var(--muted); font-size: 13px; line-height: 1.65; }

.suggestions { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 14px; }
.suggestions button {
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  background: transparent;
  font-size: 11px;
  font-style: italic;
}
.suggestions button:hover { border-color: var(--gold); color: var(--ink); }

.messages { display: grid; gap: 34px; padding: 38px 5%; }
.messages:empty { display: none; }

.message { display: grid; grid-template-columns: 108px 1fr; gap: 24px; }
.message-label {
  padding-top: 4px;
  color: var(--faint);
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: .14em;
}
.message-text {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: 17px;
  line-height: 1.75;
}
.message.user .message-text { color: var(--muted); font-style: italic; }
.message.model .message-text::after {
  content: "";
  display: inline-block;
  width: 1px;
  height: 1em;
  margin-left: 3px;
  background: var(--gold);
  vertical-align: -.15em;
  animation: blink .8s steps(1) infinite;
}
.message.model.done .message-text::after { display: none; }

.composer { position: relative; margin-top: 22px; border: 1px solid var(--line); background: rgba(32, 30, 25, .82); }
.voice-row { display: flex; align-items: center; gap: 12px; padding: 13px 16px; border-bottom: 1px solid var(--line); }
.voice-row label,
.summary-row label,
.memory-row > span { color: var(--faint); font-family: var(--mono); font-size: 9px; letter-spacing: .15em; }
.voice-row select { appearance: none; padding: 0 20px 0 0; border: 0; outline: 0; background: transparent; font-family: var(--serif); font-size: 12px; font-style: italic; }
.tune-button { margin-left: auto; }

.summary-row { display: grid; grid-template-columns: auto 1fr; align-items: center; gap: 16px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.summary-row input {
  width: 100%;
  padding: 0;
  border: 0;
  outline: 0;
  color: var(--muted);
  background: transparent;
  font-size: 11px;
  font-style: italic;
}
.summary-row select {
  appearance: none;
  width: 100%;
  padding: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--muted);
  font-family: var(--serif);
  font-size: 12px;
  font-style: italic;
}
.summary-row select:focus { color: var(--ink); }
.summary-row input:focus { color: var(--ink); }

.memory-row { display: grid; grid-template-columns: auto 1fr; align-items: start; gap: 16px; padding: 10px 16px; border-bottom: 1px solid var(--line); background: rgba(0, 0, 0, .08); }
.memory-row output { color: var(--gold); font-family: var(--mono); font-size: 9px; line-height: 1.5; overflow-wrap: anywhere; }
.memory-row output.empty { color: var(--faint); font-style: italic; }

.tuning { display: grid; grid-template-columns: repeat(4, 1fr); gap: 20px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.tuning[hidden] { display: none; }
.tuning label { display: grid; gap: 9px; color: var(--muted); font-family: var(--mono); font-size: 9px; }
.tuning span { display: flex; justify-content: space-between; }
.tuning output { color: var(--gold); }
input[type="range"] { width: 100%; height: 1px; accent-color: var(--gold); }

.writing-row { display: flex; align-items: stretch; }
textarea {
  width: 100%;
  min-height: 92px;
  resize: vertical;
  padding: 22px;
  border: 0;
  outline: 0;
  color: var(--ink);
  background: transparent;
  font-size: 17px;
  line-height: 1.5;
}
textarea::placeholder { color: var(--faint); font-style: italic; }
textarea:disabled { opacity: .55; }

.send-button {
  display: flex;
  min-width: 118px;
  align-items: center;
  justify-content: center;
  gap: 9px;
  border: 0;
  border-left: 1px solid var(--line);
  color: var(--paper);
  background: var(--gold);
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: .12em;
}
.send-button:hover:not(:disabled) { background: #cfb472; }
.send-button:disabled { cursor: wait; opacity: .4; }

.composer-foot { display: flex; justify-content: space-between; padding: 10px 16px; border-top: 1px solid var(--line); color: var(--faint); font-family: var(--mono); font-size: 8px; letter-spacing: .08em; }
.load-track { position: absolute; right: 0; bottom: -1px; left: 0; height: 1px; overflow: hidden; }
.load-track span { display: block; width: 0; height: 100%; background: var(--gold); transition: width .18s ease; }

dialog {
  width: min(570px, calc(100% - 32px));
  padding: 46px;
  border: 1px solid var(--line);
  color: var(--ink);
  background: #1d1b17;
  box-shadow: 0 30px 100px rgba(0,0,0,.55);
}
dialog::backdrop { background: rgba(10, 9, 7, .76); backdrop-filter: blur(4px); }
.dialog-close { position: absolute; top: 12px; right: 16px; border: 0; color: var(--muted); background: transparent; font-size: 27px; }
dialog h2 { margin: 0 0 24px; font-size: 30px; font-weight: 400; }
dialog > p:not(.eyebrow) { color: var(--muted); font-size: 13px; line-height: 1.7; }
dialog dl { display: grid; grid-template-columns: 1fr 1fr; margin: 26px 0; border-top: 1px solid var(--line); }
dialog dl div { padding: 13px 0; border-bottom: 1px solid var(--line); }
dialog dt { color: var(--faint); font-family: var(--mono); font-size: 8px; letter-spacing: .13em; }
dialog dd { margin: 5px 0 0; font-size: 13px; }
.source-link { color: var(--gold); font-family: var(--mono); font-size: 9px; letter-spacing: .12em; text-decoration: none; }

.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
noscript { display: block; padding: 20px; color: #fff; background: var(--red); text-align: center; }

@keyframes pulse { 50% { opacity: .35; } }
@keyframes blink { 50% { opacity: 0; } }

@media (max-width: 680px) {
  .shell { width: min(100% - 24px, 980px); padding-top: 16px; }
  .masthead { grid-template-columns: 1fr 1fr; }
  .status { order: 3; grid-column: 1 / -1; justify-content: center; margin-top: 16px; }
  .intro { padding: 58px 3% 50px; }
  h1 { font-size: 38px; }
  .message { grid-template-columns: 1fr; gap: 7px; }
  .message-text { font-size: 15px; }
  .tuning { grid-template-columns: 1fr 1fr; }
  .summary-row, .memory-row { grid-template-columns: 1fr; gap: 7px; }
  .writing-row { flex-direction: column; }
  .send-button { min-height: 48px; border-top: 1px solid var(--line); border-left: 0; }
  dialog { padding: 34px 25px; }
}

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