* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: "Segoe UI", Arial, sans-serif;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    background:
        radial-gradient(circle at 0% 0%, rgba(56, 189, 248, 0.12), transparent 35%),
        radial-gradient(circle at 100% 0%, rgba(59, 130, 246, 0.14), transparent 35%),
        linear-gradient(180deg, #f5f9ff 0%, #eef3fb 100%);
    color: #1f2937;
    padding: 24px 16px 8px;
}

.app {
    width: 100%;
    max-width: 860px;
    margin: 0 auto;
    background: rgba(255, 255, 255, 0.95);
    border: 1px solid #dfe8f5;
    border-radius: 16px;
    box-shadow: 0 18px 40px rgba(18, 54, 99, 0.12);
    padding: 24px;
    backdrop-filter: blur(6px);
    touch-action: manipulation;
}

.title-row {
    display: flex;
    align-items: center;
    gap: 14px;
    margin: 0 0 20px;
}

.project-logo {
    width: 48px;
    height: 48px;
    border-radius: 0;
    box-shadow: none;
    flex-shrink: 0;
    mix-blend-mode: multiply;
}

h1 {
    margin: 0;
    font-size: 34px;
    line-height: 1.2;
    color: #5d78a2;
    font-weight: 700;
}

.form-row {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
}

.field {
    flex: 1 1 260px;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.voice-instruction-label {
    margin-top: 6px;
    font-size: 0.92rem;
    font-weight: 700;
    color: #4b5563;
}

.voice-instruction-input {
    min-height: 52px;
    resize: vertical;
    line-height: 1.45;
}

.ai-settings-block {
    margin: 0 0 16px;
    border: 1px solid #dfe8f5;
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.75);
    padding: 0 4px 4px;
}

.ai-settings-summary {
    list-style: none;
    cursor: pointer;
    padding: 10px 4px 8px;
    font-weight: 700;
    font-size: 1.05rem;
    color: #4b5563;
    user-select: none;
    -webkit-user-select: none;
}

.ai-settings-summary::-webkit-details-marker {
    display: none;
}

