:root {
    --bg-color: #121212;
    --text-color: #ffffff;
    --card-bg: #1e1e1e;
    --input-bg: #2d2d2d;
    --border-color: #555555;
    --hover-bg: #363636;
    --accent-color: #60a5fa;
    --success-color: #4ade80;
    --error-color: #f87171;
    --warning-color: #f6fa15;
    --info-color: #22d3ee;
}

body {
    font-family: 'M PLUS Rounded 1c', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    margin: 0;
    padding: 10px;
    box-sizing: border-box;
}

.container {
    text-align: center;
    width: 100%;
    max-width: 500px;
    background: rgba(30, 30, 30, 0.7);
    padding: 1.5rem;
    border-radius: 12px;
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    position: relative;
}

/* --- Controls & Header --- */
.top-controls {
    position: absolute;
    top: 1rem;
    right: 1rem;
    display: flex;
    gap: 8px;
    align-items: center;
}

.lang-toggle {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 8px;
    border-radius: 4px;
    border: 1px solid var(--border-color);
    font-size: 0.8rem;
    background: var(--input-bg);
    color: var(--text-color);
    user-select: none;
}

.lang-option {
    cursor: pointer;
    opacity: 0.5;
    transition: opacity 0.2s;
}

.lang-option:hover {
    opacity: 0.8;
}

.lang-option.active {
    opacity: 1;
    font-weight: bold;
    text-shadow: 0 0 5px rgba(255, 255, 255, 0.3);
}

.btn-help {
    background: var(--input-bg);
    border: 1px solid var(--border-color);
    color: var(--text-color);
    border-radius: 50%;
    width: 24px;
    height: 24px;
    font-size: 0.9rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
}

.btn-help:hover {
    background: var(--hover-bg);
    color: var(--accent-color);
}

header h1 {
    margin-top: 0;
    font-size: 1.5rem;
}

.mode-switch {
    margin-bottom: 1rem;
}

.mode-switch button {
    background: none;
    border: none;
    cursor: pointer;
    font-weight: bold;
    color: #b0b0b0;
    padding: 0.5rem;
    font-size: 0.9rem;
}

.mode-switch button:hover {
    color: #ffffff;
}

.mode-switch button.active {
    color: var(--accent-color);
    border-bottom: 2px solid var(--accent-color);
}

/* --- Display Area --- */
#display-area {
    height: 300px;
    background: #000000;
    margin: 1rem 0;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    border-radius: 8px;
    overflow: hidden;
    position: relative;
    border: 1px solid var(--border-color);
}

#sign-image {
    max-height: 100%;
    max-width: 100%;
    object-fit: contain;
}

#loading-msg {
    font-size: 1.2rem;
    color: #e0e0e0;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 100%;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8);
}

/* --- Inputs & Actions --- */
.input-area {
    margin-top: 1rem;
    width: 100%;
}

.input-area input {
    font-size: 1.5rem;
    padding: 0.75rem;
    width: 100%;
    text-align: center;
    border: 2px solid var(--border-color);
    border-radius: 6px;
    background: var(--input-bg);
    color: var(--text-color);
    box-sizing: border-box;
    transition: all 0.3s ease;
}

.input-area input:focus {
    border-color: var(--accent-color);
    outline: none;
    box-shadow: 0 0 10px var(--accent-color), 0 0 20px rgba(96, 165, 250, 0.4);
}

.input-area input::placeholder,
.input-area textarea::placeholder {
    color: #879dce;
}

#feedback {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    background: rgba(0, 0, 0, 0.7);
    padding: 8px 10px;
    box-sizing: border-box;
    text-align: center;
    font-weight: bold;
    font-size: 1.1rem;
    z-index: 10;
    pointer-events: none;
    /* Let clicks pass through to the image */
    backdrop-filter: blur(2px);
}

/* Automatically hide the feedback block if it's completely empty */
#feedback:empty {
    display: none;
}

#feedback a {
    pointer-events: auto;
    /* Allow clicking the dictionary links specifically */
    color: var(--accent-color);
    text-decoration: underline;
    margin: 0 5px;
    font-size: 0.9rem;
}

