/* ── Theme: Sakura Pink Kawaii ── */
body {
    background: #fef6f9;
    background-image:
        radial-gradient(circle at 10% 20%, rgba(248,165,194,0.06) 0%, transparent 50%),
        radial-gradient(circle at 90% 80%, rgba(248,165,194,0.06) 0%, transparent 50%),
        radial-gradient(circle at 50% 50%, rgba(248,165,194,0.03) 0%, transparent 70%);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans SC", "Noto Sans JP", sans-serif;
    margin: 0;
    padding: 0;
    min-height: 100vh;
}

/* ── Centered layout ── */
.container {
    max-width: 800px;
    margin: 40px auto;
    padding: 40px;
    background: #ffffff;
    border-radius: 16px;
    box-shadow: 0 4px 20px rgba(248,165,194,0.12);
}

/* ── Title ── */
h1 {
    text-align: center;
    color: #f27a9e;
    font-size: 1.4em;
    margin-bottom: 24px;
    border-bottom: 2px solid #fcedf2;
    padding-bottom: 16px;
}

/* ── Input textarea ── */
textarea {
    width: 100%;
    padding: 14px 16px;
    border: 1px solid #f0dce6;
    border-radius: 12px;
    font-size: 1em;
    font-family: inherit;
    line-height: 1.6;
    resize: vertical;
    box-sizing: border-box;
    min-height: 120px;
    background: #fefafe;
    color: #5a4a52;
}

textarea:focus {
    outline: none;
    border-color: #f8a5c2;
    box-shadow: 0 0 0 3px rgba(248,165,194,0.15);
}

textarea::placeholder {
    color: #d4b8c4;
}

/* ── Voice input: wrapper ── */
.input-wrapper {
    position: relative;
    width: 100%;
}

.input-wrapper textarea {
    padding-right: 48px;
}

/* ── Mic button ── */
#mic-btn {
    position: absolute;
    bottom: 12px;
    right: 12px;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    background: rgba(248,165,194,0.2);
    color: #f27a9e;
    font-size: 0.75em;
    font-weight: bold;
    cursor: pointer;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: inherit;
    transition: background 0.2s, color 0.2s, box-shadow 0.2s;
    line-height: 1;
}

#mic-btn:hover {
    background: rgba(248,165,194,0.35);
}

#mic-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

#mic-btn.recording {
    background: #e74c3c;
    color: #fff;
    box-shadow: 0 0 0 0 rgba(231, 76, 60, 0.5);
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0% { box-shadow: 0 0 0 0 rgba(231, 76, 60, 0.5); }
    50% { box-shadow: 0 0 0 10px rgba(231, 76, 60, 0); }
    100% { box-shadow: 0 0 0 0 rgba(231, 76, 60, 0); }
}

/* ── Language toggle ── */
.lang-toggle {
    position: absolute;
    bottom: 14px;
    right: 52px;
    font-size: 0.6em;
    color: #d4b8c4;
    cursor: pointer;
    z-index: 11;
    padding: 2px 4px;
    user-select: none;
    transition: color 0.2s;
}

.lang-toggle:hover {
    color: #f27a9e;
}

/* ── Translate button ── */
#translate-btn {
    display: inline-block;
    margin-top: 12px;
    padding: 10px 32px;
    background: linear-gradient(135deg, #f8a5c2, #f27a9e);
    color: #fff;
    border: none;
    border-radius: 25px;
    font-size: 1em;
    cursor: pointer;
    font-family: inherit;
    box-shadow: 0 2px 8px rgba(248,165,194,0.25);
    transition: all 0.2s;
}

#translate-btn:hover {
    background: linear-gradient(135deg, #f8a5c2, #f27a9e);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(248,165,194,0.35);
}

/* ── Result area ── */
.result-area {
    background: #fcf4f8;
    border-radius: 12px;
    padding: 20px;
    padding-bottom: 44px;
    margin-top: 20px;
    border: 1px solid #f0dce6;
    min-height: 60px;
}

/* ── Detection line ── */
.detection {
    color: #b8a9d4;
    font-size: 0.9em;
    margin: 0 0 10px 0;
}

/* ── Translation text ── */
.translation {
    font-size: 1.2em;
    font-weight: bold;
    color: #5a4a52;
    margin: 0 0 8px 0;
}

/* ── Furigana (ruby annotations) ── */
.furigana {
    font-size: 1.1em;
    line-height: 2;
    color: #b8a9d4;
    margin: 0;
}

ruby rt {
    font-size: 0.7em;
    color: #c9b8d4;
}

/* ── Error message ── */
.error {
    color: #d32f2f;
    margin: 0;
}

/* ── Loading state ── */
.loading {
    color: #b8a9d4;
    font-style: italic;
}

/* ── Save vocabulary button ── */
.save-btn {
    display: inline-block;
    margin-top: 12px;
    padding: 8px 24px;
    background: #7ac7a0;
    color: #fff;
    border: none;
    border-radius: 25px;
    font-size: 0.95em;
    cursor: pointer;
    font-family: inherit;
    transition: background 0.2s, transform 0.2s;
}

.save-btn:hover:not(:disabled) {
    background: #6ab890;
    transform: translateY(-1px);
}

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