.ai-settings-summary-text {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.ai-settings-gear-icon {
    flex-shrink: 0;
    display: block;
    color: #5d78a2;
    /* margin-top: 2px; */
}

.ai-settings-block[open] .ai-settings-gear-icon {
    color: #3d5a80;
}

.ai-settings-body {
    display: flex;
    flex-direction: column;
    gap: 14px;
    padding: 10px 8px;
}

.ai-settings-body .field {
    flex: none;
    width: 100%;
}

.api-key-form {
    margin: 0;
    padding: 0;
    border: none;
    min-width: 0;
}

.api-key-input-row {
    display: flex;
    flex-wrap: wrap;
    align-items: stretch;
    gap: 10px;
}

.api-key-input {
    flex: 1 1 200px;
    min-width: 0;
    border: 1px solid #cfd8e3;
    border-radius: 10px;
    padding: 10px 12px;
    font-size: 15px;
    background: #fff;
    color: #243447;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.api-key-input:focus {
    outline: none;
    border-color: #4a90ff;
    box-shadow: 0 0 0 3px rgba(74, 144, 255, 0.16);
}

.api-key-clear-btn {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 34px;
    min-height: 34px;
    padding: 10px;
    margin-top: 2px;
    margin-bottom: 2px;
    border-radius: 8px;
    border: 1px solid #f87171;
    background: #fef2f2;
    color: #dc2626;
    cursor: pointer;
    touch-action: manipulation;
    box-sizing: border-box;
}

.api-key-clear-btn:hover {
    background: #fee2e2;
    border-color: #ef4444;
    color: #b91c1c;
}

.api-key-clear-btn:focus-visible {
    outline: 2px solid #dc2626;
    outline-offset: 2px;
}

.api-key-clear-svg {
    display: block;
}

.language-field-above-prompt {
    margin: 0 0 8px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.language-field-above-prompt .field-label-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

label {
    font-weight: 700;
    color: #4b5563;
}

select,
textarea {
    border: 1px solid #cfd8e3;
    border-radius: 10px;
    padding: 10px 12px;
    font-size: 15px;
    background: #fff;
    color: #243447;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

select {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

select:focus,
textarea:focus {
    outline: none;
    border-color: #4a90ff;
    box-shadow: 0 0 0 3px rgba(74, 144, 255, 0.16);
}

.prompt-section {
    margin-top: 20px;
}

.prompt-section > label {
    display: block;
    margin-bottom: 8px;
}

.prompt-section .prompt-section-label-row {
    margin-bottom: 8px;
}

.prompt-actions .task-voice-btn {
    flex-shrink: 0;
    width: 48px;
    height: 48px;
    min-width: 48px;
    min-height: 48px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    line-height: 1;
    border-radius: 50%;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.prompt-actions .task-voice-btn.recording {
    border-color: #e74c3c;
    background: #fdecea;
    box-shadow: 0 0 0 2px rgba(231, 76, 60, 0.25);
}

textarea {
    width: 100%;
    min-height: 140px;
    resize: vertical;
    font-family: inherit;
}

.prompt-actions {
    margin-top: 10px;
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.result-separator {
    margin: 30px 0 30px;
    height: 1px;
    background: linear-gradient(90deg, rgba(148, 163, 184, 0), rgba(148, 163, 184, 0.55), rgba(148, 163, 184, 0));
}

button {
    border: 1px solid #cfd8e3;
    border-radius: 10px;
    padding: 10px 14px;
    font-size: 15px;
    background: #ffffff;
    color: #243447;
    cursor: pointer;
    transition: all 0.2s ease;
}

button:hover {
    background: #f3f6fa;
    transform: translateY(-1px);
}

button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

#generateTextButton {
    background: linear-gradient(180deg, #3183ff 0%, #1f6feb 100%);
    border-color: #2366d1;
    color: white;
}

#generateTextButton:hover:not(:disabled) {
    background: linear-gradient(180deg, #2876ec 0%, #1a5ec8 100%);
}

#questionButton {
    background: linear-gradient(180deg, #22c55e 0%, #16a34a 100%);
    border-color: #15803d;
    color: #ffffff;
    font-weight: 600;
}

#questionButton:hover:not(:disabled) {
    background: linear-gradient(180deg, #16a34a 0%, #15803d 100%);
}

.clear-task-btn {
    box-sizing: border-box;
    width: 40px;
    height: 40px;
    min-width: 40px;
    min-height: 40px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 0;
    font-size: 0;
    direction: ltr;
    border-radius: 50%;
    color: #475569;
}

.clear-task-btn .clear-task-svg {
    display: block;
    width: 18px;
    height: 18px;
    flex: 0 0 auto;
}

.clear-task-btn:hover:not(:disabled) {
    color: #1e293b;
    background: #f1f5f9;
}

.main-result-tabs .tab-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 52px;
    padding: 10px 12px;
}

.main-result-tabs .tab-icon-svg {
    display: block;
    vertical-align: middle;
}

.tutor-answer-host {
    margin-top: 8px;
    border: 1px solid #dbe3ee;
    border-radius: 12px;
    padding: 16px 18px 20px;
    background: #ffffff;
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.06);
}

.tutor-answer-host .word-insight-content {
    flex: none;
    min-height: 0;
    max-height: none;
    overflow-x: auto;
    overflow-y: visible;
}

.generated-text {
    margin-top: 14px;
    border: 1px solid #dbe3ee;
    border-radius: 10px;
    padding: 12px;
    background: #fbfdff;
    color: #1f2937;
    min-height: 56px;
    white-space: pre-wrap;
    line-height: 1.45;
}

.generated-text.is-hidden {
    display: none;
}

.generated-text.is-loading {
    background: #f8fbff;
    color: #4b5563;
    min-height: unset;
    padding: 12px 8px 13px;
    white-space: normal;
}

.gen-loading-wrap {
    display: flex;
    flex-direction: column;
    gap: 0;
    margin: 0;
    padding: 0;
}

.gen-loading-top {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0;
    padding: 0;
    min-height: 0;
}

.gen-loading-spinner {
    flex-shrink: 0;
    width: 24px;
    height: 24px;
    border: 2px solid rgba(49, 131, 255, 0.22);
    border-top-color: #3183ff;
    border-radius: 50%;
    animation: gen-loading-spin 0.85s linear infinite;
}

@keyframes gen-loading-spin {
    to { transform: rotate(360deg); }
}

.gen-loading-msg {
    display: block;
    margin: 0;
    padding: 0;
    flex: 1;
    min-width: 0;
    font-size: 14px;
    line-height: 1.2;
}

.gen-loading-bar {
    margin-top: 5px;
    height: 3px;
    background: #e2e8f0;
    border-radius: 3px;
    overflow: hidden;
}

.gen-loading-bar span {
    display: block;
    height: 100%;
    width: 38%;
    border-radius: 3px;
    background: linear-gradient(90deg, #3183ff, #60a5fa, #3183ff);
    background-size: 200% 100%;
    animation: gen-loading-bar-slide 1.15s ease-in-out infinite;
}

@keyframes gen-loading-bar-slide {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(280%); }
}

.generated-text.is-error {
    background: #fff6f6;
    border-color: #f2c7c7;
    color: #9f1d1d;
}

.generated-text.is-success {
    background: #f5fbf7;
    border-color: #c9e8d2;
    color: #1d5130;
}

.result-area {
    margin-top: 16px;
}

.exercise-tabs {
    display: flex;
    gap: 10px;
    margin-bottom: 16px;
    background: #f1f8ff;
    padding: 5px;
    border-radius: 10px;
    border: 1px solid #d4e7ff;
}

.tab-btn {
    flex: 1;
    border: none;
    background: transparent;
    border-radius: 7px;
    font-weight: 700;
    cursor: pointer;
    color: #617184;
    transition: 0.2s ease;
}

.tab-btn.active {
    background: #ffffff;
    color: #3498db;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.06);
}

.instructions-banner {
    background: #e8f4fd;
    border-left: 4px solid #3498db;
    padding: 8px 10px;
    border-radius: 4px 8px 8px 4px;
    margin-bottom: 12px;
    font-size: 13px;
    color: #2c3e50;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.instructions-banner p {
    margin: 0;
}

.sentences-container {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.sentence-card {
    background: white;
    border-radius: 12px;
    padding: 16px;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.03);
    border: 1px solid #ecf0f1;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s, border-color 0.2s;
    user-select: none;
    -webkit-user-select: none;
    touch-action: manipulation;
}

.sentence-card.last-active {
    border-color: #bdc3c7;
    box-shadow: 0 4px 10px rgba(189, 195, 199, 0.15);
    border-left: 6px solid #bdc3c7;
}

.sentence-card.playing {
    border-color: #3498db;
    box-shadow: 0 4px 15px rgba(52, 152, 219, 0.2);
    transform: scale(1.01);
    border-left: 6px solid #3498db;
}

.sentence-card.loading {
    border-color: #f39c12;
    border-left: 6px solid #f39c12;
    animation: pulse-loading 1.5s infinite;
}

.sentence-card.auto-playing {
    border-color: #2ecc71;
    box-shadow: 0 4px 15px rgba(46, 204, 113, 0.2);
    transform: scale(1.01);
    border-left: 6px solid #2ecc71;
}

@keyframes pulse-loading {
    0% { box-shadow: 0 0 0 0 rgba(243, 156, 18, 0.4); }
    70% { box-shadow: 0 0 0 10px rgba(243, 156, 18, 0); }
    100% { box-shadow: 0 0 0 0 rgba(243, 156, 18, 0); }
}

.text-cell {
    font-size: 18px;
    line-height: 1.5;
    padding: 8px;
    border-radius: 8px;
    transition: background-color 0.3s;
}

.text-cell.study {
    color: #2c3e50;
    font-weight: 500;
    margin-bottom: 8px;
}

.text-cell.translation {
    color: #7f8c8d;
    font-size: 16px;
    border-top: 1px dashed #ecf0f1;
}

.text-cell.hidden-text {
    color: transparent;
    text-shadow: 0 0 12px rgba(44, 62, 80, 0.5);
    background-color: #f8f9fa;
}

.text-cell.revealed-text {
    color: inherit;
    text-shadow: none;
    background-color: transparent;
}

#speakingPane {
    margin-top: 8px;
    position: relative;
}

.speaking-card-wrap {
    position: relative;
}

.speaking-flashcard {
    background: #f9f9f9;
    border: 2px solid #ecf0f1;
    border-radius: 12px;
    padding: 30px 20px;
    text-align: center;
    min-height: 340px;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    align-items: center;
    overflow-y: auto;
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    touch-action: manipulation;
}

/* Ожидание ответа TTS от ИИ — только рамка карточки, оранжевая пульсация */
.speaking-flashcard.tts-loading {
    border-color: #e67e22;
    animation: speaking-tts-wait-border 1.1s ease-in-out infinite;
}

@keyframes speaking-tts-wait-border {
    0%,
    100% {
        box-shadow: 0 0 0 0 rgba(230, 126, 34, 0.35);
    }
    50% {
        box-shadow: 0 0 0 4px rgba(230, 126, 34, 0.55), 0 0 18px 2px rgba(230, 126, 34, 0.3);
    }
}

@media (prefers-reduced-motion: reduce) {
    .speaking-flashcard.tts-loading {
        animation: none;
        box-shadow: 0 0 0 3px rgba(230, 126, 34, 0.55);
    }
}

.speaking-flashcard.loading {
    border-color: #f39c12;
}

.speaking-flashcard.playing {
    border-color: #3498db;
}

.speaking-flashcard .native-text {
    font-size: 20px;
    color: #7f8c8d;
    margin-bottom: 20px;
    pointer-events: none;
}

.speaking-flashcard .target-text {
    font-size: 24px;
    font-weight: bold;
    color: #2c3e50;
    pointer-events: none;
}

.speaking-flashcard .target-text:not(.hidden-text) {
    pointer-events: auto;
}

.speaking-flashcard .target-text.hidden-text {
    color: #bdc3c7;
    font-weight: normal;
    letter-spacing: 2px;
}

.chunk-indicator {
    font-size: 12px;
    color: #e67e22;
    font-weight: bold;
    text-transform: uppercase;
    margin-bottom: 10px;
    letter-spacing: 1px;
}

.stt-result-box {
    margin-top: 20px;
    padding: 15px;
    background: #ffffff;
    border: 1px dashed #bdc3c7;
    border-radius: 8px;
    width: 100%;
    font-size: 20px;
    color: #34495e;
}

.stt-result-box strong {
    color: #7f8c8d;
    font-size: 12px;
    text-transform: uppercase;
    display: block;
    margin-bottom: 5px;
}

.speaking-nav {
    margin-top: 18px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    align-items: center;
}

.speaking-progress-bar-container {
    width: 80%;
    height: 6px;
    background-color: #ecf0f1;
    border-radius: 4px;
    overflow: hidden;
}

.speaking-progress-bar {
    height: 100%;
    width: 0%;
    background-color: #3498db;
    transition: width 0.3s ease-out;
}

.speaking-nav-row {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 12px;
}

.speaking-nav-btn {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    font-size: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #ffffff;
    color: #3498db;
    box-shadow: 0 4px 6px rgba(52, 152, 219, 0.3);
    border: 2px solid #3498db;
    cursor: pointer;
    padding: 0;
}

.speaking-nav-btn:hover {
    background: #f1f8ff;
    transform: translateY(-2px);
}

.speaking-nav-btn:active {
    transform: translateY(0);
}

.speaking-nav-btn.stt-btn {
    color: #e74c3c;
    border-color: #e74c3c;
}

.speaking-nav-btn.stt-btn:hover {
    background: #fdf2f1;
}

.speaking-nav-btn.stt-btn.recording {
    background: #f19a93;
    color: white;
    animation: pulse-red 1.5s infinite;
}

@keyframes pulse-red {
    0% { box-shadow: 0 0 0 0 rgba(241, 154, 147, 0.55); }
    70% { box-shadow: 0 0 0 15px rgba(241, 154, 147, 0); }
    100% { box-shadow: 0 0 0 0 rgba(231, 76, 60, 0); }
}

.speaking-progress {
    font-size: 14px;
    font-weight: bold;
    color: #95a5a6;
    text-align: center;
}

.status {
    display: none;
    margin-top: 14px;
    min-height: 22px;
    font-size: 14px;
    color: #6b7280;
}

#micOverlay {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.8);
    z-index: 20;
    background: white;
    border: 4px solid #e74c3c;
    border-radius: 50%;
    width: 100px;
    height: 100px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 10px 25px rgba(231, 76, 60, 0.4);
    font-size: 40px;
    opacity: 0;
    visibility: hidden;
    transition: 0.2s;
    pointer-events: none;
}

#micOverlay.visible {
    opacity: 1;
    visibility: visible;
    transform: translate(-50%, -50%) scale(1);
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0% { box-shadow: 0 0 0 0 rgba(231, 76, 60, 0.7); }
    70% { box-shadow: 0 0 0 20px rgba(231, 76, 60, 0); }
    100% { box-shadow: 0 0 0 0 rgba(231, 76, 60, 0); }
}

.hub-footer {
    margin-top: auto;
    padding: 0 12px 6px;
    text-align: center;
    color: #71829a;
    font-size: 14px;
    border-top: none;
}

.hub-footer::before {
    content: "";
    display: block;
    border-top: 1px solid rgba(148, 163, 184, 0.35);
    margin: 20px 0 12px;
}

.footer-content p {
    margin: 4px 0;
}

.footer-content a {
    color: #5d78a2;
    text-decoration: none;
}

.footer-content a:hover {
    text-decoration: underline;
}

.scroll-top-btn,
.next-tab-btn {
    position: fixed;
    right: 30px;
    width: 50px;
    height: 50px;
    background-color: rgba(52, 152, 219, 0.6);
    color: white;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    line-height: normal;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
    opacity: 0;
    visibility: hidden;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    transition: opacity 0.3s, visibility 0.3s, transform 0.3s;
}

.scroll-top-btn {
    bottom: 100px;
    transform: translateY(20px);
}

.scroll-top-btn.scroll-top-btn--solo {
    bottom: 34px;
}

.next-tab-btn {
    bottom: 30px;
    transform: translateY(20px);
}

.scroll-top-btn.visible,
.next-tab-btn.visible {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.scroll-top-btn:hover,
.next-tab-btn:hover {
    background-color: rgba(52, 152, 219, 0.6);
    color: white;
}

.scroll-top-btn.visible:hover,
.next-tab-btn.visible:hover {
    transform: translateY(0);
}

.scroll-top-btn:not(.visible):hover,
.next-tab-btn:not(.visible):hover {
    transform: translateY(20px);
}

@media (max-width: 700px) {
    .app {
        padding: 8px 0 0;
        border-radius: 0;
        border: none;
        box-shadow: none;
        background: transparent;
        backdrop-filter: none;
    }

    h1 {
        font-size: 28px;
    }

    .speaking-flashcard {
        min-height: 280px;
    }

    #voiceSelect {
        font-size: 14px;
    }
}

/* Слово в раскрытом тексте аудирования / говорения (клик — справка) */
.text-cell.study.revealed-text .study-word,
.speaking-flashcard .target-text:not(.hidden-text) .study-word {
    cursor: pointer;
    border-radius: 4px;
    padding: 0 1px;
    -webkit-tap-highlight-color: transparent;
    transition: background-color 0.15s ease;
}

.text-cell.study.revealed-text .study-word:hover,
.speaking-flashcard .target-text:not(.hidden-text) .study-word:hover {
    background-color: rgba(59, 130, 246, 0.14);
}

body.word-insight-open {
    overflow: hidden;
}

.word-insight-root {
    position: fixed;
    inset: 0;
    z-index: 2400;
    display: block;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.22s ease;
}

.word-insight-root.is-hidden {
    display: none;
}

.word-insight-root.word-insight--visible {
    opacity: 1;
    pointer-events: auto;
}

.word-insight-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.48);
}

