:root {
  /* The owner asked for smaller text overall (2026-11-13); every font size in style.css and m.css uses this. */
  --m-text-scale: 0.9;
  --bg-1: #f8fbff;
  --bg-2: #ffffff;
  --bg-3: #f7fbff;

  --card: #ffffff;
  --card-soft: #f8fafc;
  --card-hover: #f3f7ff;

  --text: #182033;
  --muted: #697386;

  --primary: #3267ff;
  --primary-soft: rgba(50, 103, 255, 0.1);
  --primary-soft-2: rgba(50, 103, 255, 0.06);

  --success: #16834a;
  --danger: #d64545;
  --warning: #9a6400;

  --border: rgba(130, 146, 174, 0.22);
  --border-strong: rgba(130, 146, 174, 0.34);

  --shadow: 0 2px 4px rgba(29, 57, 107, 0.08);
  --shadow-soft: 0 2px 4px rgba(29, 57, 107, 0.06);
  --key-shadow: 0 2px 4px rgba(32, 44, 75, 0.05);

  /* Every other colour of the page's sheets is a token too, so that [data-mode="dark"] below changes them all. A
     number at the end of a name is the tint's alpha in the light page. */
  --text-strong: #121a2c;
  --border-faint: rgba(130, 146, 174, 0.2);

  /* Surfaces: fields, buttons and tools, the switches' thumbs, the template groups, tinted boxes, the keys. */
  --field: #ffffff;
  --field-tint: #fbfcff;
  --field-highlight: rgba(255, 255, 255, 0.8);
  --control: #ffffff;
  --thumb: #ffffff;
  --thumb-content: #e3eaff;
  --group: #f6f8fc;
  --group-open: #f8fbff;
  --card-tint: #fbfcff;
  --box-tint: #fbfcfe;
  --key-top: #ffffff;
  --key-bottom: #f5f7fb;
  --key-bottom-hover: #eef4ff;

  /* Filled buttons keep white text in both modes, so their fill stays deep; a mark or badge on --primary takes
     --on-primary. */
  --primary-fill: #3267ff;
  --primary-fill-hover: #2457e6;
  --danger-fill: #d64545;
  --teal-fill: #00a68f;
  --on-fill: #ffffff;
  --on-fill-ring: rgba(255, 255, 255, 0.22);
  --on-fill-line: rgba(255, 255, 255, 0.45);
  --on-primary: #ffffff;
  --primary-strong: #17327a;

  --primary-a05: rgba(50, 103, 255, 0.05);
  --primary-a08: rgba(50, 103, 255, 0.08);
  --primary-a09: rgba(50, 103, 255, 0.09);
  --primary-a13: rgba(50, 103, 255, 0.13);
  --primary-a18: rgba(50, 103, 255, 0.18);
  --primary-a20: rgba(50, 103, 255, 0.2);
  --primary-a22: rgba(50, 103, 255, 0.22);
  --primary-a24: rgba(50, 103, 255, 0.24);
  --primary-a30: rgba(50, 103, 255, 0.3);
  --primary-a34: rgba(50, 103, 255, 0.34);
  --primary-a35: rgba(50, 103, 255, 0.35);
  --primary-a42: rgba(50, 103, 255, 0.42);
  --primary-a45: rgba(50, 103, 255, 0.45);
  --primary-a56: rgba(50, 103, 255, 0.56);
  --primary-a58: rgba(50, 103, 255, 0.58);
  --primary-a60: rgba(50, 103, 255, 0.6);

  --danger-soft: #fff1f1;
  --danger-soft-hover: #ffe9e9;
  --danger-soft-strong: #ffe4e4;
  --danger-faint: #fff5f5;
  --danger-wash: #fff8f8;
  --danger-a08: rgba(214, 69, 69, 0.08);
  --danger-a22: rgba(214, 69, 69, 0.22);
  --danger-a32: rgba(214, 69, 69, 0.32);
  --danger-a35: rgba(214, 69, 69, 0.35);
  --danger-a45: rgba(214, 69, 69, 0.45);

  --warning-soft: rgba(154, 100, 0, 0.1);
  --warning-soft-2: rgba(154, 100, 0, 0.08);
  --warning-edge: #e0a100;
  --busy: #f0a000;
  --success-soft: #eef9f2;
  --success-ring: rgba(22, 131, 74, 0.15);

  --teal-a05: rgba(0, 166, 143, 0.05);
  --teal-a07: rgba(0, 166, 143, 0.07);
  --teal-a10: rgba(0, 166, 143, 0.1);
  --teal-a12: rgba(0, 166, 143, 0.12);
  --teal-a50: rgba(0, 166, 143, 0.5);
  --teal-text: #0b6b5d;

  /* The Anweisungen in the side list, apart from every other category: their edge, the text on their tint (about
     7:1), the header's tint, the groups' wash and the lines between. */
  --m-anweisung: #0b7a69;
  --m-anweisung-text: #0a5c50;
  --m-anweisung-tint: #e3f4f1;
  --m-anweisung-tint-hover: #d3eee8;
  --m-anweisung-wash: #f1faf8;
  --m-anweisung-line: rgba(11, 122, 105, 0.32);

  --dot-off: #a4aebd;
  --scrollbar: rgba(105, 115, 134, 0.38);
  --scrollbar-thumb: rgba(105, 115, 134, 0.28);
  --scrollbar-thumb-hover: rgba(105, 115, 134, 0.42);
  --ink-hover: rgba(18, 26, 44, 0.08);
  --toast-bg: #182033;
  --toast-text: #ffffff;
  --code-bg: #0f172a;
  --code-text: #e2e8f0;
  --video-bg: #0d1220;
  --drop-overlay: rgba(248, 251, 255, 0.92);

  /* Shadow colours; deeper in the dark. */
  --shade-08: rgba(24, 32, 51, 0.08);
  --shade-16: rgba(24, 32, 51, 0.16);
  --shade-20: rgba(24, 32, 51, 0.2);
  --shade-24: rgba(24, 32, 51, 0.24);
  --shade-28: rgba(24, 32, 51, 0.28);
  --shade-blue-12: rgba(29, 57, 107, 0.12);
  --shade-blue-14: rgba(29, 57, 107, 0.14);
  --shade-blue-18: rgba(29, 57, 107, 0.18);

  /* The tones of the icons drawn in devices.js (m.css's .m-ic-* take them; Fluent's keep their own colours): bright
     on the light page; in the dark a page is dark too, so that the lines on it, in the text's colour, still show. */
  --icon-paper: #ffffff;
  --icon-sky: #cde0ff;
  --icon-orange: #f97316;
  --icon-red: #ef4444;
  --icon-teal: #14b8a6;
  --icon-white: #ffffff;

  --radius-lg: 22px;
  --radius-md: 15px;
  --radius-sm: 11px;
}

