:root {
  color-scheme: light;
  font-family: Arial, 'Malgun Gothic', sans-serif;
  --page: #fff;
  --text: #000;
  --link: #00e;
  --muted: #666;
  --line: #ddd;
  --edge: #aaa;
  --button: #eee;
  --pressed: #d9d9d9;
  --hover: #f2f2f2;
  --error: #a00;
  color: var(--text);
  background: var(--page);
}
:root[data-theme="dark"] { color-scheme: dark; --page: #171717; --text: #eee; --link: #a4baff; --muted: #b3b3b3; --line: #414141; --edge: #777; --button: #303030; --pressed: #494949; --hover: #292929; --error: #ffaaaa; }
* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; min-height: 100svh; display: flex; flex-direction: column; -webkit-text-size-adjust: 100%; }
[hidden] { display: none !important; }
button, input, select { font: inherit; }
a { color: var(--link); text-decoration: underline; }
button { cursor: pointer; touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
button:disabled { cursor: default; }
:focus-visible { outline: 2px solid var(--link); outline-offset: 4px; }
.home {
  flex: 1;
  display: flex;
  justify-content: center;
  padding: clamp(42px, 14vh, 120px) 20px 60px;
}
.home-content { width: min(100%, 600px); text-align: center; }
.identity h1 {
  margin: 0;
  font-family: 'Times New Roman', serif;
  font-size: clamp(56px, 12vw, 82px);
  font-weight: 400;
  line-height: 1.1;
  overflow-wrap: anywhere;
}
.identity p { margin: 8px 0 0; font-size: 17px; line-height: 1.5; }
.search-decoration { width: min(100%, 440px); margin: 32px auto 0; }
.search-box { display: flex; align-items: center; border: 1px solid var(--link); border-radius: 2px; background: var(--page); }
.search-box:focus-within { outline: 2px solid var(--link); outline-offset: 3px; }
.search-line { display: block; min-width: 0; width: 100%; height: 44px; padding: 0 10px; border: 0; background: transparent; color: var(--text); font-size: 16px; }
.search-line:focus { outline: none; }
.search-submit { display: grid; place-items: center; flex: 0 0 44px; width: 44px; height: 44px; padding: 0; border: 0; background: transparent; color: var(--muted); }
.search-submit:hover { background: var(--hover); }
.search-submit:active { background: var(--pressed); }
.search-submit:focus-visible { outline-offset: -5px; }
.refresh { min-height: 44px; padding: 7px 16px; border: 1px outset var(--edge); border-radius: 0; background: var(--button); color: var(--text); font-size: 15px; line-height: 20px; }
.refresh:active:enabled { border-style: inset; background: var(--pressed); box-shadow: inset 1px 1px 2px #0003; transform: translateY(1px); }
/* The blog opens over the page, so nothing navigates away. On a phone it covers the
   screen completely; on a wide screen the main page stays beside it and can be folded. */
.home-content { transition: transform 0.3s ease, opacity 0.3s ease; }
.blog-layer {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  grid-template-rows: minmax(0, 1fr);
  overflow: hidden;
  overscroll-behavior: contain;
  background: var(--page);
  transform: translateX(100%);
  visibility: hidden;
  transition: transform 0.34s cubic-bezier(.22,.61,.36,1), visibility 0s linear 0.34s;
}
body.blog-open .blog-layer {
  transform: translateX(0);
  visibility: visible;
  transition-delay: 0s;
}
body.blog-open { overflow: hidden; }
body.blog-open .home-content { transform: translateX(-18%); opacity: 0.2; }
.blog-frame { grid-row: 1; grid-column: 1; position: relative; z-index: 0; display: block; width: 100%; height: 100%; min-height: 0; border: 0; background: var(--page); opacity: 0; transition: opacity 0.16s ease; }
/* The panel slides first and the blog fades in once it has arrived, so no text is visible
   mid-slide. A delay does this in CSS alone: relying on a transitionend event failed when
   reopening mid-close, because an unchanged transform fires no event and the blog stayed
   invisible. Closing has no delay, so the text leaves with the panel. */
body.blog-open .blog-frame { opacity: 1; transition-delay: 0.3s; }
.blog-loading {
  grid-row: 1;
  grid-column: 1;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: var(--page);
  color: var(--muted);
  font-size: 15px;
  visibility: hidden;
  opacity: 0;
  transition: opacity 0.16s ease, visibility 0s linear 0.16s;
}
body.blog-open .blog-layer:not([data-loaded="true"]) .blog-loading {
  visibility: visible;
  opacity: 1;
  transition-delay: 0.3s, 0.3s;
}
.blog-spinner {
  width: 18px;
  height: 18px;
  border: 2px solid var(--line);
  border-top-color: var(--link);
  border-radius: 50%;
  animation: blog-spin 0.8s linear infinite;
}
@keyframes blog-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .home-content { transition-duration: 0.12s; }
  .blog-layer { transition-duration: 0.18s, 0s; }
  body.blog-open .blog-frame { transition-delay: 0.16s; }
  body.blog-open .blog-layer:not([data-loaded="true"]) .blog-loading { transition-delay: 0.16s, 0.16s; }
  .blog-spinner { animation-duration: 1.4s; }
}
.search-popup { width: min(100% - 32px, 320px); padding: 24px; border: 1px solid var(--edge); color: var(--text); background: var(--page); text-align: center; }
.search-popup::backdrop { background: #0005; }
.search-popup p { margin: 0 0 20px; font-size: 16px; line-height: 1.5; }
.links { display: flex; align-items: center; justify-content: center; flex-wrap: wrap; column-gap: 20px; row-gap: 4px; margin-top: 46px; font-size: 15px; }
.links > a, .tools summary { display: inline-flex; align-items: center; min-height: 44px; padding: 10px 2px; white-space: nowrap; }
.links a[aria-disabled] { cursor: default; }
.formerly { font-size: 13px; margin-left: 3px; }
.tools { position: relative; }
.tools summary { display: flex; align-items: center; list-style: none; cursor: pointer; color: var(--link); text-decoration: underline; }
.tools summary::-webkit-details-marker { display: none; }
.tools-menu { position: absolute; z-index: 1; top: calc(100% - 1px); left: 50%; transform: translateX(-50%); width: 132px; padding: 3px; border: 1px solid var(--edge); background: var(--page); text-align: left; }
.tools-menu a, .tools-menu .text-link { display: flex; align-items: center; width: 100%; min-height: 44px; padding: 10px 12px; }
.tools-menu a:hover, .tools-menu button:hover { background: var(--hover); }
.site-credit { display: flex; justify-content: center; align-items: center; flex-wrap: wrap; gap: 4px 18px; margin: 16px 0 0; color: var(--muted); font-size: 13px; line-height: 1.7; }
.site-credit a, .text-link { display: inline-flex; align-items: center; min-height: 44px; }
.text-link { padding: 0; border: 0; background: none; color: var(--link); text-decoration: underline; }
.donation { width: min(100% - 32px, 760px); margin: 0 auto 40px; }
.home .donation, .ip-page .donation { width: 100%; margin: 24px auto 0; text-align: left; }
.donation .status { text-align: center; }
.donation .refresh { display: block; margin: 16px auto; }
.donation-currency { display: flex; align-items: center; justify-content: center; gap: 12px; margin-bottom: 20px; font-size: 15px; }
.donation-currency select { min-height: 44px; padding: 6px 12px; border: 1px solid var(--edge); border-radius: 0; color: var(--text); background: var(--page); font-size: 16px; }
#donate-status:empty, #checkout:empty { display: none; }
.ip-page { flex: 1; padding: clamp(35px, 10vh, 90px) 24px 60px; }
.ip-content { width: min(100%, 520px); margin: auto; }
.ip-top { display: flex; justify-content: space-between; align-items: center; font-size: 15px; }
.ip-top .tools-menu { left: auto; right: 0; transform: none; }
.back { display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 8px 0; font-size: 15px; }
.ip-content h1 { margin: 25px 0 27px; font-family: 'Times New Roman', serif; font-size: 44px; font-weight: 400; }
.ip-data { margin: 0; }
.ip-data > div { display: grid; grid-template-columns: 100px minmax(0, 1fr); align-items: baseline; gap: 16px; padding: 18px 0; border-bottom: 1px solid var(--line); }
.ip-data > div:first-child { border-top: 1px solid var(--line); }
.ip-data dt { font-size: 15px; }
.ip-data dd { margin: 0; font-size: 16px; line-height: 1.5; overflow-wrap: anywhere; }
.ip-data .address { font-size: 25px; font-variant-numeric: tabular-nums; }
.country-flag { vertical-align: -5px; margin-right: 4px; }
.ip-actions { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 12px 18px; margin-top: 19px; min-height: 44px; }
.status { flex: 1; min-width: 150px; margin: 0; color: var(--muted); font-size: 15px; line-height: 1.7; }
.status.error { color: var(--error); }
.refresh { flex: none; }
.refresh:disabled { color: var(--muted); }
.ip-note { margin: 24px 0 0; color: var(--muted); font-size: 13px; line-height: 1.9; }
#ip-type-note:empty { display: none; }
@media (max-width: 520px) {
  .home { padding: clamp(48px, 11svh, 90px) max(16px, env(safe-area-inset-right)) 48px max(16px, env(safe-area-inset-left)); }
  .search-decoration { margin-top: 28px; }
  .links { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); width: min(100%, 420px); column-gap: 12px; row-gap: 2px; margin: 40px auto 0; }
  .links > * { min-width: 0; justify-self: stretch; text-align: center; }
  .links > a, .links > .text-link, .links .tools summary { justify-content: center; white-space: normal; }
  .links > :last-child:nth-child(odd) { grid-column: 1 / -1; justify-self: center; }
  .formerly { font-size: 12px; }
  .site-credit > span { flex-basis: 100%; text-align: center; }
  .ip-page { padding: 30px max(20px, env(safe-area-inset-right)) 40px max(20px, env(safe-area-inset-left)); }
  .ip-data > div { grid-template-columns: minmax(116px, 36%) minmax(0, 1fr); gap: 12px; }
  .ip-data .address { font-size: 22px; }
}
@media (max-height: 480px) and (orientation: landscape) {
  .home, .ip-page { padding-top: 28px; }
}

.grape-page { flex: 1; display: flex; padding: clamp(35px, 8vh, 80px) 24px 48px; }
.grape-content { width: min(100%, 560px); margin: auto; }
.grape-content h1 { margin: 25px 0 20px; font-family: 'Times New Roman', serif; font-size: 44px; font-weight: 400; }
.grape-hud { display: flex; justify-content: space-between; align-items: baseline; flex-wrap: wrap; gap: 8px 18px; margin-bottom: 16px; }
.grape-score { margin: 0; font-size: 19px; }
.grape-score strong { font-variant-numeric: tabular-nums; }
.grape-hud .status { text-align: right; }
.grape-board { position: relative; box-shadow: 0 10px 24px #20102a12; }
.grape-grid {
  display: grid;
  grid-template-columns: repeat(16, 1fr);
  width: 100%;
  aspect-ratio: 1;
  border: 1px solid var(--edge);
  background: var(--hover);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  overscroll-behavior: contain;
}
.grape-cell {
  position: relative;
  min-width: 0;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 0;
  background: transparent;
  color: var(--text);
  cursor: pointer;
}
.grape-cell.grape {
  overflow: visible;
  z-index: 1;
  border-color: transparent;
  background: linear-gradient(135deg, color-mix(in srgb, var(--grape-color, #6f2da8) 10%, transparent), transparent);
}
.grape-cell.grape::before {
  position: absolute;
  inset: 4%;
  content: '';
  border-radius: 44% 44% 50% 50%;
  background:
    radial-gradient(circle at 38% 28%, #ffffffa8 0 8%, transparent 10%),
    radial-gradient(circle at 68% 28%, #ffffff7a 0 7%, transparent 9%),
    radial-gradient(circle at 28% 55%, #ffffff69 0 6%, transparent 8%),
    radial-gradient(circle at 50% 50%, var(--grape-color, #6f2da8) 0 24%, transparent 26%),
    radial-gradient(circle at 29% 70%, var(--grape-color, #6f2da8) 0 22%, transparent 24%),
    radial-gradient(circle at 72% 70%, var(--grape-color, #6f2da8) 0 22%, transparent 24%),
    radial-gradient(circle at 50% 88%, var(--grape-color, #6f2da8) 0 20%, transparent 22%);
  filter: drop-shadow(0 1px 1px #210c3566);
}
.grape-cell.grape::after {
  position: absolute;
  top: 8%;
  left: 45%;
  width: 19%;
  height: 24%;
  content: '';
  border-radius: 90% 0 90% 0;
  background: #4a812d;
  transform: rotate(-24deg);
}
.grape-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 18px;
  padding: 24px;
  background: color-mix(in srgb, var(--page) 88%, transparent);
  text-align: center;
}
.grape-message { margin: 0; font-size: 16px; line-height: 1.8; }
.difficulty-picker { display: flex; align-items: center; justify-content: center; gap: 10px; margin: 0; padding: 0; border: 0; }
.difficulty-picker legend { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.difficulty-picker label { display: flex; align-items: center; gap: 5px; min-height: 36px; cursor: pointer; }
.difficulty-picker input { width: 16px; height: 16px; margin: 0; accent-color: #6f2da8; }
.grape-page .donation { width: 100%; margin: 24px auto 0; text-align: left; }

.qr-page { flex: 1; padding: clamp(35px, 10vh, 90px) 24px 60px; }
.qr-content { width: min(100%, 560px); margin: auto; }
.qr-content h1 { margin: 25px 0 27px; font-family: 'Times New Roman', serif; font-size: 44px; font-weight: 400; }
.qr-form { display: flex; flex-direction: column; gap: 20px; margin: 0 0 28px; }
.qr-field { display: flex; flex-direction: column; gap: 7px; font-size: 15px; }
.qr-field textarea, .qr-field input[type="number"], .qr-field select {
  width: 100%;
  min-width: 0;
  max-width: 100%;
  min-height: 44px;
  padding: 9px 11px;
  border: 1px solid var(--edge);
  border-radius: 0;
  color: var(--text);
  background: var(--page);
  font-size: 16px;
}
.qr-field textarea { resize: vertical; line-height: 1.6; overflow-wrap: anywhere; }
.qr-field select:disabled { color: var(--muted); }
.qr-options { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; align-items: start; }
.qr-more { font-size: 14px; }
.qr-more summary { display: flex; align-items: center; min-height: 44px; color: var(--link); text-decoration: underline; cursor: pointer; list-style: none; }
.qr-more summary::-webkit-details-marker { display: none; }
.qr-more-body { display: flex; flex-direction: column; gap: 18px; padding: 4px 0 0; }
.qr-logo-row { display: flex; align-items: center; flex-wrap: wrap; gap: 12px; }
.qr-logo-row input[type="file"] {
  flex: 1;
  min-width: 190px;
  /* A 44px tall row keeps the file picker comfortable to tap on a phone. */
  min-height: 44px;
  padding: 6px 0;
  font-size: 14px;
  color: var(--text);
}
.qr-logo-row input[type="file"]::file-selector-button {
  min-height: 44px;
  margin-right: 10px;
  padding: 6px 14px;
  border: 1px outset var(--edge);
  border-radius: 0;
  background: var(--button);
  color: var(--text);
  font: inherit;
  cursor: pointer;
}
.qr-hint { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.7; }
#qr-scan-tip { text-align: center; }
.qr-result { display: flex; flex-direction: column; align-items: center; gap: 14px; }
#qr-canvas { display: block; width: 100%; height: auto; border: 1px solid var(--line); background: #fff; image-rendering: pixelated; }
.qr-result .status { flex: none; text-align: center; }
.qr-summary { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.7; text-align: center; }
.qr-summary:empty { display: none; }
.qr-actions { display: flex; justify-content: center; flex-wrap: wrap; gap: 12px; }
.qr-page .donation { width: 100%; margin: 24px auto 0; text-align: left; }
.qr-page .ip-note { margin-top: 26px; }

@media (max-width: 520px) {
  .grape-page { padding: 24px max(12px, env(safe-area-inset-right)) 36px max(12px, env(safe-area-inset-left)); }
  .grape-content { width: 100%; }
  .grape-content h1 { margin: 16px 0 14px; font-size: clamp(34px, 10vw, 44px); }
  .grape-hud { margin-bottom: 12px; }
  .grape-score { font-size: 17px; }
  .grape-hud .status { min-width: 0; font-size: 13px; }
  .grape-overlay { gap: 14px; padding: 18px; }
  .grape-message { font-size: 14px; line-height: 1.6; }
  .difficulty-picker { gap: 8px; font-size: 14px; }
}

@media (max-width: 520px) {
  .qr-page { padding: 30px max(20px, env(safe-area-inset-right)) 40px max(20px, env(safe-area-inset-left)); }
  .qr-content h1 { margin: 16px 0 20px; font-size: clamp(34px, 10vw, 44px); }
  .qr-options { grid-template-columns: minmax(0, 1fr); gap: 16px; }
  .qr-actions .refresh { flex: 1 1 auto; }
}

.share-page { flex: 1; padding: clamp(35px, 10vh, 90px) 24px 60px; }
.share-content { width: min(100%, 560px); margin: auto; }
.share-content h1 { margin: 25px 0 16px; font-family: 'Times New Roman', serif; font-size: 44px; font-weight: 400; }
.share-heading { margin: 28px 0 12px; font-size: 15px; font-weight: 700; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.share-list { margin: 0; padding: 0; list-style: none; }

/* Radar: devices sit on the arcs, nearest ring first. */
.radar { margin: 8px 0 4px; }
.radar-stage {
  position: relative;
  width: 100%;
  aspect-ratio: 400 / 250;
  /* On a narrow phone the arcs would sit too close together for the device icons to
     separate, so the stage keeps a minimum height. */
  min-height: 230px;
}
.radar-arcs { position: absolute; inset: 0; width: 100%; height: 100%; }
.radar-arcs path {
  fill: none;
  stroke: var(--radar, #09f);
  stroke-width: 15;
  stroke-linecap: round;
  opacity: 0.22;
}
.radar-searching .radar-arcs path { animation: radar-pulse 2.4s ease-in-out infinite; }
.radar-searching .radar-arcs path:nth-child(2) { animation-delay: 0.2s; }
.radar-searching .radar-arcs path:nth-child(3) { animation-delay: 0.4s; }
.radar-searching .radar-arcs path:nth-child(4) { animation-delay: 0.6s; }
@keyframes radar-pulse {
  0%, 100% { opacity: 0.16; }
  50% { opacity: 0.5; }
}
@media (prefers-reduced-motion: reduce) {
  .radar-searching .radar-arcs path { animation: none; opacity: 0.3; }
}
.radar-peers { position: absolute; inset: 0; margin: 0; padding: 0; list-style: none; }
/* Each device is placed by the script with --x and --y as percentages of the stage. */
.radar-peer { position: absolute; left: var(--x); top: var(--y); transform: translate(-50%, -50%); }
.radar-peer-file { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
/* Only the icon sits on the arc. A panel would cover neighbouring devices, so the name and
   code are drawn beneath it without a background. */
.radar-peer-send {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  width: 74px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--text);
  font-size: 11px;
  line-height: 1.3;
  text-align: center;
  cursor: pointer;
}
.radar-peer-icon {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 1px solid var(--edge);
  border-radius: 50%;
  /* Opaque so the arc does not run through the icon itself. */
  background: var(--page);
  color: var(--radar, #09f);
}
.radar-peer-send:hover .radar-peer-icon { background: var(--hover); border-color: var(--radar, #09f); }
.radar-peer-send:active .radar-peer-icon { background: var(--pressed); }
.radar-peer-file:focus-visible + .radar-peer-send .radar-peer-icon {
  outline: 2px solid var(--link);
  outline-offset: 3px;
}
.radar-peer-name {
  display: block;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  /* A faint halo keeps the label readable where it crosses an arc. */
  text-shadow: 0 0 3px var(--page), 0 0 3px var(--page), 0 0 3px var(--page);
}
.radar-peer-code {
  color: var(--muted);
  font-family: 'Courier New', monospace;
  font-size: 10px;
  letter-spacing: 1px;
  text-shadow: 0 0 3px var(--page), 0 0 3px var(--page);
}
.radar-note { margin: 4px 0 0; color: var(--muted); font-size: 14px; line-height: 1.7; text-align: center; }
.radar-note.error { color: var(--error); }
.share-about { margin-top: 26px; font-size: 14px; }
.share-about summary { display: flex; align-items: center; min-height: 44px; color: var(--link); text-decoration: underline; cursor: pointer; list-style: none; }
.share-about summary::-webkit-details-marker { display: none; }
.share-about-body { display: flex; flex-direction: column; gap: 10px; padding: 4px 0 0; }
.share-about input { width: 100%; min-width: 0; min-height: 44px; padding: 9px 11px; border: 1px solid var(--edge); border-radius: 0; color: var(--text); background: var(--page); font-size: 16px; }
.share-about strong { font-family: 'Courier New', monospace; letter-spacing: 2px; }

.typing-page { flex: 1; padding: clamp(35px, 10vh, 90px) 24px 60px; }
.typing-content { width: min(100%, 660px); margin: auto; }
.typing-content h1 { margin: 25px 0 20px; font-family: 'Times New Roman', serif; font-size: 44px; font-weight: 400; }
.typing-bar { display: flex; align-items: center; flex-wrap: wrap; gap: 12px 16px; margin-bottom: 18px; }
.typing-picker { display: flex; align-items: center; flex-wrap: wrap; gap: 12px; flex: 1 1 260px; }
.typing-toggles { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.typing-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  padding: 7px 14px;
  border: 1px solid var(--edge);
  border-radius: 0;
  background: var(--page);
  color: var(--text);
  font-size: 14px;
  white-space: nowrap;
}
.typing-toggle:hover { background: var(--hover); }
.typing-toggle[aria-pressed="false"] { color: var(--muted); }
.typing-langs { display: flex; gap: 8px; }
.typing-lang {
  min-height: 44px;
  padding: 7px 16px;
  border: 1px solid var(--edge);
  border-radius: 0;
  background: var(--page);
  color: var(--text);
  font-size: 15px;
}
.typing-lang:hover { background: var(--hover); }
.typing-lang[aria-selected="true"] { background: var(--text); color: var(--page); border-color: var(--text); }
.typing-choose { flex: 1; min-width: 190px; }
.typing-choose select {
  width: 100%;
  min-width: 0;
  min-height: 44px;
  padding: 9px 11px;
  border: 1px solid var(--edge);
  border-radius: 0;
  color: var(--text);
  background: var(--page);
  /* 16px stops iOS from zooming the page when the menu is focused. */
  font-size: 16px;
}
.typing-stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin: 0 0 20px; }
.typing-stats > div { padding: 12px 14px; border: 1px solid var(--line); }
.typing-stats dt { margin: 0 0 4px; color: var(--muted); font-size: 13px; }
.typing-stats dd { margin: 0; font-size: 24px; font-variant-numeric: tabular-nums; }
.typing-unit { color: var(--muted); font-size: 13px; }
.typing-passage {
  padding: 20px 22px;
  border: 1px solid var(--edge);
  background: var(--hover);
  font-size: 21px;
  line-height: 2.1;
  word-break: keep-all;
  overflow-wrap: anywhere;
  user-select: none;
}
.typing-passage .ch {
  color: var(--muted);
  border-radius: 2px;
  /* A gentle sweep on the current character only. Longer transitions on every character
     left a trailing wave behind fast typing. */
  transition: color 80ms ease-out;
}
.typing-passage .ch.correct { color: var(--text); }
/* The syllable being composed stays visible while it is being built, so typing looks
   continuous instead of a character appearing all at once. */
.typing-passage .ch.composing {
  color: var(--text);
  background: var(--line);
}
.typing-passage .ch.wrong { color: var(--page); background: var(--error); }
.typing-passage .ch.cursor { box-shadow: inset 0 -2px 0 var(--link); color: var(--text); }
@media (prefers-reduced-motion: reduce) {
  .typing-passage .ch { transition: none; }
}
/* The capture field must stay focusable for Korean and Chinese input methods, so it is
   moved off screen rather than hidden, which would stop composition entirely. */
.typing-capture {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  border: 0;
  opacity: 0;
  overflow: hidden;
  resize: none;
  /* Keeping it near the caret stops phones from scrolling away while typing. */
  left: 50%;
  pointer-events: none;
}
.typing-stage { display: flex; align-items: stretch; gap: 18px; }
.typing-main { flex: 1; min-width: 0; position: relative; }
.typing-passage { cursor: text; }
.typing-passage:focus-visible { outline: 2px solid var(--link); outline-offset: 3px; }
.typing-main .qr-hint { margin-top: 8px; }

/* Save the Stickman: a cliff on the left with lava rising from the bottom. */
.game-scene { flex: 0 0 116px; display: flex; flex-direction: column; gap: 8px; }
.game-cliff {
  position: relative;
  flex: 1;
  min-height: 240px;
  overflow: hidden;
  border: 1px solid var(--edge);
  background: linear-gradient(180deg, var(--hover) 0%, var(--page) 62%, #6b4a3a 62%, #4a3228 100%);
}
.game-stickman {
  position: absolute;
  left: 50%;
  bottom: 38%;
  transform: translateX(-50%);
  color: var(--text);
  transition: transform 0.25s ease;
}
.game-stickman.game-safe { color: #2e7d32; }
.game-stickman.game-gone { opacity: 0.25; transform: translateX(-50%) translateY(6px); }
.game-lava {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: calc(var(--level, 0%) * 0.38 + 0%);
  background: linear-gradient(180deg, #ff9d2f 0%, #e5361b 60%, #a3170a 100%);
  transition: height 0.2s linear;
}
.game-lava-top {
  position: absolute;
  top: -4px;
  left: 0;
  right: 0;
  height: 8px;
  background: #ffce4f;
  filter: blur(2px);
}
.game-danger .game-cliff { box-shadow: inset 0 0 0 2px #e5361b; }
.game-readout { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.5; text-align: center; }
.game-danger .game-readout { color: var(--error); }
@media (prefers-reduced-motion: reduce) {
  .game-lava, .game-stickman { transition: none; }
}

.typing-setup { width: min(100% - 32px, 400px); padding: 22px; border: 1px solid var(--edge); color: var(--text); background: var(--page); }
.typing-setup::backdrop { background: #0006; }
.typing-setup h2 { margin: 0 0 10px; font-size: 20px; }
.setup-group { display: flex; flex-wrap: wrap; gap: 8px 16px; margin: 16px 0 0; padding: 0; border: 0; }
.setup-group legend { padding: 0; color: var(--muted); font-size: 13px; }
/* The whole label is the touch target, so the small radio dot is easy to hit on a phone. */
.setup-group label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 44px;
  min-height: 44px;
  padding: 0 12px 0 10px;
  border: 1px solid var(--line);
  font-size: 15px;
  cursor: pointer;
}
.setup-group label:hover { background: var(--hover); }
.setup-group label:has(input:checked) { border-color: var(--text); background: var(--hover); }
.setup-group label:has(input:focus-visible) { outline: 2px solid var(--link); outline-offset: 2px; }
.setup-group input { width: 18px; height: 18px; margin: 0; }
.typing-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 12px 18px; margin-top: 16px; }
.typing-page .donation { width: 100%; margin: 24px auto 0; text-align: left; }
.typing-result { width: min(100% - 32px, 560px); padding: 22px; border: 1px solid var(--edge); color: var(--text); background: var(--page); }
.typing-result::backdrop { background: #0006; }
.typing-result h2 { margin: 0 0 14px; font-size: 20px; }
#result-card { display: block; width: 100%; height: auto; border: 1px solid var(--line); }
.typing-result-actions { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 10px; margin-top: 16px; }
#result-status:empty { display: none; }

@media (max-width: 520px) {
  .typing-page { padding: 30px max(20px, env(safe-area-inset-right)) 40px max(20px, env(safe-area-inset-left)); }
  .typing-content h1 { margin: 16px 0 16px; font-size: clamp(34px, 10vw, 44px); }
  .typing-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .typing-stats > div { padding: 10px 12px; }
  .typing-stats dd { font-size: 20px; }
  .typing-passage { padding: 16px; font-size: 19px; line-height: 2; }
  .typing-choose { flex: 1 1 100%; }
  .typing-toggles { width: 100%; }
  .typing-toggle { flex: 1; justify-content: center; }
  .typing-result-actions .refresh { flex: 1 1 auto; justify-content: center; }
  /* The cliff moves above the passage so the text keeps the full width. */
  .typing-stage { flex-direction: column; gap: 12px; }
  .game-scene { flex: none; flex-direction: row; align-items: center; gap: 12px; }
  .game-cliff { flex: 1; min-height: 96px; }
  .game-stickman svg { width: 28px; height: 44px; }
  .game-readout { flex: 0 0 76px; text-align: left; }
}
.share-transfers:not(:has(.share-transfer)) { display: none; }
.share-transfer { padding: 14px 0; border-bottom: 1px solid var(--line); }
.share-transfer:first-child { border-top: 1px solid var(--line); }
.share-transfer-name { margin: 0 0 4px; font-size: 16px; overflow-wrap: anywhere; }
.share-transfer-actions:empty { display: none; }
.share-transfer-actions { margin-top: 8px; }
.share-download { display: inline-flex; align-items: center; min-height: 44px; font-size: 15px; }
.share-prompt { width: min(100% - 32px, 380px); padding: 24px; border: 1px solid var(--edge); color: var(--text); background: var(--page); }
.share-prompt::backdrop { background: #0005; }
.share-prompt h2 { margin: 0 0 12px; font-size: 19px; }
.share-prompt p { margin: 0 0 10px; font-size: 15px; line-height: 1.6; overflow-wrap: anywhere; }
.share-prompt-actions { display: flex; justify-content: flex-end; gap: 12px; margin-top: 20px; }
.share-page .donation { width: 100%; margin: 24px auto 0; text-align: left; }
.share-page .ip-note { margin-top: 26px; }

/* Blog editor. The post-login editor follows the familiar shape of hosted blog editors:
   a top bar, a post list on the side and a paper-like writing surface. */
.editor-root { background: var(--hover); }
.editor-page { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.editor-unlock { width: min(100% - 48px, 420px); margin: auto; padding: 32px 28px; border: 1px solid var(--line); border-radius: 10px; background: var(--page); box-shadow: 0 12px 32px #0001; }
.editor-unlock-title { margin: 0 0 10px; font-family: 'Times New Roman', serif; font-size: 34px; font-weight: 400; }
.editor-login-note { margin: 0 0 14px; color: var(--muted); font-size: 15px; line-height: 1.7; }
.editor-login-slot { min-height: 44px; }
.editor-unlock-back { margin: 16px 0 0; font-size: 14px; }
.editor-unlock-back a { display: inline-flex; align-items: center; gap: 6px; min-height: 44px; }

.editor-app { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.editor-topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 12px;
  min-height: 56px; padding: 6px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--page);
}
.editor-topbar-title { font-size: 15px; font-weight: 700; }
.editor-topbar-home { display: inline-flex; align-items: center; gap: 6px; min-height: 44px; padding: 0 4px; font-size: 14px; text-decoration: none; }
.editor-topbar-home:hover { text-decoration: underline; }
.editor-user { margin-left: auto; color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.editor-topbar-actions { display: flex; align-items: center; gap: 8px; }
.ed-btn {
  min-height: 38px; padding: 6px 14px;
  border: 1px solid var(--line); border-radius: 6px;
  background: var(--page); color: var(--text);
  font-size: 14px; line-height: 1.4; white-space: nowrap;
}
.ed-btn:hover { background: var(--hover); }
.ed-btn:active { background: var(--pressed); }
.ed-btn-primary { border-color: var(--link); background: var(--link); color: var(--page); font-weight: 600; }
.ed-btn-primary:hover { filter: brightness(1.12); background: var(--link); }
.ed-btn-block { width: 100%; }
.ed-icon-btn { display: none; place-items: center; width: 40px; height: 40px; padding: 0; border: 1px solid var(--line); border-radius: 6px; background: var(--page); color: var(--text); }

.editor-shell { flex: 1; display: grid; grid-template-columns: 244px minmax(0, 1fr); min-height: 0; }
.editor-side {
  padding: 14px 12px 24px; overflow-y: auto;
  border-right: 1px solid var(--line); background: var(--page);
}
.editor-side-title { margin: 20px 4px 8px; color: var(--muted); font-size: 12px; font-weight: 700; letter-spacing: 0.06em; }
.editor-side .ed-btn-block { margin-top: 2px; }
.editor-side .editor-analytics-link { margin-top: 9px; text-align: left; }
.editor-analytics-link.is-active { border-color: var(--link); color: var(--link); }
.editor-item-list { margin: 0; padding: 0; list-style: none; }
.editor-item { display: flex; align-items: stretch; border-radius: 8px; }
.editor-item.is-active { background: var(--hover); }
.editor-item-open {
  flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px;
  padding: 9px 10px; border: 0; background: none; color: var(--text);
  text-align: left; font-size: 14px;
}
.editor-item-open:hover { text-decoration: underline; }
.editor-item-title { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.editor-item-meta { color: var(--muted); font-size: 12px; }
.editor-badge { display: inline-block; padding: 0 6px; border: 1px solid var(--line); border-radius: 999px; color: var(--muted); font-size: 11px; }
.editor-item-delete { flex: 0 0 auto; margin: 6px 6px 6px 0; padding: 0 8px; border: 0; border-radius: 6px; background: none; color: var(--muted); font-size: 12px; }
.editor-item-delete:hover { background: var(--pressed); color: var(--error); }
.editor-item-empty { padding: 8px 10px; color: var(--muted); font-size: 13px; }
.editor-side-backdrop { position: fixed; inset: 0; z-index: 8; background: #0006; }

.editor-workspace {
  width: min(100%, 920px); margin: 22px auto; padding: 26px 30px 20px;
  border: 1px solid var(--line); border-radius: 12px;
  background: var(--page); box-shadow: 0 12px 32px #0001;
}
.editor-analytics-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.editor-analytics-heading h1 { margin: 4px 0 0; font-size: clamp(25px, 4vw, 34px); }
.editor-analytics-eyebrow { color: var(--muted); font-size: 11px; font-weight: 700; letter-spacing: .15em; }
.editor-analytics-period { margin: 14px 0 20px; color: var(--muted); font-size: 14px; }
.editor-analytics-total { display: flex; flex-direction: column; gap: 8px; padding: 20px; border: 1px solid var(--line); border-radius: 8px; }
.editor-analytics-total span { color: var(--muted); font-size: 14px; }
.editor-analytics-total strong { font-size: clamp(32px, 5vw, 48px); line-height: 1; }
.editor-analytics h2 { margin: 32px 0 15px; font-size: 18px; }
.editor-analytics-day { display: grid; grid-template-columns: 44px minmax(0, 1fr) 50px; align-items: center; gap: 12px; min-height: 34px; font-size: 13px; }
.editor-analytics-day strong { text-align: right; font-variant-numeric: tabular-nums; }
.editor-analytics-track { height: 10px; border-radius: 999px; background: var(--hover); overflow: hidden; }
.editor-analytics-track span { display: block; height: 100%; border-radius: inherit; background: var(--link); }
.editor-analytics-paths { padding: 0; margin: 0; list-style: none; }
.editor-analytics-paths li { display: flex; justify-content: space-between; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.editor-analytics-paths li span { min-width: 0; overflow-wrap: anywhere; }
.editor-analytics-paths li strong { flex: none; font-variant-numeric: tabular-nums; }
.editor-analytics-note { margin: 20px 0 0; color: var(--muted); font-size: 12px; line-height: 1.6; }
.editor-title-input { width: 100%; padding: 6px 0 12px; border: 0; border-bottom: 1px solid var(--line); background: none; color: var(--text); font-size: 28px; font-weight: 700; }
.editor-title-input::placeholder { color: var(--muted); opacity: 0.6; }
.editor-title-input:focus { outline: none; border-bottom-color: var(--link); }
.editor-desc-input { width: 100%; margin-top: 12px; padding: 6px 0; border: 0; background: none; color: var(--muted); font-size: 15px; }
.editor-desc-input:focus { outline: none; color: var(--text); }
.editor-meta-row { display: flex; align-items: center; flex-wrap: wrap; gap: 8px 14px; margin-top: 10px; padding-bottom: 12px; border-bottom: 1px solid var(--line); }
.editor-seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.editor-seg-btn { min-height: 38px; padding: 6px 14px; border: 0; background: var(--page); color: var(--muted); font-size: 13px; cursor: pointer; }
.editor-seg-btn + .editor-seg-btn { border-left: 1px solid var(--line); }
.editor-seg-btn.is-active { background: var(--link); color: #fff; }
.editor-date-field { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }
.editor-date-field input { min-height: 38px; padding: 4px 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--page); color: var(--text); font-size: 14px; }
.editor-schedule-note { color: var(--muted); font-size: 13px; }

.editor-tabs { display: none; gap: 4px; margin-top: 12px; }
.editor-tab { flex: 1; min-height: 38px; border: 1px solid var(--line); border-radius: 6px; background: var(--page); color: var(--muted); font-size: 14px; }
.editor-tab.is-active { border-color: var(--link); color: var(--link); font-weight: 600; }

.editor-mdtoolbar {
  display: flex; align-items: center; gap: 4px;
  margin-top: 12px; padding: 5px;
  border: 1px solid var(--line); border-radius: 8px;
  background: var(--hover);
  overflow-x: auto;
}
.editor-mdtoolbar button { flex: 0 0 auto; min-width: 38px; min-height: 34px; padding: 4px 10px; border: 0; border-radius: 6px; background: none; color: var(--text); font-size: 14px; }
.editor-mdtoolbar button:hover { background: var(--pressed); }
.editor-md-divider { flex: 0 0 auto; width: 1px; height: 20px; background: var(--line); }

.editor-panes { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 18px; margin-top: 14px; }
.editor-write-pane textarea {
  width: 100%; min-height: 52vh; padding: 4px 2px;
  border: 0; background: none; color: var(--text);
  font-size: 16px; line-height: 1.8; resize: vertical;
}
.editor-write-pane textarea:focus { outline: none; }
.editor-preview { min-height: 52vh; padding: 4px 14px; border-left: 1px solid var(--line); font-size: 15px; line-height: 1.8; overflow-wrap: anywhere; }
.editor-preview h1 { margin: 0 0 14px; font-size: 26px; }
.editor-preview h2, .editor-preview h3 { margin: 22px 0 8px; font-size: 19px; }
.editor-preview p { margin: 10px 0; }
.editor-preview ul { margin: 10px 0; padding-left: 22px; }
.editor-preview img { max-width: 100%; height: auto; border-radius: 6px; }
.editor-preview pre { padding: 10px 12px; border: 1px solid var(--line); border-radius: 6px; overflow-x: auto; font-size: 13px; }
.editor-preview blockquote { margin: 10px 0; padding-left: 12px; border-left: 3px solid var(--line); color: var(--muted); }
.editor-status { margin: 12px 0 0; font-size: 14px; }

.editor-confirm { width: min(100% - 32px, 380px); padding: 22px; border: 1px solid var(--line); border-radius: 10px; background: var(--page); color: var(--text); box-shadow: 0 16px 40px #0003; }
.editor-confirm::backdrop { background: #0006; }
.editor-confirm p { margin: 0; font-size: 15px; line-height: 1.6; }
.editor-confirm-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

@media (max-width: 900px) {
  .ed-icon-btn { display: grid; }
  .editor-shell { grid-template-columns: minmax(0, 1fr); }
  .editor-side {
    position: fixed; top: 0; bottom: 0; left: 0; z-index: 9;
    width: min(82vw, 300px);
    transform: translateX(-105%);
    transition: transform 0.22s ease;
    box-shadow: 12px 0 32px #0002;
  }
  .editor-side.is-open { transform: translateX(0); }
  .editor-workspace { width: 100%; margin: 0; padding: 18px 16px 16px; border: 0; border-radius: 0; box-shadow: none; }
  .editor-tabs { display: flex; }
  .editor-panes { grid-template-columns: minmax(0, 1fr); }
  .editor-panes .editor-preview { display: none; }
  .editor-panes.show-preview .editor-preview { display: block; border-left: 0; }
  .editor-panes.show-preview .editor-write-pane { display: none; }
}
@media (max-width: 560px) {
  .editor-topbar { gap: 6px; padding: 6px 10px; }
  .editor-topbar-title { display: none; }
  .editor-user { display: none; }
  .editor-topbar-actions { margin-left: auto; }
  .ed-btn { min-height: 36px; padding: 5px 10px; font-size: 13px; }
  .editor-title-input { font-size: 22px; }
  .editor-write-pane textarea { min-height: 46vh; font-size: 16px; }
}

@media (max-width: 520px) {
  .share-page { padding: 30px max(20px, env(safe-area-inset-right)) 40px max(20px, env(safe-area-inset-left)); }
  .share-content h1 { margin: 16px 0 14px; font-size: clamp(34px, 10vw, 44px); }
  .radar-peer-send { width: 64px; font-size: 10px; }
  .radar-peer-icon { width: 40px; height: 40px; }
  .radar-arcs path { stroke-width: 13; }
  .share-prompt-actions .refresh { flex: 1; justify-content: center; }
}

