/* Colors */

:root {
  --paper: #FAF6EE;
  --ink: #231F19;
  --muted: #635E54;
  --soft: #6D655A;
  --faint: #6D6760;
  --hair: rgba(35, 31, 25, 0.16);
  --line: rgba(35, 31, 25, 0.32);
  --red: #78242A;
  --red-dk: #521A1E;
  --on-red: #F7F0E3;
  --plum: #523653;
  --shadow: rgba(35, 31, 25, 0.18);
  --pop-shadow: rgba(35, 31, 25, 0.5);
  --surface: rgba(35, 31, 25, 0.06);
  --field: #FFFDF9;
  --ok: #2F5D3A;
  --invert: 0;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
  --serif: "EB Garamond", Georgia, serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #1E1A16;
    --ink: #EFE7D8;
    --muted: #B5AB9B;
    --soft: #A79D8D;
    --faint: #968D82;
    --hair: rgba(239, 231, 216, 0.18);
    --line: rgba(239, 231, 216, 0.36);
    --red: #D2777D;
    --red-dk: #E08E93;
    --on-red: #1E1A16;
    --plum: #B197B3;
    --shadow: rgba(0, 0, 0, 0.5);
    --pop-shadow: rgba(0, 0, 0, 0.7);
    --surface: rgba(239, 231, 216, 0.08);
    --field: #28231E;
    --ok: #8CC49A;
    --invert: 1;
    color-scheme: dark;
  }
}

/* Page */

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--serif);
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--red);
}

a:hover {
  color: var(--plum);
}

button {
  font: inherit;
  cursor: pointer;
}

.app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* The column is offset from the left by (window width - column width) / 2 in vw, which ignores the scrollbar,
   so the column stays put when a scrollbar appears. */
:root {
  --col: 1120px;
  --col-left: max(0px, calc((100vw - var(--col)) / 2));
}

.wrap {
  width: min(var(--col), calc(100% - var(--col-left)));
  margin: 0 0 0 var(--col-left);
  padding: 0 clamp(20px, 5vw, 84px);
}

.stripe {
  display: flex;
  height: 15px;
}

.stripe i {
  flex: 1;
}

/* Header */

