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

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

header {
    background: linear-gradient(135deg, #0ea5e9 0%, #06b6d4 50%, #10b981 100%);
    color: white;
    padding: 16px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 2px 12px rgba(14,165,233,0.2);
}

header h1 {
    font-size: 22px;
    font-weight: 600;
}

.header-actions {
    display: flex;
    gap: 10px;
    align-items: center;
}

.btn {
    padding: 8px 20px;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-primary {
    background: #4CAF50;
    color: white;
}

.btn-primary:hover {
    background: #45a049;
}

.btn-primary:disabled {
    background: #a5d6a7;
    cursor: not-allowed;
}

.btn-secondary {
    background: rgba(255,255,255,0.2);
    color: white;
}

.btn-secondary:hover {
    background: rgba(255,255,255,0.3);
}

.btn-danger {
    background: #f44336;
    color: white;
}

.btn-danger:hover {
    background: #da190b;
}

.btn-info {
    background: #2196F3;
    color: white;
}

.btn-info:hover {
    background: #1976D2;
}

.btn-info:disabled {
    background: #90caf9;
    cursor: not-allowed;
}

.btn-warning {
    background: #ff9800;
    color: white;
}

.btn-warning:hover {
    background: #e68900;
}

.btn-warning:disabled {
    background: #ffcc80;
    cursor: not-allowed;
}

.btn-success {
    background: #4CAF50;
    color: white;
}

.btn-success:hover {
    background: #388E3C;
}

.main-container {
    display: flex;
    gap: 20px;
    padding: 20px;
    max-width: 1400px;
    margin: 0 auto;
    min-height: calc(100vh - 64px);
}

.left-panel {
    flex: 1;
    min-width: 0;
}

.right-panel {
    width: 340px;
    flex-shrink: 0;
}

.panel {
    background: white;
    border-radius: 10px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
    margin-bottom: 16px;
    overflow: hidden;
}

.panel-header {
    padding: 12px 16px;
    background: #f8f9fa;
    border-bottom: 1px solid #eee;
    font-weight: 600;
    font-size: 14px;
    color: #555;
}

.panel-body {
    padding: 16px;
}

.canvas-wrapper {
    position: relative;
    width: 100%;
    background: #1a1a1a;
    border-radius: 4px;
    overflow: hidden;
    cursor: grab;
}

.canvas-wrapper:active {
    cursor: grabbing;
}

#imageCanvas {
    display: block;
    width: 100%;
    height: 500px;
    background: #1a1a1a;
}

.toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}

.toolbar-group {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 8px;
    background: #f5f5f5;
    border-radius: 4px;
}

.toolbar-group label {
    font-size: 12px;
    color: #666;
    white-space: nowrap;
}

.toolbar-group input[type="number"] {
    width: 60px;
    padding: 4px 6px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 13px;
    text-align: center;
}

.toolbar-group input[type="number"]:focus {
    outline: none;
    border-color: #667eea;
}

.toolbar-group span {
    font-size: 12px;
    color: #888;
}

.section-divider {
    height: 1px;
    background: #e0e0e0;
    margin: 12px 0;
}

.grid-result {
    overflow-x: auto;
}

.grid-table {
    border-collapse: collapse;
    margin: 0 auto;
}

.grid-table td {
    border: 1px solid #ddd;
    text-align: center;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
    position: relative;
    user-select: none;
}

.grid-table td .cell-input {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 5;
}

.grid-table td:hover {
    background: #e3f2fd;
}

.grid-table td.selected {
    background: #bbdefb;
    border-color: #1976D2;
    box-shadow: inset 0 0 0 2px #1976D2;
}

.grid-table td.conf-high {
    background: #e8f5e9;
}

.grid-table td.conf-medium {
    background: #fff8e1;
}

.grid-table td.conf-low {
    background: #ffebee;
}

.grid-table td.conf-high.selected {
    background: #c8e6c9;
}

.grid-table td.conf-medium.selected {
    background: #fff9c4;
}

.grid-table td.conf-low.selected {
    background: #ffcdd2;
}

.cell-input {
    width: 60px;
    height: 36px;
    border: 2px solid #1976D2;
    border-radius: 4px;
    font-size: 16px;
    font-weight: 600;
    text-align: center;
    outline: none;
}

.counter-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 10px;
}

.counter-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    background: #fff;
    border-radius: 12px;
    border: 1px solid #eaeaea;
    border-left: 4px solid #eaeaea;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}

.counter-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0,0,0,0.1);
    border-color: #d5d5d5;
}

.counter-item.all-sel {
    background: #f0f4ff;
    border-color: #b3c6ff;
}

.counter-swatch {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    flex-shrink: 0;
    box-shadow: inset 0 1px 3px rgba(0,0,0,0.2), 0 1px 2px rgba(0,0,0,0.08);
}

.counter-char {
    font-weight: 700;
    font-size: 14px;
    flex: 1;
    font-family: 'SF Mono', 'Consolas', 'Menlo', monospace;
    letter-spacing: 0.5px;
}

.counter-count-num {
    font-weight: 600;
    font-size: 11px;
    color: #777;
    background: #f3f4f6;
    padding: 2px 9px;
    border-radius: 10px;
    min-width: 32px;
    text-align: center;
}

