/* Fonts ship with the site (fonts/, built by fonts/subset.py), so the pages make
   no request outside it. unicode-range means a script's file loads only when
   text in that script is on screen. */
@font-face {
  font-family: "Public Sans";
  src: url("fonts/public-sans.woff2") format("woff2");
  font-weight: 400 700;
  font-display: swap;
  unicode-range: U+0020-007E, U+00A0-024F, U+2010-2027, U+2030-205E, U+20AC, U+2116, U+2122, U+2190-2193, U+25CC;
}
@font-face {
  font-family: "Martian Mono";
  src: url("fonts/martian-mono.woff2") format("woff2");
  font-weight: 400 500;
  font-display: swap;
  unicode-range: U+0020-007E, U+00A0-024F, U+0400-04FF, U+2010-2027, U+2030-205E, U+20AC, U+20B4, U+2116, U+2122, U+2190-2193, U+25CC;
}
@font-face {
  font-family: "Noto Sans Thai";
  src: url("fonts/noto-sans-thai.woff2") format("woff2");
  font-weight: 400 500;
  font-display: swap;
  unicode-range: U+0E00-0E7F, U+25CC;
}
@font-face {
  font-family: "Noto Sans JP";
  src: url("fonts/noto-sans-jp.woff2") format("woff2");
  font-weight: 400 500;
  font-display: swap;
  unicode-range: U+3000-303F, U+3040-30FF, U+FF01-FF60;
}
@font-face {
  font-family: "Noto Sans Greek";
  src: url("fonts/noto-sans-greek.woff2") format("woff2");
  font-weight: 400 500;
  font-display: swap;
  unicode-range: U+0370-03FF;
}
@font-face {
  font-family: "Noto Sans Arabic";
  src: url("fonts/noto-sans-arabic.woff2") format("woff2");
  font-weight: 400 500;
  font-display: swap;
  unicode-range: U+0600-06FF, U+200C-200D, U+25CC, U+FB50-FDFF, U+FE70-FEFF;
}
@font-face {
  font-family: "Noto Sans Devanagari";
  src: url("fonts/noto-sans-devanagari.woff2") format("woff2");
  font-weight: 400 500;
  font-display: swap;
  unicode-range: U+0900-097F, U+200C-200D, U+25CC;
}
/* kanji: the JIS level-1 set, a larger file that loads only when kanji are on screen */
@font-face {
  font-family: "Noto Sans JP";
  src: url("fonts/noto-sans-jp-kanji.woff2") format("woff2");
  font-weight: 400 500;
  font-display: swap;
  /* minus the notes' Chinese example (U+5988 U+9A6C U+9A82 U+9EBB, set in Noto Sans SC), so a kana-only page never pulls this file in */
  unicode-range: U+4E00-5987, U+5989-9A6B, U+9A6D-9A81, U+9A83-9EBA, U+9EBC-9FFF;
}
/* Hangul: a larger file that loads only when Korean is on screen */
@font-face {
  font-family: "Noto Sans KR";
  src: url("fonts/noto-sans-kr.woff2") format("woff2");
  font-weight: 400 500;
  font-display: swap;
  unicode-range: U+3131-318E, U+AC00-D7A3;
}
@font-face {
  font-family: "Noto Sans SC";
  src: url("fonts/noto-sans-sc.woff2") format("woff2");
  font-weight: 400 500;
  font-display: swap;
  unicode-range: U+5988, U+9A6C, U+9A82, U+9EBB;
}
@font-face {
  font-family: "Noto Sans Hebrew";
  src: url("fonts/noto-sans-hebrew.woff2") format("woff2");
  font-weight: 400 500;
  font-display: swap;
  unicode-range: U+0590-05FF, U+FB1D-FB4F, U+25CC;
}

/* ---------- themes ----------
   Two independent settings, both set on <html> by theme.js (and by the
   pre-paint script in each page's <head>):
   data-paper  = parchment | carbon | ledger | blueprint | kraft (the colouring)
   data-scheme = light | dark (the resolved mode: System follows the OS)
   With no attributes at all (scripts blocked) the page is Parchment light. */
