:root {
  --bg: #0b0d12;
  --panel: #151923;
  --panel-2: #1d2230;
  --text: #e7eaf0;
  --muted: #8b93a6;
  --accent: #6aa6ff;
  --danger: #ff6a6a;
  --ok: #67d99f;
  --border: #232838;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  /* iOS safe areas */
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--danger); font-size: 14px; }

.view { min-height: 100vh; padding: 12px 14px 80px; max-width: 720px; margin: 0 auto; }

header {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; padding: 6px 0 14px;
}
header h1 { font-size: 22px; margin: 0; font-weight: 600; }
.header-actions { display: flex; gap: 6px; }

button {
  font: inherit;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 14px;
  cursor: pointer;
}
button:active { transform: scale(0.98); }
button.ghost { background: transparent; padding: 8px 10px; border-color: transparent; font-size: 18px; }
button.danger { color: var(--danger); }

input, select, textarea {
  font: inherit;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 12px 14px;
  width: 100%;
}

/* LOGIN */
#login-view { display: grid; place-items: center; }
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  padding: 28px 22px;
  border-radius: 16px;
  width: 100%; max-width: 360px;
  margin-top: 18vh;
}
.card h1 { margin: 0 0 4px; font-size: 28px; }
.card form { margin-top: 18px; display: grid; gap: 10px; }
.card button[type=submit] { background: var(--accent); border-color: var(--accent); color: #0b0d12; font-weight: 600; }

/* FILTERS */
.filters {
  display: flex; gap: 6px; overflow-x: auto;
  padding-bottom: 10px;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.filters::-webkit-scrollbar { display: none; }
.filter {
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 13px;
  background: var(--panel);
  border: 1px solid var(--border);
  white-space: nowrap;
}
.filter.active { background: var(--accent); color: #0b0d12; border-color: var(--accent); font-weight: 600; }

/* GRID */
.grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}
@media (min-width: 520px) { .grid { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 760px) { .grid { grid-template-columns: repeat(4, 1fr); } }

.tile {
  background: var(--panel);
  border-radius: 14px;
  overflow: hidden;
  position: relative;
  border: 1px solid var(--border);
  display: flex; flex-direction: column;
}
.tile img {
  width: 100%; aspect-ratio: 1 / 1;
  object-fit: cover; background: #000;
  display: block;
}
.tile-meta { padding: 8px 10px; font-size: 12px; line-height: 1.3; }
.tile-meta .title {
  font-weight: 600; font-size: 13px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.tile-meta .sub { color: var(--muted); margin-top: 2px; }
.badge {
  position: absolute; top: 8px; left: 8px;
  background: rgba(11, 13, 18, 0.7);
  border: 1px solid var(--border);
  padding: 2px 8px; border-radius: 999px;
  font-size: 11px;
}
.badge.pending { color: var(--accent); }
.badge.failed { color: var(--danger); }
.badge.wishlist { color: #ffb86a; }

/* Tighter, secondary filter row for owned/wishlist. */
.filters.compact { padding-bottom: 6px; margin-top: -2px; }
.filters.compact .kind-filter {
  padding: 5px 12px;
  border-radius: 999px;
  font-size: 12px;
  background: var(--panel);
  border: 1px solid var(--border);
  white-space: nowrap;
}
.filters.compact .kind-filter.active {
  background: var(--text); color: var(--bg); border-color: var(--text); font-weight: 600;
}

/* FAB */
.fab {
  position: fixed;
  right: calc(env(safe-area-inset-right) + 18px);
  bottom: calc(env(safe-area-inset-bottom) + 18px);
  width: 56px; height: 56px;
  border-radius: 50%;
  background: var(--accent);
  color: #0b0d12;
  font-size: 28px; font-weight: 700;
  border: none;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}

/* DETAIL */
.detail-body { display: grid; gap: 14px; }
.detail-body img { width: 100%; border-radius: 14px; background: #000; }
.kv {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 4px 0;
}
.kv .row {
  display: grid;
  grid-template-columns: 130px 1fr;
  gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
}
.kv .row:last-child { border-bottom: none; }
.kv .row label { color: var(--muted); font-size: 13px; padding-top: 8px; }
.kv .row .val input,
.kv .row .val select,
.kv .row .val textarea { padding: 8px 10px; font-size: 14px; }
.kv .row textarea { min-height: 70px; resize: vertical; }

.detail-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.detail-actions button { flex: 1 1 140px; }

/* EDITOR (Cropper.js host) */
.editor {
  position: fixed; inset: 0;
  background: #000;
  z-index: 300;
  display: grid;
  grid-template-rows: auto 1fr auto;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}
body.editor-open { overflow: hidden; }
.editor-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px;
  background: #0b0d12;
  border-bottom: 1px solid var(--border);
}
.editor-title { font-weight: 600; }
.editor-use {
  background: var(--accent);
  border-color: var(--accent);
  color: #0b0d12;
  font-weight: 600;
  padding: 8px 16px;
}
.editor-canvas {
  position: relative;
  background: #000;
  overflow: hidden;
  min-height: 0;
}
.editor-canvas img { display: block; max-width: 100%; }
.editor-tools {
  display: flex;
  justify-content: space-around;
  gap: 6px;
  padding: 12px 10px;
  background: #0b0d12;
  border-top: 1px solid var(--border);
}
.editor-tools .tool {
  flex: 1;
  font-size: 18px;
  padding: 12px 4px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  min-width: 48px;
}
.editor-tools .tool:active { background: var(--bg); }

/* TOAST */
.toast {
  position: fixed;
  left: 50%; transform: translateX(-50%);
  bottom: calc(env(safe-area-inset-bottom) + 86px);
  background: var(--panel-2);
  border: 1px solid var(--border);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 14px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
  z-index: 100;
}

/* SHEET (kind picker) */
.sheet {
  position: fixed; inset: 0;
  display: flex; align-items: flex-end;
  z-index: 200;
}
.sheet-backdrop {
  position: absolute; inset: 0;
  background: rgba(0,0,0,0.55);
  backdrop-filter: blur(2px);
}
.sheet-panel {
  position: relative;
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  background: var(--panel);
  border-top-left-radius: 22px;
  border-top-right-radius: 22px;
  border: 1px solid var(--border);
  border-bottom: none;
  padding: 22px 18px calc(env(safe-area-inset-bottom) + 22px);
  display: grid; gap: 10px;
  animation: slideUp 180ms ease;
}
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
.sheet-panel h2 { margin: 0 0 2px; font-size: 18px; }
.sheet-panel .muted { margin: 0 0 12px; font-size: 14px; }
.sheet-option {
  display: flex; align-items: center; gap: 14px;
  padding: 14px 16px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 14px;
  text-align: left;
  font-size: 16px;
}
.sheet-option:active { background: var(--bg); }
.sheet-option .opt-icon { font-size: 26px; }
.sheet-option .opt-text { display: grid; line-height: 1.25; }
.sheet-option .opt-text strong { font-weight: 600; }
.sheet-option .opt-text .muted { font-size: 13px; margin: 2px 0 0; }
.sheet-cancel {
  margin-top: 6px;
  background: transparent;
  border-color: transparent;
  color: var(--muted);
}

/* STATS */
.stat-block {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
}
.stat-block h3 { margin: 0 0 8px; font-size: 15px; color: var(--muted); font-weight: 500; }
.stat-row { display: flex; justify-content: space-between; padding: 4px 0; }
.stat-row .n { font-variant-numeric: tabular-nums; }
