/* The editor with the spellchecker that fixes the word letter by letter: the editor of a made-up writing app, Penhold,
   on warm paper. A white card with a soft layered shadow, a short draft in a book serif, three flagged words with a
   wavy line, a glass card with the fix, a count of suggestions in the corner and a clarity meter at the foot. */
:root {
  --page: #f3efe8;              /* the paper behind the card */
  --card: #fffdfa;              /* the editor */
  --edge: rgba(40, 30, 20, 0.09); /* the card's edge */
  --ink: #1f1c18;               /* the draft */
  --muted: #8a8378;             /* the small words */
  --faint: #d9d3c8;             /* rules and tracks */
  --spell: #e0483e;             /* the wavy line of a spelling mistake */
  --style: #6a55d4;             /* the wavy line of a wordy phrase */
  --fixed: #23946a;             /* the word just fixed, the clear count */
  --glass: rgba(255, 253, 250, 0.72); /* the suggestion card */
}

* {
  box-sizing: border-box;
}

html {
  touch-action: manipulation;
}

html,
body {
  margin: 0;
  overflow-x: clip;
}

body {
  min-height: 100vh;
  background:
    radial-gradient(120% 80% at 50% 0%, #faf7f2 0%, var(--page) 60%, #ebe5db 100%);
  color: var(--ink);
  font-family: 'Mona Sans Variable', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* a whisper of grain over the paper */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.35;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0.3 0 0 0 0 0.25 0 0 0 0 0.2 0 0 0 0.09 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

.stage {
  position: relative;
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: clamp(10px, 3vh, 40px) clamp(10px, 4vw, 40px);
}

/* ---------------------------------------------------------------- the card */
.doc {
  position: relative;
  width: min(560px, 100%);
  padding: clamp(14px, 3.4vh, 30px) clamp(16px, 4vw, 34px) clamp(12px, 2.8vh, 24px);
  border-radius: 22px;
  background: var(--card);
  border: 1px solid var(--edge);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.9),
    0 1px 2px rgba(60, 40, 20, 0.05),
    0 6px 14px -6px rgba(60, 40, 20, 0.12),
    0 24px 48px -18px rgba(60, 40, 20, 0.22),
    0 60px 90px -40px rgba(60, 40, 20, 0.18);
}

.doc__sheen {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  background: linear-gradient(115deg, transparent 30%, rgba(255, 255, 255, 0.55) 45%, transparent 60%);
  background-size: 260% 100%;
  background-position: 120% 0;
  mix-blend-mode: soft-light;
}

.doc__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: clamp(10px, 2.4vh, 22px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 640;
  font-size: 14px;
  letter-spacing: 0.005em;
}

.brand__mark {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: var(--ink);
  stroke-width: 1.4;
  stroke-linejoin: round;
}

.brand__mark circle {
  fill: var(--ink);
  stroke: none;
}

/* the count of suggestions, a small pill */
.count {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 30px;
  padding: 0 12px 0 5px;
  border-radius: 99px;
  background: #f6f2ec;
  border: 1px solid rgba(40, 30, 20, 0.08);
  box-shadow: inset 0 1px 0 #fff;
  font-size: 12.5px;
  font-weight: 560;
  color: #4b453d;
  white-space: nowrap;
}

.count__icon {
  position: relative;
  width: 21px;
  height: 21px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--spell);
  color: #fff;
  overflow: hidden;
}

.count__icon svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  fill: none;
}

.count__ring {
  stroke: transparent;
}

.count__check {
  stroke: #fff;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
}

.count__num {
  display: inline-block;
  font-size: 11.5px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.count__words {
  position: relative;
  display: inline-grid;
}

.count__word {
  grid-area: 1 / 1;
}

.count__word--clear {
  color: var(--fixed);
  opacity: 0;
}

.doc__kicker {
  margin: 0 0 4px;
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 560;
}

.doc__title {
  margin: 0 0 clamp(8px, 1.6vh, 14px);
  font-family: 'Newsreader Variable', Georgia, serif;
  font-weight: 560;
  font-size: clamp(21px, min(5.2vw, 4.4vh), 30px);
  line-height: 1.12;
  letter-spacing: -0.012em;
}

.doc__body {
  position: relative;
}

.text {
  margin: 0;
  font-family: 'Newsreader Variable', Georgia, serif;
  font-size: clamp(15.5px, min(3.9vw, 3.3vh), 19.5px);
  line-height: 1.62;
  color: #2c2822;
}

/* a flagged word: the wavy line is a small SVG repeated under it, drawn and pulled back with clip-path and two variables */
.flag {
  position: relative;
  display: inline-block;
  white-space: pre;
  cursor: pointer;
  border-radius: 4px;
  --draw: 0;
  --erase: 0;
  transition: background-color 0.2s;
}

.flag::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  bottom: -2px;
  height: 5px;
  pointer-events: none;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='8' height='5' viewBox='0 0 8 5'%3E%3Cpath d='M0 3.6c2 0 2-2.4 4-2.4s2 2.4 4 2.4' fill='none' stroke='%23e0483e' stroke-width='1.3' stroke-linecap='round'/%3E%3C/svg%3E") repeat-x 0 0 / 8px 5px;
  clip-path: inset(0 calc((1 - var(--draw)) * 100%) 0 calc(var(--erase) * 100%));
}

