/* Arabic Keyboard 0.3.0 */
/* Arabic Keyboard. Every rule is scoped to .akb so the theme can't break the layout. */
.akb {
  --akb-paper: #e6eef0; --akb-panel: #ffffff; --akb-ink: #04141a; --akb-muted: #2f474d;
  --akb-line: #8aa3a9; --akb-tile: #ffffff; --akb-edge: #5f7c83; --akb-press: #bfdde3;
  --akb-sea: #0b4f60; --akb-sea-ink: #ffffff; --akb-saffron: #b87408; --akb-rule: #a9c1c6;
  --akb-danger: #8c1a14;
  --akb-ar: "Noto Naskh Arabic", "Amiri", "Geeza Pro", "Traditional Arabic", "Segoe UI", Tahoma, serif;
  position: relative;
  --akb-key-h: clamp(40px, 6.4vh, 58px);
  --akb-lh: 44px;
  --akb-gap: 6px;
  width: 100%;
  max-width: 100%;
  margin: 0 auto;
  padding: 12px;
  background: var(--akb-paper);
  color: var(--akb-ink);
  border-radius: 14px;
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  .akb {
    --akb-paper: #050d10; --akb-panel: #0d1b21; --akb-ink: #f4fbfc; --akb-muted: #c0d6da;
    --akb-line: #4d6c75; --akb-tile: #163039; --akb-edge: #7fa3ad; --akb-press: #2b5360;
    --akb-sea: #7fd6e8; --akb-sea-ink: #021a20; --akb-saffron: #ffc65c; --akb-rule: #2f525d;
    --akb-danger: #ffa59d;
  }
}
.akb *, .akb *::before, .akb *::after { box-sizing: border-box; }
.akb [hidden] { display: none !important; }
.akb button, .akb input, .akb textarea { font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
.akb button { cursor: pointer; touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
.akb-title, .akb-count, .akb-mark-name, .akb-phys, .akb-status { font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
/* Stop themes from colouring keys blue on tap/hover/focus */
.akb .akb-key:hover, .akb .akb-key:focus { background: var(--akb-tile); color: var(--akb-ink); }
.akb .akb-btn:hover, .akb .akb-btn:focus { background: var(--akb-tile); color: var(--akb-ink); }
.akb .akb-primary:hover, .akb .akb-primary:focus { background: var(--akb-sea); color: var(--akb-sea-ink); }
.akb .akb-danger:hover, .akb .akb-danger:focus { color: var(--akb-danger); }
.akb button:focus-visible, .akb input:focus-visible, .akb textarea:focus-visible { outline: 3px solid var(--akb-sea); outline-offset: 2px; }

.akb-top { display: flex; align-items: baseline; gap: 8px; margin-bottom: 6px; }
.akb-title { flex: 1 1 auto; margin: 0; padding: 0; font-size: 17px; line-height: 1.2; font-weight: 700; color: inherit; }
.akb-count { font-size: 13px; font-weight: 600; color: var(--akb-muted); }

.akb-btn { height: 38px; padding: 0 12px; border: 2px solid var(--akb-edge); border-radius: 10px; background: var(--akb-tile); color: var(--akb-ink); font-size: 14px; font-weight: 700; line-height: 1; }
.akb .akb-btn:active { background: var(--akb-press); }
.akb .akb-primary:active { background: var(--akb-sea); filter: brightness(1.25); }
.akb-primary { background: var(--akb-sea); color: var(--akb-sea-ink); border-color: var(--akb-sea); }
.akb-danger { color: var(--akb-danger); border-color: var(--akb-danger); }

.akb-out {
  display: block; width: 100%; height: calc(var(--akb-lh) * 3 + 4px); min-height: calc(var(--akb-lh) * 2 + 4px); max-height: 50vh;
  margin: 0; padding: 0 14px;
  border: 2px solid var(--akb-edge); border-inline-start: 6px solid var(--akb-saffron); border-radius: 10px;
  background-color: var(--akb-panel);
  background-image: repeating-linear-gradient(to bottom, transparent 0, transparent calc(var(--akb-lh) - 1px), var(--akb-rule) calc(var(--akb-lh) - 1px), var(--akb-rule) var(--akb-lh));
  background-attachment: local;
  color: var(--akb-ink);
  font-family: var(--akb-ar); font-size: 28px; font-weight: 600; line-height: var(--akb-lh);
  resize: vertical; outline: 0;
}
.akb-out:focus { border-color: var(--akb-sea); }
.akb-out::placeholder { color: var(--akb-muted); opacity: .7; }

.akb-actions { display: flex; flex-wrap: wrap; gap: var(--akb-gap); margin: 6px 0 8px; }
.akb-actions .akb-btn { flex: 1 1 0; white-space: nowrap; }

/* Status message floats over the top so the layout never jumps */
.akb-status { position: absolute; top: 8px; left: 50%; transform: translateX(-50%); z-index: 5; max-width: 90%; padding: 6px 14px; border-radius: 999px; background: var(--akb-ink); color: var(--akb-paper); font-size: 14px; font-weight: 600; text-align: center; pointer-events: none; }
.akb-status:empty { display: none; }

/* Diacritics bar: on top, above the letters */
.akb-diac { display: flex; justify-content: center; gap: var(--akb-gap); margin-bottom: 8px; padding: 6px; background: var(--akb-panel); border: 2px solid var(--akb-line); border-radius: 12px; }
.akb-diac .akb-key { flex: 1 1 0; max-width: 130px; height: calc(var(--akb-key-h) + 6px); }
.akb-mark-glyph { display: block; font-family: system-ui, var(--akb-ar); font-size: 26px; font-weight: 700; line-height: 1; color: var(--akb-ink); }
.akb-mark-name { display: block; margin-top: 3px; font-size: 13px; font-weight: 700; line-height: 1; color: var(--akb-ink); }

/* Letter keys: full width */
.akb-keys { display: flex; flex-direction: column; gap: var(--akb-gap); }
.akb-row { display: flex; gap: var(--akb-gap); }
.akb-key {
  flex: 1 1 0; min-width: 0; height: var(--akb-key-h); padding: 0;
  background: var(--akb-tile); color: var(--akb-ink);
  border: 2px solid var(--akb-edge); border-bottom-width: 4px; border-radius: 9px;
  font-family: var(--akb-ar); font-size: calc(var(--akb-key-h) * 0.52); font-weight: 700; line-height: 1;
  overflow: hidden; user-select: none; -webkit-user-select: none;
  transition: background .08s, transform .08s;
}
.akb .akb-key:active, .akb .akb-key.is-lit { background: var(--akb-press); color: var(--akb-ink); transform: translateY(1px); }

.akb-ctl { display: flex; align-items: center; gap: var(--akb-gap); margin-top: 8px; }
.akb-ctl .akb-btn { height: calc(var(--akb-key-h) - 4px); min-height: 38px; }
.akb-space { flex: 1 1 auto; }
.akb-phys { display: inline-flex; align-items: center; gap: 6px; margin-inline-start: auto; font-size: 14px; font-weight: 600; color: var(--akb-ink); white-space: nowrap; }

/* Long-press variants popup */
.akb-pop { position: fixed; z-index: 99999; display: flex; gap: 4px; padding: 6px; background: var(--akb-panel); border: 2px solid var(--akb-edge); border-radius: 10px; box-shadow: 0 6px 20px rgba(0,0,0,.35); }
.akb-pop .akb-key { flex: 0 0 auto; width: 52px; height: 56px; font-size: 28px; }

/* Phones and narrow screens */
@media (max-width: 600px) {
  .akb { --akb-key-h: clamp(36px, 6.2vh, 46px); --akb-lh: 38px; --akb-gap: 4px; padding: 8px; border-radius: 10px; }
  .akb-title { font-size: 15px; }
  .akb-out { height: calc(var(--akb-lh) * 2 + 4px); font-size: 24px; padding: 0 10px; }
  .akb-btn { height: 36px; padding: 0 8px; font-size: 13px; }
  .akb-actions { margin: 5px 0 6px; }
  .akb-actions .akb-btn { flex: 1 1 28%; }
  .akb-diac { display: grid; grid-template-columns: repeat(4, 1fr); padding: 4px; margin-bottom: 6px; }
  .akb-diac .akb-key { max-width: none; height: 40px; display: flex; align-items: center; justify-content: center; gap: 6px; }
  .akb-mark-glyph { font-size: 20px; }
  .akb-mark-name { margin: 0; font-size: 11.5px; letter-spacing: -.1px; white-space: nowrap; }
  .akb-key { border-width: 2px; border-bottom-width: 3px; border-radius: 7px; font-size: min(calc(var(--akb-key-h) * 0.5), 4.7vw); font-weight: 600; }
  .akb-diac .akb-key { font-size: inherit; font-weight: inherit; padding: 0 2px; }
  .akb-ctl .akb-btn { font-size: 14px; }
  /* The four widest letters (dad, sad, sheen, seen) sit on the 12-key rows: give them a smaller size so they stay inside the key */
  .akb-key[data-ch="ض"], .akb-key[data-ch="ص"], .akb-key[data-ch="ش"], .akb-key[data-ch="س"] { font-size: min(calc(var(--akb-key-h) * 0.4), 3.6vw); font-weight: 600; letter-spacing: -0.3px; }
  .akb-ctl { margin-top: 6px; }
}
@media (max-width: 380px) {
  .akb-diac .akb-key { gap: 2px; }
  .akb-mark-glyph { font-size: 18px; }
  .akb-mark-name { font-size: 10.5px; }
}
/* Touch screens have no physical keyboard to switch on */
@media (hover: none) and (pointer: coarse) { .akb-phys { display: none; } }
/* Large desktop */
@media (min-width: 900px) {
  .akb { padding: 16px; }
  .akb-key { border-bottom-width: 4px; }
}
@media (max-height: 640px) and (min-width: 601px) {
  .akb { --akb-key-h: 40px; --akb-lh: 38px; }
  .akb-out { font-size: 24px; }
}
@media (prefers-reduced-motion: reduce) { .akb * { transition: none !important; } }

/* ---- Theme-proof overrides (themes often force fonts/sizes on buttons and spans) ---- */
.akb .akb-title, .akb .akb-count, .akb .akb-mark-name, .akb .akb-phys, .akb .akb-status { font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif !important; }
.akb .akb-title { margin: 0 !important; padding: 0 !important; font-size: 17px !important; line-height: 1.2 !important; font-weight: 700 !important; text-transform: none !important; letter-spacing: 0 !important; }
.akb .akb-key:hover, .akb .akb-key:focus { background: var(--akb-tile) !important; color: var(--akb-ink) !important; }
.akb .akb-key:active, .akb .akb-key.is-lit { background: var(--akb-press) !important; color: var(--akb-ink) !important; }
@media (max-width: 600px) {
  .akb .akb-title { font-size: 15px !important; }
  .akb .akb-key { font-size: min(calc(var(--akb-key-h) * 0.5), 4.4vw) !important; font-weight: 600 !important; line-height: 1 !important; padding: 0 !important; letter-spacing: 0 !important; text-transform: none !important; }
  .akb .akb-key[data-ch="ض"], .akb .akb-key[data-ch="ص"], .akb .akb-key[data-ch="ش"], .akb .akb-key[data-ch="س"] { font-size: min(calc(var(--akb-key-h) * 0.4), 3.4vw) !important; }
  .akb .akb-diac .akb-key { font-size: 12px !important; padding: 0 2px !important; }
  .akb .akb-mark-glyph { font-size: 18px !important; }
  .akb .akb-mark-name { margin: 0 !important; font-size: 10.5px !important; font-weight: 700 !important; letter-spacing: -0.1px !important; line-height: 1 !important; white-space: nowrap !important; text-transform: none !important; }
}
