:root {
  --bg: #0e1014;
  --surface: #171a21;
  --surface-2: #1f232c;
  --border: #2a2f3a;
  --text: #e7e9ee;
  --muted: #8e97a8;
  --accent: #ff9f43;
  --accent-ink: #1a1206;
  --danger: #ff6b6b;
  --ok: #4ade80;
  --radius: 10px;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; min-height: 100vh; }
a { color: inherit; text-decoration: none; }
a:hover { color: var(--accent); }
h1 { font-size: 1.6rem; margin: 0 0 .25rem; }
h2 { font-size: 1.1rem; margin: 0 0 .75rem; }
h3 { font-size: .95rem; margin: 0 0 .5rem; color: var(--muted); font-weight: 600; }
.muted { color: var(--muted); }
.wrap { max-width: 1200px; margin: 0 auto; padding: 0 16px; }

/* Header */
.top { position: sticky; top: 0; z-index: 10; background: rgba(14,16,20,.92); backdrop-filter: blur(6px); border-bottom: 1px solid var(--border); }
.top-inner { display: flex; align-items: center; justify-content: space-between; gap: 12px; height: 56px; }
.brand { font-weight: 800; letter-spacing: .2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand::before { content: ""; display: inline-block; width: 10px; height: 10px; border-radius: 3px; background: var(--accent); margin-right: 8px; }
nav { display: flex; gap: 4px; }
nav a { padding: 6px 12px; border-radius: 8px; color: var(--muted); white-space: nowrap; }
nav a.active { color: var(--text); background: var(--surface-2); }
nav a.me-link { max-width: 160px; overflow: hidden; text-overflow: ellipsis; }
main.wrap { padding-top: 24px; padding-bottom: 64px; }

/* Buttons & Forms */
.btn { display: inline-flex; align-items: center; gap: 6px; font: inherit; color: var(--text); background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 7px 14px; cursor: pointer; }
.btn:hover { border-color: #3b4252; color: var(--text); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
label { display: block; font-size: .85rem; color: var(--muted); margin: 10px 0 4px; }
input[type=text], input:not([type]) { width: 100%; font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; }
input:focus { outline: none; border-color: var(--accent); }
.hint { font-size: .8rem; color: var(--muted); margin-top: 4px; }
.err { color: var(--danger); min-height: 1.2em; margin: 8px 0 0; font-size: .9rem; }
.row { display: flex; gap: 8px; }
.row > .ac-wrap { flex: 1; }

/* Page head */
.head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.head input { max-width: 260px; }
.back { display: inline-block; color: var(--muted); margin-bottom: 14px; }

/* Tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; display: flex; flex-direction: column; transition: transform .12s, border-color .12s; }
.tile:hover { transform: translateY(-2px); border-color: var(--accent); color: var(--text); }
.tile .meta { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 12px; }
.tile .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.count { flex: none; font-size: .8rem; font-weight: 700; background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; padding: 1px 9px; color: var(--accent); }

/* Image frame */
.frame { aspect-ratio: 16 / 9; background: repeating-linear-gradient(45deg, #151820 0 10px, #181b24 10px 20px); border-bottom: 1px dashed var(--border); display: grid; place-items: center; overflow: hidden; }
.frame img { width: 100%; height: 100%; object-fit: cover; display: block; }
.frame .ph { font-size: 2rem; font-weight: 800; color: #394050; letter-spacing: 1px; text-transform: uppercase; }
.frame.big { border: 1px dashed var(--border); border-radius: var(--radius); width: 100%; max-width: 420px; }
.frame.big:has(img) { border-style: solid; }
.frame.sm { width: 64px; flex: none; border: 0; border-radius: 6px; }
.frame.sm .ph { font-size: .8rem; }

/* Detail */
.detail-head { display: grid; grid-template-columns: minmax(0, 420px) 1fr; gap: 24px; align-items: start; margin-bottom: 28px; }
.detail-head h1 { word-break: break-word; }
@media (max-width: 720px) { .detail-head { grid-template-columns: 1fr; } }
.note { font-size: .85rem; color: var(--muted); margin-top: 10px; }

/* Table */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { font-size: .8rem; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); font-weight: 600; background: var(--surface-2); }
tr:last-child td { border-bottom: 0; }
td.nick { font-weight: 600; }
.tag { display: inline-block; font-size: .8rem; padding: 1px 8px; border-radius: 6px; background: var(--surface-2); border: 1px solid var(--border); margin-right: 4px; }
.tag:hover { border-color: var(--accent); }
.me-row td.nick::after { content: "du"; font-size: .7rem; font-weight: 700; color: var(--accent-ink); background: var(--accent); border-radius: 4px; padding: 0 5px; margin-left: 6px; vertical-align: 2px; }

/* Ranking */
.rank { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.rank a { display: flex; align-items: center; gap: 12px; padding: 8px 12px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.rank a:hover { border-color: var(--accent); color: var(--text); }
.rank .pos { width: 26px; text-align: right; font-weight: 800; color: var(--muted); flex: none; }
.rank .name { flex: 1 1 160px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.rank .bar { flex: 0 1 220px; height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.rank .bar i { display: block; height: 100%; background: var(--accent); border-radius: 99px; }
@media (max-width: 560px) { .rank .bar { display: none; } }
section + section { margin-top: 32px; }

/* Cards / Profile */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; align-items: start; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; min-height: 8px; }
.chip { display: inline-flex; align-items: center; gap: 2px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; padding: 2px 4px 2px 12px; }
.chip button { font: inherit; background: none; border: 0; color: var(--muted); cursor: pointer; width: 24px; height: 24px; border-radius: 50%; line-height: 1; }
.chip button:hover { background: var(--danger); color: #fff; }
.footer-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 24px; }

/* Empty */
.empty { text-align: center; padding: 56px 16px; border: 1px dashed var(--border); border-radius: var(--radius); color: var(--muted); }
.empty .btn { margin-top: 14px; }

/* Autocomplete */
.ac-wrap { position: relative; }
.ac-list { position: absolute; z-index: 30; left: 0; right: 0; top: calc(100% + 4px); margin: 0; padding: 4px; list-style: none; background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 10px 30px rgba(0,0,0,.45); max-height: 280px; overflow-y: auto; }
.ac-list li { display: flex; justify-content: space-between; gap: 8px; padding: 7px 10px; border-radius: 6px; cursor: pointer; }
.ac-list li.on, .ac-list li:hover { background: var(--accent); color: var(--accent-ink); }
.ac-list li.on .muted, .ac-list li:hover .muted { color: var(--accent-ink); }

/* Modal */
.overlay { position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.65); display: grid; place-items: center; padding: 16px; animation: fade .12s; }
.modal { width: 100%; max-width: 440px; max-height: calc(100vh - 32px); overflow-y: auto; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 22px; box-shadow: 0 20px 60px rgba(0,0,0,.6); }
.modal .big { font-size: 1.15rem; margin: 6px 0 4px; }
.modal .or { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: .8rem; margin: 18px 0 10px; }
.modal .or::before, .modal .or::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.modal .actions { justify-content: flex-end; }
.radios label { display: flex; align-items: center; gap: 8px; color: var(--text); font-size: .95rem; margin: 6px 0; cursor: pointer; }
@keyframes fade { from { opacity: 0; } }

/* Toasts */
#toasts { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); z-index: 100; display: grid; gap: 8px; width: min(420px, calc(100% - 32px)); }
.toast { background: var(--surface-2); border: 1px solid var(--border); border-left: 4px solid var(--ok); border-radius: 8px; padding: 10px 14px; box-shadow: 0 8px 24px rgba(0,0,0,.5); animation: fade .15s; }
.toast.err { border-left-color: var(--danger); }