:root,
:root[data-paper="parchment"] {
  color-scheme: light;
  --bg: #f1e7d0;
  --surface: #fbf6ea;
  --key: #f8f1e0;
  --ink: #2a2118;
  --muted: #645641;
  --line: #e0d2b3;
  --line-strong: #2a2118;
  --accent: #2f4f9a;
  --accent-ink: #ffffff;
  --warn: #8f4310;
  --shadow: 42 33 24;
}
:root[data-scheme="dark"],
:root[data-paper="parchment"][data-scheme="dark"] {
  color-scheme: dark;
  --bg: #1b1611;
  --surface: #231d16;
  --key: #2b241b;
  --ink: #efe4cc;
  --muted: #b4a68b;
  --line: #3a3127;
  --line-strong: #5c4e3c;
  --accent: #93abee;
  --accent-ink: #1b1611;
  --warn: #f0a35e;
  --shadow: 0 0 0;
}
:root[data-paper="carbon"] {
  color-scheme: light;
  --bg: #eceef3;
  --surface: #ffffff;
  --key: #f7f8fb;
  --ink: #161a2b;
  --muted: #565c73;
  --line: #d9dce7;
  --line-strong: #161a2b;
  --accent: #3d3bd6;
  --accent-ink: #ffffff;
  --warn: #8f4310;
  --shadow: 22 26 43;
}
:root[data-paper="carbon"][data-scheme="dark"] {
  color-scheme: dark;
  --bg: #111318;
  --surface: #181b22;
  --key: #1f232b;
  --ink: #e8eaf0;
  --muted: #a0a6b6;
  --line: #2c313c;
  --line-strong: #4a5263;
  --accent: #a3a1ff;
  --accent-ink: #111318;
  --warn: #f0a35e;
  --shadow: 0 0 0;
}
:root[data-paper="ledger"] {
  color-scheme: light;
  --bg: #e8eeea;
  --surface: #fbfdfc;
  --key: #f3f7f5;
  --ink: #0f2a22;
  --muted: #4b6057;
  --line: #d2ddd7;
  --line-strong: #0f2a22;
  --accent: #0b7258;
  --accent-ink: #ffffff;
  --warn: #8f4310;
  --shadow: 15 42 34;
}
:root[data-paper="ledger"][data-scheme="dark"] {
  color-scheme: dark;
  --bg: #0e1915;
  --surface: #13211c;
  --key: #192a23;
  --ink: #e2eee8;
  --muted: #9cb4a9;
  --line: #24362e;
  --line-strong: #3f5a4e;
  --accent: #55c7a4;
  --accent-ink: #0e1915;
  --warn: #f0a35e;
  --shadow: 0 0 0;
}
:root[data-paper="blueprint"] {
  color-scheme: light;
  --bg: #e5edf6;
  --surface: #f7fafd;
  --key: #eef3f9;
  --ink: #0f2747;
  --muted: #475f80;
  --line: #cbd8e7;
  --line-strong: #0f2747;
  --accent: #1d5fd1;
  --accent-ink: #ffffff;
  --warn: #8f4310;
  --shadow: 15 39 71;
}
:root[data-paper="blueprint"][data-scheme="dark"] {
  color-scheme: dark;
  --bg: #0f2a52;
  --surface: #13325f;
  --key: #183a6b;
  --ink: #eaf2ff;
  --muted: #a9c1e4;
  --line: #26497c;
  --line-strong: #5076ad;
  --accent: #f4c95d;
  --accent-ink: #0f2a52;
  --warn: #ffb38a;
  --shadow: 0 0 0;
}
:root[data-paper="kraft"] {
  color-scheme: light;
  --bg: #e2cdaa;
  --surface: #efe1c7;
  --key: #e9d7b8;
  --ink: #2a1c0f;
  --muted: #5a4630;
  --line: #cab08a;
  --line-strong: #2a1c0f;
  --accent: #165e68;
  --accent-ink: #ffffff;
  --warn: #8f4310;
  --shadow: 42 28 15;
}
:root[data-paper="kraft"][data-scheme="dark"] {
  color-scheme: dark;
  --bg: #1c140c;
  --surface: #251b11;
  --key: #2d2216;
  --ink: #f0e0c3;
  --muted: #bba582;
  --line: #3c2e1f;
  --line-strong: #5f4a32;
  --accent: #62bcc6;
  --accent-ink: #1c140c;
  --warn: #f0a35e;
  --shadow: 0 0 0;
}

