/* Hangul keyboard: the home-page letter grid doubles as a keyboard */

.hangul-char {
    background: none;
    border: none;
    padding: 0;
    font-family: inherit;
    cursor: pointer;
    border-radius: var(--border-radius-sm);
}

.hangul-char:focus-visible {
    outline: 2px solid var(--link-color);
    outline-offset: 6px;
}

.hangul-char.pressed {
    animation: hk-press 0.35s ease-out;
}

@keyframes hk-press {
    0% { transform: scale(1); }
    40% { transform: scale(1.35); color: var(--text-color); }
    100% { transform: scale(1); }
}

.hangul-keyboard-hint {
    text-align: center;
    margin-top: 14px;
    opacity: 0.75;
    font-size: 0.95rem;
}

/* Floating pane (non-modal so the grid stays clickable) */
.hk-pane {
    position: fixed;
    left: 50%;
    bottom: 24px;
    transform: translateX(-50%);
    width: min(560px, calc(100% - 32px));
    max-height: 60vh;
    overflow-y: auto;
    z-index: 900;
    padding: 16px 18px;
    background: var(--card-bg);
    color: var(--text-color);
    border: 1px solid var(--glass-border);
    border-radius: var(--border-radius-lg);
    box-shadow: var(--glass-shadow);
    backdrop-filter: blur(var(--glass-blur));
    -webkit-backdrop-filter: blur(var(--glass-blur));
    animation: hk-slide-up 0.25s ease-out;
}

.hk-pane[hidden] {
    display: none;
}

@keyframes hk-slide-up {
    from { opacity: 0; transform: translate(-50%, 20px); }
    to { opacity: 1; transform: translate(-50%, 0); }
}

/* Leave room so the pane never hides the last row of the grid */
body.hk-open .page-wrapper {
    padding-bottom: 260px;
}

.hk-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: -6px -8px 8px;
    padding: 6px 8px;
    border-radius: var(--border-radius-md);
    cursor: grab;
    touch-action: none; /* let a finger drag the pane instead of scrolling the page */
    user-select: none;
    -webkit-user-select: none;
}

.hk-header:hover {
    background: rgba(127, 127, 127, 0.08);
}

.hk-header:focus-visible {
    outline: 2px solid var(--link-color);
}

.hk-grip {
    opacity: 0.5;
    font-size: 1.1rem;
}

.hk-header .hk-icon-btn {
    margin-left: auto;
}

/* Once dragged, the pane is placed by left/top instead of being centred at the bottom */
.hk-pane.hk-moved {
    transform: none;
    bottom: auto;
    animation: hk-fade-in 0.2s ease-out;
}

.hk-pane.hk-dragging {
    opacity: 0.9;
    animation: none;
}

.hk-pane.hk-dragging .hk-header {
    cursor: grabbing;
}

@keyframes hk-fade-in {
    from { opacity: 0; }
    to { opacity: 1; }
}

.hk-title {
    font-size: 1rem;
    font-weight: 600;
    margin: 0;
    opacity: 0.8;
}

.hk-icon-btn {
    background: none;
    color: var(--text-color);
    font-size: 1.1rem;
    width: 32px;
    height: 32px;
    border-radius: 50%;
}

.hk-icon-btn:hover {
    background: rgba(127, 127, 127, 0.15);
}