.hd {
  text-align: center;
  padding-top: clamp(36px, 6vh, 64px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.motif {
  display: inline-block;
  transform: rotate(-3deg);
  filter: drop-shadow(0 5px 12px var(--shadow));
}

.motif img {
  display: block;
  width: 96px;
  height: auto;
}

.hd h1 {
  font: 500 clamp(40px, 6vw, 58px)/1 var(--serif);
  letter-spacing: -0.01em;
  margin: 0;
}

.hd h1 b {
  color: var(--red);
  font-weight: 500;
}

main.wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding-top: clamp(28px, 5vh, 56px);
  padding-bottom: clamp(28px, 5vh, 56px);
}

/* Form */

.compose {
  width: 100%;
}

.bot {
  display: flex;
  align-items: flex-end;
  gap: 14px;
  width: 100%;
  margin-bottom: 12px;
}

.input {
  flex: 1;
  font: 400 clamp(16px, 1.7vw, 18px)/1.6 var(--mono);
  color: var(--ink);
  background: var(--field);
  border: 1px solid var(--hair);
  border-radius: 28px;
  box-shadow: 0 4px 16px -6px var(--shadow);
  padding: 13px 24px;
  resize: none;
  outline: none;
  min-height: 56px;
  max-height: 200px;
  field-sizing: content;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.input:hover {
  box-shadow: 0 6px 20px -6px var(--shadow);
}

.input::placeholder {
  color: var(--faint);
}

.input:focus {
  border-color: var(--line);
  box-shadow: 0 6px 22px -6px var(--shadow);
  outline: none;
}

/* Only show a focus ring on the text field when it was reached with the keyboard. */
html[data-kb] .input:focus {
  border-color: var(--plum);
}

.input:disabled {
  color: var(--faint);
}

.go {
  font: 500 13px/1 var(--mono);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  background: var(--red);
  border: none;
  border-radius: 99px;
  height: 56px;
  padding: 0 28px;
  color: var(--on-red);
  transition: background 0.2s;
  white-space: nowrap;
}

.go:hover {
  background: var(--red-dk);
}

.go:disabled {
  background: var(--faint);
  color: var(--paper);
  cursor: default;
}

.under {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 16px;
  width: 100%;
  padding: 0 24px;
  margin: 0 0 clamp(28px, 5vh, 48px);
}

.count {
  font: 400 12px/1 var(--mono);
  letter-spacing: 0.06em;
  color: var(--faint);
  font-variant-numeric: tabular-nums;
}

.try {
  font: italic 400 15px/1 var(--serif);
  color: var(--faint);
  background: none;
  border: none;
  padding: 4px 0;
  text-decoration: underline dotted;
  text-underline-offset: 3px;
  transition: color 0.2s;
}

.try:hover {
  color: var(--plum);
}

.try:disabled {
  cursor: default;
  color: var(--hair);
}

.turnstile {
  display: flex;
  justify-content: center;
  margin-top: 12px;
}

.turnstile:empty {
  display: none;
}

.note,
.paused {
  font-style: italic;
  font-weight: 400;
  font-family: var(--serif);
  line-height: 1.45;
  color: var(--red);
  text-align: center;
  text-wrap: balance;
}

.note {
  font-size: clamp(18px, 2.2vw, 22px);
  max-width: 40ch;
  margin: -18px auto 36px;
}

.paused {
  font-size: clamp(20px, 2.6vw, 26px);
  max-width: 32ch;
  margin: 8px auto clamp(28px, 5vh, 48px);
}

/* Carousel */

.nav {
  display: flex;
  align-items: center;
  gap: 18px;
  margin-bottom: 28px;
  min-height: 32px;
}

.nav-btn {
  width: 32px;
  height: 32px;
  border-radius: 99px;
  border: 1px solid var(--hair);
  background: none;
  color: var(--ink);
  display: grid;
  place-items: center;
  transition: border-color 0.2s, color 0.2s;
}

.nav-btn:hover {
  border-color: var(--red);
  color: var(--red);
}

.nav-btn:disabled {
  opacity: 0.3;
  cursor: default;
  border-color: var(--hair);
  color: var(--ink);
}

.dots {
  display: flex;
  gap: 9px;
  align-items: center;
}

/* A 24px hit area around a 7px dot; the negative margin keeps the dots close together. */
.dot {
  width: 24px;
  height: 24px;
  margin: 0 -8px;
  border-radius: 99px;
  background: none;
  border: none;
  padding: 0;
  display: grid;
  place-items: center;
}

.dot i {
  width: 7px;
  height: 7px;
  border-radius: 99px;
  background: var(--hair);
  transition: background 0.2s, transform 0.2s;
}

.dot:hover i {
  background: var(--faint);
}

.dot.on i {
  background: var(--plum);
  transform: scale(1.25);
}

.dot.mine i {
  background: var(--red);
  opacity: 0.45;
}

.dot.mine.on i {
  opacity: 1;
}

.dot:focus-visible {
  outline: 1px solid var(--plum);
  outline-offset: -4px;
}

.pos {
  font: 400 12px/1 var(--mono);
  letter-spacing: 0.1em;
  color: var(--faint);
  font-variant-numeric: tabular-nums;
  min-width: 72px;
  text-align: center;
}

/* Translation card */

.card {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  animation: rise 0.45s ease both;
}

.col {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 0;
}

.lbl-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-bottom: 18px;
}

.lbl {
  font: 400 12px/1 var(--mono);
  letter-spacing: 0.2em;
  text-transform: uppercase;
}

.lbl.before {
  color: var(--red);
  font-weight: 500;
}

.lbl.after {
  color: var(--plum);
  font-weight: 500;
}

.orig {
  font: 400 clamp(16px, 1.7vw, 18px)/1.6 var(--mono);
  color: var(--muted);
  max-width: 44ch;
  margin: 0;
  text-wrap: pretty;
}

.rule {
  width: 52px;
  height: 1px;
  background: var(--line);
  margin: 44px 0;
}

.fred {
  font: 400 clamp(26px, 3.7vw, 40px)/1.45 var(--serif);
  max-width: 28ch;
  margin: 0;
  text-wrap: pretty;
}

.fred em {
  color: var(--plum);
}

@media (min-width: 860px) {
  .card {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 1px minmax(0, 1.25fr);
    align-items: start;
    gap: 0 clamp(28px, 4vw, 52px);
  }

  .card .rule {
    width: 1px;
    height: auto;
    align-self: stretch;
    margin: 0;
  }

  .card .fred {
    font-size: clamp(24px, 2.6vw, 32px);
  }
}

.copy {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  color: var(--faint);
  background: none;
  border: none;
  border-radius: 6px;
  padding: 0;
  transition: color 0.2s, background 0.2s;
}

.copy:hover {
  color: var(--plum);
  background: var(--surface);
}

.copy-before:hover {
  color: var(--red);
}

.copy:focus-visible {
  outline: 1px solid var(--plum);
  outline-offset: 2px;
}

.copy.done {
  color: var(--ok);
}

.copy .i-done,
.copy.done .i-copy {
  display: none;
}

.copy.done .i-done {
  display: block;
}

/* Loader */

.loader {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 20px 0;
}

.loader-cap {
  font: italic 400 18px/1 var(--serif);
  color: var(--faint);
  margin: 0;
}

.stitch {
  stroke-dasharray: 40;
  stroke-dashoffset: 40;
  animation: knit 1.8s ease-in-out infinite;
}

/* Footer */

.flourish {
  margin: 40px auto 24px;
  width: min(100%, 360px);
  height: 14px;
  color: var(--hair);
  position: relative;
}

.flourish::before,
.flourish::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  height: 1px;
  background: currentColor;
}

