:root {
  --bg: #130d1f;
  --surface: #1b1429;
  --surface-hi: #241a37;
  --line: #2f2445;
  --text: #ece6f6;
  --muted: #958aae;
  --accent: #9a62ff;
  --accent-hi: #ae82ff;
  --gold: #f4c430;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 "Rubik", "Segoe UI", system-ui, sans-serif;
}

/* faint GD-style grid behind the header only */
body::before {
  content: "";
  position: absolute; inset: 0 0 auto 0; height: 340px; z-index: -1;
  background-image:
    linear-gradient(var(--line) 1px, transparent 1px),
    linear-gradient(90deg, var(--line) 1px, transparent 1px);
  background-size: 40px 40px;
  opacity: .35;
  mask-image: linear-gradient(#000, transparent);
}

.top, main, .foot { max-width: 1100px; margin: 0 auto; padding-left: 20px; padding-right: 20px; }

/* header */
.top {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding-top: 36px; padding-bottom: 20px;
}
.brand { display: flex; align-items: center; gap: 14px; }
.cube {
  width: 40px; height: 40px; flex-shrink: 0;
  background: var(--accent);
  border: 3px solid #0d0816;
  box-shadow: inset 0 0 0 5px var(--accent), inset 0 0 0 9px #0d0816;
  border-radius: 4px;
  transition: transform .35s cubic-bezier(.3, 1.6, .5, 1);
}
.brand:hover .cube { transform: translateY(-6px) rotate(90deg); }
h1 { margin: 0; font-size: 1.75rem; font-weight: 800; letter-spacing: -.01em; }
.sub { margin: 2px 0 0; color: var(--muted); }

/* buttons */
.btn {
  font: inherit; font-weight: 500;
  padding: 8px 14px; border-radius: 6px; cursor: pointer;
  color: var(--text); background: var(--surface); border: 1px solid var(--line);
  transition: background .15s, border-color .15s;
}
.btn:hover { background: var(--surface-hi); border-color: #46386a; }
.btn.accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.accent:hover { background: var(--accent-hi); border-color: var(--accent-hi); }
.btn.small { padding: 5px 10px; font-size: .9rem; }
:focus-visible { outline: 2px solid var(--accent-hi); outline-offset: 2px; }

/* page tabs */
.tabs {
  max-width: 1100px; margin: 0 auto 22px; padding: 0 20px;
  display: flex; gap: 4px; border-bottom: 1px solid var(--line);
}
.tabs a {
  position: relative; padding: 10px 14px;
  color: var(--muted); text-decoration: none; font-weight: 500;
  transition: color .15s;
}
.tabs a:hover { color: var(--text); }
.tabs a::after {
  content: ""; position: absolute; left: 10px; right: 10px; bottom: -1px; height: 3px;
  background: var(--accent); border-radius: 3px 3px 0 0;
  transform: scaleX(0); transition: transform .2s ease-out;
}
.tabs a[aria-current="page"] { color: var(--text); }
.tabs a[aria-current="page"]::after { transform: scaleX(1); }

/* info line */
.info {
  display: flex; align-items: center; flex-wrap: wrap; gap: 8px;
  color: var(--muted); margin-bottom: 18px;
}
.info b { color: var(--text); }
.info a { color: var(--accent-hi); }
.meter {
  display: inline-block; width: 120px; height: 6px; border-radius: 3px;
  background: var(--line); overflow: hidden; margin-left: 4px;
}
.meter span { display: block; height: 100%; background: var(--accent); }
.muted { color: var(--muted); }

/* unsaved banner */
.banner {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 10px 14px; margin-bottom: 14px;
  border: 1px solid #6b5a1e; border-left: 4px solid var(--gold); border-radius: 6px;
  background: #221c12; color: #eedc9a;
}
.banner p { margin: 0; }
.banner code { background: rgba(255,255,255,.08); padding: 1px 5px; border-radius: 3px; }
.banner-actions { display: flex; gap: 6px; }

/* search + add */
.toolbar { display: flex; gap: 10px; margin-bottom: 12px; }
.toolbar input {
  flex: 1; font: inherit; color: var(--text);
  background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 9px 12px;
}
.toolbar input::placeholder { color: var(--muted); }

/* the list */
.table { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.thead, .row {
  display: grid;
  align-items: center; gap: 12px;
  padding: 0 16px;
}
.levels .thead, .levels .row { grid-template-columns: 56px minmax(170px, 2fr) 110px 1fr 84px 1.2fr 112px; }
.players .thead, .players .row { grid-template-columns: 56px minmax(150px, 1.6fr) 100px 100px 1.4fr 70px 70px; }
.thead {
  padding-top: 10px; padding-bottom: 10px;
  font-size: .82rem; font-weight: 500; color: var(--muted);
  border-bottom: 1px solid var(--line);
}
.num { text-align: right; font-variant-numeric: tabular-nums; }
.list { list-style: none; margin: 0; padding: 0; }

.row {
  position: relative;
  padding-top: 12px; padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
  transition: background .15s;
}
.row:last-child { border-bottom: 0; }
.row::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px;
  background: var(--accent);
  transform: scaleY(0); transition: transform .2s ease-out;
}
.row:hover { background: var(--surface-hi); }
.row:hover::before { transform: scaleY(1); }
.row.intro { animation: fade-in .4s ease-out both; animation-delay: calc(var(--i) * 30ms); }
@keyframes fade-in { from { opacity: 0; transform: translateY(6px); } }

.place { font-weight: 800; font-size: 1.15rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.row.top1 .place { color: var(--gold); font-size: 1.35rem; }
.row.top1::before { background: var(--gold); transform: scaleY(1); }
.row.top2 .place, .row.top3 .place { color: var(--text); }

.lvl-name { font-weight: 700; font-size: 1.02rem; overflow-wrap: anywhere; }
.lvl-by { color: var(--muted); font-size: .85rem; }
.cell { overflow-wrap: anywhere; }
.cell .lbl { display: none; }

/* difficulty tag, coloured like the sheet cells */
.tag {
  display: inline-block; padding: 2px 8px; border-radius: 3px;
  background: var(--c); color: var(--fg);
  font-size: .85rem; font-weight: 500;
}

.id-btn {
  font: inherit; font-size: .88rem; font-variant-numeric: tabular-nums;
  color: var(--muted); background: none; border: 0; padding: 2px 0; cursor: pointer;
  border-bottom: 1px dashed #4b3d6c;
}
.id-btn:hover { color: var(--text); border-bottom-color: var(--accent); }

.edit-tools { grid-column: 2 / -1; display: flex; gap: 6px; padding-top: 2px; }
.mini {
  font: inherit; font-size: .82rem; cursor: pointer;
  color: var(--muted); background: var(--bg); border: 1px solid var(--line); border-radius: 4px; padding: 3px 9px;
}
.mini:hover { color: var(--text); border-color: #46386a; }
.mini:disabled { opacity: .35; cursor: default; }
.mini.danger:hover { color: #ff9b9b; border-color: #7a2f3a; }

.empty { margin: 0; padding: 32px 16px; text-align: center; color: var(--muted); }

/* difficulties board, one column per tier like the sheet */
.tier-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; }
.tier {
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px; overflow: hidden;
  animation: fade-in .4s ease-out both;
}
.tier-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 7px 12px; background: var(--c); color: var(--fg);
  font-weight: 700; text-transform: capitalize;
}
.tier-count { font-weight: 500; font-size: .85rem; opacity: .75; }
.tier ul { list-style: none; margin: 0; padding: 4px 0; }
.tier li {
  display: flex; justify-content: space-between; gap: 8px;
  padding: 6px 12px; font-size: .92rem;
}
.tier li + li { border-top: 1px solid var(--line); }
.tier .mod { color: var(--muted); font-weight: 700; }
.tier .none { margin: 0; padding: 10px 12px; font-size: .9rem; }
.empty-tier .tier-head { opacity: .55; }
.foot { color: var(--muted); font-size: .85rem; padding-top: 18px; padding-bottom: 40px; }

/* dialogs */
.modal {
  width: min(540px, calc(100% - 32px)); padding: 0;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--line); border-radius: 8px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, .5);
}
.modal::backdrop { background: rgba(6, 3, 12, .7); }
.modal form { padding: 20px; }
.modal h2 { margin: 0 0 12px; font-size: 1.25rem; }
.modal input, .modal select {
  display: block; width: 100%; margin-top: 4px;
  font: inherit; color: var(--text);
  background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px;
}
.modal select option { background: var(--bg); }
.form-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.form-grid label { font-size: .85rem; color: var(--muted); }
.form-grid .span2 { grid-column: span 2; }
.form-grid .span3 { grid-column: 1 / -1; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.error { color: #ff9b9b; font-size: .88rem; margin: 6px 0 0; }
.shake { animation: shake .3s; }
@keyframes shake { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }

/* toast */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 12px);
  padding: 8px 14px; border-radius: 6px;
  background: var(--text); color: var(--bg); font-weight: 500; font-size: .9rem;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* phones */
@media (max-width: 860px) {
  .thead { display: none; }
  .levels .row, .players .row { grid-template-columns: 44px 1fr 1fr; row-gap: 8px; }
  .row .place { grid-row: 1 / span 4; align-self: start; padding-top: 2px; }
  .row .main { grid-column: 2 / -1; }
  .cell .lbl { display: block; font-size: .75rem; color: var(--muted); }
  .num { text-align: left; }
  .form-grid { grid-template-columns: 1fr 1fr; }
  .form-grid .span2 { grid-column: 1 / -1; }
}
@media (max-width: 520px) {
  .top { flex-direction: column; align-items: flex-start; }
  .toolbar { flex-direction: column; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before { animation: none !important; transition: none !important; }
}
