/* ===== RESET & BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg-base:      #0d0f14;
  --bg-surface:   #13161e;
  --bg-elevated:  #1a1e2a;
  --bg-hover:     #21273a;
  --border:       #272d3f;
  --border-light: #313848;

  --accent:       #6c8ef7;
  --accent-dim:   #3b4f99;
  --accent-glow:  rgba(108,142,247,0.18);
  --accent2:      #a78bfa;
  --gold:         #f0b429;
  --gold-dim:     #7a5c14;

  --text-primary:   #e8eaf0;
  --text-secondary: #8b92a8;
  --text-muted:     #555d75;
  --text-code:      #7dd3fc;

  --success:  #34d399;
  --warning:  #fbbf24;
  --danger:   #f87171;

  --radius-sm: 6px;
  --radius:    10px;
  --radius-lg: 16px;

  --shadow-sm:  0 1px 3px rgba(0,0,0,.5);
  --shadow:     0 4px 16px rgba(0,0,0,.5);
  --shadow-lg:  0 16px 48px rgba(0,0,0,.7);

  --sidebar-w: 280px;
  --header-h:  56px;
  --font-main: 'Inter', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Mono', monospace;

  --transition: 150ms ease;
}

html { height: 100%; }

body {
  font-family: var(--font-main);
  background: var(--bg-base);
  color: var(--text-primary);
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

code {
  font-family: var(--font-mono);
  color: var(--text-code);
  background: rgba(125,211,252,.08);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: .85em;
}

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ===== HEADER ===== */
.header {
  height: var(--header-h);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  z-index: 100;
}

.header-inner {
  height: 100%;
  max-width: 100%;
  padding: 0 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

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

.logo-icon {
  width: 34px; height: 34px;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  border-radius: var(--radius-sm);
  display: grid; place-items: center;
  box-shadow: 0 0 20px var(--accent-glow);
}
.logo-icon svg { width: 18px; height: 18px; color: white; }

.logo-text { display: flex; flex-direction: column; line-height: 1; }
.logo-title { font-size: 15px; font-weight: 700; color: var(--text-primary); letter-spacing: -.3px; }
.logo-sub   { font-size: 10px; color: var(--text-muted); margin-top: 2px; letter-spacing: .3px; text-transform: uppercase; }

.header-games { display: flex; gap: 6px; }
.game-badge {
  font-size: 10px; font-weight: 600;
  padding: 3px 8px;
  border-radius: 99px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-light);
  color: var(--text-muted);
  letter-spacing: .3px;
  transition: var(--transition);
}
.game-badge:hover { color: var(--accent); border-color: var(--accent-dim); }

/* ===== APP LAYOUT ===== */
.app-layout {
  flex: 1;
  display: flex;
  overflow: hidden;
}

/* ===== SIDEBAR ===== */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 10px;
}

.sidebar-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .8px;
  color: var(--text-muted);
}

/* ===== BUTTONS ===== */
.btn-icon {
  width: 30px; height: 30px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  cursor: pointer;
  display: grid; place-items: center;
  transition: var(--transition);
}
.btn-icon svg { width: 16px; height: 16px; }
.btn-icon:hover { background: var(--bg-elevated); color: var(--text-primary); border-color: var(--border-light); }
.btn-icon[data-active="true"] { background: var(--accent-dim); color: var(--accent); border-color: var(--accent-dim); }

.btn-primary {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 9px 18px;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font-main);
  font-size: 13px; font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  box-shadow: 0 4px 14px var(--accent-glow);
}
.btn-primary:hover { filter: brightness(1.1); transform: translateY(-1px); }
.btn-primary:active { transform: translateY(0); }

.btn-outline {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 7px 14px;
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  font-family: var(--font-main);
  font-size: 12px; font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
}
.btn-outline:hover { background: var(--bg-elevated); color: var(--text-primary); border-color: var(--accent-dim); }

/* ===== DROPZONE ===== */
.dropzone {
  margin: 0 12px 12px;
  border: 1.5px dashed var(--border-light);
  border-radius: var(--radius);
  padding: 22px 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  transition: var(--transition);
  background: transparent;
}
.dropzone:hover, .dropzone.drag-over {
  border-color: var(--accent);
  background: var(--accent-glow);
}
.dropzone-icon svg { width: 36px; height: 36px; color: var(--text-muted); }
.dropzone:hover .dropzone-icon svg, .dropzone.drag-over .dropzone-icon svg { color: var(--accent); }

.dropzone-text { font-size: 12px; color: var(--text-secondary); text-align: center; }
.dropzone-hint { font-size: 11px; color: var(--text-muted); }

