:root[data-theme="light"] {
    --primary: #6366F1;
    --primary-hover: #4F46E5;
    --primary-bg: #EEF2FF;
    --primary-glow: rgba(99, 102, 241, 0.2);
    --bg: #F8FAFC;
    --text-main: #0F172A;
    --text-muted: #64748B;
    --card: #FFFFFF;
    --border: #E2E8F0;
    --error: #F43F5E;
    --error-bg: #FEF2F2;
    --success: #10B981;
    --success-bg: #ECFDF5;
    --shadow: 0 20px 35px -10px rgba(99, 102, 241, 0.08), 0 10px 20px -10px rgba(0, 0, 0, 0.03);
}

:root[data-theme="dark"] {
    --primary: #818CF8;
    --primary-hover: #6366F1;
    --primary-bg: rgba(99, 102, 241, 0.2);
    --primary-glow: rgba(129, 140, 248, 0.3);
    --bg: #090D16;
    --text-main: #F8FAFC;
    --text-muted: #94A3B8;
    --card: #131D31;
    --border: #1E293B;
    --error: #FB7185;
    --error-bg: rgba(244, 63, 94, 0.15);
    --success: #34D399;
    --success-bg: rgba(16, 185, 129, 0.15);
    --shadow: 0 20px 35px -10px rgba(0, 0, 0, 0.5), 0 10px 20px -10px rgba(0, 0, 0, 0.3);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

body {
    font-family: 'Plus Jakarta Sans', 'Noto Sans Thai', sans-serif;
    background-color: var(--bg);
    color: var(--text-main);
    margin: 0;
    padding: 12px;
    display: flex;
    justify-content: center;
    min-height: 100vh;
    overflow-y: auto;
    transition: background-color 0.4s ease, color 0.4s ease;
}

.container {
    width: 100%;
    max-width: 480px;
    background: var(--card);
    padding: 26px 20px 140px 20px;
    border-radius: 28px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    margin-top: 5px;
    margin-bottom: 20px;
    align-self: flex-start;
    position: relative;
    transition: background-color 0.4s ease, border-color 0.4s ease, box-shadow 0.4s ease;
}

.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2px;
}

h1 { font-size: 24px; color: var(--primary); margin: 0; font-weight: 800; letter-spacing: -0.5px; }

.header-actions {
    display: flex;
    gap: 6px;
    align-items: center;
}

.theme-toggle-btn, .install-pwa-btn {
    background: var(--bg);
    border: 2px solid var(--border);
    color: var(--text-main);
    width: 40px;
    height: 40px;
    border-radius: 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 17px;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}
.theme-toggle-btn:hover, .install-pwa-btn:hover { border-color: var(--primary); }
.theme-toggle-btn:active, .install-pwa-btn:active { transform: scale(0.9); }

.watermark {
    font-size: 11px;
    font-weight: 700;
    color: var(--primary);
    opacity: 0.8;
    margin-bottom: 22px;
    letter-spacing: 0.5px;
}

h3 { font-size: 14px; margin-bottom: 10px; color: var(--text-main); display: flex; justify-content: space-between; align-items: center; font-weight: 700; }

.hidden { display: none !important; }

.setting-section {
    background: var(--bg);
    border: 1.5px solid var(--border);
    border-radius: 20px;
    padding: 16px;
    margin-bottom: 16px;
    transition: background-color 0.4s ease, border-color 0.4s ease;
}

.setting-section h2 {
    font-size: 14px;
    color: var(--primary);
    margin: 0 0 12px 0;
    font-weight: 800;
    letter-spacing: -0.2px;
}

.setting-group { margin-bottom: 10px; }
.setting-group:last-child { margin-bottom: 0; }
.chip-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

label.chip {
    display: block; padding: 11px 10px; border: 2px solid var(--border);
    border-radius: 14px; text-align: center; font-size: 12px;
    font-weight: 700; color: var(--text-muted); background: var(--card);
    cursor: pointer; transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1); user-select: none;
}
label.chip:hover { border-color: var(--primary); }
label.chip:has(input:checked) {
    background: var(--primary-bg); border-color: var(--primary); color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-glow);
}
label.chip input { display: none; }

.tab-bar {
    display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 12px;
}
.tab-btn {
    padding: 11px; border: 2px solid var(--border); background: var(--card);
    border-radius: 14px; font-size: 13px; font-weight: 700; color: var(--text-muted);
    cursor: pointer; transition: all 0.25s ease; font-family: inherit; text-align: center;
}
.tab-btn:hover { border-color: var(--primary); }
.tab-btn.active {
    background: var(--primary); border-color: var(--primary); color: white;
    box-shadow: 0 6px 16px var(--primary-glow);
}

.kana-scroll-container {
    display: flex;
    gap: 10px;
    overflow-x: auto;
    padding-bottom: 8px;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
}
.kana-scroll-container::-webkit-scrollbar {
    height: 6px;
}
.kana-scroll-container::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 10px;
}