.word-insight-dialog {
    position: absolute;
    background: #fff;
    color: #1f2937;
    box-shadow: 0 24px 48px rgba(15, 23, 42, 0.2);
    padding: 20px 22px 22px;
    max-width: 100%;
    box-sizing: border-box;
    transition: transform 0.26s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.22s ease;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
}

/* Десктоп: центрированное модальное окно */
.word-insight-root:not(.word-insight--sheet) .word-insight-dialog {
    left: 50%;
    top: 50%;
    width: min(480px, calc(100vw - 32px));
    max-height: min(82vh, 680px);
    border-radius: 14px;
    transform: translate(-50%, -50%) scale(0.96);
    opacity: 0.96;
    overflow: hidden;
}

.word-insight-root:not(.word-insight--sheet).word-insight--visible .word-insight-dialog {
    transform: translate(-50%, -50%) scale(1);
    opacity: 1;
}

/* Узкий экран: нижняя шторка */
.word-insight-root.word-insight--sheet .word-insight-dialog {
    left: 0;
    right: 0;
    bottom: 0;
    top: auto;
    width: 100%;
    max-height: min(70vh, 520px);
    border-radius: 16px 16px 0 0;
    padding-bottom: max(22px, env(safe-area-inset-bottom, 0px));
    transform: translateY(100%);
    opacity: 1;
    overflow: hidden;
}