.dropzone-sm {
  margin: 6px 12px 8px;
  padding: 12px;
  flex-direction: row;
  gap: 10px;
  border-radius: var(--radius-sm);
}
.dropzone-icon-sm svg { width: 18px; height: 18px; color: var(--accent); }
.dropzone-text-sm { font-size: 12px; color: var(--text-secondary); }

/* ===== FILE LIST ===== */
.file-list { overflow: visible; }
.file-list-items { display: flex; flex-direction: column; gap: 2px; padding: 4px 8px; }

.file-item {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: var(--transition);
  border: 1px solid transparent;
}
.file-item:hover { background: var(--bg-elevated); }
.file-item.active { background: var(--accent-dim); border-color: var(--accent-dim); }

.file-item-icon { font-size: 14px; flex-shrink: 0; }
.file-item-name { font-size: 12px; font-weight: 500; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-item.active .file-item-name { color: var(--accent); }
.file-item-badge { font-size: 10px; background: var(--bg-base); padding: 1px 6px; border-radius: 99px; color: var(--text-muted); }

/* ===== SIDEBAR SECTIONS ===== */
.sidebar-section { padding: 0 0 8px; }
.section-label {
  font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: .8px;
  color: var(--text-muted); padding: 8px 16px 4px;
}

.files-555-list { padding: 0 12px; display: flex; flex-direction: column; gap: 3px; }
.file-555-item {
  display: flex; align-items: center; gap: 6px;
  padding: 5px 8px; border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  font-size: 11px; color: var(--text-secondary);
}
.file-555-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--success); flex-shrink: 0; }

/* ===== BITMAP TREE ===== */
.bitmap-tree { flex: 1; min-height: 0; overflow-y: auto; padding-bottom: 16px; }
.bitmap-group { border-radius: 0; }
.bitmap-group-header {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 16px;
  cursor: pointer;
  transition: var(--transition);
  font-size: 12px; font-weight: 500;
}
.bitmap-group-header:hover { background: var(--bg-elevated); }
.bitmap-group-header.active { color: var(--accent); }

.bitmap-group-arrow {
  width: 14px; height: 14px; color: var(--text-muted);
  transition: transform var(--transition);
  flex-shrink: 0;
}
.bitmap-group-header.open .bitmap-group-arrow { transform: rotate(90deg); }
.bitmap-group-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bitmap-group-count { font-size: 10px; color: var(--text-muted); background: var(--bg-base); padding: 1px 6px; border-radius: 99px; }

/* ===== MAIN CONTENT ===== */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg-base);
}

/* ===== WELCOME ===== */
.welcome-screen {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
}
.welcome-inner { text-align: center; max-width: 480px; }

.welcome-graphic {
  width: 120px; height: 120px;
  margin: 0 auto 28px;
  position: relative;
}

.welcome-diamonds {
  position: relative;
  width: 100%; height: 100%;
}

