:root {
    --primary: #4a90e2;
    --bg: #f5f7fa;
    --card-bg: #ffffff;
    --text: #333;
    --shadow: 0 4px 6px rgba(0,0,0,0.1);
}

html, body {
    height: 100%;
    height: 100dvh;
    margin: 0;
    padding: 0;
    overflow: hidden;
    overscroll-behavior: none;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg);
    color: var(--text);
}

#app {
    display: flex;
    flex-direction: column;
    height: 100%;
    height: 100dvh;
    padding: 8px 12px;
    box-sizing: border-box;
    max-width: 700px;
    margin: 0 auto;
    width: 100%;
}

#main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

#deck-list-view {
    flex: 1;
    overflow-y: auto;
}

#study-view {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.study-header {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 5px;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
    margin-bottom: 4px;
}

header h1 {
    font-size: 1.3rem;
    margin: 0;
}

#settings-toggle-btn {
    font-size: 1.3rem;
    background: none;
    border: none;
    padding: 6px 8px;
    cursor: pointer;
    border-radius: 8px;
    color: var(--text);
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: unset;
}

#settings-toggle-btn:hover {
    background: #e8e8e8;
}

.settings-panel {
    flex-shrink: 0;
    background: var(--card-bg);
    border-radius: 10px;
    box-shadow: var(--shadow);
    padding: 10px 12px;
    margin-bottom: 8px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.settings-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}

.url-row {
    flex-wrap: nowrap;
}

.url-row input {
    flex: 1;
    min-width: 0;
    padding: 8px 10px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 0.9rem;
}

.url-row button {
    flex-shrink: 0;
}

.setting {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.95rem;
    cursor: pointer;
}

.setting-slider {
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
    cursor: default;
}

.setting-slider input[type="range"] {
    width: 100%;
    accent-color: var(--primary, #5c6bc0);
}

.grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 12px;
    padding-bottom: 8px;
}

.deck-card {
    background: var(--card-bg);
    padding: 12px;
    border-radius: 10px;
    box-shadow: var(--shadow);
    cursor: default;
    text-align: center;
    transition: transform 0.2s;
    font-size: 1rem;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    overflow: hidden;
    box-sizing: border-box;
}

.deck-card h3 {
    margin: 0 0 2px 0;
    font-size: 1rem;
    word-break: break-word;
}

.deck-card p {
    margin: 0 0 4px 0;
    font-size: 0.85rem;
    color: #888;
}

.choice-list {
    list-style: none;
    padding: 0;
    margin: 10px 0;
}

.choice-list li {
    padding: 5px 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    margin-bottom: 5px;
}

.choice-list li.correct {
    background: #e8f5e9;
    border-color: #4caf50;
    font-weight: bold;
}

.question-choices li {
    cursor: pointer;
}

.question-choices li:hover {
    background: #f0f0f0;
}

.question-choices li.selected {
    background: #e3f2fd;
    border-color: var(--primary);
}

.hidden {
    display: none !important;
}

.card-container {
    width: 100%;
    max-width: 600px;
    flex: 1;
    min-height: 0;
    margin: 0 auto;
}

.flashcard {
    position: relative;
    width: 100%;
    height: 100%;
    cursor: default;
}

.card-face {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    background: var(--card-bg);
    border-radius: 12px;
    box-shadow: var(--shadow);
    padding: 15px 20px;
    box-sizing: border-box;
    overflow: hidden;
}

.card-question {
    font-size: 1.8rem;
    font-weight: bold;
    margin: 0 0 10px 0;
    width: 100%;
    text-align: center;
    flex-shrink: 0;
}

