/**
 * Neural Network Digit Recognition - Styles
 *
 * Author: xiebingqiang@gmail.com
 * Site:   https://lab.xiebq.com/nn-visualizer/
 * Built with Claude Code (https://claude.ai/claude-code)
 */

/* -- Local fonts -- */
@font-face {
    font-family: 'Caveat';
    font-weight: 400;
    font-style: normal;
    font-display: swap;
    src: url('fonts/caveat-400.ttf') format('truetype');
}

@font-face {
    font-family: 'Caveat';
    font-weight: 700;
    font-style: normal;
    font-display: swap;
    src: url('fonts/caveat-700.ttf') format('truetype');
}

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

body {
    background: #ffffff;
    margin: 0;
    min-height: 100vh;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
}

/* -- Top toolbar -- */
#toolbar {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 24px;
    height: 48px;
    background: #fafafa;
    border-bottom: 1px solid #e5e7eb;
}

#back-link {
    display: flex;
    align-items: center;
    gap: 6px;
    color: #666;
    text-decoration: none;
    font-size: 13px;
    transition: color 0.15s;
}

#back-link:hover { color: #111; }

.toolbar-right {
    display: flex;
    align-items: center;
    gap: 10px;
}

#lang-toggle {
    display: flex;
    align-items: center;
    gap: 5px;
    background: none;
    border: 1px solid transparent;
    color: #666;
    font-size: 13px;
    cursor: pointer;
    padding: 5px 10px;
    border-radius: 6px;
    transition: all 0.15s;
    font-family: inherit;
}

#lang-toggle:hover {
    color: #111;
    background: #f0f0f0;
    border-color: #e5e7eb;
}

#download-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    background: #3b82f6;
    color: #fff;
    border: none;
    font-size: 13px;
    font-weight: 500;
    padding: 6px 14px;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.15s;
    font-family: inherit;
}

#download-btn:hover { background: #2563eb; }
#download-btn:disabled { opacity: 0.6; cursor: not-allowed; }

/* -- App container -- */
#app {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 12px 24px 16px;
    max-width: 760px;
    margin: 0 auto;
}

/* -- Page title -- */
#page-title {
    text-align: center;
    font-size: 18px;
    font-weight: 600;
    color: #222;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
}

/* -- Output section (digits + grid) -- */
#output-section {
    width: 100%;
}

/* -- Digit labels -- */
#digit-labels {
    display: flex;
    width: 100%;
    padding: 0 3px;
}

.digit-label {
    flex: 1;
    text-align: center;
    font-family: 'Caveat', cursive;
    font-size: 22px;
    font-weight: 700;
    color: #333;
    user-select: none;
    line-height: 1.2;
    padding-bottom: 1px;
}

/* -- Output grid -- */
#output-grid {
    display: flex;
    justify-content: space-between;
    width: 100%;
    padding: 0 3px;
}

.output-cell {
    width: 7.5%;
    aspect-ratio: 1;
    border: 1.5px solid #222;
    border-radius: 3px;
    background: #fff;
    position: relative;
    overflow: hidden;
}

.output-fill {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 0%;
    background: #222;
    transition: height 0.15s;
}

.output-pct {
    position: absolute;
    bottom: 2px;
    left: 0;
    right: 0;
    text-align: center;
    font-size: 9px;
    color: #666;
    z-index: 1;
    line-height: 1;
}

.output-pct.on-dark { color: #fff; }

/* -- Network container -- */
#network-container {
    width: 100%;
    background: #f4f4f4;
    border-radius: 10px;
    overflow: hidden;
    position: relative;
}

#network-svg {
    width: 100%;
    height: auto;
    display: block;
}

/* -- Narration overlay -- */
#narration {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 82%;
    max-width: 400px;
    background: rgba(255, 255, 255, 0.65);
    border-radius: 8px;
    padding: 6px 12px;
    font-size: 11px;
    line-height: 1.5;
    color: #555;
    pointer-events: none;
    transition: opacity 0.2s;
    opacity: 0;
    text-align: center;
}

#narration.visible { opacity: 1; }
#narration .num { font-weight: 600; color: #222; }
#narration .green { color: rgb(22, 163, 74); }
#narration .pink { color: rgb(219, 39, 119); }

/* -- Neuron tooltip -- */
#neuron-tooltip {
    position: absolute;
    pointer-events: none;
    opacity: 0;
    transform: translateX(-50%) translateY(4px);
    transition: opacity 0.15s, transform 0.15s;
    background: rgba(255, 255, 255, 0.82);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-radius: 10px;
    padding: 8px 10px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.12), 0 0 1px rgba(0,0,0,0.08);
    z-index: 20;
    min-width: 76px;
    text-align: center;
}