.correct {
    color: var(--success-color);
}

.incorrect {
    color: var(--error-color);
}

.warning {
    color: var(--warning-color);
}

.game-actions {
    display: flex;
    justify-content: center;
    gap: 8px;
    margin-top: 1rem;
    flex-wrap: wrap;
}

.game-actions button {
    padding: 12px 20px;
    font-size: 1rem;
    cursor: pointer;
    background: linear-gradient(135deg, var(--accent-color), #3b82f6);
    color: #000000;
    font-weight: bold;
    border: none;
    border-radius: 6px;
    transition: all 0.2s ease;
    flex: 1;
    min-width: 100px;
}

.game-actions button:hover {
    opacity: 0.9;
    transform: scale(1.02);
    box-shadow: 0 4px 12px rgba(96, 165, 250, 0.4);
}

#btn-skip {
    background: linear-gradient(135deg, var(--info-color), #0ea5e9);
}

#btn-skip:hover {
    box-shadow: 0 4px 12px rgba(34, 211, 238, 0.4);
}

button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* --- Settings & Controls --- */
.controls {
    margin-top: 1.5rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border-color);
}

.speed-control {
    margin-bottom: 1rem;
}

.presets button {
    font-size: 0.8rem;
    margin: 2px;
    padding: 4px 8px;
    cursor: pointer;
    border: 1px solid var(--border-color);
    background: var(--input-bg);
    color: var(--text-color);
    border-radius: 4px;
}

.presets button:hover {
    background: var(--hover-bg);
    border-color: var(--accent-color);
}

input[type="range"] {
    width: 100%;
    direction: rtl;
    margin: 10px 0;
}

select,
input[type="number"],
input[type="text"],
textarea {
    background: var(--input-bg);
    color: var(--text-color);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    padding: 4px;
}

select {
    max-width: 100%;
}

input[type="number"] {
    width: 50px;
}

textarea {
    width: 100%;
    box-sizing: border-box;
    resize: vertical;
    padding: 8px;
    font-family: inherit;
}

/* --- Advanced Options --- */
.advanced-options {
    text-align: left;
    margin-bottom: 1rem;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 0.5rem;
    font-size: 0.9rem;
    color: #ddd;
}

.advanced-options summary {
    cursor: pointer;
    font-weight: bold;
    outline: none;
    color: var(--text-color);
    text-align: center;
}

.advanced-options[open] summary {
    margin-bottom: 0.5rem;
}

.option-group {
    margin: 0.5rem 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.option-group label {
    margin-right: 10px;
    flex: 1;
    text-align: left;
}

.option-group select {
    flex: 0 0 auto;
}

/* --- Filtering & Checkboxes --- */
#row-selector-group {
    margin-top: 1rem;
    padding-top: 0.5rem;
    border-top: 1px solid var(--border-color);
    transition: opacity 0.3s;
}

#row-selector-group.disabled-group {
    opacity: 0.5;
    pointer-events: none;
}

.row-header {
    margin-bottom: 5px;
    font-size: 0.85rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.row-actions button {
    padding: 2px 8px;
    font-size: 0.75rem;
    margin-left: 5px;
    background: var(--input-bg);
    border: 1px solid var(--border-color);
    color: var(--text-color);
    border-radius: 4px;
    cursor: pointer;
}

.checkbox-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    max-height: 275px;
    overflow-y: auto;
    background: rgba(0, 0, 0, 0.2);
    padding: 5px;
    border-radius: 4px;
}

.checkbox-item {
    display: flex;
    align-items: center;
    font-size: 0.8rem;
    text-align: left;
    padding: 2px;
}

.checkbox-item input {
    margin-right: 8px;
    transform: scale(1.1);
}

.len-filter-inputs {
    display: flex;
    align-items: center;
    gap: 8px;
}

.len-filter-inputs span {
    font-size: 0.8rem;
}

#filter-stats {
    font-size: 0.9rem;
    margin-bottom: 8px;
    padding: 4px;
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.05);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.stats-count {
    font-weight: bold;
}