/* Night mode: theme.js sets data-mode on <html> before the sheets load. The same tokens, dark; body text and
   controls keep WCAG AA contrast, and filled buttons keep their white text on a deeper fill. */
:root[data-mode="dark"] {
  color-scheme: dark;

  --bg-1: #0f1420;
  --bg-2: #151b29;
  --bg-3: #121826;
  --card: #182031;
  --card-soft: #1c2537;
  --card-hover: #222c41;
  --text: #e6eaf2;
  --muted: #9aa4b8;
  --primary: #6f94ff;
  --primary-soft: rgba(111, 148, 255, 0.14);
  --primary-soft-2: rgba(111, 148, 255, 0.09);
  --success: #3ccf7f;
  --danger: #ff6b6b;
  --warning: #e0a73a;
  --border: rgba(160, 175, 205, 0.18);
  --border-strong: rgba(160, 175, 205, 0.3);
  --shadow: 0 2px 4px rgba(0, 0, 0, 0.28);
  --shadow-soft: 0 2px 4px rgba(0, 0, 0, 0.22);
  --key-shadow: 0 2px 4px rgba(0, 0, 0, 0.25);
  --m-field: #121a29;

  --text-strong: #f1f4f9;
  --border-faint: rgba(160, 175, 205, 0.16);

  --field: #121a29;
  --field-tint: #141d30;
  --field-highlight: rgba(255, 255, 255, 0.03);
  --control: #1c2537;
  --thumb: #253049;
  --thumb-content: #283a66;
  --group: #1a2232;
  --group-open: #1c263b;
  --card-tint: #1b2438;
  --box-tint: #1a2234;
  --key-top: #222c41;
  --key-bottom: #1c2537;
  --key-bottom-hover: #26314a;

  --primary-fill: #3a66f0;
  --primary-fill-hover: #2f5be0;
  --danger-fill: #c93c3c;
  --teal-fill: #00836d;
  --on-fill: #ffffff;
  --on-fill-ring: rgba(255, 255, 255, 0.22);
  --on-fill-line: rgba(255, 255, 255, 0.45);
  --on-primary: #0f1420;
  --primary-strong: #a9c0ff;

  --primary-a05: rgba(111, 148, 255, 0.07);
  --primary-a08: rgba(111, 148, 255, 0.14);
  --primary-a09: rgba(111, 148, 255, 0.14);
  --primary-a13: rgba(111, 148, 255, 0.17);
  --primary-a18: rgba(111, 148, 255, 0.24);
  --primary-a20: rgba(111, 148, 255, 0.26);
  --primary-a22: rgba(111, 148, 255, 0.3);
  --primary-a24: rgba(111, 148, 255, 0.32);
  --primary-a30: rgba(111, 148, 255, 0.38);
  --primary-a34: rgba(111, 148, 255, 0.42);
  --primary-a35: rgba(111, 148, 255, 0.44);
  --primary-a42: rgba(111, 148, 255, 0.5);
  --primary-a45: rgba(111, 148, 255, 0.52);
  --primary-a56: rgba(111, 148, 255, 0.66);
  --primary-a58: rgba(111, 148, 255, 0.66);
  --primary-a60: rgba(111, 148, 255, 0.7);

  --danger-soft: rgba(255, 107, 107, 0.12);
  --danger-soft-hover: rgba(255, 107, 107, 0.18);
  --danger-soft-strong: rgba(255, 107, 107, 0.2);
  --danger-faint: rgba(255, 107, 107, 0.1);
  --danger-wash: rgba(255, 107, 107, 0.07);
  --danger-a08: rgba(255, 107, 107, 0.12);
  --danger-a22: rgba(255, 107, 107, 0.32);
  --danger-a32: rgba(255, 107, 107, 0.4);
  --danger-a35: rgba(255, 107, 107, 0.42);
  --danger-a45: rgba(255, 107, 107, 0.55);

  --warning-soft: rgba(224, 167, 58, 0.14);
  --warning-soft-2: rgba(224, 167, 58, 0.1);
  --warning-edge: #e0a73a;
  --busy: #f0b13a;
  --success-soft: rgba(60, 207, 127, 0.12);
  --success-ring: rgba(60, 207, 127, 0.2);

  --teal-a05: rgba(45, 212, 191, 0.04);
  --teal-a07: rgba(45, 212, 191, 0.08);
  --teal-a10: rgba(45, 212, 191, 0.12);
  --teal-a12: rgba(45, 212, 191, 0.14);
  --teal-a50: rgba(45, 212, 191, 0.5);
  --teal-text: #4fd1b9;

  --m-anweisung: #3fc9b0;
  --m-anweisung-text: #8fe3d3;
  --m-anweisung-tint: #163632;
  --m-anweisung-tint-hover: #1b423d;
  --m-anweisung-wash: #172b2c;
  --m-anweisung-line: rgba(63, 201, 176, 0.36);

  --dot-off: #727d93;
  --scrollbar: rgba(154, 164, 184, 0.38);
  --scrollbar-thumb: rgba(154, 164, 184, 0.28);
  --scrollbar-thumb-hover: rgba(154, 164, 184, 0.45);
  --ink-hover: rgba(230, 234, 242, 0.1);
  --toast-bg: #2a3550;
  --toast-text: #ffffff;
  --code-bg: #0b1120;
  --code-text: #e2e8f0;
  --video-bg: #080b13;
  --drop-overlay: rgba(15, 20, 32, 0.92);

  --shade-08: rgba(0, 0, 0, 0.25);
  --shade-16: rgba(0, 0, 0, 0.4);
  --shade-20: rgba(0, 0, 0, 0.45);
  --shade-24: rgba(0, 0, 0, 0.5);
  --shade-28: rgba(0, 0, 0, 0.5);
  --shade-blue-12: rgba(0, 0, 0, 0.35);
  --shade-blue-14: rgba(0, 0, 0, 0.38);
  --shade-blue-18: rgba(0, 0, 0, 0.4);

  --icon-paper: #2b3652;
  --icon-sky: #9fbdf2;
  --icon-orange: #fb923c;
  --icon-red: #f87171;
  --icon-teal: #2dd4bf;
  --icon-white: #ffffff;
}