.word-insight-root.word-insight--sheet.word-insight--visible .word-insight-dialog {
    transform: translateY(0);
}

.word-insight-close {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 10px;
    background: rgba(241, 245, 249, 0.95);
    color: #475569;
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

.word-insight-close:hover {
    background: #e2e8f0;
    color: #1e293b;
}

.word-insight-word {
    margin: 0 40px 12px 0;
    font-size: 1.45rem;
    font-weight: 700;
    color: #0f172a;
    line-height: 1.25;
    word-break: break-word;
}

.word-insight-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 14px;
    padding: 28px 12px 8px;
    min-height: 120px;
}

.word-insight-loading[hidden] {
    display: none !important;
}

.word-insight-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid #e2e8f0;
    border-top-color: #3b82f6;
    border-radius: 50%;
    animation: word-insight-spin 0.75s linear infinite;
}

@keyframes word-insight-spin {
    to {
        transform: rotate(360deg);
    }
}

.word-insight-loading-text {
    margin: 0;
    font-size: 0.95rem;
    color: #64748b;
    text-align: center;
}

.word-insight-error {
    margin: 0;
    font-size: 0.9rem;
    line-height: 1.45;
    color: #b91c1c;
    padding: 4px 0;
}

.word-insight-error[hidden] {
    display: none !important;
}