.hk-body {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* Typed text */
.hk-output {
    min-height: 56px;
    padding: 8px 12px;
    font-family: 'Noto Sans KR', sans-serif;
    font-size: 2rem;
    line-height: 1.4;
    word-break: break-all;
    border-radius: var(--border-radius-md);
    background: rgba(127, 127, 127, 0.08);
}

.hk-placeholder {
    font-size: 1rem;
    opacity: 0.55;
}

.hk-current {
    color: var(--link-color);
    border-bottom: 3px solid var(--link-color);
    animation: hk-blink 1s steps(2) infinite;
}

@keyframes hk-blink {
    50% { border-bottom-color: transparent; }
}

/* Current syllable: block diagram + explanation */
.hk-builder {
    display: flex;
    align-items: center;
    gap: 16px;
}

.hk-block {
    flex: 0 0 auto;
    width: 96px;
    height: 96px;
    display: grid;
    gap: 3px;
    padding: 4px;
    border: 2px dashed var(--glass-border);
    border-radius: var(--border-radius-md);
    font-family: 'Noto Sans KR', sans-serif;
}

.hk-block[hidden] {
    display: none;
}

/* Tall vowels sit to the right, wide vowels below, finals at the bottom */
.hk-block.layout-right { grid-template: "cho jung" 1fr / 1fr 1fr; }
.hk-block.layout-right.has-final { grid-template: "cho jung" 1fr "jong jong" 1fr / 1fr 1fr; }
.hk-block.layout-below { grid-template: "cho" 1fr "jung" 1fr / 1fr; }
.hk-block.layout-below.has-final { grid-template: "cho" 1fr "jung" 1fr "jong" 1fr / 1fr; }
.hk-block.layout-mixed { grid-template: "cho jung" 1fr ". jung" 1fr / 1fr 1fr; }
.hk-block.layout-mixed.has-final { grid-template: "cho jung" 1fr ". jung" 1fr "jong jong" 1fr / 1fr 1fr; }

.hk-slot {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
    font-weight: 700;
    border-radius: 6px;
    animation: hk-slot-in 0.3s ease-out;
}

.hk-slot-cho { grid-area: cho; background: rgba(33, 150, 243, 0.18); }
.hk-slot-jung { grid-area: jung; background: rgba(76, 175, 80, 0.2); }
.hk-slot-jong { grid-area: jong; background: rgba(255, 152, 0, 0.22); }

@keyframes hk-slot-in {
    from { opacity: 0; transform: scale(0.4); }
    to { opacity: 1; transform: scale(1); }
}

.hk-explain {
    flex: 1;
    min-width: 0;
}

.hk-formula {
    margin: 0 0 4px;
    font-size: 1rem;
}

.hk-formula strong {
    color: var(--link-color);
    font-size: 1.15rem;
}

.hk-note {
    margin: 0;
    font-size: 0.9rem;
    opacity: 0.8;
}

.hk-voice-warning {
    margin: 10px 0 0;
    font-size: 0.85rem;
    opacity: 0.7;
}

/* Reading speed slider, just above the buttons */
.hk-speed {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 12px;
    font-size: 0.9rem;
}

.hk-speed-label {
    white-space: nowrap;
}

.hk-rate {
    flex: 1;
    min-width: 0;
    accent-color: var(--link-color);
    cursor: pointer;
}

.hk-speed-value {
    min-width: 3.2em;
    text-align: right;
    font-variant-numeric: tabular-nums;
    font-weight: 600;
}

.hk-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 12px;
}

.hk-btn {
    flex: 1 1 auto;
    padding: 9px 12px;
    border-radius: 50px;
    background: rgba(127, 127, 127, 0.12);
    border: 1px solid var(--glass-border);
    color: var(--text-color);
    font-weight: 500;
    transition: background var(--transition-speed);
}

.hk-btn:hover {
    background: rgba(127, 127, 127, 0.22);
}

.hk-btn.hk-primary {
    background: var(--link-color);
    color: #fff;
    border-color: transparent;
}

.hk-btn:focus-visible,
.hk-icon-btn:focus-visible {
    outline: 2px solid var(--link-color);
    outline-offset: 2px;
}

/* Phones: the navbar is fixed to the bottom, so float above it */
@media (max-width: 767px) {
    .hk-pane {
        bottom: calc(var(--nav-height-mobile, 65px) + 10px);
        max-height: 55vh;
        padding: 12px 14px;
    }

    .hk-output {
        font-size: 1.6rem;
    }

    .hk-block {
        width: 76px;
        height: 76px;
    }

    .hk-btn {
        padding: 8px 10px;
        font-size: 0.9rem;
    }
}

@media (prefers-reduced-motion: reduce) {
    .hangul-char,
    .hangul-char.pressed,
    .hk-pane,
    .hk-slot,
    .hk-current {
        animation: none !important;
    }
}
