@font-face {
  font-family: "ET Book";
  src: url("../essay/fonts/et-book/et-book-display-italic-old-style-figures.woff") format("woff");
  font-style: italic;
  font-display: swap;
}

:root {
  color-scheme: light;
  --page: #fff;
  --rule: rgba(60, 60, 67, 0.16);
  --text: #000;
  --muted: #8e8e93;
  --incoming: #e5e5ea;
  --incoming-text: #000;
  --outgoing: #0b93f6;
  --outgoing-text: #fff;
  --avatar-a: #f0c86b;
  --avatar-b: #be6c38;
  --chart-card: #f7f7f8;
  --chart-control: #e5e5ea;
  --chart-control-active: #fff;
  --chart-grid: #dedee2;
  --chart-spy: #666a70;
  --chart-fixed: #a87612;
  --chart-fixed3: #a84e59;
  --chart-dynamic: #16746d;
  --max-thread: 430px;
}

[data-theme="dark"] {
  color-scheme: dark;
  --page: #000;
  --rule: rgba(255, 255, 255, 0.11);
  --text: #fff;
  --muted: #8e8e93;
  --incoming: #3a3a3c;
  --incoming-text: #f7f7f8;
  --outgoing: #0a84ff;
  --chart-card: #1c1c1e;
  --chart-control: #343438;
  --chart-control-active: #55555c;
  --chart-grid: #343438;
  --chart-spy: #a6abb2;
  --chart-fixed: #d1a33e;
  --chart-fixed3: #d47a84;
  --chart-dynamic: #61b2aa;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--page);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", sans-serif;
  font-size: 17px;
  -webkit-font-smoothing: antialiased;
}
button, a { -webkit-tap-highlight-color: transparent; }

.reading-progress {
  position: fixed;
  inset: 0 0 auto;
  z-index: 50;
  height: 2px;
  background: transparent;
}
.reading-progress span {
  display: block;
  width: 0;
  height: 100%;
  background: var(--muted);
}

.theme-toggle {
  position: absolute;
  top: 16px;
  right: 16px;
  z-index: 40;
  display: grid;
  width: 36px;
  height: 36px;
  place-items: center;
  padding: 8px;
  border: 0;
  border-radius: 50%;
  color: var(--muted);
  background: color-mix(in srgb, var(--page) 82%, transparent);
  cursor: pointer;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}