.word-insight-content {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overflow-x: auto;
    text-align: left;
    font-size: 0.95rem;
    line-height: 1.55;
    color: #334155;
    -webkit-overflow-scrolling: touch;
}

.word-insight-content[hidden] {
    display: none !important;
}

.word-insight-content h3,
.word-insight-content h4 {
    margin: 1.1em 0 0.4em;
    font-size: 1.05rem;
    color: #0f172a;
    line-height: 1.3;
}

.word-insight-content h3:first-child,
.word-insight-content h4:first-child,
.word-insight-content > *:first-child {
    margin-top: 0;
}

.word-insight-content p {
    margin: 0.5em 0;
}

.word-insight-content ul,
.word-insight-content ol {
    margin: 0.4em 0;
    padding-left: 1.35em;
}

.word-insight-content .insight-lang {
    cursor: pointer;
    color: #1d4ed8;
    border-bottom: 1px dashed rgba(29, 78, 216, 0.45);
    padding: 0 1px;
    border-radius: 3px;
    -webkit-tap-highlight-color: transparent;
    transition: background-color 0.15s ease, color 0.15s ease;
}

.word-insight-content .insight-lang:hover {
    background-color: rgba(59, 130, 246, 0.12);
    color: #1e40af;
}

.word-insight-content .insight-lang:focus-visible {
    outline: 2px solid #3b82f6;
    outline-offset: 2px;
}

