* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: #0d1117;
    color: #e6edf3;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
}

.container {
    text-align: center;
    padding: 2rem;
}

h1 { font-size: 2rem; margin-bottom: 0.25rem; }
.subtitle { color: #8b949e; margin-bottom: 1rem; }

/* ── API Config ────────────────────────── */
.api-config {
    margin-bottom: 1.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.api-config label {
    font-size: 0.85rem;
    color: #8b949e;
}

.api-config input {
    width: 420px;
    max-width: 80vw;
    padding: 0.45rem 0.75rem;
    border: 1px solid #30363d;
    border-radius: 6px;
    background: #161b22;
    color: #e6edf3;
    font-size: 0.85rem;
    font-family: monospace;
}

/* ── Mode Toggle ───────────────────────── */
.mode-toggle {
    display: inline-flex;
    border: 1px solid #30363d;
    border-radius: 10px;
    overflow: hidden;
    margin-bottom: 2rem;
}

.toggle-btn {
    padding: 0.6rem 1.4rem;
    background: #161b22;
    color: #8b949e;
    border: none;
    font-size: 0.95rem;
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
}

.toggle-btn + .toggle-btn { border-left: 1px solid #30363d; }

.toggle-btn.active {
    background: #238636;
    color: #fff;
    font-weight: 600;
}

.toggle-btn:hover:not(.active) {
    background: #21262d;
    color: #c9d1d9;
}

/* ── Main Layout ───────────────────────── */
.main-area {
    display: flex;
    gap: 3rem;
    align-items: flex-start;
    justify-content: center;
    flex-wrap: wrap;
}

.input-section {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.mode-panel { display: none; flex-direction: column; align-items: center; }
.mode-panel.active { display: flex; }

/* ── Canvas ────────────────────────────── */
canvas {
    border: 2px solid #30363d;
    border-radius: 12px;
    cursor: crosshair;
    background: #000;
    touch-action: none;
}

/* ── Upload Area ───────────────────────── */
.upload-area {
    width: 280px;
    height: 280px;
    border: 2px dashed #30363d;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: border-color 0.2s, background 0.2s;
    overflow: hidden;
    background: #0d1117;
    position: relative;
}

.upload-area:hover,
.upload-area.drag-over {
    border-color: #58a6ff;
    background: #161b22;
}

.upload-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.4rem;
    color: #8b949e;
}

.upload-icon { font-size: 2.5rem; margin-bottom: 0.3rem; }
.upload-hint { font-size: 0.75rem; color: #484f58; }

.image-preview {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border-radius: 10px;
}

.hidden { display: none !important; }

/* ── Buttons ───────────────────────────── */
.button-row { margin-top: 1rem; display: flex; gap: 1rem; }

.btn {
    padding: 0.6rem 1.6rem;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    cursor: pointer;
    font-weight: 600;
    transition: opacity 0.2s;
}
.btn:hover { opacity: 0.85; }

.btn-clear {
    background: #21262d;
    color: #c9d1d9;
    border: 1px solid #30363d;
}

.btn-predict { background: #238636; color: #fff; }

/* ── Result ────────────────────────────── */
.result-section { min-width: 260px; }

.prediction-box {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: 1.5rem;
}

.prediction-box .label {
    font-size: 0.85rem;
    color: #8b949e;
    text-transform: uppercase;
    letter-spacing: 0.1em;
}

.prediction-box .digit {
    font-size: 5rem;
    font-weight: 700;
    line-height: 1.1;
    color: #58a6ff;
}

/* ── Confidence bars ───────────────────── */
.confidence-bars { width: 100%; }

.bar-row {
    display: flex;
    align-items: center;
    margin-bottom: 0.35rem;
    font-size: 0.85rem;
}

.bar-label {
    width: 1.2rem;
    text-align: right;
    margin-right: 0.5rem;
    color: #8b949e;
}

.bar-track {
    flex: 1;
    height: 14px;
    background: #161b22;
    border-radius: 7px;
    overflow: hidden;
}

.bar-fill {
    height: 100%;
    border-radius: 7px;
    background: #238636;
    transition: width 0.4s ease;
}

.bar-fill.highlight { background: #58a6ff; }

.bar-value {
    width: 3rem;
    text-align: right;
    margin-left: 0.5rem;
    color: #8b949e;
    font-variant-numeric: tabular-nums;
}

/* ── Responsive ────────────────────────── */

/* Tablet and below (≤768px) */
@media (max-width: 768px) {
    body {
        align-items: flex-start;
        padding: 0;
    }

    .container {
        padding: 1.25rem 1rem;
        width: 100%;
        max-width: 100%;
    }

    h1 {
        font-size: 1.35rem;
        line-height: 1.3;
    }

    .subtitle {
        font-size: 0.85rem;
    }

    .main-area {
        flex-direction: column;
        align-items: center;
        gap: 1.5rem;
    }

    .input-section {
        width: 100%;
        align-items: center;
    }

    .result-section {
        min-width: unset;
        width: 100%;
        max-width: 100%;
        padding: 0 0.5rem;
        box-sizing: border-box;
    }

    .confidence-bars {
        width: 100%;
    }
}

/* Mobile (≤480px) */
@media (max-width: 480px) {
    h1 {
        font-size: 1.05rem;
        line-height: 1.4;
        padding: 0 0.25rem;
    }

    .subtitle {
        font-size: 0.8rem;
        padding: 0 0.5rem;
        margin-bottom: 1rem;
    }

    .mode-toggle {
        display: flex;
        width: 100%;
        margin-bottom: 1.25rem;
    }

    .toggle-btn {
        flex: 1;
        padding: 0.6rem 0.5rem;
        font-size: 0.85rem;
    }

    /* Canvas scales to viewport width with padding */
    .mode-panel.active {
        width: 100%;
        align-items: center;
    }

    canvas {
        width: min(280px, 88vw) !important;
        height: min(280px, 88vw) !important;
    }

    .upload-area {
        width: min(280px, 88vw);
        height: min(280px, 88vw);
    }

    .button-row {
        width: min(280px, 88vw);
        display: flex;
        gap: 0.75rem;
        margin-top: 0.85rem;
    }

    .btn {
        flex: 1;
        padding: 0.65rem 0;
        font-size: 0.95rem;
    }

    .prediction-box {
        display: flex;
        flex-direction: row;
        align-items: center;
        justify-content: center;
        gap: 1rem;
        margin-bottom: 1rem;
    }

    .prediction-box .label {
        font-size: 0.8rem;
    }

    .prediction-box .digit {
        font-size: 3.5rem;
    }

    .bar-row {
        font-size: 0.8rem;
        margin-bottom: 0.3rem;
    }

    .bar-track {
        height: 12px;
    }

    .bar-value {
        width: 2.8rem;
        font-size: 0.75rem;
    }
}
