/* The assistant's page. Made for a phone held in one hand; on a wide screen it
   stays a narrow column. Colors follow the device's light or dark setting. */

:root {
  --bg: #f4f5f2;
  --card: #ffffff;
  --ink: #17201b;
  --soft: #5f6b64;
  --line: #dfe4de;
  --accent: #0f6e56;
  --on-accent: #ffffff;
  --mine: #0f6e56;
  --on-mine: #ffffff;
  --warn-bg: #fff4dd;
  --warn-ink: #7a4a00;
  --ok: #1f9d6f;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1412;
    --card: #1a211e;
    --ink: #e8ede9;
    --soft: #98a39c;
    --line: #2a332f;
    --accent: #3fb593;
    --on-accent: #06231b;
    --mine: #17624f;
    --on-mine: #effaf6;
    --warn-bg: #33270f;
    --warn-ink: #ffd68a;
    --ok: #3fb593;
  }
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

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

body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
  overflow: hidden;
}

h1,
h2,
p {
  margin: 0;
}

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

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.unseen {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* Not signed in */

.door {
  max-width: 26rem;
  margin: 0 auto;
  padding: 22vh 24px 24px;
  text-align: center;
}

.door h1 {
  font-size: 1.5rem;
  line-height: 1.2;
  margin-bottom: 12px;
}

.door p {
  color: var(--soft);
}

.main-button {
  margin-top: 28px;
  min-width: 12rem;
  min-height: 52px;
  padding: 0 28px;
  border: 0;
  border-radius: 26px;
  background: var(--accent);
  color: var(--on-accent);
  font-weight: 650;
  font-size: 1.0625rem;
  cursor: pointer;
}

.main-button:disabled {
  opacity: 0.6;
}

/* Signed in. The page is as tall as what the keyboard leaves visible (the
   script keeps --tall and --down in step with it), and only the conversation
   scrolls. */

.chat {
  position: fixed;
  top: var(--down, 0px);
  left: 0;
  right: 0;
  height: 100vh;
  height: var(--tall, 100dvh);
  max-width: 46rem;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
}

.top {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 2px 12px;
  padding: max(10px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 10px
    max(16px, env(safe-area-inset-left));
  border-bottom: 1px solid var(--line);
  background: var(--bg);
}

.who {
  min-width: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 10px;
}

.top h1 {
  font-size: 1.0625rem;
  font-weight: 650;
  line-height: 1.25;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.top select {
  max-width: 100%;
  min-height: 32px;
  padding: 2px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
  font-size: 0.9375rem;
}

.quiet-button {
  min-height: 44px;
  padding: 0 6px;
  border: 0;
  background: none;
  color: var(--soft);
  font-size: 0.9375rem;
  cursor: pointer;
}

.state {
  grid-column: 1 / -1;
  font-size: 0.8125rem;
  color: var(--soft);
}

.state::before {
  content: "";
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-right: 6px;
  border-radius: 50%;
  background: var(--soft);
}

.state.current::before {
  background: var(--ok);
}

.state.behind {
  margin-top: 6px;
  padding: 8px 10px;
  border-radius: 10px;
  background: var(--warn-bg);
  color: var(--warn-ink);
}

.state.behind::before {
  background: var(--warn-ink);
}

.scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
  padding: 12px max(12px, env(safe-area-inset-right)) 8px max(12px, env(safe-area-inset-left));
}

/* Before the first question */

.start {
  margin: auto 0;
  padding: 24px 8px;
  text-align: center;
}

.start h2 {
  font-size: 1.375rem;
  line-height: 1.25;
  margin-bottom: 6px;
}

.start p {
  color: var(--soft);
}

.ideas {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: 24rem;
  margin: 24px auto 0;
}

.ideas button {
  min-height: 48px;
  padding: 10px 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--card);
  text-align: left;
  cursor: pointer;
}

/* The conversation */

.thread {
  list-style: none;
  margin: 0;
  /* Pushes a short conversation down to the box where the next question is typed. */
  margin-top: auto;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.thread li {
  display: flex;
  flex-direction: column;
}

.day {
  align-items: center;
  margin: 10px 0 4px;
  font-size: 0.75rem;
  color: var(--soft);
  text-transform: capitalize;
}

.bubble {
  max-width: min(86%, 34rem);
  padding: 9px 14px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.asked {
  align-items: flex-end;
  margin-top: 8px;
}

.asked .bubble {
  background: var(--mine);
  color: var(--on-mine);
  border-radius: 18px 18px 4px 18px;
}

.told {
  align-items: flex-start;
}

.told .bubble {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px 18px 18px 4px;
}

.told.off .bubble {
  background: none;
  border-style: dashed;
  color: var(--soft);
}

.told strong {
  font-weight: 650;
}

.when {
  margin: 2px 6px 0;
  font-size: 0.6875rem;
  color: var(--soft);
}

/* While the answer is being worked out */

.working {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--soft);
}

.dots {
  display: inline-flex;
  gap: 4px;
}

.dots span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
  animation: pulse 1.2s ease-in-out infinite;
}

.dots span:nth-child(2) {
  animation-delay: 0.15s;
}

.dots span:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes pulse {
  0%,
  80%,
  100% {
    opacity: 0.25;
  }
  40% {
    opacity: 1;
  }
}

@media (prefers-reduced-motion: reduce) {
  .dots span {
    animation: none;
    opacity: 0.6;
  }
}

/* Where a question is typed */

.trouble {
  margin: 0 12px 8px;
  padding: 8px 12px;
  border-radius: 10px;
  background: var(--warn-bg);
  color: var(--warn-ink);
  font-size: 0.875rem;
}

.composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 8px max(12px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom))
    max(12px, env(safe-area-inset-left));
  border-top: 1px solid var(--line);
  background: var(--bg);
}

.composer textarea {
  flex: 1;
  min-width: 0;
  min-height: 46px;
  max-height: 9.5rem;
  padding: 11px 16px;
  border: 1px solid var(--line);
  border-radius: 23px;
  background: var(--card);
  /* Below 16px an iPhone zooms the page when the box is tapped. */
  font-size: 1rem;
  line-height: 1.4;
  resize: none;
}

.composer textarea:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

.composer textarea::placeholder {
  color: var(--soft);
}

.composer button {
  flex: none;
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
  color: var(--on-accent);
  cursor: pointer;
}

.composer button:disabled {
  background: var(--line);
  color: var(--soft);
  cursor: default;
}