.word-insight-content .insight-lang.insight-lang--tts-loading {
    color: #ea580c;
    border-bottom-color: rgba(234, 88, 12, 0.55);
    cursor: wait;
    pointer-events: none;
}

/* Подсказка у подписи поля (модалка / шторка на телефоне) */
.field-label-row {
    display: flex;
    align-items: center;
    gap: 5px;
    flex-wrap: nowrap;
}

.field-label-row label {
    margin: 0;
}

.field-help-icon-btn {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin: 0;
    padding: 0;
    border: none;
    background: transparent;
    box-shadow: none;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    appearance: none;
    color: #3183ff;
}

.field-help-icon-btn:hover,
.field-help-icon-btn:active {
    background: transparent;
    color: #3183ff;
    box-shadow: none;
}

.field-help-icon-btn:focus {
    outline: none;
}

.field-help-icon-btn:focus-visible {
    outline: 1px dotted #2366d1;
    outline-offset: 2px;
}

.field-help-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    border: 1.5px solid currentColor;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
    font-size: 9px;
    font-style: normal;
    font-weight: 800;
    line-height: 1;
    letter-spacing: 0;
    padding-bottom: 0.5px;
    -webkit-font-smoothing: antialiased;
}

body.field-help-open {
    overflow: hidden;
}