.theme-toggle:hover { color: var(--text); }
.theme-toggle svg {
  grid-area: 1 / 1;
  width: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.theme-toggle .icon-sun { display: none; }
[data-theme="dark"] .theme-toggle .icon-moon { display: none; }
[data-theme="dark"] .theme-toggle .icon-sun { display: block; }

.avatar-mini {
  display: grid;
  place-items: center;
  overflow: hidden;
  color: transparent;
  background: url("frog.png") center / cover no-repeat;
  font-size: 0;
}
.thread {
  width: min(100%, var(--max-thread));
  min-height: 100vh;
  margin: 0 auto;
  padding: 0 16px 16px 48px;
}
.cover {
  display: flex;
  flex-direction: column;
  min-height: 42vh;
  align-items: center;
  justify-content: center;
  margin-left: -32px;
  padding: 12vh 20px 10vh;
  text-align: center;
}
.cover h1 {
  margin: 0;
  font-family: "Instrument Serif", "ET Book", Georgia, serif;
  font-size: 52px;
  font-style: italic;
  font-weight: 400;
  letter-spacing: 0;
  line-height: 1;
}
.cover__proper {
  align-self: flex-end;
  margin-top: 18px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.45;
  text-align: right;
  text-decoration: none;
}
.cover__proper > span,
.cover__proper-title { display: block; }
.cover__proper-title {
  color: inherit;
  font-weight: 400;
  text-decoration: underline;
  text-decoration-color: color-mix(in srgb, currentColor 60%, transparent);
  text-underline-offset: 0.2em;
}
.cover__proper:hover { color: var(--text); }

.date-divider {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding-top: 8px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.01em;
  text-transform: lowercase;
}
.exchange { padding: 0 0 28px; }
.chapter-label {
  margin: 0 0 18px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  font-style: italic;
  letter-spacing: 0;
  text-align: center;
  text-transform: lowercase;
}
.message-row {
  position: relative;
  display: flex;
  align-items: flex-end;
  width: 100%;
  margin-top: 2px;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity .35s ease, transform .35s ease;
}
.message-row.is-visible { opacity: 1; transform: none; }
.message-row.incoming {
  justify-content: flex-start;
  gap: 8px;
  margin-left: -32px;
}
.message-row.outgoing {
  justify-content: flex-end;
  padding-right: 10px;
}
.message-row.first { margin-top: 14px; }
.message-row.last, .message-row.solo { margin-bottom: 14px; }
.avatar-mini {
  position: relative;
  bottom: 0;
  flex: 0 0 auto;
  width: 22px;
  height: 22px;
  border-radius: 50%;
}
.incoming:not(.last):not(.solo) .bubble { margin-left: 30px; }
.bubble {
  position: relative;
  max-width: 300px;
  padding: 8px 14px;
  border-radius: 18px;
  font-size: 16px;
  letter-spacing: 0;
  line-height: 1.28;
  overflow-wrap: break-word;
  text-transform: lowercase;
}
.incoming .bubble { color: var(--incoming-text); background: var(--incoming); }
.outgoing .bubble { color: var(--outgoing-text); background: var(--outgoing); }
.incoming.middle .bubble, .incoming.last .bubble { border-top-left-radius: 5px; }
.incoming.first:not(.last) .bubble, .incoming.middle .bubble { border-bottom-left-radius: 5px; }
.outgoing.middle .bubble, .outgoing.last .bubble { border-top-right-radius: 5px; }
.outgoing.first:not(.last) .bubble, .outgoing.middle .bubble { border-bottom-right-radius: 5px; }
.incoming.last .bubble::before, .incoming.solo .bubble::before {
  content: "";
  position: absolute;
  bottom: 0;
  left: -7px;
  width: 13px;
  height: 18px;
  border-bottom-right-radius: 13px 10px;
  background: var(--incoming);
}
.incoming.last .bubble::after, .incoming.solo .bubble::after {
  content: "";
  position: absolute;
  bottom: 0;
  left: -10px;
  width: 10px;
  height: 20px;
  border-bottom-right-radius: 10px;
  background: var(--page);
}
.outgoing.last .bubble::before, .outgoing.solo .bubble::before {
  content: "";
  position: absolute;
  right: -7px;
  bottom: 0;
  width: 13px;
  height: 18px;
  border-bottom-left-radius: 13px 10px;
  background: var(--outgoing);
}
.outgoing.last .bubble::after, .outgoing.solo .bubble::after {
  content: "";
  position: absolute;
  right: -10px;
  bottom: 0;
  width: 10px;
  height: 20px;
  border-bottom-left-radius: 10px;
  background: var(--page);
}

.formula { font-family: Georgia, serif; text-transform: none; }
.chart-message {
  align-items: flex-end;
  margin-top: 16px;
  margin-bottom: 22px;
}
.chart-attachment {
  flex: 1 1 auto;
  min-width: 0;
  max-width: 336px;
  margin: 0;
  padding: 13px 10px 10px;
  overflow: hidden;
  border: 1px solid var(--rule);
  border-radius: 8px;
  background: var(--chart-card);
}
.chart-attachment__head {
  display: block;
  margin: 0 2px 10px;
  font-size: 11px;
  line-height: 1.35;
}
.chart-attachment__title {
  display: block;
  color: var(--text);
  font-size: 13px;
  font-weight: 400;
}
.chart-attachment__head span { color: var(--muted); }
.chart-canvas {
  position: relative;
  width: 100%;
}
.chart-canvas--curve { height: 188px; }
.chart-canvas--history { height: 224px; }
.chart-canvas--results { height: 218px; }
.chart-modes {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 2px;
  width: 100%;
  margin-top: 10px;
  padding: 2px;
  border-radius: 7px;
  background: var(--chart-control);
}
.chart-mode {
  min-width: 0;
  min-height: 28px;
  padding: 4px 8px;
  border: 0;
  border-radius: 5px;
  color: var(--muted);
  background: transparent;
  font: inherit;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0;
  cursor: pointer;
}
.chart-mode.is-active {
  color: var(--text);
  background: var(--chart-control-active);
}
.chart-mode:focus-visible {
  outline: 2px solid var(--outgoing);
  outline-offset: 1px;
}
.chart-legend {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 5px 10px;
  margin: 8px 2px 0;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.2;
}
.chart-legend span {
  display: flex;
  align-items: center;
  min-width: 0;
  white-space: nowrap;
}
.chart-legend i {
  flex: 0 0 auto;
  width: 14px;
  height: 2px;
  margin-right: 5px;
  border-radius: 1px;
  background: var(--muted);
}
.chart-legend i[data-chart-color="spy"] { background: var(--chart-spy); }
.chart-legend i[data-chart-color="fixed"] { background: var(--chart-fixed); }
.chart-legend i[data-chart-color="fixed3"] { background: var(--chart-fixed3); }
.chart-legend i[data-chart-color="dynamic"] { background: var(--chart-dynamic); }
.final-exchange { padding-bottom: 0; }
@media (min-width: 760px) {
  .thread { padding-right: 16px; }
}

@media (max-width: 420px) {
  .thread { padding-right: 12px; padding-left: 40px; }
  .cover {
    min-height: 46vh;
    margin-left: -28px;
    padding-top: 14vh;
    padding-bottom: 12vh;
  }
  .cover h1 { font-size: 46px; }
  .bubble { max-width: 280px; }
  .message-row.incoming { margin-left: -28px; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .message-row { opacity: 1; transform: none; transition: none; }
}
