:root {
  --bg:      #1a1a2e;
  --surface: #16213e;
  --border:  #2a3a5e;
  --accent:  #4cc9f0;
  --purple:  #7b2fff;
  --text:    #c8d6e5;
  --muted:   #5a6a80;
  --danger:  #f64f59;
  --success: #43e97b;
}

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

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 14px;
  overflow: hidden;
}

/* ── Landing overlay ────────────────────────────────────────────────────── */
#landing {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  transition: opacity 0.3s;
}
#landing.hidden { opacity: 0; pointer-events: none; }

.landing-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 40px 48px;
  width: 480px;
  max-width: 90vw;
}

.landing-box h1 { font-size: 22px; font-weight: 600; color: var(--accent); margin-bottom: 6px; }
.landing-box p  { color: var(--muted); margin-bottom: 28px; line-height: 1.5; }

.path-input-row {
  display: flex;
  gap: 0;
  margin-bottom: 12px;
  border: 1px solid var(--border);
  border-radius: 4px;
  overflow: hidden;
}
.path-input-row:focus-within { border-color: var(--accent); }

#path-display {
  flex: 1;
  background: var(--bg);
  border: none;
  outline: none;
  color: var(--text);
  padding: 8px 12px;
  font-size: 13px;
  min-width: 0;
  font-family: inherit;
}
#path-display::placeholder { color: var(--muted); }

#browse-btn,
#browse-files-btn {
  background: var(--surface);
  border: none;
  border-left: 1px solid var(--border);
  color: var(--text);
  padding: 8px 14px;
  cursor: pointer;
  font-size: 13px;
  white-space: nowrap;
  font-family: inherit;
}
#browse-btn:hover,
#browse-files-btn:hover { color: var(--accent); }

#init-btn {
  width: 100%;
  background: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 4px;
  color: #0a0a1a;
  font-weight: 600;
  font-size: 13px;
  padding: 10px;
  cursor: pointer;
  font-family: inherit;
}
#init-btn:disabled { opacity: 0.4; cursor: not-allowed; }
#init-btn:not(:disabled):hover { background: #6dd4f7; border-color: #6dd4f7; }

#progress-bar-wrap {
  margin-top: 14px;
  height: 3px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
  display: none;
}
#progress-bar-wrap.visible { display: block; }
#progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--purple), var(--accent));
  width: 0%;
  transition: width 0.15s;
}

#landing-status {
  margin-top: 12px;
  font-size: 11px;
  color: var(--muted);
  min-height: 16px;
  font-family: system-ui, -apple-system, sans-serif;
}
#landing-status.error   { color: var(--danger); }
#landing-status.success { color: var(--success); }

/* ── Main app ───────────────────────────────────────────────────────────── */
#app { display: none; flex-direction: column; height: 100vh; }
#app.visible { display: flex; }

#header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 8px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
  flex-wrap: wrap;
}

#header .title {
  font-weight: 600;
  color: var(--accent);
  white-space: nowrap;
  cursor: pointer;
}
#header .title:hover { opacity: 0.75; }
#header .sep { color: var(--border); user-select: none; }

#search {
  flex: 1;
  min-width: 160px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  padding: 6px 10px;
  font-size: 13px;
  outline: none;
  font-family: inherit;
}
#search:focus { border-color: var(--accent); }

#count { color: var(--muted); font-size: 12px; white-space: nowrap; }

/* Filters */
.filter-row { display: flex; gap: 8px; align-items: center; }
.filter-row label { font-size: 12px; color: var(--muted); white-space: nowrap; }
.filter-row select {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  padding: 5px 8px;
  font-size: 12px;
  outline: none;
}
.filter-row select:focus { border-color: var(--accent); }

button {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  padding: 9px 16px;
  cursor: pointer;
  font-size: 13px;
  white-space: nowrap;
  font-family: inherit;
}
button:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
button:disabled { opacity: 0.45; cursor: not-allowed; }

/* strings status pill */
#strings-pill {
  display: none;
  font-size: 12px;
  color: var(--purple);
  white-space: nowrap;
}
#strings-pill.visible { display: inline-block; }

/* Grid */
#string-prompt {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 14px;
  background: color-mix(in srgb, var(--accent) 12%, var(--surface));
  border-bottom: 1px solid color-mix(in srgb, var(--accent) 30%, var(--border));
  font-size: 13px;
  color: var(--accent);
}
#string-prompt button { font-size: 12px; }
#string-prompt-dismiss { opacity: 0.5; }
#string-prompt-dismiss:hover { opacity: 1; }

#grid-container { flex: 1; overflow-y: auto; padding: 12px; }
#grid { position: relative; }

.sprite-cell {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 6px;
  gap: 4px;
  transition: border-color 0.15s;
}
.sprite-cell:hover { border-color: var(--accent); }

.sprite-cell canvas {
  width: 80px;
  height: 80px;
  object-fit: contain;
  image-rendering: pixelated;
  background: #0d0d1a;
  border-radius: 2px;
}

.sprite-cell .label {
  font-size: 10px;
  color: var(--muted);
  text-align: center;
  word-break: break-all;
  line-height: 1.3;
  max-height: 2.6em;
  overflow: hidden;
  width: 100%;
}
.sprite-cell .label.has-name { color: var(--text); }

/* Detail modal */
#detail {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.78);
  z-index: 50;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
#detail.visible { display: flex; }

.detail-modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  display: flex;
  flex-direction: row;
  gap: 0;
  max-width: 780px;
  width: 100%;
  max-height: 90vh;
  overflow: hidden;
  position: relative;
}

.detail-close {
  position: absolute;
  top: 10px;
  right: 12px;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  z-index: 1;
  letter-spacing: 0;
}
.detail-close:hover { color: var(--text); background: var(--border); }

.detail-preview {
  flex: 0 0 auto;
  background: #0d0d1a;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px;
  min-width: 200px;
  max-width: 400px;
  border-right: 1px solid var(--border);
}

#detail-canvas {
  display: block;
  max-width: 320px;
  max-height: calc(90vh - 120px);
  image-rendering: pixelated;
}

.detail-info {
  flex: 1;
  padding: 28px 32px 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow-y: auto;
  min-width: 0;
}

.detail-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  word-break: break-all;
  padding-right: 28px;
}
.detail-title .resolved-name {
  color: var(--accent);
  display: block;
  font-size: 13px;
  margin-top: 4px;
  font-weight: 400;
}

.detail-meta {
  border-collapse: collapse;
  width: 100%;
  font-size: 13px;
}
.detail-meta td {
  padding: 7px 0;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.detail-meta td:first-child {
  color: var(--muted);
  white-space: nowrap;
  padding-right: 20px;
  width: 90px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.detail-meta td:last-child {
  color: var(--text);
  font-family: monospace;
  font-size: 12px;
  word-break: break-all;
}
.detail-meta .name-cell { color: var(--accent); font-family: inherit; }

.detail-actions { display: flex; gap: 8px; margin-top: auto; padding-top: 8px; }

/* Frame strip (animation frames in detail modal) */
#frame-strip {
  display: none;
  flex-direction: row;
  flex-wrap: wrap;
  gap: 4px;
  padding: 10px 0 0;
  justify-content: center;
  max-width: 400px;
}
#frame-strip.visible { display: flex; }
.frame-thumb {
  width: 40px; height: 40px;
  background: #0d0d1a;
  border: 1px solid var(--border);
  border-radius: 3px;
  cursor: pointer;
  image-rendering: pixelated;
}
.frame-thumb.active { border-color: var(--accent); }
.frame-thumb:hover:not(.active) { border-color: var(--muted); }