.question-content-area {
    width: 100%;
    flex: 1;
    min-height: 0;
    overflow: hidden;
    margin-bottom: 8px;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.card-answer {
    font-size: 1.8rem;
    margin: 20px 0;
    width: 100%;
    text-align: center;
}

.choice-list {
    list-style: none;
    padding: 0;
    margin: 10px 0;
    width: 100%;
}

.choice-list li {
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 8px;
    margin-bottom: 6px;
    font-size: 1rem;
    background: white;
    transition: all 0.2s;
    text-align: center;
    word-break: break-word;
}

.question-choices li {
    cursor: pointer;
}

.question-choices li:hover {
    background: #f8f9fa;
    border-color: var(--primary);
}

.question-choices li.selected {
    background: #e3f2fd;
    border-color: var(--primary);
}

.choice-list li.correct {
    background: #e8f5e9;
    border-color: #4caf50;
    color: #2e7d32;
    font-weight: bold;
}

.choice-list li.wrong-choice {
    background: #ffebee;
    border: 2px solid #f44336;
    color: #c62828;
    font-weight: bold;
}

.choice-list li.wrong-choice::before {
    content: '❌ ';
}

.choice-list li.correct::before {
    content: '✅ ';
}

.answer-verdict {
    font-size: 2rem;
    font-weight: bold;
    text-align: center;
    padding: 15px;
    border-radius: 10px;
    margin-bottom: 15px;
    letter-spacing: 1px;
}

.verdict-correct {
    background: #e8f5e9;
    color: #2e7d32;
}

.verdict-wrong {
    background: #ffebee;
    color: #c62828;
}

.typed-answer-display {
    min-height: 32px;
    border-bottom: 2px solid var(--primary);
    margin: 5px 0 8px 0;
    font-size: 1.3rem;
    display: flex;
    align-items: center;
    justify-content: center;
    letter-spacing: 2px;
    flex-shrink: 0;
    white-space: pre;
}

.typed-answer-display::after {
    content: '|';
    animation: blink 1s step-start infinite;
    margin-left: 2px;
    color: var(--primary);
    font-weight: 100;
}

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

.virtual-keyboard {
    display: flex;
    flex-direction: column;
    gap: 4px;
    align-items: center;
    margin-top: 5px;
    width: 100%;
}

.keyboard-row {
    display: flex;
    justify-content: center;
    gap: 4px;
    width: 100%;
}

.key-btn {
    padding: 9px 0;
    flex: 1;
    max-width: 40px;
    min-height: 38px;
    background-color: white;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 0.9rem;
    font-weight: bold;
    cursor: pointer;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
    transition: all 0.1s;
    user-select: none;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.key-btn.space-key {
    max-width: 180px;
    flex: 0 0 55%;
}

.key-btn.bksp-key {
    max-width: 55px;
    background-color: #ffebee;
    color: #c62828;
}

.key-btn:active {
    background-color: #f5f5f5;
    transform: translateY(2px);
}

.hint-section {
    width: 100%;
    text-align: center;
    border-top: 1px solid #eee;
    padding-top: 8px;
    flex-shrink: 0;
    background: var(--card-bg);
}

.hint {
    font-size: 0.85rem;
    color: #666;
    margin: 5px 0 0 0;
    line-height: 1.3;
}

.card-back {
    display: none;
}

.study-actions {
    display: flex;
    justify-content: center;
    gap: 15px;
    margin-top: 8px;
    flex-shrink: 0;
}

button {
    padding: 10px 16px;
    border-radius: 8px;
    border: 1px solid #ccc;
    background: white;
    cursor: pointer;
    font-size: 0.95rem;
    min-height: 44px;
    touch-action: manipulation;
}

button:hover {
    background: #f0f0f0;
}

.quiz-btn.wrong {
    background: #f44336;
    color: white;
    border: none;
}

.quiz-btn.right {
    background: #4caf50;
    color: white;
    border: none;
}

#next-btn {
    background: var(--primary);
    color: white;
    border: none;
    padding: 8px 20px;
    font-size: 1.05rem;
}

#next-btn:hover {
    background: #3a7bc8;
}

/* Result View */
#result-view {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

.result-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    width: 100%;
    max-width: 400px;
    text-align: center;
}

.result-icon {
    font-size: 3.5rem;
    line-height: 1;
}

.result-container h2 {
    margin: 0;
    font-size: 1.6rem;
}

.result-deck-name {
    margin: 0;
    color: #888;
    font-size: 0.95rem;
}

.result-score {
    margin: 8px 0;
}

.score-circle {
    width: 110px;
    height: 110px;
    border-radius: 50%;
    background: conic-gradient(#4caf50 var(--score-pct, 0%), #eee var(--score-pct, 0%));
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.score-circle::before {
    content: '';
    position: absolute;
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: white;
}

.score-circle {
    position: relative;
}

#result-percent {
    position: relative;
    font-size: 1.6rem;
    font-weight: bold;
    color: var(--text);
}

.result-stats {
    display: flex;
    gap: 20px;
    justify-content: center;
    width: 100%;
}

.stat {
    flex: 1;
    background: var(--card-bg);
    border-radius: 10px;
    padding: 12px 8px;
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.stat-num {
    font-size: 1.8rem;
    font-weight: bold;
}

.correct-stat .stat-num { color: #4caf50; }
.wrong-stat .stat-num { color: #f44336; }
.total-stat .stat-num { color: var(--primary); }

.stat-label {
    font-size: 0.8rem;
    color: #888;
}

.result-actions {
    display: flex;
    gap: 12px;
    width: 100%;
}

.result-actions button {
    flex: 1;
}

#result-retry-btn {
    background: var(--primary);
    color: white;
    border: none;
}

#result-retry-btn:hover {
    background: #3a7bc8;
}

#result-review-btn {
    background: #ff9800;
    color: white;
    border: none;
}

#result-review-btn:hover {
    background: #e65100;
}