:root[data-paper="blueprint"][data-scheme="dark"] {
  --heat-ink: #eaf2ff;
  --heat-scale: 0.6; /* at full scale a much-used key's tint reached #6780a5, 3.6:1 under the pale legends */
}
:root {
  /* script faces follow Public Sans so kana and other scripts in labels and notes use the bundled fonts */
  --ui: "Public Sans", "Noto Sans JP", "Noto Sans Thai", "Noto Sans Hebrew", "Noto Sans Greek", "Noto Sans Arabic", "Noto Sans Devanagari", "Noto Sans KR", "Noto Sans SC", system-ui, sans-serif;
  --mono: "Martian Mono", ui-monospace, monospace;
  --script: "Noto Sans Thai", "Noto Sans JP", "Noto Sans Hebrew", "Noto Sans Greek", "Noto Sans Arabic", "Noto Sans Devanagari", "Noto Sans KR", "Noto Sans SC";
  --gutter: clamp(16px, 4vw, 56px);
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --accent-soft: color-mix(in oklab, var(--heat-ink, var(--accent)) 14%, var(--key));
}

* {
  box-sizing: border-box;
}
html {
  background: var(--bg);
}
body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 var(--ui);
  -webkit-font-smoothing: antialiased;
}
::selection {
  background: var(--accent);
  color: var(--accent-ink);
}
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
* {
  scrollbar-color: var(--line-strong) transparent;
  scrollbar-width: thin;
}
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}
svg.icon {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: none;
}

/* ---------- header ---------- */
.top {
  display: flex;
  align-items: center;
  gap: 32px;
  padding: 16px var(--gutter);
  border-bottom: 1px solid var(--line-strong);
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font: 500 15px var(--mono);
  letter-spacing: -0.02em;
  color: var(--ink);
  text-decoration: none;
  white-space: nowrap;
}
.brand b {
  font-weight: 500;
  color: var(--accent);
  margin: 0 1px;
}
.logo {
  width: 30px;
  height: 30px;
  flex: none;
}
.logo-base {
  fill: var(--ink);
}
:root[data-scheme="dark"] .logo-base {
  fill: var(--line-strong);
}
.logo-top {
  fill: var(--bg);
  transition: transform 0.25s var(--ease-out);
}
.logo-latin {
  fill: var(--ink);
}
.logo-script {
  fill: var(--accent);
}
/* the key in the logo presses when you point at it */
.brand:hover .logo-top,
.brand:hover .logo-latin,
.brand:hover .logo-script {
  transform: translateY(1.5px);
}
.logo-top,
.logo-latin,
.logo-script {
  transition: transform 0.2s var(--ease-out);
}

.tabs {
  display: flex;
  gap: 2px;
}
.tabs a {
  padding: 8px 14px;
  border-radius: 6px;
  color: var(--ink);
  text-decoration: none;
  white-space: nowrap;
}
.tabs a:hover {
  background: var(--key);
}
.tabs a[aria-current="page"] {
  background: var(--ink);
  color: var(--bg);
}

/* display settings */
.settings {
  position: relative;
  margin-left: auto;
}
.theme-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px 7px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font: 500 14px var(--ui);
  cursor: pointer;
  transition: border-color 0.15s;
}
.theme-btn:hover {
  border-color: var(--line-strong);
}
.swatch {
  width: 16px;
  height: 16px;
  flex: none;
  border-radius: 50%;
  border: 1px solid var(--line-strong);
  /* one element, so ring and dot share a centre: the accent fills the disc and
     a 4px ring of paper colour inside the border leaves a 6px dot */
  background: var(--accent);
  box-shadow: inset 0 0 0 4px var(--bg);
}
.theme-btn .mode-icon {
  width: 16px;
  height: 16px;
  color: var(--muted);
}
.theme-btn .chev {
  width: 14px;
  height: 14px;
  transition: transform 0.25s var(--ease-out);
}
.theme-btn[aria-expanded="true"] .chev {
  transform: rotate(180deg);
}
.settings-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  z-index: 20;
  width: 320px;
  padding: 14px;
  display: grid;
  gap: 16px;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  box-shadow: 0 16px 40px rgb(var(--shadow) / 0.22);
  transform-origin: top right;
  animation: pop-in 0.26s var(--ease-out);
}
.settings-panel[hidden] {
  display: none;
}
.set-group {
  display: grid;
  gap: 8px;
}
.mode-switch {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
}
.mode-switch label {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 6px;
  font-size: 14px;
}
.mode-switch .icon {
  width: 15px;
  height: 15px;
}
.papers {
  display: grid;
  gap: 2px;
}
.paper {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  transition: background-color 0.15s;
}
.paper:hover {
  background: var(--key);
}
.paper input {
  position: absolute;
  opacity: 0;
  inset: 0;
  margin: 0;
  cursor: pointer;
}
.paper:has(input:focus-visible) {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}
.paper-swatch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  width: 40px;
  height: 28px;
  flex: none;
  overflow: hidden;
  border-radius: 6px;
  border: 1px solid rgb(var(--shadow) / 0.3);
}
.paper-swatch i {
  position: relative;
  background: var(--l-bg);
}
.paper-swatch i + i {
  background: var(--d-bg);
}
.paper-swatch i::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 9px;
  height: 9px;
  translate: -50% -50%;
  border-radius: 2px;
  background: var(--l-ac);
}
.paper-swatch i + i::after {
  background: var(--d-ac);
}
.paper-text {
  display: grid;
  min-width: 0;
}
.paper-name {
  font: 500 14px var(--ui);
}
.paper-note {
  font: 12px var(--ui);
  color: var(--muted);
}
.paper .check {
  margin-left: auto;
  color: var(--accent);
  opacity: 0;
  transform: scale(0.6);
  transition:
    opacity 0.2s,
    transform 0.3s var(--ease-out);
}
.paper:has(input:checked) {
  background: var(--key);
}
.paper:has(input:checked) .check {
  opacity: 1;
  transform: none;
}
@keyframes pop-in {
  from {
    opacity: 0;
    transform: translateY(-6px) scale(0.97);
  }
}
/* the theme change wipes in from the control used (theme.js) */
/* clicks pass through the wipe to the real page underneath */
::view-transition {
  pointer-events: none;
}
.theme-vt::view-transition-old(root),
.theme-vt::view-transition-new(root) {
  animation: none;
  mix-blend-mode: normal;
}