.flag--style::after {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='8' height='5' viewBox='0 0 8 5'%3E%3Cpath d='M0 3.6c2 0 2-2.4 4-2.4s2 2.4 4 2.4' fill='none' stroke='%236a55d4' stroke-width='1.3' stroke-linecap='round'/%3E%3C/svg%3E");
}

.flag.is-open {
  background-color: rgba(224, 72, 62, 0.08);
}

.flag--style.is-open {
  background-color: rgba(106, 85, 212, 0.09);
}

@media (hover: hover) {
  .flag:not(.is-done):hover {
    background-color: rgba(224, 72, 62, 0.07);
  }

  .flag--style:not(.is-done):hover {
    background-color: rgba(106, 85, 212, 0.08);
  }
}

.flag.is-done {
  cursor: text;
}

/* one letter of a flagged word */
.ch {
  display: inline-block;
  white-space: pre;
}

.ch--ghost {
  position: absolute;
  top: 0;
  pointer-events: none;
}

.caret {
  display: inline-block;
  width: 1.5px;
  height: 1.05em;
  margin-left: 2px;
  vertical-align: -0.16em;
  background: var(--ink);
  border-radius: 1px;
  animation: blink 1.1s steps(1) infinite;
}

@keyframes blink {
  50% {
    opacity: 0;
  }
}

/* ---------------------------------------------------------------- the foot */
.doc__foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-top: clamp(12px, 2.6vh, 22px);
  padding-top: clamp(10px, 2vh, 16px);
  border-top: 1px solid rgba(40, 30, 20, 0.07);
  font-size: 12px;
  color: var(--muted);
}

.meter {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
}

.meter__label {
  font-weight: 560;
  color: #5c564c;
}

.meter__bar {
  position: relative;
  width: clamp(70px, 22vw, 130px);
  height: 5px;
  border-radius: 99px;
  background: #efe9df;
  box-shadow: inset 0 1px 1px rgba(60, 40, 20, 0.08);
  overflow: hidden;
}

.meter__fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: 68%;
  border-radius: inherit;
  background: linear-gradient(90deg, #e9a23b, #23946a);
  background-size: 160px 100%;
}

.meter__val {
  font-weight: 650;
  color: #3c372f;
  font-variant-numeric: tabular-nums;
  min-width: 2ch;
}

.doc__words {
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

/* ---------------------------------------------------------------- the glass card with the fix */
.pop {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 5;
  width: max-content;
  max-width: min(260px, calc(100% - 20px));
  padding: 11px 12px 12px;
  border-radius: 14px;
  background: var(--glass);
  -webkit-backdrop-filter: blur(14px) saturate(1.4);
  backdrop-filter: blur(14px) saturate(1.4);
  border: 1px solid rgba(255, 255, 255, 0.85);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.95),
    0 0 0 1px rgba(40, 30, 20, 0.06),
    0 10px 24px -8px rgba(60, 40, 20, 0.28),
    0 30px 50px -24px rgba(60, 40, 20, 0.3);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.pop.is-on {
  visibility: visible;
  pointer-events: auto;
}

.pop__kind {
  display: inline-flex;
  align-items: center;
  font-size: 10.5px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  font-weight: 650;
  color: var(--spell);
}

.pop--style .pop__kind {
  color: var(--style);
}

.pop__why {
  display: block;
  margin-top: 2px;
  font-size: 12px;
  color: var(--muted);
}

.pop__row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
}

.pop__fix {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 34px;
  padding: 0 10px 0 12px;
  border: 0;
  border-radius: 10px;
  background: var(--ink);
  color: #fffaf2;
  font: 600 15px/1 'Newsreader Variable', Georgia, serif;
  cursor: pointer;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.18), 0 6px 14px -6px rgba(30, 20, 10, 0.5);
}

.pop__enter {
  width: 14px;
  height: 14px;
  fill: none;
  stroke: rgba(255, 250, 242, 0.6);
  stroke-width: 1.4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.pop__ignore {
  height: 34px;
  padding: 0 10px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font: 560 12.5px/1 'Mona Sans Variable', system-ui, sans-serif;
  cursor: pointer;
}

@media (hover: hover) {
  .pop__ignore:hover {
    background: rgba(40, 30, 20, 0.05);
    color: #4b453d;
  }
}

.pop__fix:focus-visible,
.pop__ignore:focus-visible,
.flag:focus-visible {
  outline: 2px solid var(--style);
  outline-offset: 2px;
}

/* ---------------------------------------------------------------- the drawn pointer of the pilot */
.pointer {
  position: absolute;
  left: 0;
  top: 0;
  z-index: 9;
  width: 22px;
  height: 22px;
  pointer-events: none;
  opacity: 0;
  fill: #1f1c18;
  stroke: #fff;
  stroke-width: 1.4;
  stroke-linejoin: round;
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.25));
}

@media (max-width: 420px) {
  .doc__kicker {
    display: none;
  }

  .doc__words {
    display: none;
  }
}
