:root {
    --bg: #F5F5F0;
    --ink: #000000;
    --answer-ink: #333333;
    --line-color: #DDDDD8;
    --toolbar-bg: rgba(245, 245, 240, 0.92);
    --toolbar-border: #000000;
    --btn-bg: #FFFFFF;
    --btn-hover: #E8E8E3;
    --btn-active-bg: #000000;
    --btn-active-fg: #FFFFFF;
    --danger-bg: #FFFFFF;
    --danger-border: #000000;
    --confirm-bg: #FFFFFF;
    --confirm-shadow: rgba(0,0,0,0.2);
    --badge-bg: rgba(245,245,240,0.95);
    --font-ui: 'IBM Plex Sans', system-ui, sans-serif;
    --font-hand: 'Caveat', cursive;
}

body.dark-mode {
    --bg: #1A1A1A;
    --ink: #E8E8E3;
    --answer-ink: #BBBBBB;
    --line-color: #2A2A2A;
    --toolbar-bg: rgba(26, 26, 26, 0.92);
    --toolbar-border: #E8E8E3;
    --btn-bg: #2A2A2A;
    --btn-hover: #3A3A3A;
    --btn-active-bg: #E8E8E3;
    --btn-active-fg: #1A1A1A;
    --danger-bg: #2A2A2A;
    --danger-border: #E8E8E3;
    --confirm-bg: #2A2A2A;
    --confirm-shadow: rgba(0,0,0,0.5);
    --badge-bg: rgba(26,26,26,0.95);
}

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

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    font-family: var(--font-ui);
    background: var(--bg);
    touch-action: none;
    -webkit-user-select: none;
    user-select: none;
}

canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    touch-action: none;
}

#canvas-bg {
    z-index: 1;
}

#canvas-strokes {
    z-index: 2;
}

#canvas-active {
    z-index: 3;
}

#toolbar {
    position: fixed;
    bottom: 16px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 100;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    background: var(--toolbar-bg);
    border: 2.5px solid var(--toolbar-border);
    border-radius: 16px;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    transition: opacity 0.4s ease, transform 0.4s ease;
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
}

#toolbar.hidden-toolbar {
    opacity: 0;
    transform: translateX(-50%) translateY(20px);
    pointer-events: none;
}

.toolbar-btn {
    width: 56px;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--btn-bg);
    border: 2.5px solid var(--toolbar-border);
    border-radius: 12px;
    color: var(--ink);
    cursor: pointer;
    transition: background 0.15s, transform 0.1s;
    flex-shrink: 0;
}

.toolbar-btn:hover {
    background: var(--btn-hover);
}

.toolbar-btn:active {
    transform: scale(0.92);
}

.toolbar-btn.active {
    background: var(--btn-active-bg);
    color: var(--btn-active-fg);
}

.toolbar-btn.btn-danger {
    background: var(--danger-bg);
    border-color: var(--danger-border);
}

#toolbar-footer {
    width: 100%;
    text-align: center;
    margin-top: 4px;
}

#toolbar-footer a {
    font-size: 10px;
    color: var(--ink);
    opacity: 0.3;
    text-decoration: none;
    font-family: var(--font-ui);
}

#toolbar-footer a:hover {
    opacity: 0.6;
}

#confirm-dialog {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0,0,0,0.3);
}

#confirm-dialog.hidden {
    display: none;
}

.confirm-content {
    background: var(--confirm-bg);
    border: 2.5px solid var(--toolbar-border);
    border-radius: 16px;
    padding: 28px 36px;
    text-align: center;
    box-shadow: 0 8px 32px var(--confirm-shadow);
}

.confirm-content p {
    font-family: var(--font-ui);
    font-size: 18px;
    font-weight: 600;
    color: var(--ink);
    margin-bottom: 20px;
}

.confirm-buttons {
    display: flex;
    gap: 12px;
    justify-content: center;
}

.confirm-btn {
    padding: 12px 28px;
    font-family: var(--font-ui);
    font-size: 15px;
    font-weight: 600;
    border: 2.5px solid var(--toolbar-border);
    border-radius: 10px;
    cursor: pointer;
    background: var(--btn-bg);
    color: var(--ink);
    transition: background 0.15s;
    min-width: 100px;
}

.confirm-btn:hover {
    background: var(--btn-hover);
}

#confirm-yes {
    background: var(--btn-active-bg);
    color: var(--btn-active-fg);
}

#recognition-badge {
    position: fixed;
    top: 16px;
    right: 16px;
    z-index: 100;
    padding: 8px 16px;
    background: var(--badge-bg);
    border: 2px solid var(--toolbar-border);
    border-radius: 10px;
    font-family: var(--font-ui);
    font-size: 13px;
    color: var(--ink);
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    transition: opacity 0.3s;
    max-width: 300px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

#recognition-badge.hidden {
    display: none;
}

#solve-indicator {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 150;
    padding: 12px 24px;
    background: var(--badge-bg);
    border: 2px solid var(--toolbar-border);
    border-radius: 12px;
    font-family: var(--font-ui);
    font-size: 14px;
    color: var(--ink);
    opacity: 0.9;
}

#solve-indicator.hidden {
    display: none;
}

@media (max-width: 500px) {
    .toolbar-btn {
        width: 48px;
        height: 48px;
    }
    
    #toolbar {
        gap: 6px;
        padding: 8px 12px;
        bottom: 10px;
    }
}