/* ==========================================
   JuziGenius (句子Genius) - Master Stylesheet
   Optimized for Pixel Tablet & Linux PWA Deployment
   ========================================== */

:root {
    --bg-color: #121214;
    --surface-color: #1e1e24;
    --card-bg: #262630;
    --text-primary: #f0f0f5;
    --text-secondary: #a0a0b0;
    --accent-gold: #f39c12;
    --accent-orange: #e67e22;
    --accent-red: #e74c3c;
    --accent-green: #2ecc71;
    --accent-blue: #2980b9;
    --accent-purple: #8e44ad;
    --border-color: #3f3f50;
}

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

body {
    background-color: var(--bg-color);
    color: var(--text-primary);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    overflow-x: hidden;
}

#app-container {
    width: 100%;
    max-width: 540px;
    background-color: var(--surface-color);
    border-radius: 16px;
    border: 1px solid var(--border-color);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.6);
    padding: 20px 24px 28px 24px;
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
}

/* --- Top Header Bar --- */
#top-bar {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 14px;
    padding-bottom: 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.07);
}

.top-btn {
    background-color: var(--card-bg);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
    padding: 6px 14px;
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.top-btn:hover {
    color: var(--text-primary);
    border-color: var(--accent-gold);
}

.top-btn:active {
    transform: scale(0.96);
}

#btn-import {
    background-color: rgba(142, 68, 173, 0.15);
    border-color: rgba(142, 68, 173, 0.5);
    color: #d2b4de;
}

#btn-import:hover {
    background-color: var(--accent-purple);
    color: white;
}

#btn-discuss {
    background-color: rgba(41, 128, 185, 0.15);
    border-color: rgba(41, 128, 185, 0.5);
    color: #aed6f1;
}

#btn-discuss:hover {
    background-color: var(--accent-blue);
    color: white;
}

/* --- Character Progress Counter & Mascot Avatar --- */
#top-bar-center {
    display: flex;
    align-items: center;
    gap: 10px;
}

#character-counter {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.85rem;
    color: var(--text-secondary);
    background-color: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--border-color);
    padding: 4px 12px;
    border-radius: 20px;
}

/* The avatar art is a self-contained round mascot on a transparent
   background, so it needs no circular crop or ring -- object-fit: cover plus
   border-radius: 50% would clip the leaf off the top and draw a gold ring
   around transparent corners. drop-shadow follows the alpha silhouette, so
   the warm glow traces the mascot instead of a square box. */
.mascot-avatar-small {
    width: 26px;
    height: 26px;
    object-fit: contain;
    filter: drop-shadow(0 0 4px rgba(243, 156, 18, 0.5));
}

#counter-value {
    color: var(--accent-gold);
    font-weight: bold;
}

/* --- Due-for-Review Counter (SM-2) --- */
#due-counter {
    display: flex;
    align-items: center;
    font-size: 0.85rem;
    color: var(--text-secondary);
    background-color: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--border-color);
    padding: 4px 12px;
    border-radius: 20px;
    transition: background-color 0.2s ease, border-color 0.2s ease;
}

#due-counter-value {
    color: var(--text-secondary);
    font-weight: bold;
    transition: color 0.2s ease;
}

#due-counter.has-due {
    border-color: var(--accent-red);
    background-color: rgba(231, 76, 60, 0.15);
}

#due-counter.has-due #due-counter-value {
    color: var(--accent-red);
}

/* --- Prompt Zone --- */
#english-prompt {
    font-size: 1.3rem;
    font-weight: 600;
    text-align: center;
    color: var(--text-primary);
    margin-bottom: 16px;
    letter-spacing: 0.4px;
    font-family: Georgia, serif;
    min-height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 8px;
}

/* --- Assembly Line (Slots) --- */
#assembly-line {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
    margin-bottom: 18px;
    min-height: 45px;
}

.character-slot {
    width: 40px;
    height: 40px;
    background-color: var(--card-bg);
    border: 2px solid var(--border-color);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.3rem;
    font-weight: bold;
    color: var(--text-primary);
    transition: all 0.25s ease;
}