.kana-column-box {
    min-width: 95px;
    flex: 0 0 auto;
    border: 2px solid var(--border);
    border-radius: 16px;
    padding: 10px;
    background: var(--card);
    display: flex;
    flex-direction: column;
    gap: 6px;
    scroll-snap-align: start;
    transition: border-color 0.3s ease;
}

.kana-column-header {
    display: flex;
    justify-content: center;
    border-bottom: 1px dashed var(--border);
    padding-bottom: 6px;
}

.kana-column-items {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

label.kana-item-box {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    padding: 7px 4px;
    border: 1.5px solid var(--border);
    border-radius: 10px;
    background: var(--bg);
    cursor: pointer;
    transition: all 0.2s ease;
    user-select: none;
}
label.kana-item-box:hover { border-color: var(--primary); }
label.kana-item-box:has(input:checked) {
    background: var(--primary-bg);
    border-color: var(--primary);
    color: var(--primary);
}

label.kana-item-box input { display: none; }

.item-text {
    font-size: 13px;
    font-weight: 700;
    color: var(--text-main);
    text-align: center;
}

label.kana-item-box:has(input:checked) .item-text {
    color: var(--primary);
}

.custom-section {
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.custom-card {
    border: 2px solid var(--border);
    border-radius: 18px;
    padding: 16px;
    background: var(--card);
    transition: border-color 0.3s ease;
}
.custom-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}
.custom-card-title {
    font-size: 14px;
    font-weight: 800;
    color: var(--text-main);
}
.custom-input {
    width: 100%;
    padding: 11px 14px;
    font-size: 13px;
    border: 2px solid var(--border);
    border-radius: 12px;
    background: var(--bg);
    color: var(--text-main);
    font-family: inherit;
    outline: none;
    font-weight: 600;
    transition: all 0.2s ease;
}
.custom-input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-glow); }

.vocab-item-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--bg);
    padding: 9px 12px;
    border-radius: 12px;
    border: 1px solid var(--border);
    margin-bottom: 6px;
    font-size: 12px;
}
.vocab-item-info {
    display: flex;
    gap: 10px;
    align-items: center;
    font-weight: 600;
}

.danger-btn {
    background: var(--error-bg);
    color: var(--error);
    border: 1px solid var(--error);
    border-radius: 9px;
    padding: 6px 11px;
    font-size: 11px;
    font-weight: 700;
    cursor: pointer;
    font-family: inherit;
    transition: 0.2s;
}
.danger-btn:active { transform: scale(0.95); opacity: 0.8; }

.edit-btn {
    background: var(--primary-bg);
    color: var(--primary);
    border: 1px solid var(--primary);
    border-radius: 9px;
    padding: 6px 11px;
    font-size: 11px;
    font-weight: 700;
    cursor: pointer;
    font-family: inherit;
    transition: 0.2s;
    margin-right: 4px;
}
.edit-btn:active { transform: scale(0.95); opacity: 0.8; }

.add-category-box {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
}

.inline-edit-box {
    background: var(--bg);
    border: 2px solid var(--primary);
    border-radius: 14px;
    padding: 14px;
    margin-top: 8px;
    margin-bottom: 8px;
    box-shadow: 0 6px 20px var(--primary-glow);
    display: flex;
    flex-direction: column;
    gap: 10px;
    animation: fadeIn 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}
.inline-edit-inputs {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}
.inline-edit-actions {
    display: flex;
    justify-content: flex-end;
    gap: 6px;
    margin-top: 4px;
}
.inline-save-btn {
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 10px;
    padding: 7px 16px;
    font-size: 11px;
    font-weight: 700;
    cursor: pointer;
    font-family: inherit;
}
.inline-cancel-btn {
    background: var(--border);
    color: var(--text-main);
    border: none;
    border-radius: 10px;
    padding: 7px 16px;
    font-size: 11px;
    font-weight: 700;
    cursor: pointer;
    font-family: inherit;
}

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

.floating-btn-container {
    position: fixed;
    bottom: 15px;
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
    max-width: 440px;
    padding: 0 15px;
    z-index: 100;
    pointer-events: none;
}

button.primary-btn {
    width: 100%; padding: 15px; background: var(--primary); color: white;
    border: none; border-radius: 16px; font-size: 15px; font-weight: 800;
    cursor: pointer; transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1); 
    box-shadow: 0 8px 25px var(--primary-glow);
    font-family: inherit; pointer-events: auto;
}
button.primary-btn:hover { background: var(--primary-hover); }
button.primary-btn:active { transform: scale(0.97); }

button.primary-btn.disabled {
    background: var(--border);
    color: var(--text-muted);
    box-shadow: none;
    opacity: 0.6;
    cursor: not-allowed;
    pointer-events: none;
}

button.text-btn {
    background: none; border: none; color: var(--primary);
    font-size: 12px; font-weight: 700; cursor: pointer; padding: 3px;
}
button.text-btn:hover { text-decoration: underline; }

