/* Djinn. Night ink, lamplight, and one brass accent.
   No web fonts and no third-party requests: the page talks to the keykeeper
   and nothing else, so type comes from carefully chosen system stacks. */

:root {
  --ink: #0b0f15;
  --ink-2: #121821;
  --ink-3: #1a222e;
  --line: #263140;
  --paper: #ede6d6;
  --muted: #8d95a3;
  --brass: #e3ab4f;
  --brass-deep: #b9792a;
  --ember: #ff8046;
  --ok: #86cfae;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", "URW Palladio L", Georgia, serif;
  --sans: "Avenir Next", Avenir, "Segoe UI Variable Text", "Segoe UI", "Helvetica Neue", system-ui, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  background:
    radial-gradient(120% 60% at 50% 118%, rgba(227, 171, 79, 0.16), transparent 62%),
    radial-gradient(80% 50% at 12% -10%, rgba(64, 98, 132, 0.22), transparent 70%),
    var(--ink);
  color: var(--paper);
  font: 400 1rem/1.55 var(--sans);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* Paper grain over everything, so the dark never looks like flat plastic. */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.07;
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  z-index: 10;
}

.shell {
  display: flex;
  flex-direction: column;
  max-width: 31rem;
  height: 100dvh;
  margin: 0 auto;
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
}

.mast {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.1rem 1.5rem 0.6rem;
}

.wordmark {
  font: 600 0.82rem/1 var(--serif);
  letter-spacing: 0.42em;
  text-transform: uppercase;
  color: var(--brass);
}

.badge {
  font: 0.68rem/1 var(--mono);
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: 99px;
  padding: 0.35rem 0.6rem;
}

#stage {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 0.5rem 1.5rem 2rem;
}

.screen > * {
  animation: rise 0.6s var(--ease) both;
}
.screen > :nth-child(2) { animation-delay: 0.05s; }
.screen > :nth-child(3) { animation-delay: 0.1s; }
.screen > :nth-child(4) { animation-delay: 0.16s; }
.screen > :nth-child(5) { animation-delay: 0.22s; }
.screen > :nth-child(n + 6) { animation-delay: 0.28s; }

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
}

/* --- Type ---------------------------------------------------------------- */

h1 {
  font: 500 1.9rem/1.12 var(--serif);
  letter-spacing: -0.01em;
  margin: 0 0 0.75rem;
  text-wrap: balance;
}

h1.display {
  font-size: clamp(2.2rem, 9vw, 2.9rem);
  line-height: 1.04;
  margin-bottom: 1.1rem;
}

.eyebrow {
  font: 600 0.72rem/1 var(--sans);
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 0.9rem;
}

.lede {
  color: #c9c3b6;
  font-size: 1.04rem;
  margin: 0 0 1.5rem;
  text-wrap: pretty;
}

.fine {
  color: var(--muted);
  font-size: 0.86rem;
  margin: 1.1rem 0 0;
}

code {
  font: 0.86em var(--mono);
  color: var(--brass);
  background: rgba(227, 171, 79, 0.08);
  padding: 0.12em 0.4em;
  border-radius: 4px;
}

b {
  font-weight: 600;
  color: #fff8e9;
}

.warn {
  border-left: 2px solid var(--ember);
  background: rgba(255, 128, 70, 0.06);
  color: #e6d3c4;
  font-size: 0.88rem;
  margin: 1.25rem 0 0;
  padding: 0.7rem 0.9rem;
  border-radius: 0 8px 8px 0;
}

.error {
  color: var(--ember);
  font-size: 0.9rem;
  margin: 0.9rem 0 0;
}
.error:empty {
  display: none;
}

/* --- The lamp ------------------------------------------------------------- */
/* The one recurring image: dim and slow when the Djinni sleeps, quick while
   it wakes, bright with a rising wisp when it is awake, cold when paused. */

.lamp {
  --size: 2.4rem;
  --heat: 0.3;
  --beat: 5.5s;
  --core: #f6c773;
  --halo: #d5631f;
  position: relative;
  flex: none;
  width: var(--size);
  height: var(--size);
}

.lamp-large {
  --size: 6.5rem;
  margin: 2.6rem 0 2.6rem 1.2rem;
}
.lamp-large i:nth-child(1) {
  inset: -42%;
}

.lamp i {
  position: absolute;
  inset: 0;
  border-radius: 50%;
}

.lamp i:nth-child(1) {
  inset: -45%;
  background: radial-gradient(closest-side, var(--halo), transparent);
  opacity: calc(var(--heat) * 0.55);
  filter: blur(6px);
  animation: breathe var(--beat) ease-in-out infinite;
}