/* ---------- tool ---------- */
main {
  padding: 24px var(--gutter) 64px;
  max-width: 1440px;
  margin: 0 auto;
}
.intro {
  display: grid;
  gap: 4px;
  margin-bottom: 22px;
}
h1 {
  font: 600 22px/1.2 var(--ui);
  letter-spacing: -0.02em;
  margin: 0;
}
.intro p {
  margin: 0;
  text-wrap: pretty;
  color: var(--muted);
  max-width: 100ch;
}

.controls {
  display: flex;
  align-items: flex-end;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 20px;
}
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1 1 220px;
  max-width: 300px;
  min-width: 0;
}
.label,
.field label {
  font: 500 11px var(--mono);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}
.select {
  position: relative;
  container-type: inline-size;
}
/* a narrow picker drops the key preview so the layout name fits */
@container (max-width: 270px) {
  .select-preview {
    display: none;
  }
}
.select-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  height: 44px;
  padding: 0 12px;
  font: 15px var(--ui);
  color: var(--ink);
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
  cursor: pointer;
  transition:
    border-color 0.15s,
    box-shadow 0.25s var(--ease-out);
}
.select-btn:hover,
.select-btn[aria-expanded="true"] {
  border-color: var(--line-strong);
}
.select-value {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.select-preview,
.opt-preview {
  font: 13px var(--mono), var(--script), sans-serif;
  color: var(--muted);
  letter-spacing: 0.08em;
  white-space: nowrap;
}
.select-btn .icon {
  width: 14px;
  height: 14px;
  color: var(--muted);
  transition: transform 0.25s var(--ease-out);
}
.select-btn[aria-expanded="true"] .icon {
  transform: rotate(180deg);
}
.listbox {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 6px);
  z-index: 15;
  max-height: 340px;
  overflow: auto;
  margin: 0;
  padding: 6px;
  list-style: none;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  box-shadow: 0 16px 40px rgb(var(--shadow) / 0.2);
  transform-origin: top center;
  animation: pop-in 0.22s var(--ease-out);
}
.listbox:focus {
  outline: none;
}
.drop-up .listbox {
  top: auto;
  bottom: calc(100% + 6px);
  transform-origin: bottom center;
}
.listbox[hidden] {
  display: none;
}
.listbox [role="option"] {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 6px;
  cursor: pointer;
  /* options drop in one after another */
  animation: opt-in 0.3s var(--ease-out) backwards;
}
.listbox [role="option"]:nth-child(2) { animation-delay: 15ms; }
.listbox [role="option"]:nth-child(3) { animation-delay: 30ms; }
.listbox [role="option"]:nth-child(4) { animation-delay: 45ms; }
.listbox [role="option"]:nth-child(5) { animation-delay: 60ms; }
.listbox [role="option"]:nth-child(6) { animation-delay: 75ms; }
.listbox [role="option"]:nth-child(7) { animation-delay: 90ms; }
.listbox [role="option"]:nth-child(n + 8) { animation-delay: 105ms; }
@keyframes opt-in {
  from {
    opacity: 0;
    transform: translateY(-4px);
  }
}
.opt-label {
  flex: 1;
}
.listbox .active {
  background: var(--key);
}
.listbox [aria-selected="true"] {
  font-weight: 600;
}
.listbox .check {
  width: 16px;
  height: 16px;
  color: var(--accent);
  visibility: hidden;
}
.listbox [aria-selected="true"] .check {
  visibility: visible;
}
/* Auto-detect swapped the layouts: both pickers flash once */
.select.flash .select-btn {
  animation: flash 0.9s var(--ease-out);
}
@keyframes flash {
  0%,
  100% {
    box-shadow: 0 0 0 0 transparent;
  }
  20% {
    box-shadow: 0 0 0 3px var(--accent);
    border-color: var(--accent);
  }
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 44px;
  padding: 0 18px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
  font: 500 15px var(--ui);
  cursor: pointer;
  transition:
    border-color 0.15s,
    background-color 0.15s,
    transform 0.1s;
}
.btn:hover {
  border-color: var(--line-strong);
}
.btn:active {
  transform: translateY(1px);
}
.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}
/* an on/off button (Mixed text): pressed marks the current choice with the accent */
.btn.toggle[aria-pressed="true"] {
  border-color: var(--accent);
  color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent);
}
.btn.icon-only {
  width: 44px;
  padding: 0;
}
.btn.icon-only .icon {
  transition: transform 0.35s var(--ease-out);
}
.btn.icon-only:hover .icon {
  transform: rotate(180deg);
}