/* A dialog's backdrop: set on it, as older browsers give a backdrop none of the page's custom properties. */
::backdrop {
  --backdrop: rgba(18, 26, 44, 0.42);
  --backdrop-strong: rgba(18, 26, 44, 0.72);
}

:root[data-mode="dark"] ::backdrop {
  --backdrop: rgba(0, 0, 0, 0.55);
  --backdrop-strong: rgba(0, 0, 0, 0.8);
}

* {
  box-sizing: border-box;
}

html {
  height: 100%;
}

/* The page is German and left to right. One font stack everywhere: --m-font (m.css, which loads after this file)
   draws Persian characters in Vazir and everything else in the system font. */
body {
  margin: 0;
  height: 100vh;
  overflow: hidden;
  font-family: var(--m-font, system-ui, sans-serif);
  color: var(--text);
  background:
    radial-gradient(
      circle at top left,
      var(--primary-soft-2),
      transparent 32%
    ),
    radial-gradient(
      circle at bottom right,
      var(--teal-a05),
      transparent 30%
    ),
    linear-gradient(135deg, var(--bg-1), var(--bg-2) 55%, var(--bg-3));
}

/* =========================
   Main Layout
========================= */
.page,
.main-column,
.workspace,
.left-column,
.right-column,
.templates-boxes,
.templates-list {
  background: transparent !important;
}

/* The side column (transfer, devices, templates; still called right-column) comes first, on the left. m.css places
   the parts on wide screens. */
.page {
  width: min(1320px, calc(100% - 28px));
  height: calc(100vh - 28px);
  margin: 14px auto;
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 14px;
  overflow: hidden;
}

.main-column {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.right-column {
  min-width: 0;
  min-height: 0;
  height: 100%;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: transparent;
}

/* =========================
   Shared Cards
========================= */

.mode-card,
.editor-card,
.keyboard-card,
.templates-search-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}

