.monkey-dictionary {
    position: fixed;
    right: max(22px, env(safe-area-inset-right));
    bottom: max(22px, env(safe-area-inset-bottom));
    z-index: 900;
    color: #2d4036;
    font-size: 14px;
}
.monkey-dictionary [hidden] { display: none !important; }
.monkey-dictionary button { font: inherit; cursor: pointer; touch-action: manipulation; min-height: 44px; }
.monkey-dictionary-toggle {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    width: 78px; height: 78px; margin-left: auto;
    border: 3px solid #fffefa; border-radius: 50%;
    background: #fff0c9; color: #694820;
    box-shadow: 0 6px 24px #553b2429;
    font-size: 11px !important; font-weight: 700 !important;
    transition: transform .18s, background .18s;
}
.monkey-dictionary-toggle:hover { transform: translateY(-3px); background: #ffe7ac; }
.monkey-dictionary-face { display: block; width: 44px; height: 44px; flex-shrink: 0; }
.monkey-mouth-open { display: none; }
.monkey-dictionary-toggle[aria-expanded="true"] .monkey-mouth-closed { display: none; }
.monkey-dictionary-toggle[aria-expanded="true"] .monkey-mouth-open { display: inline; }
.monkey-dictionary-panel {
    position: absolute; right: 0; bottom: 92px;
    width: min(350px, calc(100vw - 32px));
    max-height: calc(100vh - 130px);
    max-height: calc(100dvh - 130px); overflow-y: auto; overscroll-behavior: contain;
    padding: 22px; box-sizing: border-box;
    background: #fffefa; border: 1px solid #e1e7d8; border-radius: 22px;
    box-shadow: 0 12px 48px #2d40362b;
}
.monkey-dictionary-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; margin-bottom: 18px; }
.monkey-dictionary-heading h2 { margin: 0; font-size: 20px; color: #326747; }
.monkey-dictionary-heading p { margin: 4px 0 0; font-size: 12px; color: #717d72; }
.monkey-dictionary-close { flex-shrink: 0; width: 44px; height: 44px; border: 0; border-radius: 50%; background: #f0f3e9; color: #617061; font-size: 24px !important; line-height: 1; }
.monkey-dictionary label { display: block; margin-bottom: 8px; font-weight: 600; font-size: 13px; }
.monkey-dictionary-label-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 4px; }
.monkey-dictionary-label-row label { margin-bottom: 0; }
.monkey-dictionary-clear { flex-shrink: 0; padding: 8px 10px; border: 0; border-radius: 8px; background: #f0f3e9; color: #326747; font-size: 13px !important; }
.monkey-dictionary-search { display: flex; gap: 8px; }
.monkey-dictionary-search input { flex: 1; min-width: 0; width: 0; padding: 11px 12px; border: 1px solid #cbd7c4; border-radius: 10px; background: white; color: #2d4036; font: inherit; font-size: 16px; }
.monkey-dictionary-search button { flex-shrink: 0; padding: 10px 16px; border: 0; border-radius: 10px; background: #32755d; color: white; font-weight: 600; }
.monkey-dictionary-status { margin: 12px 0; color: #667168; font-size: 13px; line-height: 1.6; }
.monkey-dictionary-status[data-error="true"] { color: #ac433d; }
.monkey-dictionary-result { padding: 16px; border-radius: 14px; background: #f0f5e9; overflow-wrap: anywhere; }
.monkey-dictionary-result h3 { margin: 0 0 6px; font-size: 23px; color: #326747; }
#monkey-dictionary-meaning { margin: 0; line-height: 1.8; white-space: pre-line; }
.monkey-dictionary-voices { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }
.monkey-dictionary-voices button { padding: 9px 10px; min-height: 44px; background: #fffefa; color: #326747; border: 1px solid #d3dfc9; border-radius: 9px; font-size: 13px; }
.monkey-dictionary-source { margin: 10px 0 0; color: #717d72; font-size: 11px; }
.monkey-dictionary-note { margin: 14px 0 0; color: #717d72; font-size: 11px; line-height: 1.6; }
@media (max-width: 600px) {
    .monkey-dictionary { right: max(16px, env(safe-area-inset-right)); bottom: max(16px, env(safe-area-inset-bottom)); }
    .monkey-dictionary-toggle { width: 66px; height: 66px; }
    .monkey-dictionary-face { width: 36px; height: 36px; }
    .monkey-dictionary-panel { padding: 18px; }
    .monkey-dictionary-voices button { flex: 1; }
}
/* Keep the form inside the visible screen, including when a phone keyboard opens.
   A scrollable top-aligned panel also works on short landscape screens. */
@media (max-width: 600px), (max-height: 500px) {
    .monkey-dictionary-panel {
        position: fixed;
        right: max(16px, env(safe-area-inset-right));
        top: calc(var(--dictionary-visible-top, 0px) + 12px + env(safe-area-inset-top));
        bottom: auto;
        max-height: calc(100vh - 24px);
        max-height: calc(var(--dictionary-visible-height, 100dvh) - 24px - env(safe-area-inset-top));
        -webkit-overflow-scrolling: touch;
    }
}
@media (hover: none) {
    .monkey-dictionary-toggle:hover { transform: none; }
}
@media (prefers-reduced-motion: reduce) { .monkey-dictionary-toggle { transition: none; } }
@media print { .monkey-dictionary { display: none !important; } }

/* Tablets can remain wide while the Android keyboard is open. */
.monkey-dictionary.dictionary-editing .monkey-dictionary-panel {
    position: fixed;
    right: max(16px, env(safe-area-inset-right));
    top: calc(var(--dictionary-visible-top, 0px) + 8px);
    bottom: auto;
    max-height: calc(var(--dictionary-visible-height, 100dvh) - 16px);
}
.monkey-dictionary.dictionary-editing .monkey-dictionary-heading { margin-bottom: 6px; }
.monkey-dictionary.dictionary-editing .monkey-dictionary-heading p { display: none; }
