:root {
    --primary-color: #ff9a9e;
    --secondary-color: #fecfef;
    --text-color: #555;
    --bg-color: #fafafa;
    --canvas-bg: #fff;
}

body {
    font-family: "UD Digi Kyokasho N-R", "UD Digi Kyokasho NP-R", "UD Digi Kyokasho", "BIZ UDPGothic", "Hiragino Maru Gothic Pro", sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    margin: 0;
    overflow: hidden;
    /* Prevent body scroll */
}

.main-layout {
    display: flex;
    width: 100vw;
    height: 100vh;
    flex-direction: row-reverse;
    /* Sidebar on Right */
}

.sidebar {
    width: 80px;
    background: #fff;
    border-left: 2px solid var(--secondary-color);
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 20px 0;
    overflow-y: auto;
    gap: 10px;
    box-shadow: -5px 0 15px rgba(0, 0, 0, 0.05);
    z-index: 9999;
    /* Aggressively high z-index */
    position: relative;
    pointer-events: auto;
    /* Ensure clicks are captured */
}

.content {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    position: relative;
}

.sidebar-btn {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: #f0f0f0;
    border: none;
    color: var(--text-color);
    font-weight: bold;
    font-size: 1.2rem;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 0;
    font-family: inherit;
}

.sidebar-btn:hover {
    background: var(--secondary-color);
    color: #fff;
}

.sidebar-btn.active {
    background: var(--primary-color);
    color: #fff;
    transform: scale(1.1);
    box-shadow: 0 4px 10px rgba(255, 118, 117, 0.4);
}

.separator {
    width: 60%;
    height: 2px;
    background: #eee;
    margin: 5px 0;
}

/* Adjust Canvas Area for layout */
.canvas-wrapper {
    position: relative;
    width: min(80vw, 400px);
    height: min(80vw, 400px);
    /* ... rest same ... */

    margin: 0 auto 20px;
    background-color: var(--canvas-bg);
    border-radius: 20px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
    overflow: hidden;
    /* Optional: Add a grid or paper texture here */
    border: 4px solid var(--secondary-color);
}

#guide-layer,
#drawing-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

#guide-layer {
    pointer-events: none;
}

#drawing-layer {
    pointer-events: auto;
    cursor: crosshair;
}

/* Adjust canvas resolution vs display size */
/* drawing-layer fits wrapper */


.controls {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 20px;
    margin-bottom: 20px;
}

#current-char-display {
    font-size: 2rem;
    font-weight: bold;
    width: 60px;
}

button {
    background-color: var(--primary-color);
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 50px;
    font-size: 1rem;
    cursor: pointer;
    transition: transform 0.1s, background-color 0.2s;
    font-family: inherit;
}

button:active {
    transform: scale(0.95);
}

button:hover {
    background-color: #ff7675;
}

.reset-btn {
    background-color: #74b9ff;
}

.reset-btn:hover {
    background-color: #0984e3;
}

.feedback {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(255, 255, 255, 0.95);
    padding: 20px 60px;
    border-radius: 50px;
    font-size: 2.5rem;
    font-weight: bold;
    color: #ff6b6b;
    border: 4px solid #ff6b6b;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s;
    white-space: nowrap;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    z-index: 100;
}

.feedback.show {
    opacity: 1;
    animation: popIn 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes popIn {
    0% {
        transform: translate(-50%, -50%) scale(0.5);
    }

    100% {
        transform: translate(-50%, -50%) scale(1);
    }
}

.hidden {
    display: none !important;
}

.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.9);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 5px solid #f3f3f3;
    border-top: 5px solid var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 20px;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

.settings {
    margin-bottom: 10px;
}

select {
    padding: 8px 16px;
    font-size: 1rem;
    border-radius: 20px;
    border: 2px solid var(--primary-color);
    color: var(--text-color);
    font-family: inherit;
    outline: none;
}

/* Floating Action Button for Settings */
.fab-settings {
    position: fixed;
    top: 20px;
    left: 20px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background-color: #fff;
    border: 3px solid var(--primary-color);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
    font-size: 2rem;
    z-index: 100001;
    /* Higher than EVERYTHING */
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    padding: 0;
    transition: transform 0.2s, background-color 0.2s;
}

.fab-settings:hover {
    transform: scale(1.1);
    background-color: #ffe0e0;
}


/* Modal Styles */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100000;
    backdrop-filter: blur(5px);
}

.modal-content {
    background: #fff;
    padding: 30px;
    border-radius: 20px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    width: 90%;
    max-width: 500px;
    max-height: 80vh;
    overflow-y: auto;
    text-align: center;
    position: relative;
    border: 4px solid var(--secondary-color);
}

.modal-actions {
    margin-top: 20px;
    display: flex;
    justify-content: center;
    gap: 10px;
}

.char-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 10px;
    margin: 20px 0;
}

.char-toggle {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 2px solid #ddd;
    border: 2px solid #ddd;
    background: #fff;
    cursor: pointer;
    font-weight: bold;
    color: #555;
    transition: all 0.2s;
    position: relative;
    /* For badge positioning */
}

.char-toggle.selected {
    background: var(--primary-color);
    color: #fff;
    border-color: var(--primary-color);
    box-shadow: 0 4px 10px rgba(255, 107, 107, 0.3);
}

.settings-panel p {
    margin-bottom: 20px;
    color: #888;
}

.mode-switch {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin-bottom: 20px;
    font-weight: bold;
}

.mode-switch label {
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
}

.primary-btn-large {
    background: var(--primary-color);
    color: white;
    border: none;
    padding: 12px 30px;
    border-radius: 50px;
    font-size: 1.2rem;
    font-weight: bold;
    cursor: pointer;
    width: 100%;
    margin-top: 20px;
    box-shadow: 0 4px 10px rgba(255, 107, 107, 0.4);
    transition: transform 0.1s, background-color 0.2s;
}

.primary-btn-large:active {
    transform: scale(0.98);
}

.selection-preview-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 10px;
    background: #f9f9f9;
    border-radius: 10px;
    min-height: 50px;
    max-height: 120px;
    overflow-y: auto;
    border: 2px dashed #ddd;
    align-items: center;
}

.preview-item {
    background: var(--primary-color);
    color: white;
    padding: 5px 12px;
    border-radius: 20px;
    font-weight: bold;
    cursor: pointer;
    position: relative;
    user-select: none;
    animation: popIn 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.preview-item:hover {
    background: #ff7675;
}

.preview-item::after {
    content: "×";
    margin-left: 5px;
    font-size: 0.8rem;
    opacity: 0.7;
}

.placeholder-text {
    color: #ccc;
    font-size: 0.9rem;
    width: 100%;
    text-align: center;
}