.stats-warn {
    color: var(--error-color);
    display: none;
}

.stats-warn.visible {
    display: inline;
    margin-left: 5px;
}

/* --- Feedback & Score --- */
#share-section {
    margin-top: 1rem;
    padding: 1rem;
    background: var(--input-bg);
    border-radius: 8px;
    border: 1px solid var(--border-color);
}

#btn-share {
    background: linear-gradient(135deg, var(--success-color), #22c55e);
    color: black;
    border: none;
    padding: 8px 16px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 1rem;
    font-weight: bold;
    transition: all 0.2s ease;
}

#btn-share:hover {
    opacity: 0.9;
    transform: scale(1.02);
    box-shadow: 0 4px 12px rgba(74, 222, 128, 0.4);
}

#practice-score-container {
    margin-top: 1rem;
    padding: 0.5rem;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 6px;
    font-weight: bold;
    color: var(--success-color);
}

.hidden {
    display: none !important;
}

/* --- Modal --- */
.modal {
    border: none;
    background: transparent;
    padding: 0;
    margin: auto;
    overflow: visible;
}

.modal::backdrop {
    background-color: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(2px);
}

.modal-content {
    background: rgba(30, 30, 30, 0.7);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    padding: 2rem;
    border-radius: 12px;
    max-width: 600px;
    width: 85%;
    max-height: 90vh;
    overflow-y: auto;
    position: relative;
    text-align: left;
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.7);
    color: var(--text-color);
    line-height: 1.6;
}

.close-btn {
    position: absolute;
    top: 1rem;
    right: 1rem;
    font-size: 1.5rem;
    cursor: pointer;
    background: none;
    border: none;
    color: var(--text-color);
    padding: 5px;
    line-height: 1;
}

.modal-body h2 {
    margin-top: 0;
    color: var(--accent-color);
}

.modal-body ol {
    padding-left: 1.2rem;
}

.modal-body li {
    margin-bottom: 0.5rem;
}

/* --- Stats Modal Specifics --- */
.stats-content {
    max-width: 800px;
    display: block;
}

.stats-explanation {
    font-size: 0.85rem;
    color: #aaa;
    margin-top: -10px;
    margin-bottom: 15px;
    font-style: italic;
}

.stats-summary {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border-color);
}

.stats-graph-container {
    height: auto;
    overflow-y: visible;
    padding-right: 0;
}

.stats-row {
    display: flex;
    align-items: center;
    margin-bottom: 6px;
    font-size: 0.9rem;
}

.stats-label {
    width: 40px;
    font-weight: bold;
    flex-shrink: 0;
}

.stats-bar-area {
    flex: 1;
    background: rgba(255, 255, 255, 0.05);
    height: 18px;
    border-radius: 4px;
    overflow: hidden;
    position: relative;
    display: flex;
    align-items: center;
}

/* Stacked Bar Segments */
.bar-segment {
    height: 100%;
    transition: width 0.5s ease-out;
}

.bar-history {
    background-color: #3b82f6;
    /* Darker Blue */
    opacity: 0.6;
}

.bar-today {
    background-color: var(--accent-color);
    /* Bright Blue */
    box-shadow: 0 0 5px var(--accent-color);
    z-index: 2;
}

.stats-count-text {
    margin-left: 8px;
    font-size: 0.8rem;
    color: #aaa;
    min-width: 30px;
}

/* Tooltip on hover */
.stats-row:hover .stats-bar-area {
    background: rgba(255, 255, 255, 0.1);
}

/* Toggle Switch */
.toggle-switch {
    position: relative;
    display: inline-flex;
    align-items: center;
    cursor: pointer;
    gap: 8px;
}

.toggle-switch input {
    display: none;
}

.toggle-switch .slider {
    position: relative;
    width: 36px;
    height: 20px;
    background-color: #555;
    border-radius: 20px;
    transition: .4s;
    display: inline-block;
}

.toggle-switch .slider:before {
    position: absolute;
    content: "";
    height: 16px;
    width: 16px;
    left: 2px;
    bottom: 2px;
    background-color: white;
    border-radius: 50%;
    transition: .4s;
}