.practice-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 14px;
    background: var(--bg);
    padding: 10px 14px;
    border-radius: 16px;
    border: 1px solid var(--border);
}

.back-home-btn {
    background: var(--card);
    border: 1.5px solid var(--border);
    color: var(--text-muted);
    font-size: 11px;
    font-weight: 700;
    padding: 6px 12px;
    border-radius: 12px;
    cursor: pointer;
    transition: 0.2s;
    font-family: inherit;
}
.back-home-btn:hover { border-color: var(--primary); color: var(--primary); }
.back-home-btn:active { transform: scale(0.95); }

.progress { 
    font-size: 12px; font-weight: 700; color: var(--text-muted);
}

.flip-card-container {
    background-color: transparent;
    width: 100%;
    height: 170px;
    perspective: 1000px;
    margin-bottom: 14px;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.flip-card-inner {
    position: relative;
    width: 100%;
    height: 100%;
    text-align: center;
    transition: transform 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
    transform-style: preserve-3d;
}

.flip-card-inner.flipped {
    transform: rotateY(180deg);
}

.flip-card-front, .flip-card-back {
    position: absolute;
    width: 100%;
    height: 100%;
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
    border-radius: 22px;
    border: 2px solid var(--border);
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 14px;
    transition: border-color 0.4s ease, background-color 0.4s ease;
}

.flip-card-front { background: var(--card); }
.flip-card-back { background: var(--primary-bg); border-color: var(--primary); transform: rotateY(180deg); }

.question-text { 
    font-size: 56px; font-weight: 800; margin: 0; line-height: 1.1; 
    color: var(--text-main);
}

.answer-text {
    font-size: 48px; font-weight: 800; margin: 0; line-height: 1.1; 
    color: var(--primary);
}

.note-text-display {
    font-size: 13px; font-weight: 700; color: var(--text-muted); margin-top: 8px;
}

.tag {
    position: absolute; top: 12px; right: 12px;
    background: var(--primary); color: white;
    padding: 4px 10px; border-radius: 8px; font-size: 10px; font-weight: 700;
}

.audio-btn {
    position: absolute; top: 12px; left: 12px;
    background: var(--bg); border: 1.5px solid var(--border); font-size: 14px;
    width: 38px; height: 38px; border-radius: 12px;
    cursor: pointer; display: flex; align-items: center; justify-content: center;
    transition: 0.2s; z-index: 10;
}
.audio-btn:hover { border-color: var(--primary); }
.audio-btn:active { transform: scale(0.9); }

.hint-text-label {
    position: absolute; bottom: 10px; font-size: 10px; color: var(--text-muted); font-weight: 600; opacity: 0.8;
}

input.answer-input {
    width: 100%; padding: 13px 15px; font-size: 19px; text-align: center;
    border: 2px solid var(--border); border-radius: 16px;
    background: var(--bg); color: var(--text-main); font-weight: 700;
    transition: all 0.25s ease; font-family: inherit; margin-bottom: 10px; outline: none;
}
input.answer-input:focus { border-color: var(--primary); background: var(--card); box-shadow: 0 0 0 4px var(--primary-glow); }

.choices-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.choice-btn {
    padding: 15px; font-size: 17px; font-weight: 700;
    border: 2px solid var(--border); background: var(--card);
    border-radius: 16px; cursor: pointer; transition: all 0.2s ease; color: var(--text-main); font-family: inherit;
    box-shadow: 0 3px 8px rgba(0,0,0,0.02);
}
.choice-btn:hover { border-color: var(--primary); color: var(--primary); }
.choice-btn:active { background: var(--primary-bg); border-color: var(--primary); transform: scale(0.96); }

.feedback { 
    text-align: center; 
    font-weight: 800; 
    font-size: 14px; 
    margin-bottom: 10px; 
    min-height: 24px; 
    transition: all 0.3s ease;
}
.text-error { 
    color: var(--error); 
    background-color: var(--error-bg); 
    padding: 7px 16px; 
    border-radius: 12px; 
    border: 1px solid var(--error);
    box-shadow: 0 4px 15px rgba(244, 63, 94, 0.15);
    animation: shake 0.4s; 
}
.text-success {
    color: var(--success);
    background-color: var(--success-bg);
    padding: 7px 16px;
    border-radius: 12px;
    border: 1px solid var(--success);
    box-shadow: 0 4px 15px rgba(16, 185, 129, 0.15);
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-4px); }
    75% { transform: translateX(4px); }
}

.mistake-list {
    background: var(--bg); padding: 16px; border-radius: 16px;
    margin-bottom: 16px; max-height: 200px; overflow-y: auto; border: 1.5px solid var(--border); line-height: 1.6;
}
.summary-btn { margin-bottom: 10px; margin-top: 0; box-shadow: 0 6px 20px var(--primary-glow); }
.summary-btn:active { transform: scale(0.98); }