/* Deck card mode buttons */
.deck-mode-btns {
    display: flex;
    gap: 8px;
    margin-top: 10px;
    justify-content: center;
}

.mode-btn {
    flex: 1;
    min-height: 36px;
    font-size: 0.85rem;
    padding: 6px 8px;
}

.study-btn {
    background: #e3f2fd;
    border-color: var(--primary);
    color: var(--primary);
}

.quiz-btn-deck {
    background: #fff3e0;
    border-color: #ff9800;
    color: #e65100;
}

/* Review mistakes page */
#review-view {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.review-header {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
}

.review-header h2 {
    margin: 0;
    font-size: 1.2rem;
}

.review-list {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding-bottom: 8px;
}

.review-item {
    background: var(--card-bg);
    border-radius: 10px;
    box-shadow: var(--shadow);
    padding: 12px 16px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.review-question {
    font-size: 1.3rem;
    font-weight: bold;
    text-align: center;
    padding-bottom: 6px;
    border-bottom: 1px solid #eee;
}

.review-row {
    display: flex;
    align-items: baseline;
    gap: 8px;
}

.review-label {
    font-size: 0.8rem;
    font-weight: bold;
    white-space: nowrap;
    flex-shrink: 0;
}

.wrong-label { color: #f44336; }
.correct-label { color: #4caf50; }

.review-answer {
    font-size: 1rem;
}

.wrong-answer { color: #c62828; }
.correct-answer { color: #2e7d32; font-weight: bold; }

/* ── Browse View ───────────────────────────────── */
#browse-view {
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
}

.browse-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: var(--card-bg);
    box-shadow: var(--shadow);
    flex-shrink: 0;
}

.browse-header h2 {
    margin: 0;
    font-size: 1.2rem;
    flex: 1;
}

.browse-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
    overflow-y: auto;
    padding: 16px;
    flex: 1;
}

.browse-item {
    background: var(--card-bg);
    border-radius: 12px;
    box-shadow: var(--shadow);
    padding: 14px 18px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.browse-question {
    font-size: 1.15rem;
    font-weight: bold;
    color: var(--text-color);
    padding-bottom: 6px;
    border-bottom: 1px solid rgba(0,0,0,0.08);
}

.browse-answer {
    font-size: 1rem;
    color: #2e7d32;
    font-weight: 600;
}

.browse-hints {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    padding-top: 4px;
}

.browse-hint-text {
    margin: 0;
    font-size: 0.88rem;
    color: var(--text-muted, #666);
    font-style: italic;
}

.browse-speak-btn {
    background: #e3f2fd;
    border: 1px solid #90caf9;
    color: #1565c0;
    border-radius: 16px;
    padding: 4px 12px;
    font-size: 0.82rem;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.15s;
}

.browse-speak-btn:hover {
    background: #bbdefb;
}

/* ── JSON Paste Modal ──────────────────────────── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-box {
    background: var(--card-bg);
    border-radius: 14px;
    padding: 24px;
    width: min(480px, 92vw);
    display: flex;
    flex-direction: column;
    gap: 14px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.25);
}

.modal-title-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

#json-paste-clipboard-btn {
    font-size: 0.82rem;
    padding: 5px 12px;
    border-radius: 8px;
    border: 1px solid #ccc;
    background: #f5f5f5;
    cursor: pointer;
    white-space: nowrap;
}

#json-paste-clipboard-btn:hover {
    background: #e8e8e8;
}

.modal-box h3 {
    margin: 0;
    font-size: 1.1rem;
}

#json-paste-area {
    width: 100%;
    height: 220px;
    font-family: monospace;
    font-size: 0.82rem;
    padding: 10px;
    border: 1px solid #ccc;
    border-radius: 8px;
    resize: vertical;
    box-sizing: border-box;
}

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

.modal-actions button {
    padding: 8px 20px;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    font-size: 0.95rem;
}

#json-paste-cancel-btn {
    background: #eee;
    color: #333;
}

#json-paste-load-btn {
    background: var(--primary, #5c6bc0);
    color: #fff;
}