.toggle-switch input:checked+.slider {
    background-color: var(--accent-color);
}

.toggle-switch input:checked+.slider:before {
    transform: translateX(16px);
}

.label-text {
    font-size: 0.9rem;
}

/* Weakest Controls */
.stats-controls-row {
    margin-bottom: 1rem;
    padding-bottom: 1rem;
    border-bottom: 1px dashed var(--border-color);
}

.weakest-controls {
    display: flex;
    align-items: center;
    gap: 10px;
    justify-content: flex-start;
}

#btn-study-weakest {
    background-color: var(--info-color);
    color: black;
    border: none;
    padding: 6px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: bold;
    transition: opacity 0.2s;
}

#btn-study-weakest:hover {
    opacity: 0.8;
}

#weakest-threshold {
    width: 50px;
    padding: 5px;
    text-align: center;
}

/* --- Export/Import UI --- */
.stats-export-import {
    margin-bottom: 1rem;
    border: 1px solid var(--border-color);
    padding: 0.5rem;
    border-radius: 6px;
}

.stats-export-import summary {
    cursor: pointer;
    font-weight: bold;
    color: var(--accent-color);
    margin-bottom: 0.5rem;
}

.export-import-actions {
    display: flex;
    gap: 10px;
    margin-top: 5px;
}

.export-import-actions button {
    flex: 1;
    padding: 6px;
    cursor: pointer;
    background-color: var(--input-bg);
    border: 1px solid var(--border-color);
    color: var(--text-color);
    border-radius: 4px;
}

.export-import-actions button:hover {
    background-color: var(--hover-bg);
    border-color: var(--accent-color);
}

.error-msg {
    color: var(--error-color);
    font-size: 0.9rem;
    margin-top: 5px;
}

/* --- Debug UI --- */
.debug-section {
    margin-top: 1rem;
    text-align: center;
}

.btn-debug {
    background-color: transparent;
    border: 1px solid var(--border-color);
    color: #888;
    font-size: 0.8rem;
    padding: 8px 16px;
    border-radius: 4px;
    cursor: pointer;
    width: 100%;
}

.btn-debug:hover {
    background-color: rgba(255, 255, 255, 0.05);
    color: var(--text-color);
}

/* --- Utilities --- */
.section-divider {
    margin-bottom: 1rem;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 1rem;
}

.custom-words-label {
    display: block;
    margin-bottom: 5px;
}

.len-filter-toggle {
    justify-content: flex-start;
    margin-bottom: 8px;
}

.len-filter-toggle label {
    flex: 0 0 auto;
    margin-right: 8px;
}

.len-filter-group {
    padding-left: 1.5rem;
    margin-bottom: 12px;
}

.warning-setting-group {
    margin-top: 1.5rem;
    justify-content: flex-start;
    border-top: 1px dashed var(--border-color);
    padding-top: 1rem;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
}

/* --- Warning Modal Specifics --- */
.warning-modal-content {
    max-width: 400px;
    text-align: center;
}

.warning-title {
    color: var(--warning-color);
    margin-top: 0;
    margin-bottom: 1rem;
}

.warning-modal-body {
    text-align: left;
}

.warning-actions {
    margin-top: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

#warning-dont-show {
    transform: scale(1.2);
}

#btn-dismiss-warning {
    background-color: var(--warning-color);
    color: black;
    border: none;
    padding: 12px;
    border-radius: 6px;
    font-size: 1rem;
    font-weight: bold;
    cursor: pointer;
    transition: opacity 0.2s;
}

#btn-dismiss-warning:hover {
    opacity: 0.8;
}