/* segmented control (romaji output) */
.field:has(.segmented) {
  flex: none;
  max-width: none;
}
.segmented {
  display: inline-flex;
  padding: 3px;
  gap: 2px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}
.segmented label {
  position: relative;
  white-space: nowrap;
  text-transform: none;
  letter-spacing: 0;
  padding: 8px 16px;
  border-radius: 6px;
  font: 15px var(--ui);
  color: var(--ink);
  cursor: pointer;
}
.segmented input {
  position: absolute;
  opacity: 0;
  inset: 0;
  margin: 0;
  cursor: pointer;
}
.segmented label:has(input:checked) {
  background: var(--ink);
  color: var(--bg);
}
.segmented label:has(input:focus-visible) {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* panes: two halves of one ruled frame */
.panes {
  display: grid;
  grid-template-columns: 1fr 1fr;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: var(--surface);
  overflow: hidden;
}
.pane {
  position: relative;
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding: 14px 20px 16px;
}
.pane + .pane {
  border-left: 1px solid var(--line-strong);
}
.pane-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 10px;
  margin-bottom: 12px;
  border-bottom: 1px solid var(--line);
  font: 500 11px var(--mono);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}
.pane-head label {
  color: inherit;
}
.count {
  font-variant-numeric: tabular-nums;
}
.text-in,
.text-out {
  flex: 1;
  width: 100%;
  min-height: 168px;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--ink);
  font: 22px/1.5 var(--mono), var(--script), sans-serif;
  letter-spacing: -0.01em;
  caret-color: var(--accent);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.text-in {
  resize: none;
}
.text-in:focus,
.text-out:focus {
  outline: none;
}
.pane:has(:focus-visible) .pane-head {
  border-bottom-color: var(--accent);
}
.text-in::placeholder,
.text-out .placeholder {
  color: var(--muted);
  opacity: 1;
  font: 15px/1.5 var(--ui);
  letter-spacing: 0;
}
.text-out {
  position: relative;
  padding-bottom: 52px;
  max-height: 340px;
  overflow: auto;
}
/* pinned to the top-left so it lines up with box A's placeholder */
.text-out .placeholder {
  position: absolute;
  top: 0;
  left: 0;
}
.caret {
  display: inline-block;
  width: 2px;
  height: 1.15em;
  margin-left: 1px;
  vertical-align: -0.2em;
  background: var(--accent);
  opacity: 0;
}
.text-out.typing .caret,
.text-out:focus .caret {
  opacity: 1;
}
.text-out:focus .caret {
  animation: blink 1.05s steps(1) infinite;
}
@keyframes blink {
  50% {
    opacity: 0;
  }
}