/* =========================
   Header / Hero
========================= */

/* The typing panel's head: only the language card; the panel's own header names it. */
.hero {
  display: block;
  margin-bottom: 14px;
  flex: 0 0 auto;
}

h1 {
  margin: 0 0 6px;
  font-size: calc(28px * var(--m-text-scale, 1));
  letter-spacing: -0.4px;
  color: var(--text-strong);
}

/* =========================
   Mode Switch
========================= */

/* One row: the language badge and its shortcut at the start, the two language buttons at the end; they wrap on a
   narrow screen. */
.mode-card {
  padding: 12px 14px;
  min-width: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px 14px;
}

.mode-indicator {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 118px;
  justify-content: center;
  padding: 9px 12px;
  border-radius: 999px;
  color: var(--on-fill);
  background: linear-gradient(135deg, var(--primary-fill), var(--teal-fill));
  box-shadow: 0 8px 18px var(--primary-a22);
  font-size: calc(13px * var(--m-text-scale, 1));
}

.dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--on-fill);
  box-shadow: 0 0 0 4px var(--on-fill-ring);
}

.switch-help {
  color: var(--muted);
  font-size: calc(12px * var(--m-text-scale, 1));
  line-height: 1.6;
  text-align: start;
}

.mode-buttons {
  flex: 0 1 260px;
  min-width: 200px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

/* =========================
   Buttons
========================= */

button,
input,
select {
  font-family: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
}

.mode-btn,
.action-btn,
.keyboard-toggle,
.template-card,
.template-icon-button,
.template-add-button,
.template-dialog-close,
.template-editor-save,
.template-editor-cancel,
.mini-btn,
.category-toggle,
.subcategory-toggle {
  border: 0;
  cursor: pointer;
  transition:
    transform 0.14s ease,
    background 0.14s ease,
    box-shadow 0.14s ease,
    border-color 0.14s ease;
}

.mode-btn {
  background: var(--card-soft);
  color: var(--text);
  padding: 10px 12px;
  border-radius: 13px;
  border: 1px solid var(--border);
}

.mode-btn.active {
  background: var(--primary-fill);
  color: var(--on-fill);
  border-color: transparent;
  box-shadow: 0 8px 18px var(--primary-a20);
}

.mode-btn:hover,
.action-btn:hover,
.keyboard-toggle:hover,
.key:hover,
.template-card:hover,
.template-add-button:hover,
.template-dialog-close:hover,
.template-editor-save:hover,
.template-editor-cancel:hover,
.mini-btn:hover,
.category-toggle:hover,
.subcategory-toggle:hover {
  transform: translateY(-1px);
}

.mode-btn:active,
.action-btn:active,
.keyboard-toggle:active,
.key:active,
.template-card:active,
.template-add-button:active,
.template-dialog-close:active,
.template-editor-save:active,
.template-editor-cancel:active,
.mini-btn:active,
.category-toggle:active,
.subcategory-toggle:active {
  transform: translateY(0);
}

/* =========================
   Editor
========================= */

.workspace {
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}

.left-column {
  min-width: 0;
  min-height: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
}

.editor-card {
  padding: 14px;
  margin-bottom: 14px;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.toolbar {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 10px;
  flex: 0 0 auto;
}

.actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.action-btn {
  color: var(--on-fill);
  background: var(--primary-fill);
  box-shadow: 0 8px 18px var(--primary-a18);
  padding: 10px 13px;
  font-size: calc(13px * var(--m-text-scale, 1));
  border-radius: 13px;
}

.action-btn.secondary,
.mini-btn {
  background: var(--card-soft);
  color: var(--text);
  box-shadow: none;
  border: 1px solid var(--border);
}

.action-btn.secondary:hover,
.mini-btn:hover {
  background: var(--card-hover);
}

.action-btn.danger {
  background: var(--danger-soft);
  color: var(--danger);
  border: 1px solid var(--danger-a22);
  box-shadow: none;
}

.action-btn.danger:hover {
  background: var(--danger-soft-hover);
}

.counter {
  color: var(--muted);
  font-size: calc(13px * var(--m-text-scale, 1));
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Every text area follows its own dir (owner text has dir="auto"). */
textarea {
  width: 100%;
  flex: 1 1 auto;
  min-height: 0;
  resize: none;
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 18px;
  font-size: calc(23px * var(--m-text-scale, 1));
  line-height: 1.9;
  font-family: var(--m-font, system-ui, sans-serif);
  text-align: start;
  background: var(--field);
  outline: none;
  color: var(--text);
  box-shadow: inset 0 1px 0 var(--field-highlight);
}

/* The Persian typing box: right to left in both typing modes, as the owner keeps it. */
#text {
  direction: rtl;
  text-align: start;
  unicode-bidi: embed;
}

/* While empty it shows the German placeholder, which would read „… Hier tippen“ right to left; still on the right. */
#text:placeholder-shown {
  direction: ltr;
  text-align: right;
}

textarea:focus {
  border-color: var(--primary-a56);
  box-shadow: 0 0 0 4px var(--primary-a09);
}

.copy-storage-note {
  margin: 8px 2px 0;
  color: var(--muted);
  font-size: calc(11px * var(--m-text-scale, 1));
  line-height: 1.7;
}

.status-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-top: 10px;
  color: var(--muted);
  font-size: calc(13px * var(--m-text-scale, 1));
  min-height: 22px;
  flex-wrap: wrap;
  flex: 0 0 auto;
}