#neuron-tooltip.visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

#neuron-tooltip .tooltip-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 8px;
    margin-bottom: 5px;
}

#neuron-tooltip .tooltip-title {
    font-size: 11px;
    font-weight: 600;
    color: #333;
}

#neuron-tooltip .tooltip-activation {
    font-size: 10px;
    color: #888;
    font-variant-numeric: tabular-nums;
}

#neuron-tooltip .tooltip-canvas {
    display: block;
    margin: 0 auto;
    border-radius: 4px;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
}

#neuron-tooltip .tooltip-footer {
    font-size: 9px;
    color: #aaa;
    margin-top: 4px;
    line-height: 1.5;
}

#neuron-tooltip .tt-pos { color: rgb(34, 197, 94); }
#neuron-tooltip .tt-neg { color: rgb(236, 72, 153); }

#neuron-tooltip::after {
    content: '';
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    border: 5px solid transparent;
}

#neuron-tooltip.arrow-down::after {
    bottom: -10px;
    border-top-color: rgba(255, 255, 255, 0.82);
}

#neuron-tooltip.arrow-up::after {
    top: -10px;
    border-bottom-color: rgba(255, 255, 255, 0.82);
}

/* -- Intro text -- */
#intro {
    text-align: center;
    color: #999;
    font-size: 12px;
    line-height: 1.5;
    margin-top: 6px;
    padding: 0 12px;
}

/* -- Legend -- */
#legend {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 4px;
    margin: 2px 0 0;
    justify-content: center;
    padding: 0 4px;
}

.legend-line {
    display: inline-block;
    width: 14px;
    height: 2px;
    border-radius: 1px;
}

.legend-line.green { background: rgba(34, 197, 94, 0.7); }
.legend-line.pink { background: rgba(236, 72, 153, 0.7); }

.legend-sep {
    width: 1px;
    height: 12px;
    background: #ddd;
    margin: 0 2px;
}

.legend-box {
    display: inline-block;
    width: 10px;
    height: 10px;
    border: 1px solid #ccc;
    border-radius: 1px;
}

.legend-text {
    font-size: 11px;
    color: #999;
    margin-right: 2px;
}

.legend-text.muted { color: #bbb; }

.legend-check {
    font-size: 11px;
    color: #999;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 3px;
    user-select: none;
}

.legend-check input {
    margin: 0;
    cursor: pointer;
}

/* -- Draw section: canvas + clear stacked -- */
#draw-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    margin-top: 10px;
}

/* -- Canvas -- */
#canvas-container {
    position: relative;
    width: 260px;
    height: 260px;
    border-radius: 8px;
    overflow: hidden;
    background: #e8e8e8;
    cursor: crosshair;
    flex-shrink: 0;
}

#draw-canvas {
    position: absolute;
    top: 0; left: 0;
    width: 260px; height: 260px;
    z-index: 2;
}

#grid-canvas {
    position: absolute;
    top: 0; left: 0;
    width: 260px; height: 260px;
    z-index: 1;
    pointer-events: none;
}

/* -- Clear button -- */
#clear-btn {
    padding: 6px 36px;
    border-radius: 6px;
    border: 1.5px solid #d1d5db;
    background: #fff;
    font-size: 13px;
    font-weight: 500;
    color: #333;
    cursor: pointer;
    transition: all 0.15s;
    font-family: inherit;
    white-space: nowrap;
}

#clear-btn:hover {
    background: #f3f4f6;
    border-color: #9ca3af;
}

/* -- Responsive: mobile -- */
@media (max-width: 700px) {
    #app {
        padding: 10px 12px 12px;
    }

    #page-title { font-size: 15px; margin-bottom: 6px; }

    .digit-label { font-size: 20px; }

    #draw-section {
        flex-direction: column;
        align-items: center;
    }

    #canvas-container,
    #draw-canvas,
    #grid-canvas {
        width: 252px;
        height: 252px;
    }
}

@media (max-width: 540px) {
    #toolbar {
        padding: 0 12px;
        height: 44px;
    }

    #download-btn span,
    #back-link span { display: none; }

    #download-btn { padding: 6px 10px; }
    #lang-toggle { font-size: 12px; padding: 5px 8px; }

    #app { padding: 8px 8px 10px; }

    #page-title { font-size: 14px; }

    #intro { font-size: 11px; }

    .digit-label { font-size: 18px; }

    #output-grid { gap: 3px; }

    .output-pct { font-size: 7px; }

    #narration {
        font-size: 10px;
        padding: 5px 8px;
    }

    .legend-text, .legend-check { font-size: 10px; }

    #canvas-container,
    #draw-canvas,
    #grid-canvas {
        width: 224px;
        height: 224px;
    }
}
