/* Online Hebrew keyboard (public tool). A sheet of paper to type on, a line that names each letter,
   a strip of vowel marks, and a keyboard drawn in CSS. It uses the chart page's colours (--chart-*) from public.css. */

/* This page only: a smaller title and less space around it, so the paper and the whole keyboard
   are on the first screen. */
.pub-main:has([data-public-tool="keyboard"]) > .pub-breadcrumbs { margin-bottom: 0; }
.pub-main:has([data-public-tool="keyboard"]) > .pub-page-header--chart { margin-block: 0.9rem 1.1rem; }
.pub-main:has([data-public-tool="keyboard"]) > .pub-page-header--chart h1 { font-size: clamp(2rem, 5vw, 3rem); }

.kb-page {
    --kb-ink: var(--chart-ink, #3c473e);
    --kb-strip: 2.5rem;
    --kb-legend: #4b4d50;
    --kb-glow: 240, 170, 40;
    display: flex;
    flex-direction: column;
}
.kb-stage { display: flex; flex-direction: column; gap: 0.5rem; }

/* The sheet of paper. The typed Hebrew is the biggest thing on the page. */
.kb-paper {
    display: flex;
    flex-direction: column;
    padding: 0.5rem 0.6rem 0.35rem;
    border: 1px solid #e8e4da;
    border-radius: 1rem;
    background: #fffdf9;
    box-shadow: 0 12px 26px -20px rgba(60, 71, 62, 0.55);
}
.kb-paper-bar { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; min-height: 2.5rem; }

.kb-seg { position: relative; display: grid; grid-template-columns: 1fr 1fr; padding: 3px; border-radius: 999px; background: #f1efe9; }
.kb-seg-thumb {
    position: absolute;
    inset-block: 3px;
    left: 3px;
    width: calc((100% - 6px) / 2);
    border-radius: 999px;
    background: var(--chart-toggle, #3c473e);
    box-shadow: 0 2px 0 #000;
    transition: transform 280ms cubic-bezier(0.22, 1, 0.36, 1);
}
.kb-seg-thumb.is-second { transform: translateX(100%); }
.public-site .chart-page .kb-seg-option {
    position: relative;
    z-index: 1;
    min-height: 2.25rem;
    padding: 0 1rem;
    border: 0;
    border-radius: 999px;
    background: transparent;
    color: var(--chart-muted);
    font-size: 0.82rem;
    font-weight: 800;
    white-space: nowrap;
    cursor: pointer;
    transition: color 200ms ease;
    -webkit-tap-highlight-color: transparent;
}
.public-site .chart-page .kb-seg-option[aria-pressed="true"] { color: #fff; }

.kb-actions { display: flex; align-items: center; gap: 0.4rem; }
.kb-count { color: var(--chart-muted); font-size: 0.82rem; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.public-site .chart-page .kb-action {
    min-height: 2.25rem;
    padding: 0 0.95rem;
    border: 1.5px solid #e1ddd3;
    border-radius: 999px;
    background: #fff;
    color: var(--kb-ink);
    font-size: 0.82rem;
    font-weight: 800;
    white-space: nowrap;
    cursor: pointer;
    touch-action: manipulation;
}
.public-site .chart-page .kb-action--primary { border-color: var(--chart-toggle); background: var(--chart-toggle); color: #fff; box-shadow: 0 2px 0 #000; }
.public-site .chart-page .kb-action:disabled { opacity: 0.4; cursor: default; box-shadow: none; }

.kb-text, .kb-practice { height: 6.4rem; }
.public-site .chart-page .kb-text {
    display: block;
    width: 100%;
    resize: none;
    padding: 0 0.5rem;
    border: 0;
    border-radius: 0.6rem;
    background: transparent;
    color: var(--kb-ink);
    font-family: Rubik, sans-serif;
    font-size: 2.5rem;
    font-weight: 500;
    line-height: 1.28;
    text-align: right;
    unicode-bidi: plaintext;
    caret-color: var(--chart-sound);
}
.public-site .chart-page .kb-text[hidden] { display: none; }
/* The English hint reads left to right, and still sits on the right where the Hebrew will start. */
.public-site .chart-page .kb-text:placeholder-shown { direction: ltr; }
.public-site .chart-page .kb-text.is-medium { font-size: 2rem; line-height: 1.4; }
.public-site .chart-page .kb-text.is-small { font-size: 1.45rem; line-height: 1.5; }
.kb-text::placeholder { color: var(--chart-faint); font-family: var(--font-sans, sans-serif); font-size: 1.05rem; font-weight: 600; line-height: 3.1; }
.public-site .chart-page .kb-text:focus,
.public-site .chart-page .kb-text:focus-visible { outline: none; box-shadow: none; }
.kb-paper:has(.kb-text:focus-visible) { border-color: #cfd8dc; }

/* Practice: the word waits in grey, and each key the visitor gets right inks the next part of it. */
/* In the practice there are no vowel marks, so the paper takes the room of the strip and nothing below it moves. */
.kb-practice { height: calc(6.4rem + var(--kb-strip) + 0.5rem); }
.kb-practice { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0.1rem; text-align: center; }
.kb-word {
    display: grid;
    width: max-content;
    margin: 0;
    font-family: Rubik, sans-serif;
    font-size: 2.5rem;
    font-weight: 500;
    line-height: 1.28;
}
.kb-word-ghost, .kb-word-ink { grid-area: 1 / 1; white-space: nowrap; }
.kb-word-ghost { color: #d9d5cc; }
.kb-word-ink { justify-self: start; color: var(--kb-ink); }
.kb-practice.is-finished .kb-word { background: linear-gradient(transparent 58%, rgba(255, 200, 0, 0.32) 58%, rgba(255, 200, 0, 0.32) 92%, transparent 92%); }
.kb-practice-line { margin: 0.35rem 0 0; color: var(--chart-muted); font-size: 0.95rem; font-weight: 600; line-height: 1.4; }
.kb-translit { color: var(--kb-ink); font-weight: 800; }
.kb-meaning { color: var(--kb-ink); font-weight: 700; }
.public-site .chart-page .kb-story-link { color: var(--kb-ink); font-weight: 700; text-decoration: underline; text-decoration-color: #b9c2bb; white-space: nowrap; }

/* The line that names the last letter. */
/* The line above the keyboard keeps one height whatever it says, so the keys never move as the text changes. */
.kb-readout { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; height: 2.9rem; overflow: hidden; padding-inline: 0.35rem; }
.kb-readout-main { display: flex; flex: 1 1 auto; align-items: center; gap: 0.6rem; min-width: 0; }
.kb-readout-glyph {
    display: grid;
    flex: 0 0 auto;
    place-items: center;
    width: 3rem;
    height: 2.75rem;
    background: url("/images/alphabet/card.png") center / 100% 100% no-repeat;
    color: var(--kb-ink);
    font-family: Rubik, sans-serif;
    font-size: 1.6rem;
    line-height: 1;
}
.kb-readout-text { color: #4b5563; font-size: 0.95rem; line-height: 1.35; }
.kb-readout-text strong { color: var(--kb-ink); font-weight: 800; }
.kb-readout-text--idle { color: var(--chart-muted); }
.kb-sound { color: var(--chart-sound); font-weight: 800; }
.public-site .chart-page .kb-fix {
    margin-inline-start: 0.25rem;
    padding: 0.2rem 0.7rem;
    border: 1.5px solid var(--chart-toggle);
    border-radius: 999px;
    background: #fff;
    color: var(--kb-ink);
    font-size: 0.82rem;
    font-weight: 800;
    cursor: pointer;
}


/* Vowel marks: a quiet strip of flat chips between the paper and the keyboard, grouped by the sound each mark makes. */
.kb-vowels { display: flex; align-items: center; justify-content: space-between; gap: 0.4rem; min-height: var(--kb-strip); padding-inline: 0.35rem; direction: ltr; }
.kb-vgroup { display: flex; align-items: center; gap: 0.25rem; }
.kb-vlabel { min-width: 0.7rem; margin-right: 0.1rem; color: var(--chart-muted); font-size: 0.72rem; font-weight: 700; line-height: 1; text-align: center; }
.public-site .chart-page .kb-chip {
    display: grid;
    place-items: center;
    width: 2.3rem;
    height: var(--kb-strip);
    padding: 0;
    border: 1px solid #e4e0d6;
    border-radius: 0.5rem;
    background: #f8f6f0;
    color: var(--kb-ink);
    cursor: pointer;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}
.public-site .chart-page .kb-chip:hover { filter: none !important; }
.public-site .chart-page .kb-chip:active { transform: none !important; background: #ebe8df; filter: none !important; }
.kb-mark { font-family: Rubik, sans-serif; font-size: 1.4rem; line-height: 1.45; }
.kb-chip .kb-mark { margin-top: -0.2rem; }
/* On a chip, the letter is only there to carry the mark, so it stays pale and the mark is dark. */
.kb-chip .kb-mark .alpha-nikkud-stack__base { color: #b4b1a7; }
.kb-chip .kb-mark .alpha-nikkud-stack__marks { color: #20261f; }

/* The desktop keyboard: an aluminium body with matte white keys, seen from straight above.
   It follows a US-ANSI board with Israeli keycaps: Latin letter top left, Hebrew letter bottom right.
   Every row is 15 key units wide, so the keys line up as they do on the real thing. */
.kp-board { display: none; }
.kd-board {
    display: flex;
    flex-direction: column;
    gap: 5px;
    padding: 10px 5px 10px 10px;
    border: 1px solid #bcbab4;
    border-radius: 0.8rem;
    background: linear-gradient(#dddbd6, #d4d2cd);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.55), 0 1px 0 #aaa8a2, 0 18px 26px -22px rgba(40, 40, 35, 0.6);
    container-type: inline-size;
}
.kd-row { display: flex; }
.public-site .chart-page .kd-key {
    position: relative;
    flex: none;
    width: calc(var(--w, 1) * 100cqw / 15 - 5px);
    height: 2.75rem;
    margin: 0 5px 0 0;
    padding: 0;
    border: 0;
    border-radius: 0.4rem;
    background: linear-gradient(#f6f6f3, #fbfbf9 70%);
    box-shadow: 0 0 0 1px rgba(40, 40, 36, 0.24), 0 1.5px 2px rgba(40, 40, 36, 0.3);
    color: var(--kb-legend);
    font-family: Rubik, sans-serif;
    font-weight: 400;
    opacity: 1;
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}
.kd-tl, .kd-bl, .kd-br, .kd-label { position: absolute; line-height: 1; pointer-events: none; }
.kd-tl { top: 0.36rem; left: 0.45rem; font-size: 0.74rem; }
.kd-bl { bottom: 0.36rem; left: 0.45rem; font-size: 0.74rem; }
.kd-br { right: 0.45rem; bottom: 0.32rem; font-size: 1.15rem; }
.kd-label { bottom: 0.4rem; left: 0.5rem; font-size: 0.62rem; letter-spacing: 0.01em; }
.is-right > .kd-label { right: 0.5rem; left: auto; }
.is-center > .kd-label { inset: 0; display: grid; place-items: center; font-size: 0.7rem; }
/* Keys that do nothing here keep their place on the board, with a fainter legend. */
.public-site .chart-page .kd-key--inert { color: #a9aaa7; cursor: default; }
.public-site .chart-page .kd-key:disabled { color: #a9aaa7; cursor: default; }
.public-site .chart-page .kd-key.is-shifted .kd-tl { color: #111; font-weight: 500; }

/* A key changes only when it is pressed: it sinks one pixel and darkens a little.
   (!important beats the site's own press and hover rules for every button, in shell.css.) */
.public-site .chart-page :is(.kd-key, .kp-key):hover { filter: none !important; }
.public-site .chart-page .kd-key:is(:active, [data-down], .is-latched):not(:disabled) {
    transform: translateY(1px) !important;
    background: #eceae6;
    box-shadow: 0 0 0 1px rgba(40, 40, 36, 0.3), 0 0.5px 1px rgba(40, 40, 36, 0.2);
    filter: none !important;
}

/* In the practice, the next key is lit from behind. */
.public-site .chart-page .kd-key.is-next {
    background: #fff8ea;
    color: #1f2021;
    box-shadow: 0 0 0 1px rgba(var(--kb-glow), 0.9), 0 0 0 3px rgba(var(--kb-glow), 0.35);
}
.kd-key.is-next::after, .kp-key.is-next::after {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: inherit;
    box-shadow: 0 0 12px 3px rgba(var(--kb-glow), 0.55);
    pointer-events: none;
    animation: kb-glow 1.2s ease-in-out infinite alternate;
}
@keyframes kb-glow { from { opacity: 0.25; } to { opacity: 1; } }

/* The phone keyboard looks like a phone's own Hebrew keyboard: flat keys, three rows of letters, one row below. */
.kp-board { flex-direction: column; gap: 0.6rem; padding: 0.5rem 0.2rem 0.45rem; border-radius: 0.6rem; background: #d5d4d0; }
.kp-row { display: flex; justify-content: center; gap: 0.36rem; }
.public-site .chart-page .kp-key {
    position: relative;
    display: grid;
    flex: 1 1 0;
    min-width: 0;
    height: 2.7rem;
    place-items: center;
    padding: 0;
    border: 0;
    border-radius: 0.32rem;
    background: #fff;
    box-shadow: 0 1px 0 #8d8c88;
    color: #1d1d1f;
    font-family: Rubik, sans-serif;
    font-size: 1.4rem;
    font-weight: 400;
    line-height: 1;
    opacity: 1;
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}
.public-site .chart-page .kp-key--fn { flex-grow: 1.5; background: #b4b3ae; }
.public-site .chart-page .kp-key--space { flex-grow: 5; }
.kp-small { font-family: var(--font-sans, sans-serif); font-size: 0.85rem; font-weight: 500; }
.public-site .chart-page .kp-key:disabled { color: #8a8985; cursor: default; }
.public-site .chart-page .kp-key:is(:active, [data-down]):not(:disabled) { transform: none !important; background: #e3e2de; filter: none !important; }
.public-site .chart-page .kp-key--fn:is(:active, [data-down]):not(:disabled) { background: #fff; }
.public-site .chart-page .kp-key.is-next { background: #fff6e0; box-shadow: 0 1px 0 #8d8c88, 0 0 0 2.5px rgba(var(--kb-glow), 0.85); }

.public-site .chart-page :is(.kd-key, .kp-key, .kb-chip, .kb-action, .kb-seg-option, .kb-fix, .kb-tab):focus { outline: none; }
.public-site .chart-page :is(.kd-key, .kp-key, .kb-chip, .kb-action, .kb-seg-option, .kb-fix, .kb-tab):focus-visible { outline: 2px solid var(--chart-sound); outline-offset: 2px; }

/* Setting up Hebrew on the visitor's own phone or computer */
.kb-section { display: flex; flex-direction: column; gap: 0.875rem; margin-block: 3.5rem 3rem; }
.public-site .chart-page .kb-section h2 { text-align: start; font-size: clamp(1.6rem, 3.6vw, 2.1rem); }
.kb-intro { margin: 0; color: #4b5563; font-size: clamp(1.0625rem, 1.5vw, 1.125rem); line-height: 1.6; }
.kb-devices { display: flex; flex-direction: column; gap: 1.1rem; padding: clamp(0.9rem, 3vw, 1.5rem); border: 1px solid #e8e4da; border-radius: 1.25rem; background: #fffdf9; }
.kb-tabs { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 3px; padding: 3px; border-radius: 999px; background: #f1efe9; }
.public-site .chart-page .kb-tab {
    min-height: 2.75rem;
    padding: 0 0.5rem;
    border: 0;
    border-radius: 999px;
    background: transparent;
    color: var(--chart-muted);
    font-size: 0.85rem;
    font-weight: 800;
    white-space: nowrap;
    cursor: pointer;
}
.public-site .chart-page .kb-tab[aria-selected="true"] { background: var(--chart-toggle); color: #fff; box-shadow: 0 2px 0 #000; }
.kb-steps { display: flex; flex-direction: column; gap: 0.7rem; margin: 0; padding: 0; list-style: none; counter-reset: kb-step; }
.kb-steps li {
    display: grid;
    grid-template-columns: 2.1rem minmax(0, 1fr);
    align-items: start;
    gap: 0.8rem;
    color: #4b5563;
    font-size: clamp(1rem, 1.5vw, 1.0625rem);
    line-height: 1.55;
    counter-increment: kb-step;
}
/* Each step number sits on a small keycap. */
.kb-steps li::before {
    content: counter(kb-step);
    display: grid;
    place-items: center;
    height: 1.9rem;
    margin-top: -0.1rem;
    border-radius: 0.5rem;
    background: #fafaf8;
    box-shadow: 0 0 0 1px rgba(40, 40, 36, 0.22), 0 1.5px 2px rgba(40, 40, 36, 0.26);
    color: var(--kb-ink);
    font-size: 0.9rem;
    font-family: Rubik, sans-serif;
    font-weight: 400;
}

/* Server-rendered copy: the same paper and keyboard, then the lesson as text. The script replaces it. */
.public-site .chart-page .kb-static :is(.kd-key, .kp-key, .kb-chip) { cursor: default; }
.kb-static-text { display: flex; flex-direction: column; gap: 2rem; margin-block: 3rem; color: #4b5563; }
.kb-static-text section { display: flex; flex-direction: column; gap: 0.75rem; }
.public-site .chart-page .kb-static-text h2 { text-align: start; font-size: clamp(1.6rem, 3.6vw, 2.1rem); }
.kb-static-text :is(p, ul, ol, h3) { margin: 0; }
.kb-static-text h3 { color: var(--kb-ink); font-family: Cause, sans-serif; font-size: 1.25rem; font-weight: 600; }
.kb-static-layout { width: 100%; border-collapse: collapse; }
.kb-static-layout th, .kb-static-layout td { padding: 0.4rem 0.6rem; border-bottom: 1px solid #e8e4da; text-align: start; }
.kb-static-text [lang="he"] { font-family: Rubik, sans-serif; font-size: 1.4rem; }


/* Narrower than a real keyboard: the phone keyboard takes its place. */
@media (max-width: 699px) {
    .kd-board { display: none; }
    .kp-board { display: flex; }
    .kb-page { --kb-chip: min(2.4rem, calc((100vw - 40px - 6.6rem) / 7)); --kb-strip: 4.9rem; }
    /* The marks sit in two rows of seven. */
    .kb-vowels { flex-wrap: wrap; justify-content: flex-start; gap: 0.3rem 0.4rem; padding-inline: 0; }
    .kb-vowels::before { content: ""; flex-basis: 100%; order: 1; }
    .kb-vgroup { gap: 0.2rem; }
    .kb-vgroup--break, .kb-vgroup--break ~ .kb-vgroup { order: 2; }
    .public-site .chart-page .kb-chip { width: var(--kb-chip); height: 2.3rem; }
    .kb-vlabel { min-width: 0.55rem; margin-right: 0; font-size: 0.68rem; }
}
@media (max-width: 480px) {
    .pub-main:has([data-public-tool="keyboard"]) > .pub-page-header--chart { margin-block: 0.5rem 0.8rem; }
    .kb-stage { gap: 0.35rem; }
    .kb-paper-bar { gap: 0.3rem; }
    .kb-actions { gap: 0.3rem; }
    .public-site .chart-page .kb-seg-option { min-height: 2.5rem; padding: 0 0.7rem; }
    .public-site .chart-page .kb-action { min-height: 2.5rem; padding: 0 0.75rem; }
    .kb-paper { padding: 0.4rem 0.4rem 0.25rem; }
    .kb-text { height: 5.9rem; }
    .kb-practice { height: calc(5.9rem + var(--kb-strip) + 0.35rem); }
    .public-site .chart-page .kb-text, .kb-word { font-size: 2.15rem; }
    .public-site .chart-page .kb-text.is-medium { font-size: 1.6rem; }
    .public-site .chart-page .kb-text.is-small { font-size: 1.25rem; }
    .kb-text::placeholder { font-size: 0.95rem; line-height: 2.9; }
    .kb-practice-line { font-size: 0.9rem; line-height: 1.35; }
    .kb-readout { height: 3.5rem; padding-inline: 0.15rem; }
    .kb-readout-glyph { width: 2.6rem; height: 2.4rem; font-size: 1.4rem; }
    .kb-readout-text { font-size: 0.82rem; line-height: 1.3; }
    /* The keyboard runs from one edge of the screen to the other, as a phone's own keyboard does. */
    .kp-board { margin-inline: -20px; border-radius: 0; }
    .kb-tabs { grid-template-columns: repeat(2, minmax(0, 1fr)); border-radius: 1.5rem; }
}

@media (prefers-reduced-motion: reduce) {
    .kb-seg-thumb { transition: none; }
    .public-site .chart-page .kd-key:is(:active, [data-down], .is-latched):not(:disabled) { transform: none !important; }
    .kd-key.is-next::after, .kp-key.is-next::after { animation: none; }
}

/* The switch says its state in words, so nobody has to read the track's colour. */

/* Under the banner: the setup steps, the layout as text and the list of keys. */
.kb-below .kb-section { margin-block: 2.5rem 2rem; }
.kb-below .kb-static-text { margin-block: 2rem; }
.kb-keys-text { margin-block: 2rem 3rem; }
.kb-keys-text table { width: 100%; border-collapse: collapse; }
.kb-keys-text :is(th, td) { padding: 0.4rem 0.6rem; border-bottom: 1px solid #e8e4da; text-align: start; }
.kb-keys-text [lang="he"] { font-family: Rubik, sans-serif; font-size: 1.4rem; }