.status {
  color: var(--success);
}

.status.warn {
  color: var(--warning);
}

/* =========================
   Templates Search Box
========================= */

.templates-search-card {
  padding: 12px;
  flex: 0 0 auto;
}

/* The title at the start, its tools at the end. */
.templates-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.templates-title {
  margin: 0;
  font-size: calc(15px * var(--m-text-scale, 1));
  text-align: start;
  color: var(--text-strong);
}

.template-search {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 13px;
  background: var(--field);
  outline: none;
  padding: 9px 10px;
  margin-bottom: 8px;
  color: var(--text);
  text-align: start;
  font-size: calc(12px * var(--m-text-scale, 1));
}

.template-search:focus {
  border-color: var(--primary-a56);
  box-shadow: 0 0 0 3px var(--primary-a08);
}

.templates-help {
  margin: 0;
  font-size: calc(11px * var(--m-text-scale, 1));
  line-height: 1.7;
  color: var(--muted);
}

/* =========================
   Templates Area
   Only the cards themselves have a background.
========================= */

.templates-boxes {
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: transparent;
  border: 0;
  box-shadow: none;
  padding: 0;
}

/* A little room between the cards and the scroll bar at the end. */
.templates-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow-y: auto;
  overflow-x: hidden;
  padding-inline-start: 1px;
  padding-inline-end: 4px;
  flex: 1 1 auto;
  min-height: 0;
  background: transparent;
  border: 0;
  box-shadow: none;
  scrollbar-width: thin;
  scrollbar-color: var(--scrollbar) transparent;
}

.templates-list::-webkit-scrollbar {
  width: 8px;
}

.templates-list::-webkit-scrollbar-track {
  background: transparent;
}

.templates-list::-webkit-scrollbar-thumb {
  background: var(--scrollbar-thumb);
  border-radius: 999px;
}

.templates-list::-webkit-scrollbar-thumb:hover {
  background: var(--scrollbar-thumb-hover);
}

/* =========================
   Category Cards
========================= */

.category {
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--card);
  box-shadow: var(--key-shadow);
  overflow: hidden;
  flex: 0 0 auto;
  transition:
    border-color 0.18s ease,
    box-shadow 0.18s ease,
    transform 0.18s ease;
}

.category.open {
  border-color: var(--primary-a24);
  box-shadow: 0 6px 18px var(--primary-a08);
}

/* One row: the toggle takes the room with the title at the start (left), the rename icon sits at its end (right). */
.category-header {
  display: flex;
  align-items: center;
  gap: 4px;
  padding-inline-end: 6px;
  background: linear-gradient(
    135deg,
    var(--primary-soft),
    var(--teal-a07)
  );
}

.category-header:hover {
  background: linear-gradient(
    135deg,
    var(--primary-a13),
    var(--teal-a10)
  );
}

.category-toggle {
  flex: 1 1 auto;
  min-width: 0;
  background: transparent;
  color: var(--text);
  text-align: start;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 7px;
  border-radius: 0;
  padding: 9px 11px;
  font-size: calc(13px * var(--m-text-scale, 1));
}

.category-toggle span {
  min-width: 0;
  overflow-wrap: anywhere;
}

.category-body {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 7px;
  background: var(--card);
  transform-origin: top;
}

.category.open > .category-body {
  animation: accordionOpen 0.32s ease-out both;
}

.category.closing > .category-body {
  animation: accordionClose 0.26s ease-in both;
}

.subcategory.open > .subcategory-body {
  animation: accordionOpen 0.28s ease-out both;
}

.subcategory.closing > .subcategory-body {
  animation: accordionClose 0.24s ease-in both;
}

.keyboard-card.open .keyboard-content {
  display: block;
  animation: accordionOpen 0.28s ease-out both;
}

/* =========================
   Subcategory Cards
========================= */

.subcategory {
  border-radius: 12px;
  background: var(--group);
  overflow: hidden;
  border: 1px solid var(--border-faint);
  transition:
    background 0.18s ease,
    border-color 0.18s ease,
    box-shadow 0.18s ease;
}

.subcategory.open {
  background: var(--group-open);
  border-color: var(--primary-a18);
  box-shadow: 0 4px 12px var(--primary-a05);
}

/* As a category's header: the toggle takes the room, the rename icon of his own group sits at its end. */
.subcategory-header {
  display: flex;
  align-items: center;
  gap: 4px;
}