/* --- Mobile --- */
@media (max-width: 600px) {
    .container {
        padding: 1rem;
        width: 100%;
    }

    header h1 {
        font-size: 1.3rem;
        margin-right: 4rem;
        text-align: left;
    }

    .top-controls {
        top: 0.8rem;
        right: 0.8rem;
    }

    #display-area {
        height: auto;
        aspect-ratio: 4/3;
        max-height: 40vh;
        margin-left: auto;
        margin-right: auto;
        margin-bottom: 0px;
    }

    .game-actions {
        margin-top: 4px;
    }

    .game-actions button {
        padding: 2px;
        font-size: 0.9rem;
        min-width: 80px;
    }

    .input-area {
        margin-top: 4px;
    }

    .input-area input {
        font-size: 1.2rem;
    }

    #word-list-container {
        flex-direction: column;
        align-items: stretch;
        text-align: left;
    }

    #word-list-container label {
        margin-bottom: 4px;
    }
}

/* --- Gamification Animations --- */
@keyframes shakeHorizontal {
    0%, 100% { transform: translateX(0); }
    10%, 30%, 50%, 70%, 90% { transform: translateX(-5px); }
    20%, 40%, 60%, 80% { transform: translateX(5px); }
}

@keyframes flashSuccess {
    0%, 100% {
        box-shadow: none;
        border-color: var(--border-color);
    }
    50% {
        box-shadow: 0 0 15px var(--success-color);
        border-color: var(--success-color);
    }
}

@keyframes checkmarkPop {
    0% { transform: scale(0); opacity: 0; }
    70% { transform: scale(1.2); opacity: 1; }
    100% { transform: scale(1); opacity: 1; }
}

.anim-shake {
    animation: shakeHorizontal 0.4s ease-in-out;
}

.anim-flash-success {
    animation: flashSuccess 0.4s ease-in-out;
}

.checkmark-icon {
    display: inline-block;
    animation: checkmarkPop 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
    font-size: 1.2em;
    margin-right: 5px;
}

/* --- Animations --- */
@keyframes slideLeft {
    from {
        transform: translateX(0);
    }

    to {
        transform: translateX(-40px);
    }
}

@keyframes slideUp {
    from {
        transform: translateY(0);
    }

    to {
        transform: translateY(-40px);
    }
}

@keyframes shrinkUpRight {
    from {
        transform: scale(1) translate(0, 0);
    }

    to {
        transform: scale(0.88) translate(10px, -10px);
    }
}

@keyframes bounce {
    0% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-10px);
    }

    100% {
        transform: translateY(0);
    }
}

.anim-slide-left {
    animation-name: slideLeft;
    animation-timing-function: cubic-bezier(0.4, 0.0, 0.2, 1);
    animation-fill-mode: forwards;
}

.anim-slide-up {
    animation-name: slideUp;
    animation-timing-function: cubic-bezier(0.4, 0.0, 0.2, 1);
    animation-fill-mode: forwards;
}

.anim-shrink-right {
    animation-name: shrinkUpRight;
    animation-timing-function: cubic-bezier(0.4, 0.0, 0.2, 1);
    animation-fill-mode: forwards;
}

.anim-bounce {
    animation-name: bounce;
    animation-timing-function: ease-in-out;
}

/* --- Animation Utilities --- */
@keyframes flashPulse {
    0% {
        background-color: var(--input-bg);
        color: var(--text-color);
        box-shadow: none;
        border-color: var(--border-color);
    }

    50% {
        background-color: var(--info-color);
        /* Bright Cyan */
        color: #000;
        box-shadow: 0 0 15px var(--info-color);
        border-color: var(--info-color);
    }

    100% {
        background-color: var(--input-bg);
        color: var(--text-color);
        box-shadow: none;
        border-color: var(--border-color);
    }
}

.input-flash {
    /* 400ms per flash x 2 iterations = 800ms total time */
    animation: flashPulse 400ms ease-in-out 2;
}

/* --- Footer --- */
footer a {
    color: var(--accent-color);
    text-decoration: none;
}

footer a:hover {
    text-decoration: underline;
}

.jmdict-credit {
    font-size: 0.75rem;
    color: #888;
    margin: 10px auto;
    max-width: 90%;
    line-height: 1.4;
}

.jmdict-credit a {
    color: #888;
    text-decoration: underline;
}

.jmdict-credit a:hover {
    color: var(--accent-color);
}