.copy-wrap {
  position: absolute;
  right: 16px;
  bottom: 14px;
}
/* key hint to the left of Copy; only where a keyboard is likely (fine pointer) */
.keys {
  position: absolute;
  right: calc(100% + 10px);
  top: 50%;
  translate: 0 -50%;
  display: flex;
  gap: 3px;
}
kbd {
  padding: 1px 5px;
  border: 1px solid var(--line);
  border-radius: 3px;
  box-shadow: inset 0 -1px 0 var(--line); /* the key's front edge */
  background: var(--key);
  color: var(--muted);
  font: 500 11px var(--mono);
}
@media (hover: none), (pointer: coarse) {
  .keys {
    display: none;
  }
}
.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}
.btn.primary:hover {
  background: color-mix(in oklab, var(--accent) 88%, var(--ink));
}
/* the "Copied" slip slides up out of the button like paper off the platen */
.slip {
  position: absolute;
  left: 50%;
  bottom: calc(100% + 6px);
  translate: -50% 0;
  padding: 4px 10px;
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  background: var(--surface);
  color: var(--ink);
  font: 500 11px var(--mono);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  clip-path: inset(100% 0 0 0);
}
.slip.out {
  animation: slip 1.4s var(--ease-out);
}
@keyframes slip {
  0% {
    opacity: 1;
    clip-path: inset(100% 0 0 0);
    transform: translateY(8px);
  }
  25%,
  75% {
    opacity: 1;
    clip-path: inset(0 0 0 0);
    transform: translateY(0);
  }
  100% {
    opacity: 0;
    clip-path: inset(0 0 0 0);
    transform: translateY(-6px);
  }
}

/* status row */
.status {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 6px 28px;
  margin: 14px 0 10px;
  font: 500 12px var(--mono);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  min-height: 20px;
}
.status b {
  font-weight: 500;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.status .lead b {
  color: var(--accent);
}
.status .warn,
.status .warn b {
  color: var(--warn);
}
.status .rule {
  margin-left: auto;
}
.status .message {
  text-transform: none;
  letter-spacing: 0;
  font: 14px var(--ui);
  color: var(--ink);
}

/* ---------- mixed text (Layout Fix): each part, kept or converted; select to reverse ---------- */
.runs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  max-height: 9.5rem;
  overflow-y: auto;
  margin: 14px 0 0;
  padding: 2px;
  list-style: none;
}
.runs[hidden] {
  display: none;
}
.runs button {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  max-width: 16em;
  min-height: 44px;
  padding: 4px 10px 5px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--key);
  color: var(--ink);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.runs button:hover {
  border-color: var(--line-strong);
}
.runs button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.runs .kept button {
  border-style: dashed;
  background: none;
}
.runs .r {
  font: 500 11px var(--mono);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}
.runs .k {
  max-width: 100%;
  overflow: hidden;
  font: 15px/1.35 var(--mono), var(--script), sans-serif;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- mora strip (Romaji): each romaji chunk above its kana ---------- */
.mora {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 4px;
  max-height: 9.5rem; /* about three rows; longer text scrolls inside the strip */
  overflow-y: auto;
  margin: 14px 0 0;
  padding: 0;
  list-style: none;
}
.mora[hidden] {
  display: none;
}
.mora li {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 30px;
  padding: 3px 7px 4px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--key);
}
.mora li.word {
  margin-left: 12px;
}
.mora .r {
  font: 500 11px var(--mono);
  color: var(--muted);
}
.mora .k {
  font: 18px/1.35 var(--script), var(--ui), sans-serif;
  color: var(--ink);
}
.mora li.latin .r,
.mora li.latin .k {
  color: var(--warn);
}
.mora li.pass {
  border-color: transparent;
  background: none;
}

/* ---------- code table: the keyboard / the kana chart ---------- */
.table {
  padding: 18px 20px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
}
.table-head {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 4px 16px;
  margin-bottom: 12px;
}
.table-head .legend {
  display: flex;
  gap: 16px;
  font: 12px var(--ui);
  color: var(--muted);
}
.table-head .legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.table-head .legend i {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  border: 1px solid var(--line);
  background: var(--key);
}
.table-head .legend i.used {
  background: var(--accent-soft);
  border-color: color-mix(in oklab, var(--accent) 45%, transparent);
}
.table-head .legend i.most {
  background: var(--accent);
  border-color: var(--accent);
}

