*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: Vazirmatn, sans-serif;
    line-height: 1.6;
    color: #333;
    height: 100vh;
    height: 100dvh;
    display: flex;
    flex-direction: column;
}

nav {
    padding: 0.75rem 1.5rem;
    border-bottom: 1px solid #ddd;
    flex-shrink: 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

nav a {
    text-decoration: none;
    color: #333;
    font-weight: bold;
}

.nav-title {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.nav-title-text {
    display: flex;
    flex-direction: column;
    line-height: 1.2;
    font-size: 0.9rem;
}

nav img {
    height: 1cm;
    width: auto;
    vertical-align: middle;
}

.nav-user {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9rem;
    color: #555;
}

.nav-avatar {
    height: 1.6rem;
    width: 1.6rem;
    border-radius: 50%;
}

.nav-logout {
    color: #999;
    text-decoration: none;
    font-weight: normal;
    font-size: 0.85rem;
}

.nav-logout:hover {
    color: #333;
}

main {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

main.chat {
    overflow: hidden;
}

/* Landing */

.landing {
    max-width: 480px;
    margin: 6rem auto;
    padding: 0 1.5rem;
    text-align: center;
}

.landing h1 {
    font-size: 2rem;
    margin-bottom: 0.75rem;
}

.landing p {
    color: #666;
    margin-bottom: 2rem;
}

.button {
    display: inline-block;
    padding: 0.65rem 1.5rem;
    background: #333;
    color: #fff;
    text-decoration: none;
    border-radius: 6px;
    font-size: 1rem;
}

.button:hover {
    background: #555;
}


/* Debug */

.message.assistant {
    position: relative;
}

.debug-btn {
    position: absolute;
    bottom: 0.3rem;
    right: 0.3rem;
    background: none;
    border: 1px solid #ccc;
    border-radius: 4px;
    padding: 0.1rem 0.4rem;
    font-size: 0.7rem;
    color: #999;
    cursor: pointer;
}

.debug-btn:hover {
    color: #333;
    border-color: #999;
}

.debug-raw {
    margin-top: 0.5rem;
    padding-top: 0.5rem;
    border-top: 1px solid #ddd;
    font-size: 0.75rem;
    color: #888;
    white-space: pre-wrap;
    word-break: break-word;
}

/* Sentences */

.sentence {
    display: block;
    margin: 0.4rem 0;
    text-align: center;
}

.speak-btns {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    gap: 0.2em;
    margin: 0 0.4em;
}

.speak-btn {
    background: none;
    border: none;
    color: #bbb;
    font-size: 0.75em;
    cursor: pointer;
    padding: 0.1em 0.2em;
    text-align: right;
}

.speak-btn:hover {
    color: #666;
}

.speak-btn.spinning {
    pointer-events: none;
}

.speak-spinner {
    height: 1em;
    width: 1em;
    vertical-align: middle;
}

.sentence-farsi {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    direction: rtl;
    margin-bottom: 0.15rem;
}

.sentence-english {
    color: #666;
    font-size: 0.9em;
}

/* Farsi words */

.word {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    vertical-align: middle;
    margin: 0 0.3em;
}

.word-farsi {
    font-size: 1.1em;
}

.word-roman {
    font-size: 0.75em;
    color: #999;
}

.word-gloss {
    font-size: 0.75em;
    color: #bbb;
    font-style: italic;
}

.word-new .word-farsi {
    color: #2a9d2a;
    font-weight: bold;
}

.word.speaking .word-farsi,
.gap.speaking {
    color: #c07000;
}

.gap {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    vertical-align: top;
    font-size: 0.85em;
    color: #aaa;
    font-style: italic;
    border: 1px dashed #ccc;
    border-radius: 4px;
    padding: 0.1em 0.4em;
}

/* Chat */

.chat-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    max-width: 720px;
    width: 100%;
    margin: 0 auto;
    padding: 0 1rem;
}

.messages {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem 0;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.message {
    max-width: 80%;
    padding: 1em;
    border-radius: 12px;
    font-size: 0.95rem;
}

.message > * {
    margin: 2em 0;
}

.message > *:first-child {
    margin-top: 0;
}

.message > *:last-child {
    margin-bottom: 0;
}

.message.user {
    align-self: flex-end;
    background: #333;
    color: #fff;
    border-bottom-right-radius: 4px;
}

.message.assistant {
    align-self: flex-start;
    background: #f0f0f0;
    color: #333;
    border-bottom-left-radius: 4px;
}

@media (max-width: 600px) {
    .message {
        max-width: 95%;
    }
}

.chat-form {
    display: flex;
    gap: 0.5rem;
    padding: 1rem 0;
    border-top: 1px solid #ddd;
    flex-shrink: 0;
}

.chat-form input {
    flex: 1;
    padding: 0.65rem 1rem;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-family: Vazirmatn, sans-serif;
    font-size: 0.95rem;
    outline: none;
}

.chat-form input:focus {
    border-color: #999;
}

.chat-form button {
    padding: 0.65rem 1.25rem;
    background: #333;
    color: #fff;
    border: none;
    border-radius: 6px;
    font-size: 1rem;
    cursor: pointer;
}

.chat-form button:hover {
    background: #555;
}

.chat-form button .loading,
.chat-form.htmx-request button .idle {
    display: none;
}

.chat-form.htmx-request button .loading {
    display: inline;
}

.chat-form.htmx-request button {
    background: #999;
    cursor: not-allowed;
}

.chat-form.htmx-request input {
    opacity: 0.5;
    pointer-events: none;
}

.mic-btn {
    padding: 0.65rem 0.85rem;
    background: #333;
    color: #fff;
    border: none;
    border-radius: 6px;
    font-size: 1rem;
    cursor: pointer;
}

.mic-btn:hover {
    background: #555;
}

.mic-btn.recording {
    background: #c0392b;
    animation: pulse 1s infinite;
}

.mic-btn:disabled {
    background: #999;
    cursor: not-allowed;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

.input-source-icon {
    font-size: 0.75em;
    margin-right: 0.4em;
    opacity: 0.7;
}

.voice-play-btn {
    background: none;
    border: none;
    color: rgba(255,255,255,0.5);
    font-size: 0.75em;
    cursor: pointer;
    padding: 0 0.2em;
    vertical-align: middle;
}

.voice-play-btn:hover {
    color: #fff;
}

/* Quiz widget */

.quiz-widget {
    background: #fff;
    border: 1px solid #ddd;
    border-radius: 8px;
    padding: 1rem;
    margin: 0.5rem 0;
}

.quiz-header {
    font-weight: bold;
    font-size: 0.8em;
    color: #999;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 0.75rem;
}

.quiz-questions {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.quiz-question label {
    display: block;
    font-size: 0.9em;
    margin-bottom: 0.25rem;
}

.quiz-question input {
    width: 100%;
    padding: 0.4rem 0.6rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-family: Vazirmatn, sans-serif;
    font-size: 0.9em;
    outline: none;
}

.quiz-question input:focus {
    border-color: #999;
}

.quiz-loading {
    display: none;
    text-align: center;
    color: #999;
    font-size: 0.9em;
    padding: 0.5rem 0;
}

.quiz-actions {
    display: flex;
    gap: 0.5rem;
    justify-content: flex-end;
}

.quiz-skip-btn {
    padding: 0.4rem 1rem;
    background: none;
    border: 1px solid #ccc;
    border-radius: 6px;
    color: #666;
    font-size: 0.9em;
    cursor: pointer;
}

.quiz-skip-btn:hover {
    border-color: #999;
    color: #333;
}

.quiz-submit-btn {
    padding: 0.4rem 1rem;
    background: #333;
    border: none;
    border-radius: 6px;
    color: #fff;
    font-size: 0.9em;
    cursor: pointer;
}

.quiz-submit-btn:hover {
    background: #555;
}

/* Collapse the quiz to a spinner while HTMX is waiting for the grading response */
.quiz-widget form.htmx-request .quiz-questions,
.quiz-widget form.htmx-request .quiz-actions {
    display: none;
}

.quiz-widget form.htmx-request .quiz-loading {
    display: block;
}

/* Quiz results */

.quiz-widget.quiz-done .quiz-quote {
    font-style: italic;
    color: #555;
    font-size: 0.9em;
    margin-bottom: 0.5rem;
}

.quiz-score {
    font-weight: bold;
    font-size: 1.1em;
    margin-bottom: 0.75rem;
}

.quiz-results {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.quiz-result-row {
    border-left: 3px solid #ddd;
    padding-left: 0.75rem;
}

.quiz-result-row.correct {
    border-left-color: #2a9d2a;
}

.quiz-result-row.incorrect {
    border-left-color: #c0392b;
}

.quiz-result-row.skipped {
    border-left-color: #ccc;
    opacity: 0.7;
}

.quiz-result-question {
    font-size: 0.85em;
    color: #666;
    margin-bottom: 0.2rem;
}

.quiz-result-answer {
    display: flex;
    align-items: baseline;
    gap: 0.4rem;
    font-size: 0.9em;
    margin-bottom: 0.2rem;
    flex-wrap: wrap;
}

.quiz-verdict {
    font-weight: bold;
}

.correct .quiz-verdict {
    color: #2a9d2a;
}

.incorrect .quiz-verdict {
    color: #c0392b;
}

.skipped .quiz-verdict {
    color: #bbb;
}

.quiz-correct-answer {
    color: #888;
    font-size: 0.85em;
}

.quiz-explanation {
    font-size: 0.8em;
    color: #888;
    font-style: italic;
}

.quiz-widget.quiz-skipped {
    opacity: 0.4;
}

.quiz-widget.quiz-error {
    color: #c0392b;
    font-size: 0.9em;
}