.character-slot.active {
    border-color: var(--accent-gold);
    background-color: rgba(243, 156, 18, 0.15);
    box-shadow: 0 0 12px rgba(243, 156, 18, 0.35);
}

.character-slot.punctuation-slot {
    background-color: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 1.2rem;
}

/* Celebratory Flash on Complete */
@keyframes successPulse {
    0% {
        background-color: var(--card-bg);
        border-color: var(--border-color);
        transform: scale(1);
    }
    40% {
        background-color: rgba(46, 204, 113, 0.35);
        border-color: var(--accent-green);
        box-shadow: 0 0 16px rgba(46, 204, 113, 0.6);
        transform: scale(1.08);
    }
    100% {
        background-color: rgba(46, 204, 113, 0.2);
        border-color: var(--accent-green);
        transform: scale(1);
    }
}

.character-slot.success-flash {
    animation: successPulse 0.7s ease forwards;
    color: #e8f8f0;
}

/* --- Workspace Layout (Sidebar + Canvas) --- */
#workspace-main {
    display: flex;
    flex-direction: row;
    gap: 16px;
    align-items: center;
    justify-content: center;
    width: 100%;
}

/* --- Action Sidebar (Vertical on the Left) --- */
#action-sidebar {
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: 90px;
}

.action-btn {
    width: 100%;
    padding: 12px 8px;
    border-radius: 8px;
    border: none;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: filter 0.2s, transform 0.1s, opacity 0.2s;
    text-align: center;
}

.action-btn:active {
    transform: scale(0.97);
}

.action-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    pointer-events: none;
}

#btn-clear {
    background-color: var(--card-bg);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
}

#btn-hint {
    background-color: #d35400;
    color: white;
}

/* --- Canvas Wrapper & InkStone Canvas --- */
#canvas-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* --- Reserved Hint Container Space --- */
#hint-display-container {
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    font-weight: bold;
    color: var(--accent-gold);
    margin-bottom: 6px;
}

#tian-zi-ge {
    background-color: #f7f2e8 !important;
    border: 3px solid #3d2f24 !important;
    border-radius: 12px;
    box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.08), 0 8px 24px rgba(0, 0, 0, 0.3);
    width: 240px;
    height: 240px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
}

#tian-zi-ge svg {
    background-color: #f7f2e8 !important;
}

/* --- Stroke Data Failure Card (character can't be practiced offline) --- */
.stroke-error-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    background-color: #fdfaf3;
    padding: 14px;
    text-align: center;
    animation: fadeIn 0.3s ease-out;
}

.stroke-error-char {
    font-size: 2.6rem;
    font-weight: 700;
    color: var(--text-secondary);
    line-height: 1;
    margin-bottom: 8px;
}

.stroke-error-title {
    font-size: 0.95rem;
    font-weight: 800;
    color: #c0392b;
    margin-bottom: 6px;
}

.stroke-error-note {
    font-size: 0.72rem;
    color: var(--text-secondary);
    line-height: 1.4;
    margin-bottom: 12px;
}

.stroke-error-note code {
    background-color: rgba(0, 0, 0, 0.06);
    border-radius: 3px;
    padding: 1px 4px;
    font-size: 0.7rem;
}

/* A character stepped past because it couldn't be rendered -- distinct from
   both an unwritten slot and a correctly written one. */
.character-slot.skipped-slot {
    border-style: dashed;
    border-color: var(--text-secondary);
    color: var(--text-secondary);
    opacity: 0.6;
}

/* --- Victory Card Display (Inside Canvas upon Completion) --- */
.victory-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    background-color: #fdfaf3;
    padding: 12px;
    text-align: center;
    animation: fadeIn 0.3s ease-out;
}

@keyframes fadeIn {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}

.victory-mascot {
    width: 80px;
    height: 80px;
    object-fit: contain;
    filter: drop-shadow(0 3px 8px rgba(243, 156, 18, 0.45));
    margin-bottom: 8px;
}

.victory-title {
    font-size: 1.1rem;
    font-weight: 800;
    color: #27ae60;
    margin-bottom: 10px;
}

/* Pronunciation controls, sitting under the assembly line with the sentence
   they act on. Styled for the dark app surface -- they previously lived on the
   victory card's parchment background and were coloured for it. */