.diamond {
  position: absolute;
  border-radius: 4px;
  animation: float-diamond 4s ease-in-out infinite;
}
.d1 { width:50px;height:50px; background:linear-gradient(135deg,#6c8ef7,#a78bfa); left:35px;top:10px; transform:rotate(45deg); animation-delay:0s; }
.d2 { width:30px;height:30px; background:linear-gradient(135deg,#f0b429,#f87171); left:5px;top:40px; transform:rotate(45deg); animation-delay:.5s; }
.d3 { width:24px;height:24px; background:linear-gradient(135deg,#34d399,#6c8ef7); left:78px;top:55px; transform:rotate(45deg); animation-delay:1s; }
.d4 { width:20px;height:20px; background:linear-gradient(135deg,#a78bfa,#f0b429); left:20px;top:75px; transform:rotate(45deg); animation-delay:1.5s; }
.d5 { width:16px;height:16px; background:linear-gradient(135deg,#f87171,#34d399); left:90px;top:20px; transform:rotate(45deg); animation-delay:2s; }

@keyframes float-diamond {
  0%,100% { transform: rotate(45deg) translateY(0); }
  50% { transform: rotate(45deg) translateY(-8px); }
}

.welcome-title { font-size: 32px; font-weight: 700; letter-spacing: -1px; margin-bottom: 12px;
  background: linear-gradient(135deg, var(--text-primary), var(--accent)); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }
.welcome-desc { font-size: 15px; color: var(--text-secondary); line-height: 1.6; margin-bottom: 28px; }

.welcome-steps { display: flex; flex-direction: column; gap: 10px; margin-bottom: 28px; text-align: left; }
.step { display: flex; align-items: center; gap: 12px; font-size: 13px; color: var(--text-secondary); }
.step-num {
  width: 22px; height: 22px; flex-shrink: 0;
  background: var(--accent-dim); color: var(--accent);
  border-radius: 50%; display: grid; place-items: center;
  font-size: 11px; font-weight: 700;
}

/* ===== VIEWER ===== */
.viewer { flex: 1; display: flex; flex-direction: column; overflow: hidden; }

/* ===== TOOLBAR ===== */
.toolbar {
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px;
  background: var(--bg-surface);
  flex-shrink: 0;
}
.toolbar-left, .toolbar-right { display: flex; align-items: center; gap: 8px; }

.divider-v { width: 1px; height: 20px; background: var(--border); }

.zoom-label {
  display: flex; align-items: center; gap: 6px;
  color: var(--text-muted); font-size: 12px;
}
input[type="range"] {
  -webkit-appearance: none;
  width: 80px; height: 4px;
  background: var(--border-light);
  border-radius: 99px; outline: none; cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 6px var(--accent-glow);
}
#zoom-label-text { font-size: 11px; color: var(--text-secondary); min-width: 22px; font-family: var(--font-mono); }

.checkbox-label {
  display: flex; align-items: center; gap: 6px;
  font-size: 12px; color: var(--text-muted); cursor: pointer;
}
.checkbox-label input[type="checkbox"] { accent-color: var(--accent); width: 13px; height: 13px; }

.image-count { font-size: 12px; color: var(--text-muted); font-family: var(--font-mono); }

/* ===== BITMAP INFO BAR ===== */
.bitmap-info-bar {
  padding: 6px 16px;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 8px;
  font-size: 12px; color: var(--text-secondary);
  flex-shrink: 0;
}
#bitmap-info-name { font-weight: 600; color: var(--text-primary); font-family: var(--font-mono); }
.info-sep { color: var(--border-light); }

/* ===== PROGRESS ===== */
.progress-bar-wrap {
  flex-shrink: 0;
  height: 3px; background: var(--bg-elevated); position: relative;
}
.progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  width: 0%; transition: width .2s ease;
  box-shadow: 0 0 8px var(--accent-glow);
}
.progress-label {
  position: absolute; right: 10px; top: 6px;
  font-size: 10px; color: var(--text-muted);
}

/* ===== IMAGE GRID ===== */
.image-grid {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-content: flex-start;
}

.image-cell {
  position: relative;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  cursor: pointer;
  transition: border-color var(--transition), box-shadow var(--transition), transform var(--transition);
  background: var(--bg-elevated);
  display: flex; flex-direction: column;
}
.image-cell:hover {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent), 0 4px 16px var(--accent-glow);
  transform: translateY(-2px);
  z-index: 2;
}
.image-cell.selected {
  border-color: var(--success);
  box-shadow: 0 0 0 1px var(--success), 0 4px 16px rgba(52, 211, 153, 0.2);
  z-index: 2;
}
.image-cell.selected::after {
  content: '✓';
  position: absolute; top: 4px; right: 4px;
  width: 18px; height: 18px;
  background: var(--success); color: var(--bg-base);
  border-radius: 50%; display: grid; place-items: center;
  font-size: 10px; font-weight: bold;
}

.image-cell canvas {
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.image-cell-info {
  padding: 3px 5px;
  font-size: 9px; color: var(--text-muted);
  font-family: var(--font-mono);
  background: var(--bg-surface);
  border-top: 1px solid var(--border);
  white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
}

/* Checkerboard background for transparent images */
.checkerboard canvas {
  background-image:
    linear-gradient(45deg, #1e222e 25%, transparent 25%),
    linear-gradient(-45deg, #1e222e 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #1e222e 75%),
    linear-gradient(-45deg, transparent 75%, #1e222e 75%);
  background-size: 10px 10px;
  background-position: 0 0, 0 5px, 5px -5px, -5px 0px;
  background-color: #161b26;
}

/* Error cell */
.image-cell.error { opacity: .4; cursor: default; }
.image-cell.error:hover { transform: none; box-shadow: none; border-color: var(--danger); }

/* Empty placeholder */
.grid-empty {
  width: 100%; padding: 60px;
  text-align: center; color: var(--text-muted); font-size: 14px;
}

/* ===== LIGHTBOX ===== */
.lightbox {
  position: fixed; inset: 0; z-index: 999;
  display: flex; align-items: center; justify-content: center;
}
.lightbox-backdrop {
  position: absolute; inset: 0;
  background: rgba(0,0,0,.85);
  backdrop-filter: blur(8px);
}
.lightbox-panel {
  position: relative; z-index: 1;
  background: var(--bg-surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  max-width: 90vw; max-height: 90vh;
  display: flex; flex-direction: column;
  overflow: hidden;
  animation: lb-in .2s ease;
}
@keyframes lb-in { from { transform: scale(.92); opacity: 0; } to { transform: scale(1); opacity: 1; } }

.lightbox-close {
  position: absolute; top: 12px; right: 12px; z-index: 2;
  width: 30px; height: 30px;
  background: var(--bg-elevated); border: 1px solid var(--border-light);
  border-radius: 50%; color: var(--text-secondary);
  cursor: pointer; display: grid; place-items: center; transition: var(--transition);
}
.lightbox-close:hover { color: var(--danger); border-color: var(--danger); }
.lightbox-close svg { width: 14px; height: 14px; }

.lightbox-nav {
  display: flex; align-items: center; gap: 12px;
  padding: 24px 24px 16px;
  min-height: 200px;
}
.lightbox-btn {
  width: 36px; height: 36px; flex-shrink: 0;
  background: var(--bg-elevated); border: 1px solid var(--border-light);
  border-radius: 50%; color: var(--text-secondary);
  cursor: pointer; display: grid; place-items: center; transition: var(--transition);
}
.lightbox-btn:hover { background: var(--accent-dim); color: var(--accent); border-color: var(--accent-dim); }
.lightbox-btn svg { width: 16px; height: 16px; }

.lightbox-image-wrap {
  flex: 1; display: flex; align-items: center; justify-content: center;
  overflow: auto; min-width: 200px; min-height: 150px;
  background-image:
    linear-gradient(45deg, #1e222e 25%, transparent 25%),
    linear-gradient(-45deg, #1e222e 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #1e222e 75%),
    linear-gradient(-45deg, transparent 75%, #1e222e 75%);
  background-size: 16px 16px;
  background-position: 0 0, 0 8px, 8px -8px, -8px 0px;
  background-color: #10131a;
  border-radius: var(--radius);
  padding: 8px;
}
#lightbox-canvas { image-rendering: pixelated; image-rendering: crisp-edges; display: block; }

.lightbox-info {
  padding: 16px 24px 20px;
  border-top: 1px solid var(--border);
  display: flex; align-items: flex-start; gap: 20px;
}
.lightbox-info-grid {
  flex: 1; display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px 20px;
}
.info-item { display: flex; flex-direction: column; gap: 2px; }
.info-key { font-size: 10px; text-transform: uppercase; letter-spacing: .5px; color: var(--text-muted); }
.info-val { font-size: 12px; font-family: var(--font-mono); color: var(--text-primary); }

/* ===== TOAST ===== */
.toast-area {
  position: fixed; bottom: 20px; right: 20px;
  display: flex; flex-direction: column; gap: 8px; z-index: 9999;
}
.toast {
  padding: 10px 16px; border-radius: var(--radius-sm);
  background: var(--bg-elevated); border: 1px solid var(--border-light);
  color: var(--text-primary); font-size: 13px;
  box-shadow: var(--shadow);
  animation: toast-in .2s ease;
  display: flex; align-items: center; gap: 8px;
}
.toast.success { border-color: var(--success); }
.toast.error   { border-color: var(--danger);  }
.toast.warning { border-color: var(--warning);  }
.toast-dot { width: 6px; height: 6px; border-radius: 50%; flex-shrink: 0; }
.toast.success .toast-dot { background: var(--success); }
.toast.error   .toast-dot { background: var(--danger); }
.toast.warning .toast-dot { background: var(--warning); }
@keyframes toast-in { from { transform: translateX(20px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
@keyframes toast-out { to { transform: translateX(20px); opacity: 0; } }

/* ===== LIST VIEW ===== */
.image-grid.list-view {
  flex-direction: column; flex-wrap: nowrap;
  gap: 2px;
}
.image-grid.list-view .image-cell {
  flex-direction: row; align-items: center;
  width: 100% !important; height: auto !important;
}
.image-grid.list-view .image-cell canvas {
  max-width: 64px; max-height: 64px;
  width: auto; height: auto;
}
.image-grid.list-view .image-cell-info {
  flex: 1; padding: 0 12px; border-top: none; border-left: 1px solid var(--border);
  font-size: 11px;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 700px) {
  :root { --sidebar-w: 220px; }
  .header-games { display: none; }
  .welcome-title { font-size: 24px; }
}