.table {
  container-type: inline-size;
}
.kb {
  --gap: 8px;
  /* the widest row is 13.55 caps (13 keys plus the Tab-row offset) */
  --cap: clamp(28px, calc((100cqw - 12 * var(--gap)) / 13.55), 84px);
  display: flex;
  flex-direction: column;
  gap: var(--gap);
}
.kb-row {
  display: flex;
  gap: var(--gap);
}
.seg {
  display: contents;
}
.kb-row:nth-child(2) {
  padding-left: calc(var(--cap) * 0.55);
}
.kb-row:nth-child(3) {
  padding-left: calc(var(--cap) * 0.7);
}
.kb-row:nth-child(4) {
  padding-left: calc(var(--cap) * 0.95);
}
.cap {
  --heat: 0;
  position: relative;
  width: var(--cap);
  height: calc(var(--cap) * 0.86);
  flex: none;
  border: 1px solid var(--line);
  border-radius: 6px;
  /* --heat-scale tones the tint down where a pale heat ink would sink the legends' contrast */
  background: color-mix(in oklab, var(--heat-ink, var(--accent)) calc(var(--heat) * var(--heat-scale, 1) * 100%), var(--key));
  color: var(--ink);
  transition:
    background-color 0.25s var(--ease-out),
    border-color 0.25s;
}
.cap.used {
  border-color: color-mix(in oklab, var(--accent) 50%, transparent);
}
.cap.hot {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: var(--accent);
}
.cap .from,
.cap .to {
  position: absolute;
  line-height: 1;
}
.cap .from {
  left: 7px;
  top: 6px;
  font: 400 clamp(10px, calc(var(--cap) * 0.17), 13px) var(--mono), var(--script), sans-serif;
  color: var(--muted);
}
.cap.used .from {
  color: var(--ink);
}
.cap.hot .from {
  color: inherit;
}
.cap .to {
  right: 7px;
  bottom: 6px;
  font: 400 clamp(14px, calc(var(--cap) * 0.3), 24px) var(--script), var(--mono), sans-serif;
}
.cap .n {
  position: absolute;
  right: 6px;
  top: 5px;
  font: 500 10px var(--mono);
  font-variant-numeric: tabular-nums;
  opacity: 0.8;
}
/* typebar strike: the key dips and rings, once per character typed out */
.cap.strike {
  animation: strike 0.24s var(--ease-out);
}
@keyframes strike {
  0% {
    transform: translateY(0);
    box-shadow: 0 0 0 0 var(--accent);
  }
  30% {
    transform: translateY(2px);
    box-shadow:
      inset 0 2px 0 rgb(var(--shadow) / 0.2),
      0 0 0 3px var(--accent);
  }
  100% {
    transform: translateY(0);
    box-shadow: 0 0 0 0 transparent;
  }
}

/* kana chart: consonant columns × vowel rows */
.chart {
  --cap: 62px;
  display: grid;
  grid-template-columns: 28px repeat(16, minmax(0, 1fr));
  gap: 6px;
}
.chart .axis:lang(ja),
.chart .axis.kana {
  text-transform: none;
}
.chart .axis {
  display: flex;
  align-items: center;
  justify-content: center;
  font: 500 11px var(--mono);
  color: var(--muted);
  text-transform: uppercase;
}
.chart .cap {
  width: auto;
  height: 50px;
}
.chart .gap {
  border: 1px dashed var(--line);
  border-radius: 6px;
}

/* notes */
.notes {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 24px 48px;
  margin-top: 40px;
  padding-top: 24px;
  border-top: 1px solid var(--line);
}
.notes h2 {
  font: 600 15px var(--ui);
  margin: 0 0 6px;
}
.notes p {
  margin: 0;
  color: var(--muted);
  max-width: 68ch;
}
.notes p + p {
  margin-top: 8px;
}
.notes kbd {
  font-size: 10px;
}
.notes code {
  font: 13px var(--mono), var(--script);
  color: var(--ink);
}

