/* Noto Sans is loaded from Google Fonts in index.html */
/* Dotted circle (◌, U+25CC) from Noto Sans, served locally because Google's Noto Sans subsets do not include it.
   Same family name + unicode-range, so it slots in only for that one character. SIL Open Font License 1.1 */
@font-face { font-family: 'Noto Sans'; font-style: normal; font-display: block; font-weight: 400 700; src: url('../fonts/noto-sans-dotted-circle.woff2') format('woff2'); unicode-range: U+25CC; }

/* Layout: one-screen tool. Writing surface fills the top half; a docked key deck holds three labelled rows below. */
:root {
  --paper: #eef0f4;
  --ink: #1a2130;
  --muted: #677086;
  --deck: #dfe3ea;
  --key: #fbfcfd;
  --key-edge: #b9c0cd;
  --accent: #9a6b12;
  --accent-soft: #f3e6c9;
  --danger: #b3261e;
  --select: #6a4aa8;
  --dots-bg: #5d6680;
  --vapor: linear-gradient(115deg, #5b3a9c 0%, #a2387e 45%, #2f6fa3 100%);
  --font-text: "Noto Sans", sans-serif;
  --font-ui: "Noto Sans", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #121620; --ink: #e7e9ef; --muted: #8b93a7; --deck: #1a1f2b;
    --key: #252b39; --key-edge: #0b0e14; --accent: #dcae52; --accent-soft: #3a3020; --danger: #f2867c; --select: #7b5cc4; --dots-bg: #3d4559;
    --vapor: linear-gradient(115deg, #f6c4ec 0%, #cdbcff 45%, #aeeef2 100%);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #121620; --ink: #e7e9ef; --muted: #8b93a7; --deck: #1a1f2b;
  --key: #252b39; --key-edge: #0b0e14; --accent: #dcae52; --accent-soft: #3a3020; --danger: #f2867c; --select: #7b5cc4; --dots-bg: #3d4559;
  --vapor: linear-gradient(115deg, #f6c4ec 0%, #cdbcff 45%, #aeeef2 100%);
  color-scheme: dark;
}

[hidden] { display: none !important; }
/* only the text field is selectable; labels, keys and the status line cannot be copied */
body { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
#text { -webkit-user-select: text; user-select: text; -webkit-touch-callout: default; }
html, body { height: 100%; }
body {
  background: var(--paper); color: var(--ink);
  font-family: var(--font-text);
  display: flex; flex-direction: column;
  overflow: hidden;
}

/* ---------- writing surface ---------- */
.page { flex: 0 0 50%; display: flex; flex-direction: column; padding-inline: max(16px, 4vw); padding-block: 20px 0; min-height: 0; }
#text {
  flex: 1; min-height: 0; width: 100%; box-sizing: border-box; padding: 0 40px 0 0;
  border: 0; outline: 0; resize: none; background: transparent; color: var(--ink);
  font-family: var(--font-text); font-size: 64px; font-weight: 700; line-height: 1.4;
  caret-color: var(--accent);
  background: var(--vapor); -webkit-background-clip: text; background-clip: text;
  color: transparent; -webkit-text-fill-color: transparent;
}
#text::selection { color: #fff; -webkit-text-fill-color: #fff; background: var(--select); }
.meta {
  display: flex; gap: 16px; align-items: center; justify-content: space-between; flex-wrap: wrap;
  font-family: var(--font-ui); font-size: 12px; color: var(--muted);
  padding-block: 10px; border-top: 1px solid color-mix(in srgb, var(--muted) 25%, transparent);
}
.meta .hint b { color: var(--ink); font-weight: 500; }
.meta button {
  font: inherit; color: var(--muted); background: none; border: 0; padding: 4px 6px; border-radius: 4px; cursor: pointer;
}
.meta button:hover { color: var(--ink); }
.meta button:focus-visible, .k:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- key deck ---------- */
.deck {
  flex: 1; min-height: 0; overflow-y: auto;
  background: var(--deck);
  border-radius: 18px 18px 0 0;
  padding-inline: max(16px, 3vw);
  padding-block: 14px calc(16px + env(safe-area-inset-bottom, 0px));
  display: flex; flex-direction: column; gap: 14px;
  /* centred via auto margins (below), so on short screens the top rows stay reachable when it scrolls */
}
.deck > :first-child { margin-top: auto; }
.deck > :last-child { margin-bottom: auto; }
.status {
  font-family: var(--font-ui); font-size: 12px; color: var(--muted);
  /* fixed box: mixed-font glyphs (◌ + marks) must never change its height, or the centred deck shifts */
  flex: 0 0 20px; height: 20px; line-height: 20px;
  display: flex; gap: 10px; align-items: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.status .cp { color: var(--accent); font-weight: 600; font-variant-numeric: tabular-nums; }
.row { display: grid; grid-template-columns: 112px 1fr; gap: 12px; align-items: start; }
.row-label {
  font-family: var(--font-ui); font-size: 11px; letter-spacing: .09em; text-transform: uppercase; color: var(--muted);
  padding-top: 12px;
}
.row-label small { display: block; letter-spacing: 0; text-transform: none; opacity: .75; margin-top: 2px; }
.keys { display: flex; flex-wrap: wrap; gap: 6px; min-width: 0; }

.k {
  --h: 44px;
  position: relative;
  min-width: 40px; height: var(--h); padding: 0 6px;
  display: inline-flex; align-items: center; justify-content: center;
  font-family: var(--font-text); font-size: 22px; line-height: 1; color: var(--ink);
  background: var(--key); border: 0; border-radius: 8px;
  box-shadow: 0 2px 0 var(--key-edge), 0 0 0 1px color-mix(in srgb, var(--key-edge) 45%, transparent);
  cursor: pointer; user-select: none; -webkit-user-select: none; touch-action: manipulation;
  transition: transform .06s ease, box-shadow .06s ease, background-color .15s;
}
.k:hover { background: color-mix(in srgb, var(--key) 85%, var(--accent)); }
.k.down, .k:active { transform: translateY(2px); box-shadow: 0 0 0 var(--key-edge), 0 0 0 1px color-mix(in srgb, var(--key-edge) 45%, transparent); }
.sup .k { min-width: 50px; --h: 56px; font-size: 42px; }
.sup .k .base { opacity: .55; }
.dia .k { min-width: 48px; font-size: 26px; }
.let .k { min-width: 46px; --h: 52px; font-size: 26px; }
.k .base { color: var(--muted); }
.k .num {
  position: absolute; top: 4px; left: 6px;
  font-family: var(--font-ui); font-size: 10px; font-weight: 600; line-height: 1; color: var(--muted);
}
.status .sc { margin-left: auto; color: var(--ink); font-weight: 600; }

.k.fn {
  font-family: var(--font-ui); font-size: 12px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted);
  padding: 0 14px;
}
.k.fn svg { width: 18px; height: 18px; }
.k.shift[data-state="once"] { background: var(--accent-soft); color: var(--accent); }
.k.shift[data-state="lock"] { background: var(--accent); color: var(--paper); }

/* ---------- overflow menu ---------- */
.menu-wrap { position: fixed; top: calc(12px + env(safe-area-inset-top, 0px)); right: max(12px, 2vw); z-index: 10; }
.menu-btn {
  position: relative; display: block; padding: 5px; line-height: 0;
  background: var(--dots-bg); color: #fff; border: 0; border-radius: 8px; cursor: pointer;
  transition: background-color .15s;
}
.menu-btn::before { content: ""; position: absolute; inset: -10px; } /* larger tap area, invisible */
.menu-btn:hover, .menu-btn[aria-expanded="true"] { background: var(--select); }
.menu-btn svg { width: 6px; height: 22px; display: block; }
/* vertical font-size slider under the three dots: up = larger, down = smaller */
.vsize {
  position: relative; margin: 14px auto 0; width: 16px; height: 168px;
  display: flex; flex-direction: column; align-items: center; justify-content: space-between;
  font-family: var(--font-ui); font-weight: 700; color: var(--muted); line-height: 1;
}
.vsize .big { font-size: 15px; }
.vsize .small { font-size: 10px; }
.vsize input {
  position: absolute; top: 50%; left: 50%;
  width: 120px; height: 16px; margin: 0;
  transform: translate(-50%, -50%) rotate(-90deg);   /* left end (smallest) ends up at the bottom */
  accent-color: var(--dots-bg); cursor: ns-resize; background: transparent;
}
.vsize input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.menu {
  position: absolute; right: 0; top: 42px; width: 260px;   /* just below the dots button, over the slider */
  background: var(--key); color: var(--ink); border-radius: 12px; padding: 14px;
  box-shadow: 0 10px 30px color-mix(in srgb, var(--ink) 18%, transparent), 0 0 0 1px color-mix(in srgb, var(--key-edge) 50%, transparent);
  display: flex; flex-direction: column; gap: 14px;
  font-family: var(--font-ui); font-size: 13px;
}
.menu-row { display: flex; flex-direction: column; gap: 8px; }
.menu-row .lbl { display: flex; justify-content: space-between; color: var(--muted); font-size: 11px; letter-spacing: .08em; text-transform: uppercase; }
.menu-row .lbl output { color: var(--ink); letter-spacing: 0; font-variant-numeric: tabular-nums; }
.size-ctl { display: flex; align-items: center; gap: 8px; }
.size-ctl input { flex: 1; accent-color: var(--accent); min-width: 0; }
.size-ctl button, .menu .action {
  font: inherit; color: var(--ink); background: var(--deck); border: 0; border-radius: 8px; cursor: pointer;
}
.size-ctl button { width: 32px; height: 32px; font-weight: 600; }
.menu .action { padding: 9px 12px; text-align: left; }
.menu .action.danger { color: var(--danger); }
.menu .action.danger[data-armed="true"] { background: var(--danger); color: var(--key); }
.menu hr { border: 0; border-top: 1px solid color-mix(in srgb, var(--muted) 25%, transparent); margin: 0; }
.menu-btn:focus-visible, .menu button:focus-visible, .menu input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.toast {
  position: fixed; left: 50%; top: calc(16px + env(safe-area-inset-top, 0px));
  transform: translate(-50%, -8px); opacity: 0; pointer-events: none;
  background: var(--ink); color: var(--paper);
  font-family: var(--font-ui); font-size: 13px; padding: 8px 14px; border-radius: 999px;
  transition: opacity .18s, transform .18s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 640px) {
  .row { grid-template-columns: 1fr; gap: 6px; }
  .row-label { padding-top: 0; }
  .row-label small { display: inline; margin-left: 6px; }
  .sup .k { min-width: 42px; --h: 48px; font-size: 28px; padding: 0 4px; }
  .let .k { min-width: 44px; --h: 46px; }
  .keys { gap: 5px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
body { margin: 0; }