.counter-bar-bg {
    position: absolute;
    left: 0;
    bottom: 0;
    width: 100%;
    height: 4px;
    background: #f5f5f5;
}

.counter-bar {
    position: absolute;
    left: 0;
    bottom: 0;
    height: 4px;
    border-radius: 0 4px 0 0;
    transition: width 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

.cell-preview { position:absolute; bottom:8px; right:8px; background:white; border-radius:8px; box-shadow:0 2px 12px rgba(0,0,0,0.3); padding:4px; z-index:50; display:flex; flex-direction:column; align-items:center; max-width:160px; }
.cell-preview canvas { display:block; width:80px; height:80px; border-radius:4px; image-rendering:pixelated; }
.cell-preview-label { font-size:11px; color:#666; margin-top:2px; text-align:center; word-break:break-all; }

.fs-overlay { position:fixed; top:0; left:0; width:100vw; height:100vh; background:#111; z-index:9999; display:flex; flex-direction:column; }
.fs-overlay.hidden { display:none; }
.fs-topbar { display:flex; justify-content:space-between; align-items:center; padding:8px 16px; background:#1a1a1a; color:#fff; }
.fs-title { font-size:15px; font-weight:600; }
.fs-close-btn { background:none; border:1px solid #555; color:#fff; padding:6px 16px; border-radius:6px; cursor:pointer; font-size:13px; }
.fs-guide-btn { background:none; border:1px solid #555; color:#ccc; padding:6px 12px; border-radius:6px; cursor:pointer; font-size:13px; transition:all 0.2s; }
.fs-guide-btn:hover { color:#fff; border-color:#888; }
.fs-body { flex:1; display:flex; overflow:hidden; }
.fs-canvas-wrap { flex:1; display:flex; align-items:center; justify-content:center; overflow:auto; padding:8px; }
.fs-canvas-wrap canvas { display:block; image-rendering:pixelated; border-radius:4px; }
.fs-counter-wrap { width:200px; background:#1a1a1a; color:#ccc; overflow-y:auto; padding:12px; border-left:1px solid #2a2a2a; }
.fs-counter-list { display:flex; flex-direction:column; gap:5px; }
.fs-counter-item { display:flex; align-items:center; gap:10px; padding:8px 10px; border-radius:10px; cursor:pointer; transition:all 0.2s ease; border-left:3px solid transparent; position:relative; overflow:hidden; }
.fs-counter-item:hover { background:rgba(255,255,255,0.06); }
.fs-counter-item.active { background:rgba(33,150,243,0.18); border-left-color:#2196F3; }
.fs-swatch { width:16px; height:16px; border-radius:50%; flex-shrink:0; box-shadow:inset 0 1px 3px rgba(0,0,0,0.4); }
.fs-char { font-weight:700; font-size:13px; font-family:'SF Mono','Consolas','Menlo',monospace; letter-spacing:0.3px; }
.fs-count { font-size:11px; opacity:0.6; font-weight:500; background:rgba(255,255,255,0.07); padding:1px 7px; border-radius:8px; }

.status-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: #f5f5f5;
    border-radius: 4px;
    font-size: 12px;
    color: #666;
    margin-top: 8px;
}

.status-bar .status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
}

.status-dot.idle { background: #9e9e9e; }
.status-dot.loading { background: #ff9800; animation: pulse 1s infinite; }
.status-dot.success { background: #4CAF50; }
.status-dot.error { background: #f44336; }

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

.selection-info {
    font-size: 12px;
    color: #666;
    padding: 4px 0;
}

.selection-info strong {
    color: #333;
}

.hidden {
    display: none !important;
}

.zoom-controls {
    display: flex;
    align-items: center;
    gap: 6px;
}

.zoom-controls input[type="range"] {
    width: 100px;
    height: 4px;
    -webkit-appearance: none;
    appearance: none;
    background: #ddd;
    border-radius: 2px;
    outline: none;
}

.zoom-controls input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: #667eea;
    cursor: pointer;
}

.loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 16px;
    z-index: 10;
    border-radius: 4px;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid rgba(255,255,255,0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-right: 12px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.batch-edit-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: #e3f2fd;
    border-radius: 4px;
    margin-top: 8px;
    font-size: 13px;
}

.batch-edit-bar input {
    width: 40px;
    padding: 4px;
    border: 1px solid #90caf9;
    border-radius: 4px;
    text-align: center;
    font-size: 14px;
}

.batch-edit-bar input:focus {
    outline: none;
    border-color: #1976D2;
}

.cell-grid-table {
    border-collapse: separate;
    border-spacing: 8px;
    margin: 0 auto;
}

.cell-grid-table td {
    vertical-align: top;
    text-align: center;
    padding: 6px;
    background: #fafafa;
    border-radius: 6px;
    border: 1px solid #e0e0e0;
}

.cell-grid-table td .cell-canvas {
    display: block;
    width: 72px;
    height: 72px;
    image-rendering: pixelated;
    border-radius: 2px;
}

.cell-grid-table td .cell-label {
    margin-top: 4px;
    font-size: 11px;
    color: #555;
    font-weight: 600;
}

@media (max-width: 900px) {
    .main-container {
        flex-direction: column;
    }
    .right-panel {
        width: 100%;
    }
}