.subcategory-header > .template-icon-button:last-child {
  margin-inline-end: 4px;
}

.subcategory-toggle {
  flex: 1 1 auto;
  min-width: 0;
  background: transparent;
  color: var(--text);
  text-align: start;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 7px;
  padding: 7px 10px;
  border-radius: 0;
  font-size: calc(12px * var(--m-text-scale, 1));
}

.subcategory-toggle:hover {
  background: var(--primary-soft-2);
}

.subcategory-toggle span {
  min-width: 0;
  overflow-wrap: anywhere;
}

.subcategory-body {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 0 6px 6px;
  transform-origin: top;
}

.subcategory.open > .subcategory-body {
  animation: accordionOpen 0.18s ease-out both;
}

.subcategory.collapsed > .subcategory-body {
  animation: accordionClose 0.14s ease-in both;
}

/* =========================
   Accordion Icons
   Before the title: pointing to the end (right) while closed, down while open.
========================= */

.category-toggle::before,
.subcategory-toggle::before {
  content: "▸";
  font-size: calc(12px * var(--m-text-scale, 1));
  color: var(--muted);
  flex: 0 0 auto;
  transition: transform 0.18s ease;
}

.category.open > .category-header > .category-toggle::before,
.subcategory.open > .subcategory-header > .subcategory-toggle::before {
  content: "▾";
}

.category-count,
.subcategory-count {
  display: none;
}

/* =========================
   Template Cards
========================= */

.template-card {
  width: 100%;
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--border-faint);
  box-shadow: none;
  text-align: start;
  line-height: 1.6;
  padding: 7px 10px;
  border-radius: 10px;
}

/* The card takes the room at the start; its icons (show, copy, and edit where he may) sit at the end (right), on the
   same line. */
.template-card-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-auto-flow: column;
  grid-auto-columns: auto;
  gap: 4px;
  align-items: center;
}

/* Whose a text, group or category is when it is another person's: his name (the system's say nothing). Under a
   text's title; at the end of a category's or group's toggle. */
.template-owner {
  color: var(--muted);
  font-size: calc(11px * var(--m-text-scale, 1));
  line-height: 1.4;
}

.template-card .template-owner {
  display: block;
  overflow-wrap: anywhere;
}

.category-toggle .template-owner,
.subcategory-toggle .template-owner {
  flex: 0 1 auto;
  margin-inline-start: auto;
}

/* Small square icons: show, copy and edit a template, rename a group or a category. */
.template-icon-button {
  flex: 0 0 auto;
  box-sizing: border-box;
  width: var(--m-h-sm);
  height: var(--m-h-sm);
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border-faint);
  border-radius: var(--m-r-ctl);
  background: var(--control);
  color: var(--muted);
  cursor: pointer;
  font-family: var(--m-font, system-ui, sans-serif);
  font-size: var(--m-fs-ctl-sm);
  line-height: 1;
  white-space: nowrap;
}

.template-icon-button .m-icon {
  width: 17px;
  height: 17px;
}

/* Without devices.js the button shows its name instead of the icon. */
.template-icon-button.template-icon-text {
  width: auto;
  padding: 0 8px;
}

.template-icon-button:not(:disabled):hover,
.template-icon-button:focus-visible {
  color: var(--primary);
  background: var(--card-hover);
  border-color: var(--primary-a35);
}

/* Drawn inside: the category and the group clip what goes past their edges. */
.template-icon-button:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: -2px;
}

.template-icon-button:disabled {
  opacity: 0.45;
  cursor: default;
}

.template-card:hover {
  background: var(--card-hover);
  border-color: var(--primary-a22);
}

.template-card-title {
  display: block;
  font-size: calc(12px * var(--m-text-scale, 1));
  color: var(--text);
  overflow-wrap: anywhere;
}

