/* Modernized virtual keyboard for touch and desktop
   - larger touch targets on mobile
   - subtle rounded keys and shadows for a polished look
*/
#virtual-keyboard {
    width: 100%;
    max-width: 720px;
    margin: 20px auto;
    padding: 12px;
    box-sizing: border-box;
}

.keyboard-row {
    display: flex;
    justify-content: center;
    gap: 8px;
    margin-bottom: 8px;
    width: 100%;
    box-sizing: border-box;
}

.keyboard-row:nth-child(2) { padding: 0 18px; }
.keyboard-row:nth-child(3) { padding: 0 10px; }

.key-btn {
    /* legacy-inspired square keys */
    flex: 1 1 0;
    height: 40px;
    min-width: 36px;
    max-width: 56px;
    padding: 4px 8px;
    border: 2px solid #777;
    border-radius: 6px;
    background-color: #f1f1f1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 15px;
    font-weight: 700;
    color: #111;
    transition: transform 120ms ease, box-shadow 120ms ease, background-color 120ms ease, border-color 120ms ease;
    margin: 0;
    box-shadow: 0 2px 0 rgba(0,0,0,0.06), inset 0 -2px 0 rgba(255,255,255,0.6);

    position: relative;
    z-index: 2;
    touch-action: manipulation;
    -webkit-tap-highlight-color: rgba(0,0,0,0.06);
    -webkit-user-select: none;
    user-select: none;
}

.key-btn:hover { background-color: #efefef; border-color: #666; transform: translateY(-1px); }
.key-btn:active,
.key-btn.pressed {
    transform: translateY(0.5px);
    box-shadow: inset 0 3px 6px rgba(0,0,0,0.08);
    background-color: #e6e6e6;
    border-color: #555;
}

.enter-key {
    flex: 2 1 0;
    max-width: 110px;
    background-color: #f1f1f1;
    color: #111;
    border-color: #777;
    font-weight: 700;
}

.backspace-key { flex: 1.4 1 0; max-width: 96px; }

.enter-key:hover { background-color: #efefef; border-color: #666; }

@media (max-width: 800px) {
    /* For smaller screens and touch devices increase hit targets */
    .key-btn { height: 56px; min-width: 46px; max-width: 76px; font-size: 18px; padding: 8px; }
    .enter-key { max-width: 140px; }
    .backspace-key { max-width: 110px; }
}

@media (pointer: coarse) {
    /* Larger target sizes for touch devices specifically */
    .key-btn { height: 64px; min-width: 52px; font-size: 20px; padding: 10px; border-radius: 12px; }
    .keyboard-row { gap: 10px; }
}

.revealed-key { background-color: #ffc107; color: #212529; transform: scale(1.02); box-shadow: 0 2px 6px rgba(0,0,0,0.12); transition: background-color 0.25s, transform 0.12s, box-shadow 0.12s; }
.revealed-word {
    text-align: center;
    margin-top: 10px;
    font-weight: 800;
    font-size: 18px;
    color: #0f172a;
    pointer-events: none; /* don't block taps to keys */
    position: relative;
    z-index: 1;
}

/* Make the visible word input visually match the revealed word box so both
   can be seen stacked (input above, reveal below). */
#word-input {
    text-align: center;
    font-weight: 800;
    font-size: 18px;
    color: #0f172a;
    background: transparent; /* let container background show */
    border: none; /* match revealed text (no input border) */
    outline: none;
    width: 100%;
    max-width: 420px;
    margin: 0 auto;
}

/* Accessibility: visible focus ring for keyboard keys */
.key-btn:focus { outline: 3px solid rgba(2,132,199,0.18); outline-offset: 3px; }

/*
  Ensure the in-app virtual keyboard is always accessible on shorter viewports
  and on touch devices. When the viewport is small or the device uses a coarse
  pointer (touch), pin the keyboard to the bottom of the viewport, respect
  the safe-area insets (iOS notch/home indicator), and allow the keyboard to
  scroll internally if it would otherwise overflow the visible area.
*/
@media (max-width: 900px), (pointer: coarse) {
    #virtual-keyboard {
        position: fixed;
        left: 0;
        right: 0;
        bottom: env(safe-area-inset-bottom, 0);
        margin: 0 auto;
        width: 100%;
        max-width: 720px;
        padding: 10px 6px;
        box-sizing: border-box;
        z-index: 1200; /* above most page chrome */
        background: linear-gradient(180deg, rgba(255,255,255,0.98), rgba(255,255,255,0.95));
        box-shadow: 0 -8px 24px rgba(2,6,23,0.12);
        /* limit height so keyboard never exceeds viewport - leave room for content */
        max-height: calc(50vh - env(safe-area-inset-bottom, 0));
        overflow-y: auto;
    /* legacy iOS momentum scrolling not required; removed to satisfy lint rules */
        border-top-left-radius: 14px;
        border-top-right-radius: 14px;
    }

    /* reduce key sizes a bit when pinned so the keyboard fits better */
    .key-btn {
        height: clamp(44px, 6.5vh, 60px);
        min-width: 0; /* must be 0 so flex shrink can bring keys within viewport width */
        max-width: 76px;
        font-size: clamp(13px, 3.8vw, 16px);
        padding: 6px 4px;
    }

    /* ensure rows center and don't overflow horizontally; override the coarse-pointer gap */
    .keyboard-row {
        justify-content: center;
        gap: clamp(4px, 1.2vw, 8px);
    }
}