.field-help-root {
    position: fixed;
    inset: 0;
    z-index: 2500;
    display: block;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.22s ease;
}

.field-help-root.is-hidden {
    display: none;
}

.field-help-root.field-help--visible {
    opacity: 1;
    pointer-events: auto;
}

.field-help-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.48);
}

.field-help-dialog {
    position: absolute;
    background: #fff;
    color: #1f2937;
    box-shadow: 0 24px 48px rgba(15, 23, 42, 0.2);
    padding: 22px 22px 24px;
    max-width: 100%;
    box-sizing: border-box;
    transition: transform 0.26s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.22s ease;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.field-help-root:not(.field-help--sheet) .field-help-dialog {
    left: 50%;
    top: 50%;
    width: min(400px, calc(100vw - 32px));
    max-height: min(82vh, 520px);
    border-radius: 14px;
    transform: translate(-50%, -50%) scale(0.96);
    opacity: 0.96;
}

.field-help-root--long:not(.field-help--sheet) .field-help-dialog {
    width: min(480px, calc(100vw - 32px));
    max-height: min(88vh, 640px);
}

.field-help-root:not(.field-help--sheet).field-help--visible .field-help-dialog {
    transform: translate(-50%, -50%) scale(1);
    opacity: 1;
}

.field-help-root.field-help--sheet .field-help-dialog {
    left: 0;
    right: 0;
    bottom: 0;
    top: auto;
    width: 100%;
    max-height: min(58vh, 420px);
    border-radius: 16px 16px 0 0;
    padding-bottom: max(24px, env(safe-area-inset-bottom, 0px));
    transform: translateY(100%);
    opacity: 1;
}

.field-help-root--long.field-help--sheet .field-help-dialog {
    max-height: min(78vh, 620px);
}

.field-help-root.field-help--sheet.field-help--visible .field-help-dialog {
    transform: translateY(0);
}

.field-help-close {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 10px;
    background: rgba(241, 245, 249, 0.95);
    color: #475569;
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

.field-help-close:hover {
    background: #e2e8f0;
    color: #1e293b;
}

.field-help-dialog-title {
    margin: 0 44px 12px 0;
    font-size: 1.35rem;
    font-weight: 700;
    color: #0f172a;
    line-height: 1.25;
}

.field-help-dialog-text {
    margin: 0;
    font-size: 1rem;
    line-height: 1.55;
    color: #334155;
}

.field-help-dialog-body {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin: 0;
}

.field-help-dialog-body p {
    margin: 0;
    font-size: 1rem;
    line-height: 1.55;
    color: #334155;
}

#geminiApiNoticeBody {
    white-space: pre-line;
}

/* История запросов */
.request-history-btn {
    box-sizing: border-box;
    width: 38px;
    height: 38px;
    min-width: 38px;
    min-height: 38px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    border: 1px solid #cbd5e1;
    background: #f8fafc;
    color: #475569;
    cursor: pointer;
    touch-action: manipulation;
}

.request-history-btn:hover:not(:disabled) {
    background: #f1f5f9;
    color: #1e293b;
}

.request-history-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.request-history-svg {
    display: block;
}

.field-help-root--history .field-help-dialog.request-history-dialog-shell {
    max-height: min(88vh, 640px);
    display: flex;
    flex-direction: column;
    width: min(440px, calc(100vw - 28px));
}

/* Шторка на узком экране: на всю ширину (общее правило .field-help--sheet не должно сужаться историей) */
.field-help-root--history.field-help--sheet .field-help-dialog.request-history-dialog-shell {
    width: 100%;
    max-width: 100%;
    left: 0;
    right: 0;
    box-sizing: border-box;
}

.request-history-tabs {
    display: flex;
    gap: 6px;
    margin: 0 0 12px;
}

.request-history-tab {
    flex: 1;
    padding: 10px 12px;
    border-radius: 10px;
    border: 1px solid #cbd5e1;
    background: #f1f5f9;
    color: #475569;
    font-weight: 600;
    font-size: 0.95rem;
    cursor: pointer;
    touch-action: manipulation;
}

.request-history-tab.active {
    background: #3183ff;
    border-color: #2366d1;
    color: #fff;
}

.request-history-list {
    flex: 1;
    min-height: 120px;
    max-height: min(52vh, 420px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.request-history-list[hidden] {
    display: none !important;
}

.request-history-empty {
    padding: 16px 8px;
    text-align: center;
    color: #64748b;
    font-size: 0.95rem;
}

.request-history-row {
    display: flex;
    align-items: stretch;
    gap: 0;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    background: #fff;
    overflow: hidden;
}

.request-history-row-main {
    flex: 1;
    min-width: 0;
    padding: 10px 12px;
    text-align: left;
    border: none;
    background: transparent;
    cursor: pointer;
    font: inherit;
    color: #1e293b;
}

.request-history-row-main:hover {
    background: #f8fafc;
}

.request-history-row-title {
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
    line-height: 1.45;
    font-size: 0.95rem;
    word-break: break-word;
}

.request-history-row-actions {
    flex: 0 0 44px;
    width: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-left: 1px solid #e2e8f0;
    background: #fafbfc;
}

.request-history-kebab {
    width: 100%;
    height: 100%;
    min-height: 44px;
    border: none;
    background: transparent;
    cursor: pointer;
    color: #64748b;
    font-size: 1.1rem;
    letter-spacing: 0.08em;
    line-height: 1;
    padding: 0;
}

.request-history-kebab:hover {
    background: #f1f5f9;
    color: #334155;
}

.request-history-menu {
    position: fixed;
    z-index: 2600;
    min-width: 180px;
    padding: 6px 0;
    border-radius: 10px;
    border: 1px solid #e2e8f0;
    background: #fff;
    box-shadow: 0 12px 32px rgba(15, 23, 42, 0.18);
}

.request-history-menu-item {
    display: block;
    width: 100%;
    padding: 10px 14px;
    border: none;
    background: none;
    text-align: left;
    font: inherit;
    font-size: 0.95rem;
    color: #1e293b;
    cursor: pointer;
}

.request-history-menu-item:hover {
    background: #f1f5f9;
}

.request-history-menu-item--danger {
    color: #b91c1c;
}

.request-history-menu-item--danger:hover {
    background: #fef2f2;
}

.request-history-rename-root {
    position: fixed;
    inset: 0;
    z-index: 2700;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.request-history-rename-root.is-hidden {
    display: none;
}

.request-history-rename-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
}

.request-history-rename-dialog {
    position: relative;
    z-index: 1;
    width: min(360px, 100%);
    padding: 18px 18px 16px;
    border-radius: 14px;
    background: #fff;
    box-shadow: 0 24px 48px rgba(15, 23, 42, 0.2);
}

.request-history-rename-title {
    margin: 0 0 10px;
    font-size: 1.05rem;
    font-weight: 700;
    color: #1e293b;
}

.request-history-rename-input {
    width: 100%;
    box-sizing: border-box;
    padding: 10px 12px;
    border-radius: 10px;
    border: 1px solid #cbd5e1;
    font-size: 1rem;
    margin-bottom: 14px;
}

.request-history-rename-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

.request-history-rename-icon-btn {
    width: 44px;
    height: 44px;
    border-radius: 10px;
    border: 1px solid #22c55e;
    background: #ecfdf5;
    color: #15803d;
    font-size: 1.25rem;
    font-weight: 700;
    cursor: pointer;
    line-height: 1;
}

.request-history-rename-icon-btn:hover {
    background: #d1fae5;
}

.request-history-rename-icon-btn--muted {
    border-color: #cbd5e1;
    background: #f8fafc;
    color: #64748b;
}

.request-history-rename-icon-btn--muted:hover {
    background: #f1f5f9;
}
