:root {
  --bg: #111316;
  --panel: #1b1e23;
  --panel-2: #24282f;
  --text: #f2f3f5;
  --muted: #9aa1ab;
  --accent: #3e7bfa;
  --danger: #e5484d;
  --radius: 22px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 18px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
input, button { font: inherit; color: inherit; }
code { background: var(--panel-2); padding: 1px 6px; border-radius: 6px; }
.muted { color: var(--muted); font-weight: normal; }
.grow { flex: 1; }

/* Header */
.bar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 32px 8px;
}
.bar h1 { margin: 0; font-size: 34px; font-weight: 700; letter-spacing: -0.02em; }
.bar-actions { display: flex; gap: 12px; }

/* Buttons */
.btn {
  border: 0; border-radius: 14px; padding: 14px 22px; min-height: 52px;
  background: var(--panel-2); cursor: pointer; font-weight: 600;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.btn:active { transform: scale(0.97); }
.btn.ghost { background: var(--panel); }
.btn.primary { background: var(--accent); color: #fff; }
.btn.danger { background: var(--danger); color: #fff; }
body.editing #btn-edit { background: var(--accent); color: #fff; }

/* Grid */
main { padding: 16px 32px 48px; }
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 22px;
}
.tile {
  position: relative;
  display: flex; flex-direction: column; align-items: center; gap: 12px;
  padding: 18px 10px 14px;
  border-radius: var(--radius);
  text-decoration: none; color: var(--text);
  background: var(--panel);
  transition: transform .08s ease;
}
.tile:active { transform: scale(0.96); }
.tile .icon {
  width: 104px; height: 104px; border-radius: 26px;
  display: grid; place-items: center; overflow: hidden;
  font-size: 54px; font-weight: 700; color: #fff;
  background: var(--tile, #2b2f36);
  box-shadow: 0 6px 18px rgba(0,0,0,.35);
}
.tile .icon img { width: 100%; height: 100%; object-fit: cover; }
.tile .name { font-weight: 600; text-align: center; font-size: 19px; }
.tile .desc { color: var(--muted); font-size: 14px; text-align: center; margin-top: -8px; }
.tile .badge {
  position: absolute; top: 10px; left: 12px; font-size: 13px; color: var(--muted);
}
.tile.add .icon { background: transparent; border: 3px dashed #444a54; color: var(--muted); box-shadow: none; }

body.editing .tile:not(.add) { outline: 2px dashed #444a54; outline-offset: -2px; }
.tile .edit-badge {
  display: none; position: absolute; top: 8px; right: 8px;
  background: var(--accent); color: #fff; border-radius: 999px;
  width: 38px; height: 38px; place-items: center; font-size: 18px;
}
body.editing .tile .edit-badge { display: grid; }
.tile.readonly .edit-badge { background: #555; }

.empty { text-align: center; margin-top: 12vh; font-size: 22px; }
.status { background: var(--panel-2); padding: 14px 18px; border-radius: 14px; margin-bottom: 18px; }
.status.err { background: #3a1517; color: #ffb4b6; }

/* Modals */
.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,.6);
  display: grid; place-items: center; padding: 24px; z-index: 10;
}
.modal[hidden] { display: none; }
.sheet {
  background: var(--panel); border-radius: 24px; padding: 28px;
  width: min(760px, 100%); max-height: 92vh; overflow: auto;
  display: flex; flex-direction: column; gap: 16px;
  user-select: text;
}
.sheet.narrow { width: min(460px, 100%); }
.sheet h2 { margin: 0 0 4px; }
.sheet label { display: flex; flex-direction: column; gap: 6px; font-weight: 600; font-size: 16px; }
.sheet input:not([type=checkbox]):not([type=file]) {
  background: var(--bg); border: 1px solid #333842; border-radius: 12px;
  padding: 14px 16px; min-height: 52px; width: 100%;
}
.sheet input[type=color] { padding: 4px 8px !important; }
.sheet input:focus { outline: 2px solid var(--accent); border-color: transparent; }
.row { display: flex; gap: 14px; align-items: flex-end; flex-wrap: wrap; }
.row .upload { flex-direction: row; font-size: 18px; }
.icon-preview {
  width: 52px; height: 52px; border-radius: 14px; background: var(--panel-2);
  display: grid; place-items: center; overflow: hidden; font-size: 28px;
}
.icon-preview img { width: 100%; height: 100%; object-fit: cover; }
label.check { flex-direction: row !important; align-items: center; gap: 12px !important; }
label.check input { width: 28px; height: 28px; accent-color: var(--accent); }
.sheet-actions { display: flex; gap: 12px; align-items: center; margin-top: 6px; }
.error { color: #ffb4b6; background: #3a1517; padding: 12px 14px; border-radius: 12px; }

@media (max-width: 600px) {
  .bar, main { padding-left: 16px; padding-right: 16px; }
  .bar h1 { font-size: 26px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 14px; }
  .tile .icon { width: 80px; height: 80px; font-size: 40px; }
}