.flourish::before {
  top: 4px;
}

.flourish::after {
  bottom: 4px;
}

.flourish i {
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(90deg, currentColor 0 1px, transparent 1px 7px);
  opacity: 0.7;
}

/* Fade the flourish out at both ends. */
.flourish i,
.flourish::before,
.flourish::after {
  -webkit-mask: linear-gradient(90deg, transparent, #000 20%, #000 80%, transparent);
  mask: linear-gradient(90deg, transparent, #000 20%, #000 80%, transparent);
}

.ftmsg {
  font: italic 400 16px/1.6 var(--serif);
  color: var(--soft);
  text-align: center;
  margin: 0 0 22px;
}

.ftmsg .kind {
  display: block;
}

.ftmsg button {
  background: none;
  border: none;
  padding: 0;
  font: inherit;
  color: inherit;
  text-decoration: underline dotted;
  text-underline-offset: 3px;
}

.ftmsg button:hover {
  color: var(--plum);
}

.ftmsg small {
  display: block;
  font-style: normal;
  font-size: 13px;
  margin-top: 16px;
  color: var(--faint);
}

.ftmsg small a {
  color: inherit;
  text-decoration: none;
}

.ftmsg small a:hover {
  color: var(--plum);
}

.heart {
  color: var(--red);
}

.ftmsg .claude {
  height: 0.95em;
  width: auto;
  vertical-align: -0.1em;
  margin: 0 1px;
}

.ftmsg .openai {
  filter: invert(var(--invert));
}

/* Dialogs */

dialog {
  border: none;
  padding: 0;
  margin: auto;
  background: var(--paper);
  color: var(--ink);
  width: calc(100% - 40px);
  max-width: 560px;
  /* dvh is the height actually visible on iPhone Safari; 100vh there runs under the toolbars. */
  max-height: calc(100vh - 40px);
  max-height: calc(100dvh - 40px);
  overflow: auto;
  box-shadow: 0 30px 80px -20px var(--pop-shadow);
  animation: rise 0.3s ease both;
}

/* Literal colors: custom properties do not reliably reach ::backdrop. */
dialog::backdrop {
  background: rgba(35, 31, 25, 0.35);
  animation: fade 0.25s ease both;
}

@media (prefers-color-scheme: dark) {
  dialog::backdrop {
    background: rgba(0, 0, 0, 0.55);
  }
}

.pop {
  position: relative;
  padding: 36px 40px 32px;
  text-align: left;
}

.pop h2 {
  font: 500 30px/1.15 var(--serif);
  margin: 0 0 6px;
}

.pop .lede {
  font: italic 400 17px/1.5 var(--serif);
  color: var(--muted);
  margin: 0 0 26px;
}

.x {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 32px;
  height: 32px;
  border: none;
  background: none;
  color: var(--faint);
  font: 400 22px/1 var(--serif);
}

.x:hover {
  color: var(--red);
}

.pop ol {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.pop li {
  display: grid;
  grid-template-columns: 40px 1fr;
  gap: 12px;
}

.pop li b {
  font: 500 24px/1 var(--serif);
  color: var(--red);
  letter-spacing: -0.02em;
}

.pop .d {
  font: 400 17px/1.5 var(--serif);
  color: var(--muted);
  margin: 0;
}

.pop .t {
  font-weight: 600;
  color: var(--ink);
}

.pop .e {
  font: italic 400 19px/1.4 var(--serif);
  color: var(--plum);
  margin: 6px 0 0 18px;
}

.pop .words p {
  font: 400 18px/1.55 var(--serif);
  color: var(--ink);
  margin: 0 0 16px;
}

.pop .words p:last-child {
  margin-bottom: 0;
}

.pop .foot {
  font: italic 400 14px/1.5 var(--serif);
  color: var(--faint);
  margin: 26px 0 0;
  border-top: 1px solid var(--hair);
  padding-top: 16px;
}

.ex-group {
  margin-top: 22px;
}

.ex-group h3 {
  font: 400 11px/1 var(--mono);
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--faint);
  margin: 0 0 8px;
}

.ex-group ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

.pop .ex-group li {
  display: block;
}

.ex-group li button {
  display: block;
  width: 100%;
  text-align: left;
  font: 400 17px/1.4 var(--serif);
  color: var(--ink);
  background: none;
  border: none;
  padding: 7px 0;
  border-bottom: 1px solid var(--hair);
  transition: color 0.2s;
}

.ex-group li:last-child button {
  border-bottom: none;
}

.ex-group li button:hover {
  color: var(--plum);
}

.ex-group li button:focus-visible {
  outline: 1px solid var(--plum);
  outline-offset: 2px;
}

/* Animations */

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@keyframes fade {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes knit {
  0% {
    stroke-dashoffset: 40;
    opacity: 0;
  }
  30% {
    opacity: 1;
  }
  60% {
    stroke-dashoffset: 0;
    opacity: 1;
  }
  100% {
    stroke-dashoffset: 0;
    opacity: 0;
  }
}

/* Small screens */

@media (max-width: 560px) {
  .bot {
    flex-direction: column;
    align-items: stretch;
    gap: 16px;
  }

  .go {
    width: 100%;
  }

  .under {
    justify-content: center;
  }

  .rule {
    margin: 30px 0;
  }

  .pop {
    padding: 28px 22px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .card,
  dialog,
  dialog::backdrop {
    animation: none;
  }

  .stitch {
    animation: none;
    stroke-dashoffset: 0;
    opacity: 0.6;
  }

  .dot i,
  .input,
  .nav-btn,
  .go,
  .copy,
  .try {
    transition: none;
  }
}