.lamp i:nth-child(2) {
  inset: 22%;
  background: radial-gradient(circle at 42% 38%, #fffaf0, var(--core) 45%, var(--halo) 100%);
  opacity: calc(0.35 + var(--heat) * 0.65);
  box-shadow: 0 0 calc(var(--size) * 0.35) var(--core);
  animation: breathe var(--beat) ease-in-out infinite reverse;
}

.lamp i:nth-child(3) {
  inset: -120% 30% 60%;
  border-radius: 50% 50% 40% 40%;
  background: linear-gradient(to top, rgba(246, 199, 115, 0.5), transparent 80%);
  filter: blur(calc(var(--size) * 0.14));
  opacity: 0;
  transform-origin: 50% 100%;
}

.lamp[data-state="waking"] {
  --heat: 0.65;
  --beat: 1.3s;
}

.lamp[data-state="awake"] {
  --heat: 1;
  --beat: 3.2s;
}
.lamp[data-state="awake"] i:nth-child(3) {
  animation: wisp 4.5s ease-in-out infinite;
}

.lamp[data-state="paused"] {
  --heat: 0.25;
  --beat: 9s;
  --core: #9fb0c4;
  --halo: #3c5068;
}

@keyframes breathe {
  50% {
    transform: scale(1.14);
    opacity: calc(var(--heat) * 0.9);
  }
}

@keyframes wisp {
  0% {
    opacity: 0;
    transform: translateY(18%) scaleX(0.7) rotate(-4deg);
  }
  40% {
    opacity: 0.55;
  }
  100% {
    opacity: 0;
    transform: translateY(-28%) scaleX(1.25) rotate(6deg);
  }
}

/* --- Buttons and fields ---------------------------------------------------- */

.actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem 0.9rem;
  margin-top: 1.75rem;
}

.btn {
  appearance: none;
  font: 600 0.95rem/1 var(--sans);
  color: var(--paper);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.85rem 1.15rem;
  cursor: pointer;
  transition:
    transform 0.15s var(--ease),
    border-color 0.15s,
    background 0.15s;
}
.btn:hover {
  border-color: var(--brass);
}
.btn:active {
  transform: translateY(1px) scale(0.99);
}
.btn:focus-visible,
input:focus-visible,
textarea:focus-visible,
.card-head:focus-visible {
  outline: 2px solid var(--brass);
  outline-offset: 2px;
}
.btn:disabled {
  opacity: 0.6;
  cursor: progress;
}
.btn[data-busy]::after {
  content: "";
  display: inline-block;
  width: 0.7em;
  height: 0.7em;
  margin-left: 0.6em;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  vertical-align: -0.05em;
  animation: spin 0.7s linear infinite;
}