.template-add-button {
  width: 100%;
  min-height: 46px;
  border: 1px dashed var(--primary-a42);
  border-radius: 12px;
  background: var(--primary-a05);
  color: var(--primary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  font-size: calc(12px * var(--m-text-scale, 1));
}

.template-add-button:hover {
  background: var(--primary-soft);
  border-color: var(--primary-a58);
}

.template-add-button:disabled {
  cursor: wait;
  opacity: 0.55;
}

.template-add-icon {
  font-size: calc(26px * var(--m-text-scale, 1));
  line-height: 1;
  font-family: var(--m-font, system-ui, sans-serif);
}

.template-add-category {
  flex: 0 0 auto;
  min-height: 58px;
  border-radius: 16px;
  background: var(--card);
  box-shadow: var(--key-shadow);
  font-size: calc(13px * var(--m-text-scale, 1));
}

.template-add-item,
.template-add-group {
  margin-top: 1px;
}

/* =========================
   The Anweisungen
   Whatever is in them attaches to a card as an Anweisung: their own colour, header, groups, texts and add buttons,
   apart from every other category. The chips on the cards keep theirs.
========================= */

.category.category-anweisungen {
  border-color: var(--m-anweisung-line);
  border-inline-start: 4px solid var(--m-anweisung);
}

.category.category-anweisungen.open {
  border-color: var(--m-anweisung-line);
  border-inline-start-color: var(--m-anweisung);
}

.category-anweisungen > .category-header {
  background: var(--m-anweisung-tint);
}

.category-anweisungen > .category-header:hover {
  background: var(--m-anweisung-tint-hover);
}

.category-anweisungen .category-toggle,
.category-anweisungen .subcategory-toggle,
.category-anweisungen .category-toggle::before,
.category-anweisungen .subcategory-toggle::before {
  color: var(--m-anweisung-text);
}

.category-anweisungen .category-toggle {
  font-weight: 600;
}

.category-anweisungen .subcategory,
.category-anweisungen .subcategory.open {
  background: var(--m-anweisung-wash);
  border-color: var(--m-anweisung-line);
}

.category-anweisungen .template-card {
  border-color: var(--m-anweisung-line);
  border-inline-start: 3px solid var(--m-anweisung);
}

.category-anweisungen .template-add-button {
  border-color: var(--m-anweisung-line);
  background: transparent;
  color: var(--m-anweisung-text);
}

.category-anweisungen .template-add-button:hover {
  border-color: var(--m-anweisung);
  background: var(--m-anweisung-tint);
}

/* =========================
   Template Editor Dialog
========================= */

.template-editor-dialog {
  width: min(520px, calc(100% - 28px));
  max-height: min(680px, calc(100vh - 28px));
  padding: 0;
  border: 1px solid var(--border-strong);
  border-radius: 20px;
  background: var(--card);
  color: var(--text);
  box-shadow: 0 24px 70px var(--shade-24);
}

.template-editor-dialog::backdrop {
  background: var(--backdrop);
  backdrop-filter: blur(2px);
}

.template-editor-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 18px;
}

/* The title at the start, the close button at the end. */
.template-editor-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.template-editor-header h2 {
  margin: 0;
  font-size: calc(18px * var(--m-text-scale, 1));
}

.template-dialog-close {
  width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--card-soft);
  color: var(--muted);
  cursor: pointer;
  font-size: calc(24px * var(--m-text-scale, 1));
  line-height: 1;
}

.template-editor-field {
  display: flex;
  flex-direction: column;
  gap: 7px;
  color: var(--text);
  font-size: calc(13px * var(--m-text-scale, 1));
}

.template-editor-field[hidden] {
  display: none;
}

/* Owner text: each field follows its dir="auto". */
.template-editor-field input,
.template-editor-field textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 13px;
  background: var(--field);
  color: var(--text);
  outline: none;
  padding: 11px 12px;
  font-family: var(--m-font, system-ui, sans-serif);
  font-size: calc(14px * var(--m-text-scale, 1));
  text-align: start;
  box-shadow: none;
}

.template-editor-field textarea {
  min-height: 190px;
  max-height: 42vh;
  flex: none;
  resize: vertical;
  line-height: 1.8;
}

.template-editor-field input:focus,
.template-editor-field textarea:focus {
  border-color: var(--primary-a56);
  box-shadow: 0 0 0 3px var(--primary-a08);
}

.template-editor-note {
  margin: -3px 0 0;
  color: var(--muted);
  font-size: calc(11px * var(--m-text-scale, 1));
  line-height: 1.7;
}

/* On a narrow phone a third button («Löschen») goes to the next line rather than past the dialog's edge. */
.template-editor-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.template-editor-save,
.template-editor-cancel {
  min-height: 42px;
  padding: 9px 18px;
  border-radius: 12px;
  cursor: pointer;
  font-size: calc(13px * var(--m-text-scale, 1));
}

.template-editor-save {
  border: 0;
  background: var(--primary-fill);
  color: var(--on-fill);
  box-shadow: 0 8px 18px var(--primary-a18);
}

.template-editor-cancel {
  border: 1px solid var(--border);
  background: var(--card-soft);
  color: var(--text);
}

/* «Öffentlich (für alle)»: a checkbox with its label on one line. */
.template-editor-check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  align-self: flex-start;
  color: var(--text);
  font-size: calc(13px * var(--m-text-scale, 1));
  cursor: pointer;
}

.template-editor-check input {
  width: 18px;
  height: 18px;
  margin: 0;
  accent-color: var(--primary);
}

/* «Löschen» of what the dialog edits: apart from saving, at the end of the row. */
.template-editor-delete {
  margin-inline-start: auto;
}

/* The eye's window: the whole text as written, each paragraph in its own direction, German or Persian. */
.template-view-text {
  min-height: 0;
  max-height: min(56vh, 460px);
  overflow-y: auto;
  padding: 11px 12px;
  border: 1px solid var(--border);
  border-radius: 13px;
  background: var(--field);
  color: var(--text);
  font-family: var(--m-font, system-ui, sans-serif);
  font-size: calc(14px * var(--m-text-scale, 1));
  line-height: 1.8;
  text-align: start;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  unicode-bidi: plaintext;
}