/* ---------- motion ---------- */
/* page entrance: sections rise in order, once */
.reveal {
  animation: rise 0.7s var(--ease-out) backwards;
  animation-delay: calc(var(--r, 0) * 70ms);
}
@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(14px);
  }
}
/* layout change: legends roll over in a wave, like a split-flap board */
.kb.roll .cap .from,
.kb.roll .cap .to {
  animation: roll 0.5s var(--ease-out) backwards;
  animation-delay: calc(var(--i, 0) * 22ms);
}
@keyframes roll {
  from {
    opacity: 0;
    transform: translateY(-70%) rotateX(80deg);
  }
}
/* swap: the two texts slide past each other */
.panes.swapping .text-in {
  animation: from-right 0.5s var(--ease-out);
}
.panes.swapping .text-out {
  animation: from-left 0.5s var(--ease-out);
}
@keyframes from-right {
  from {
    opacity: 0;
    transform: translateX(24px);
  }
}
@keyframes from-left {
  from {
    opacity: 0;
    transform: translateX(-24px);
  }
}
/* status counts tick when they change */
.status.tick b {
  display: inline-block;
  animation: tick 0.45s var(--ease-out);
}
@keyframes tick {
  from {
    opacity: 0;
    transform: translateY(-6px);
  }
}
/* copy: the icon turns into a check, drawn in */
.btn .i-done {
  display: none;
}
.btn.done .i-copy {
  display: none;
}
.btn.done .i-done {
  display: block;
  stroke-dasharray: 24;
  animation: draw 0.4s var(--ease-out);
}
@keyframes draw {
  from {
    stroke-dashoffset: 24;
  }
}
/* cross-page: the active tab glides between the two tools */
@view-transition {
  navigation: auto;
}
.tabs a[aria-current="page"] {
  view-transition-name: active-tab;
}
.top {
  position: relative;
  z-index: 30;
  view-transition-name: top-bar;
}
::view-transition-group(active-tab) {
  animation-duration: 0.4s;
  animation-timing-function: cubic-bezier(0.16, 1, 0.3, 1);
}

/* ---------- footer ---------- */
.credit {
  max-width: 1440px;
  margin: 0 auto;
  padding: 20px var(--gutter) 32px;
  border-top: 1px solid var(--line);
  font: 500 12px var(--mono);
  letter-spacing: 0.02em;
  color: var(--muted);
}
main {
  padding-bottom: 40px;
}

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  .cap .n {
    display: none;
  }
}
@media (max-width: 720px) {
  .top {
    flex-wrap: wrap;
    gap: 12px 16px;
  }
  .tabs {
    order: 3;
    width: 100%;
  }
  .tabs a {
    flex: 1;
    text-align: center;
    padding: 11px 14px;
  }
  .theme-btn {
    min-height: 44px;
    padding: 0 12px;
  }
  .panes {
    grid-template-columns: 1fr;
  }
  .pane + .pane {
    border-left: 0;
    border-top: 1px solid var(--line-strong);
  }
  .text-in,
  .text-out {
    min-height: 120px;
    font-size: 19px;
  }
  .controls .field {
    flex: 1 1 100%;
    max-width: none;
  }
  .controls .push {
    flex: 1;
  }
  .status .rule {
    margin-left: 0;
  }
  .table {
    padding: 14px 12px 10px;
  }
  .chart {
    grid-template-columns: 20px repeat(16, minmax(0, 1fr));
    gap: 3px;
  }
  .chart .cap {
    height: 40px;
  }
  .chart .cap .from {
    display: none;
  }
  .chart .cap .to {
    right: 50%;
    translate: 50% 0;
    bottom: 50%;
    transform: translateY(50%);
    font-size: 13px;
  }
}
@media (max-width: 480px) {
  .theme-btn .theme-name {
    display: none;
  }
}
@media (max-width: 620px) {
  /* the keyboard splits into a left and a right half-board, stacked */
  .kb {
    --gap: 5px;
    --cap: calc((100cqw - 6 * var(--gap)) / 7.05);
    display: grid;
  }
  .kb-row {
    display: contents;
  }
  .seg {
    display: flex;
    gap: var(--gap);
    padding-left: 0 !important;
  }
  .seg.l {
    order: 1;
  }
  .seg.r {
    order: 2;
  }
  .kb-row:first-child .seg.r {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px dashed var(--line);
  }
  .kb-row:nth-child(n + 2) .seg.l {
    padding-left: calc(var(--cap) * 0.5) !important;
  }
  .controls .field:has(select) {
    flex: 1 1 100%;
    max-width: none;
  }
  .controls .field:has(#toLayout) {
    order: 1;
  }
  .controls #swapBtn {
    order: 2;
  }
  .controls .push {
    order: 3;
  }
  .controls #mixedBtn {
    order: 4;
  }
  .field:has(.segmented) {
    flex: 1 1 100%;
    max-width: none;
  }
  .segmented {
    width: 100%;
  }
  .segmented label {
    flex: 1;
    text-align: center;
    padding: 8px 6px;
  }
}

@media (prefers-reduced-motion: reduce) {
  @view-transition {
    navigation: none;
  }
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-delay: 0s !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