#sentence-audio-controls {
    display: flex;
    justify-content: center;
    gap: 8px;
    margin-top: -8px;
    margin-bottom: 16px;
}

#sentence-audio-controls[hidden] {
    display: none;
}

.btn-audio-action {
    background-color: var(--card-bg);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 6px 12px;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.2s, transform 0.1s;
}

.btn-audio-action:hover:not(:disabled) {
    background-color: var(--border-color);
    transform: translateY(-1px);
}

.btn-audio-action:active:not(:disabled) {
    transform: translateY(0);
}

.btn-audio-action:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-next {
    background-color: #27ae60;
    color: white;
    border: none;
    border-radius: 8px;
    padding: 8px 18px;
    font-size: 0.95rem;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(39, 174, 96, 0.35);
    transition: background-color 0.2s, transform 0.1s;
}

.btn-next:hover {
    background-color: #2ecc71;
    transform: translateY(-1px);
}

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

/* --- Import Modal Overlay --- */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(4px);
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal-card {
    background-color: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: 14px;
    width: 90%;
    max-width: 480px;
    padding: 24px;
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.7);
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.modal-title {
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--text-primary);
}

.modal-subtitle {
    font-size: 0.85rem;
    color: var(--text-secondary);
    line-height: 1.4;
}

/* --- Import Modal: Mode Tabs --- */
.mode-tabs {
    display: flex;
    gap: 6px;
    background-color: rgba(0, 0, 0, 0.25);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 4px;
}

.mode-tab {
    flex: 1;
    background: transparent;
    border: none;
    border-radius: 7px;
    color: var(--text-secondary);
    font-size: 0.82rem;
    font-weight: 600;
    padding: 8px 6px;
    cursor: pointer;
    transition: background-color 0.2s, color 0.2s;
}

.mode-tab:hover {
    color: var(--text-primary);
}

.mode-tab.active {
    background-color: var(--accent-purple);
    color: white;
}

.mode-panel[hidden] {
    display: none;
}

#import-textarea {
    width: 100%;
    height: 140px;
    background-color: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    padding: 12px;
    font-size: 0.95rem;
    font-family: inherit;
    resize: vertical;
    outline: none;
}

#import-textarea:focus {
    border-color: var(--accent-gold);
}

.import-translation-label {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-top: 12px;
    margin-bottom: 6px;
}

.import-translation-textarea {
    width: 100%;
    height: 80px;
    background-color: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    padding: 12px;
    font-size: 0.9rem;
    font-family: inherit;
    resize: vertical;
    outline: none;
}

.import-translation-textarea:focus {
    border-color: var(--accent-gold);
}

.import-translation-note {
    font-size: 0.75rem;
    color: var(--text-secondary);
    line-height: 1.4;
    margin-top: 6px;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 6px;
}

.modal-btn {
    padding: 9px 16px;
    border-radius: 8px;
    border: none;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: filter 0.2s, transform 0.1s;
}

.modal-btn:active {
    transform: scale(0.97);
}

.btn-secondary {
    background-color: var(--card-bg);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
}

.btn-primary {
    background-color: var(--accent-purple);
    color: white;
}

/* --- Suggest Words: checkbox list --- */
.suggestions-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    max-height: 260px;
    overflow-y: auto;
}

.suggestions-empty {
    font-size: 0.85rem;
    color: var(--text-secondary);
    padding: 12px 0;
    text-align: center;
}

.suggestion-row {
    display: grid;
    grid-template-columns: auto auto 1fr 1.4fr;
    align-items: center;
    gap: 10px;
    background-color: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 10px 12px;
    cursor: pointer;
    transition: border-color 0.2s, background-color 0.2s;
}

.suggestion-row:hover {
    border-color: var(--accent-gold);
}

.suggestion-checkbox {
    width: 18px;
    height: 18px;
    accent-color: var(--accent-purple);
    cursor: pointer;
}

.suggestion-word {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-primary);
}

.suggestion-pinyin {
    font-size: 0.85rem;
    color: var(--accent-gold);
    white-space: nowrap;
}

.suggestion-meaning {
    font-size: 0.82rem;
    color: var(--text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