.template-view-dialog .template-editor-header h2 {
  min-width: 0;
  overflow-wrap: anywhere;
}

.template-card-meta {
  display: none;
}

.empty-templates {
  color: var(--muted);
  font-size: calc(12px * var(--m-text-scale, 1));
  line-height: 1.8;
  padding: 10px;
  background: var(--card);
  border-radius: 12px;
  border: 1px dashed var(--border-strong);
}

/* =========================
   Accordion Animation
========================= */

@keyframes accordionOpen {
  from {
    opacity: 0;
    transform: scaleY(0.96);
    max-height: 0;
  }

  to {
    opacity: 1;
    transform: scaleY(1);
    max-height: 1000px;
  }
}

@keyframes accordionClose {
  from {
    opacity: 1;
    transform: scaleY(1);
    max-height: 1000px;
  }

  to {
    opacity: 0;
    transform: scaleY(0.96);
    max-height: 0;
  }
}

/* =========================
   Keyboard Layout Toggle
========================= */

.keyboard-card {
  flex: 0 0 auto;
  margin-top: 0;
  overflow: hidden;
}

/* The label at the start, the chevron at the end. */
.keyboard-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--card);
  color: var(--text);
  text-align: start;
  font-size: calc(14px * var(--m-text-scale, 1));
  border-radius: 24px;
  padding: 14px 18px;
}

.keyboard-toggle:hover {
  background: var(--card-hover);
}

.keyboard-toggle-text {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.toggle-icon {
  width: 30px;
  height: 30px;
  flex: 0 0 30px;
  border-radius: 50%;
  background: var(--card-soft);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.18s ease;
}

.keyboard-card.open .toggle-icon {
  transform: rotate(180deg);
}

/* A keyboard's rows read left to right whatever is typed with it. */
.keyboard-content {
  display: none;
  padding: 0 16px 16px;
  overflow-x: auto;
  direction: ltr;
}

.keyboard-card.open .keyboard-content {
  display: block;
  animation: accordionOpen 0.18s ease-out both;
}

.keyboard-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin: 6px 0 12px;
  color: var(--muted);
  font-size: calc(13px * var(--m-text-scale, 1));
  min-width: 880px;
}

.keyboard {
  min-width: 880px;
}

.row {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin-bottom: 8px;
}

.key {
  min-width: 58px;
  height: 58px;
  border: 1px solid var(--border);
  border-radius: 15px;
  background: linear-gradient(180deg, var(--key-top), var(--key-bottom));
  color: var(--text);
  cursor: pointer;
  display: grid;
  grid-template-rows: 1fr 1fr auto;
  align-items: center;
  justify-items: center;
  padding: 5px 6px;
  box-shadow: var(--key-shadow);
  transition: 0.14s ease;
  font-family: var(--m-font, system-ui, sans-serif);
}

.key:hover {
  background: linear-gradient(180deg, var(--key-top), var(--key-bottom-hover));
  border-color: var(--primary-a22);
}

.key:active {
  transform: translateY(1px);
  box-shadow: none;
}

.key .shift {
  font-size: calc(13px * var(--m-text-scale, 1));
  color: var(--muted);
  min-height: 16px;
}

.key .main {
  font-size: calc(21px * var(--m-text-scale, 1));
  line-height: 1;
}

.key .latin {
  font-size: calc(11px * var(--m-text-scale, 1));
  color: var(--muted);
  font-family: var(--m-font, system-ui, sans-serif);
  margin-top: 2px;
}

.space {
  min-width: 330px;
}

.special {
  background: linear-gradient(180deg, var(--key-top), var(--key-bottom));
}

/* =========================
   Responsive
========================= */

@media (max-width: 980px) {
  body {
    height: auto;
    min-height: 100vh;
    overflow: auto;
  }

  .page {
    width: min(1320px, calc(100% - 28px));
    height: auto;
    margin: 14px auto;
    display: flex;
    flex-direction: column;
    overflow: visible;
  }

  .main-column {
    display: block;
    overflow: visible;
  }

  .right-column {
    height: auto;
    overflow: visible;
    order: -1;
    margin-bottom: 14px;
  }

  .templates-boxes {
    overflow: visible;
  }

  .templates-list {
    max-height: 340px;
    flex: unset;
  }

  .editor-card {
    display: block;
  }

  textarea {
    min-height: 260px;
    resize: vertical;
  }
}

@media (max-width: 760px) {
  .page {
    width: min(100% - 18px, 1120px);
    margin: 10px auto;
  }

  h1 {
    font-size: calc(24px * var(--m-text-scale, 1));
  }

  textarea {
    font-size: calc(20px * var(--m-text-scale, 1));
    min-height: 260px;
  }

  /* The language buttons take the whole row under the badge. */
  .mode-buttons {
    flex: 1 1 100%;
  }
}