/* ── History link (nav button) ── */
.history-btn {
    display: inline-block;
    margin-top: 12px;
    margin-left: 8px;
    padding: 8px 24px;
    background: #f8a5c2;
    color: #fff !important;
    text-decoration: none;
    border-radius: 25px;
    font-size: 0.95em;
    font-family: inherit;
    transition: background 0.2s, transform 0.2s;
}

.history-btn:hover {
    background: #f27a9e;
    color: #fff !important;
    transform: translateY(-1px);
}

/* ── Save feedback ── */
.save-feedback {
    margin-top: 8px;
    font-size: 0.9em;
    min-height: 1.2em;
}

.save-feedback.success {
    color: #7ac7a0;
}

.save-feedback.error {
    color: #d32f2f;
}

/* ── Vocab page ── */
.back-link {
    color: #b8a9d4;
    text-decoration: none;
    font-size: 0.95em;
}

.back-link:hover {
    color: #f27a9e;
    text-decoration: underline;
}

.empty-state {
    color: #d4b8c4;
    text-align: center;
    padding: 60px 0;
    font-size: 1.1em;
}

/* ── Vocab table ── */
.vocab-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 16px;
    background: #fff;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 2px 12px rgba(248,165,194,0.10);
}

.vocab-table th {
    background: #fcedf2;
    padding: 12px 16px;
    text-align: left;
    font-weight: 600;
    color: #f27a9e;
    font-size: 0.9em;
    border-bottom: 1px solid #f0dce6;
}

.vocab-table td {
    padding: 12px 16px;
    border-bottom: 1px solid #f0dce6;
    vertical-align: top;
    line-height: 1.5;
    color: #5a4a52;
}

.vocab-table tr:last-child td {
    border-bottom: none;
}

.vocab-table tr:hover td {
    background: #fef6f9;
}

.vocab-table .source-text {
    font-weight: 500;
    color: #5a4a52;
    max-width: 200px;
    word-break: break-word;
}

.vocab-table .translated-text {
    color: #5a4a52;
    max-width: 250px;
    word-break: break-word;
}

.vocab-table .furigana-preview {
    font-size: 0.9em;
    color: #b8a9d4;
    line-height: 1.8;
}

.vocab-table .date-cell {
    color: #d4b8c4;
    font-size: 0.85em;
    white-space: nowrap;
}

/* ── Mic error message ── */
.mic-error {
    margin-top: 8px;
    padding: 8px 12px;
    background: #fff0f0;
    border: 1px solid #ffd0d0;
    border-radius: 12px;
    color: #c0392b;
    font-size: 0.9em;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-4px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ── Result wrapper for TTS button positioning ── */
.result-wrapper {
    position: relative;
}

/* ── TTS Voice Output ── */
#tts-btn {
    position: absolute;
    bottom: 8px;
    right: 8px;
    padding: 4px 10px;
    font-size: 0.8em;
    background: #f8a5c2;
    color: #fff;
    border: none;
    border-radius: 25px;
    cursor: pointer;
    display: none;
    z-index: 5;
    font-family: inherit;
}

#tts-btn:hover {
    background: #f27a9e;
}

#tts-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ── Responsive ── */
@media (max-width: 600px) {
    .container {
        margin: 16px;
        padding: 24px 16px;
    }

    h1 {
        font-size: 1.2em;
    }

    textarea {
        padding: 12px 14px;
    }

    #translate-btn {
        width: 100%;
        text-align: center;
    }

    .history-btn {
        margin-left: 0;
    }

    .result-area {
        padding: 16px;
        padding-bottom: 44px;
    }

    .translation {
        font-size: 1.1em;
    }

    .furigana {
        font-size: 1em;
    }

    /* ── Voice input: mobile adjustments ── */
    .input-wrapper textarea {
        padding-right: 42px;
    }

    #mic-btn {
        width: 32px;
        height: 32px;
        bottom: 10px;
        right: 10px;
        font-size: 0.7em;
    }

    .lang-toggle {
        bottom: 12px;
        right: 46px;
        font-size: 0.55em;
    }

    /* ── Vocab table mobile ── */
    .vocab-table th,
    .vocab-table td {
        padding: 8px 10px;
        font-size: 0.9em;
    }

    .vocab-table .source-text {
        max-width: 100px;
    }

    .vocab-table .translated-text {
        max-width: 120px;
    }

}

/* ── Grammar correction result styles ── */
.corrected-section {
    background: #fef9e7;
    border-left: 3px solid #f1c40f;
    padding: 10px 14px;
    margin: 12px 0;
    border-radius: 4px;
}
.corrected-label {
    font-weight: bold;
    margin-bottom: 6px;
    color: #7d6608;
}
.corrected-original s {
    color: #999;
}
.corrected-text {
    color: #27ae60;
    margin: 4px 0;
    font-weight: 500;
}
.grammar-issues-section {
    background: #fff5f5;
    border-left: 3px solid #e74c3c;
    padding: 10px 14px;
    margin: 12px 0;
    border-radius: 4px;
}
.grammar-title {
    font-weight: bold;
    margin-bottom: 8px;
    color: #922b21;
}
.grammar-issue-item {
    border-bottom: 1px solid #fce4e4;
    padding: 6px 0;
}
.grammar-issue-item:last-child {
    border-bottom: none;
}
.issue-type {
    font-weight: bold;
    color: #c0392b;
    font-size: 0.9em;
}
.issue-msg {
    color: #333;
    margin: 2px 0;
}
.issue-suggestion {
    color: #27ae60;
    margin: 2px 0;
    font-size: 0.9em;
}