.btn-primary {
  color: #1b1304;
  background: linear-gradient(180deg, #f1c069, var(--brass) 55%, #d2953a);
  border-color: transparent;
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.35) inset,
    0 10px 30px -12px rgba(227, 171, 79, 0.7);
}
.btn-primary:hover {
  background: linear-gradient(180deg, #f6cb7d, #ebb65c 55%, #d99d42);
}

.btn-quiet {
  border-color: transparent;
  color: var(--muted);
  padding-inline: 0.5rem;
  text-decoration: underline;
  text-decoration-color: var(--line);
  text-underline-offset: 0.3em;
}
.btn-quiet:hover {
  color: var(--paper);
  border-color: transparent;
}

.btn-small {
  font-size: 0.82rem;
  padding: 0.55rem 0.8rem;
  border-radius: 8px;
}

input[type="text"],
input[type="password"],
textarea {
  width: 100%;
  font: 1rem/1.4 var(--sans);
  color: var(--paper);
  background: var(--ink-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.7rem 0.85rem;
}
::placeholder {
  color: #667080;
}

@keyframes spin {
  to {
    transform: rotate(1turn);
  }
}

/* --- Welcome --------------------------------------------------------------- */

.claims {
  list-style: none;
  margin: 0;
  padding: 0;
  border-top: 1px solid var(--line);
}
.claims li {
  padding: 0.8rem 0 0.8rem 1.6rem;
  border-bottom: 1px solid var(--line);
  color: #b9b3a7;
  font-size: 0.94rem;
  position: relative;
}
.claims li::before {
  content: "";
  position: absolute;
  left: 0.2rem;
  top: 1.32rem;
  width: 0.4rem;
  height: 0.4rem;
  border-radius: 50%;
  background: var(--brass);
  box-shadow: 0 0 10px var(--brass);
}

.dev-toggle {
  display: flex;
  gap: 0.6rem;
  align-items: flex-start;
  margin-top: 2rem;
  color: var(--muted);
  font-size: 0.8rem;
  cursor: pointer;
}
.dev-toggle input {
  accent-color: var(--brass);
  margin-top: 0.2rem;
}

/* --- Onboarding ------------------------------------------------------------ */

.pips {
  list-style: none;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0.35rem;
  margin: 0.4rem 0 2rem;
  padding: 0;
}
.pips li {
  font: 600 0.6rem/1 var(--sans);
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: #586170;
  border-top: 2px solid var(--line);
  padding-top: 0.55rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition: color 0.3s, border-color 0.3s;
}
.pips li[data-state="done"] {
  color: var(--muted);
  border-color: var(--brass-deep);
}
.pips li[data-state="now"] {
  color: var(--brass);
  border-color: var(--brass);
}

.checklist {
  list-style: none;
  margin: 0.5rem 0 0;
  padding: 0;
}
.checklist li {
  display: grid;
  grid-template-columns: 1.6rem 1fr;
  align-items: baseline;
  padding: 0.6rem 0;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  transition: color 0.3s;
}
.checklist li::before {
  content: "○";
  color: #4b5564;
}
.checklist li small {
  grid-column: 2;
  font: 0.76rem/1.4 var(--mono);
  color: var(--muted);
}
.checklist li small:empty {
  display: none;
}
.checklist li[data-state="run"] {
  color: var(--paper);
}
.checklist li[data-state="run"]::before {
  content: "";
  width: 0.7rem;
  height: 0.7rem;
  border: 2px solid var(--brass);
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  align-self: center;
}
.checklist li[data-state="done"] {
  color: var(--paper);
}
.checklist li[data-state="done"]::before {
  content: "✓";
  color: var(--ok);
}
.checklist li[data-state="skip"]::before {
  content: "–";
  color: var(--brass);
}
.checklist li[data-state="skip"] small {
  color: var(--brass);
}
.checklist li[data-state="fail"]::before {
  content: "✕";
  color: var(--ember);
}

.terms {
  display: grid;
  grid-template-columns: minmax(7.5rem, auto) 1fr;
  margin: 0;
  border-top: 1px solid var(--line);
}
.terms dt,
.terms dd {
  margin: 0;
  padding: 0.85rem 0;
  border-bottom: 1px solid var(--line);
}
.terms dt {
  font: 600 0.68rem/1.6 var(--sans);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  padding-right: 1rem;
  padding-top: 1.05rem;
}
.terms dd {
  color: #c9c3b6;
}

.phrase {
  list-style: none;
  counter-reset: word;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.45rem;
  margin: 0;
  padding: 0;
}
.phrase li {
  counter-increment: word;
  font: 0.95rem/1 var(--mono);
  background: var(--ink-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.8rem 0.5rem 0.8rem 0.65rem;
  white-space: nowrap;
  animation: rise 0.5s var(--ease) both;
  animation-delay: calc(var(--i, 0) * 30ms);
}
.phrase li::before {
  content: counter(word);
  display: inline-block;
  width: 1.5em;
  color: #5d6676;
  font-size: 0.72em;
}
@media (max-width: 23rem) {
  .phrase {
    grid-template-columns: repeat(2, 1fr);
  }
}

.phrase-check {
  display: grid;
  gap: 0.8rem;
}
.phrase-check label span {
  display: block;
  font: 600 0.68rem/1 var(--sans);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 0.4rem;
}
.phrase-check input {
  font-family: var(--mono);
}
.phrase-check input[data-ok="true"] {
  border-color: var(--ok);
  box-shadow: 0 0 0 3px rgba(134, 207, 174, 0.12);
}

.cards {
  list-style: none;
  margin: 1.25rem 0 0;
  padding: 0;
  display: grid;
  gap: 0.6rem;
}
.card {
  background: var(--ink-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  transition: border-color 0.2s;
}
.card[data-on="true"] {
  border-color: var(--brass-deep);
}
.card-head {
  appearance: none;
  width: 100%;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.2rem 1rem;
  text-align: left;
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  border-radius: 12px;
  padding: 0.9rem 1rem;
  cursor: pointer;
}
.card-head b {
  font: 500 1.15rem/1.2 var(--serif);
}
.card-head .state {
  font: 0.72rem/1.9 var(--mono);
  color: var(--muted);
}
.card[data-on="true"] .state {
  color: var(--ok);
}
.card-head small {
  grid-column: 1 / -1;
  color: var(--muted);
  font-size: 0.84rem;
}
.card-body {
  padding: 0 1rem 1rem;
  color: #b9b3a7;
  font-size: 0.88rem;
}
.card-body p {
  margin: 0 0 0.8rem;
  padding-top: 0.8rem;
  border-top: 1px solid var(--line);
}
.row {
  display: flex;
  gap: 0.5rem;
}
.row input {
  padding: 0.5rem 0.7rem;
  font-size: 0.9rem;
}
.row .btn {
  white-space: nowrap;
}

/* --- Chat ------------------------------------------------------------------ */

#stage.is-chat {
  padding: 0;
  overflow: hidden;
}
#stage.is-chat .screen {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.chat-head {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.6rem 1.5rem 1rem 1.75rem;
  border-bottom: 1px solid var(--line);
}
.chat-head > div:not(.lamp) {
  flex: 1;
  min-width: 0;
}
.chat-head h1 {
  font-size: 1.25rem;
  margin: 0;
}
.status {
  margin: 0.1rem 0 0;
  font-size: 0.8rem;
  color: var(--muted);
}

.banner {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin: 0.9rem 1.5rem 0;
  padding: 0.8rem 0.9rem;
  border: 1px solid #3c5068;
  border-radius: 12px;
  background: rgba(60, 80, 104, 0.2);
  font-size: 0.86rem;
  color: #c5cfdb;
}
.banner[hidden] {
  display: none;
}
.banner p {
  margin: 0;
  flex: 1;
}

.scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 1.25rem 1.5rem 0.5rem;
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
}

.empty {
  max-width: 17rem;
  margin: 18vh auto 0;
  text-align: center;
  color: #5f6877;
  font: italic 0.98rem/1.5 var(--serif);
}
.scroll:has(.typing:not([hidden])) .empty,
.scroll:has(.thread[data-empty="false"]) .empty {
  display: none;
}

.thread {
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
}

.msg {
  max-width: 88%;
  animation: rise 0.45s var(--ease) both;
}
.msg p {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.msg time {
  display: block;
  margin-top: 0.3rem;
  font-size: 0.68rem;
  color: #5f6877;
}

/* The Djinni speaks in the serif, set off by a lamplit rule. */
.msg-agent {
  align-self: flex-start;
  padding-left: 0.95rem;
  border-left: 2px solid var(--brass-deep);
  font: 1.08rem/1.5 var(--serif);
}
.msg-agent time {
  font-family: var(--sans);
}

.msg-user {
  align-self: flex-end;
  background: var(--ink-3);
  border: 1px solid var(--line);
  border-radius: 14px 14px 4px 14px;
  padding: 0.6rem 0.85rem;
}
.msg-user time {
  text-align: right;
}

.typing {
  display: flex;
  gap: 0.3rem;
  padding: 1.1rem 0 0.4rem 0.95rem;
}
.typing[hidden] {
  display: none;
}
.typing i {
  width: 0.38rem;
  height: 0.38rem;
  border-radius: 50%;
  background: var(--brass);
  animation: blink 1.2s ease-in-out infinite;
}
.typing i:nth-child(2) {
  animation-delay: 0.15s;
}
.typing i:nth-child(3) {
  animation-delay: 0.3s;
}
@keyframes blink {
  0%,
  100% {
    opacity: 0.2;
    transform: translateY(0);
  }
  40% {
    opacity: 1;
    transform: translateY(-3px);
  }
}

#stage.is-chat .error {
  margin: 0.4rem 1.5rem 0;
}

.composer {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  padding: 0.75rem 1.5rem 1rem;
}
.composer textarea {
  resize: none;
  border-radius: 14px;
  max-height: 10rem;
}
.composer .send {
  padding: 0.82rem 1rem;
  border-radius: 14px;
}

/* --- Details sheet ---------------------------------------------------------- */

.sheet {
  width: min(31rem, 100%);
  max-width: 100%;
  margin: auto auto 0;
  padding: 1.5rem 1.5rem calc(1.5rem + env(safe-area-inset-bottom));
  color: var(--paper);
  background: var(--ink-2);
  border: 1px solid var(--line);
  border-bottom: 0;
  border-radius: 20px 20px 0 0;
  animation: rise 0.35s var(--ease);
}
.sheet::backdrop {
  background: rgba(5, 8, 12, 0.6);
  backdrop-filter: blur(3px);
}
.sheet h2 {
  font: 500 1.4rem/1.2 var(--serif);
  margin: 0 0 1rem;
}

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