:root {
  --bg: #0b0f1a;
  --bg-2: #111727;
  --card: #141b2d;
  --card-2: #1a2238;
  --line: #24304d;
  --text: #e8ecf6;
  --muted: #8b96b3;
  --accent: #3b82f6;
  --accent-2: #f97316;
  --good: #22c55e;
  --danger: #ef4444;
  --radius: 16px;
  --tier: #64748b;
  --tier-2: #94a3b8;
  color-scheme: dark;
}

/* tier palettes */
.tier-unranked { --tier: #475569; --tier-2: #94a3b8; }
.tier-mud      { --tier: #5b4636; --tier-2: #8a6a4f; }
.tier-wood     { --tier: #7c4a1e; --tier-2: #c08a4f; }
.tier-stone    { --tier: #57606f; --tier-2: #a3acb9; }
.tier-copper   { --tier: #9a4d22; --tier-2: #e0884d; }
.tier-bronze   { --tier: #8c5a2b; --tier-2: #d39a5c; }
.tier-silver   { --tier: #6b7686; --tier-2: #dfe5ee; }
.tier-gold     { --tier: #b7861a; --tier-2: #ffd75e; }
.tier-platinum { --tier: #2a8f9e; --tier-2: #8ff0ff; }
.tier-diamond  { --tier: #2459d6; --tier-2: #8fb6ff; }
.tier-champion { --tier: #7b2fd1; --tier-2: #d1a2ff; }
.tier-gc       { --tier: #b3122e; --tier-2: #ff8a9b; }
.tier-ssl      { --tier: #e6e6f0; --tier-2: #ffffff; }
.tier-letter   { --tier: #0f766e; --tier-2: #5eead4; }
.tier-letter-top { --tier: #f59e0b; --tier-2: #fde047; }

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  background:
    radial-gradient(1200px 600px at 10% -10%, #1b2a55 0%, transparent 60%),
    radial-gradient(900px 500px at 110% 10%, #3a1d4f 0%, transparent 55%),
    var(--bg);
  background-attachment: fixed;
  color: var(--text);
  font: 15px/1.5 Inter, system-ui, -apple-system, Segoe UI, sans-serif;
  -webkit-font-smoothing: antialiased;
}
code { font-family: 'JetBrains Mono', ui-monospace, monospace; font-size: .9em; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px max(16px, calc((100% - 1120px) / 2));
  background: rgba(11, 15, 26, .75);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 800; letter-spacing: .02em; display: flex; align-items: center; gap: 10px; }
.logo {
  width: 22px; height: 22px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  clip-path: polygon(50% 0, 100% 25%, 100% 75%, 50% 100%, 0 75%, 0 25%);
}
.topnav { display: flex; gap: 18px; }
.topnav a { color: var(--muted); text-decoration: none; font-weight: 500; }
.topnav a:hover { color: var(--text); }

.wrap { max-width: 1120px; margin: 0 auto; padding: 20px 16px 60px; display: grid; gap: 16px; }
.card {
  background: linear-gradient(180deg, var(--card), var(--bg-2));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  min-width: 0;
}
.card h2 { margin: 0 0 14px; font-size: 16px; font-weight: 700; letter-spacing: .01em; }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.card-head h2 { margin: 0; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-2.align-start { align-items: start; }
@media (max-width: 820px) { .grid-2 { grid-template-columns: 1fr; } }

/* hero */
.hero {
  display: flex; gap: 28px; align-items: center;
  padding: 28px;
  background:
    radial-gradient(500px 240px at 0% 50%, color-mix(in srgb, var(--tier) 40%, transparent), transparent 70%),
    linear-gradient(180deg, var(--card), var(--bg-2));
  border-color: color-mix(in srgb, var(--tier-2) 30%, var(--line));
}
.hero-body { flex: 1; min-width: 0; display: grid; gap: 10px; }
.eyebrow { text-transform: uppercase; letter-spacing: .14em; font-size: 11px; font-weight: 700; color: var(--muted); }
.rank-name { margin: 0; font-size: clamp(28px, 5vw, 44px); line-height: 1.05; font-weight: 800; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.div-tag {
  font-size: 14px; font-weight: 700; padding: 4px 10px; border-radius: 999px;
  background: color-mix(in srgb, var(--tier-2) 18%, transparent);
  border: 1px solid color-mix(in srgb, var(--tier-2) 45%, transparent);
  color: var(--tier-2);
}
.total { color: var(--muted); }
.total strong { color: var(--text); font-family: 'JetBrains Mono', monospace; font-size: 18px; }
@media (max-width: 560px) {
  .hero { flex-direction: column; align-items: stretch; text-align: left; padding: 20px; gap: 16px; }
  .hero .emblem-lg { align-self: center; }
}

/* emblem */
.emblem {
  position: relative; flex: none;
  display: grid; place-items: center;
  background: linear-gradient(145deg, var(--tier-2), var(--tier) 60%, color-mix(in srgb, var(--tier) 60%, #000));
  clip-path: polygon(50% 0, 100% 25%, 100% 75%, 50% 100%, 0 75%, 0 25%);
  color: #fff;
  text-shadow: 0 2px 6px rgba(0, 0, 0, .45);
}
.emblem::after {
  content: ''; position: absolute; inset: 8%;
  clip-path: inherit;
  border: 2px solid rgba(255, 255, 255, .35);
  background: linear-gradient(180deg, rgba(255,255,255,.18), transparent 55%);
}
.emblem-lg { width: 132px; height: 148px; }
.emblem-lg .emblem-text { font-size: 38px; font-weight: 800; letter-spacing: .02em; z-index: 1; }
.emblem-sm { width: 30px; height: 34px; }
.emblem-sm .emblem-text { font-size: 10px; font-weight: 800; z-index: 1; }
.emblem-sm::after { border-width: 1px; }
.emblem-div {
  position: absolute; bottom: 18%; z-index: 1;
  font-size: 12px; font-weight: 800; letter-spacing: .1em;
  background: rgba(0, 0, 0, .35); padding: 1px 8px; border-radius: 999px;
}
.tier-ssl .emblem, .emblem.tier-ssl { color: #1b1f2e; text-shadow: none; }

/* progress */
.progress { display: grid; gap: 6px; margin-top: 4px; }
.progress-head { display: flex; justify-content: space-between; gap: 10px; font-size: 13px; font-weight: 600; }
.bar { height: 12px; background: rgba(255,255,255,.06); border-radius: 999px; overflow: hidden; border: 1px solid var(--line); }
.fill {
  height: 100%; border-radius: inherit;
  background: linear-gradient(90deg, var(--tier), var(--tier-2));
  box-shadow: 0 0 16px color-mix(in srgb, var(--tier-2) 50%, transparent);
  transition: width .6s cubic-bezier(.2,.8,.2,1);
}
.progress.thin .bar { height: 6px; }
.progress.thin .progress-head { font-weight: 500; color: var(--muted); }

/* forms */
.log-form { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.log-form label { display: grid; gap: 6px; font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; }
.log-form .btn { align-self: end; }
input, select {
  width: 100%;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  font: inherit;
  text-transform: none; letter-spacing: normal;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: transparent; }
.inline-field { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.inline-field input { width: 72px; padding: 6px 8px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 16px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--card-2); color: var(--text);
  font: inherit; font-weight: 600; cursor: pointer;
  transition: transform .08s, background .15s, border-color .15s;
}
.btn:hover:not(:disabled) { border-color: color-mix(in srgb, var(--accent) 60%, var(--line)); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: linear-gradient(135deg, var(--accent), #6366f1); border-color: transparent; color: #fff; }
.btn.ghost { background: transparent; }
.btn.danger { color: #fca5a5; }

.quick { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 14px; font-size: 13px; }
.chip {
  padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line);
  background: transparent; color: var(--text); font: inherit; font-weight: 600; cursor: pointer;
}
.chip:hover { background: var(--card-2); }

/* timer */
.timer-display {
  font-family: 'JetBrains Mono', monospace; font-weight: 700;
  font-size: clamp(40px, 8vw, 56px); letter-spacing: .02em;
  margin: 2px 0 14px; font-variant-numeric: tabular-nums;
}
#timer.running .timer-display { color: var(--good); text-shadow: 0 0 24px rgba(34, 197, 94, .35); }
.timer-actions { display: flex; gap: 10px; flex-wrap: wrap; }
#timer p { margin: 14px 0 0; }

/* stats */
.stats { display: grid; grid-template-columns: repeat(6, 1fr); gap: 12px; }
@media (max-width: 980px) { .stats { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 520px) { .stats { grid-template-columns: repeat(2, 1fr); } }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 14px; min-width: 0; }
.stat-label { font-size: 11px; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat-value { font-size: 22px; font-weight: 800; margin: 4px 0 2px; }
.stat-sub { font-size: 12px; color: var(--muted); }

/* chart */
.chart { width: 100%; height: auto; display: block; }
.chart .bar-day { fill: #3b5bab; }
.chart .bar-goal { fill: var(--good); }
.chart .bar-today { fill: var(--accent-2); }
.chart rect:hover { opacity: .8; }
.chart .axis { fill: var(--muted); font-size: 10px; font-family: Inter, sans-serif; }
.chart .goal-line { stroke: var(--good); stroke-dasharray: 4 4; stroke-width: 1; opacity: .7; }

/* history */
.table-wrap { max-height: 520px; overflow: auto; margin: 0 -8px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); font-weight: 700; position: sticky; top: 0; background: var(--card); }
th, td { padding: 9px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td.num, th.num { text-align: right; font-family: 'JetBrains Mono', monospace; font-variant-numeric: tabular-nums; }
th.num { font-family: inherit; }
td.actions { text-align: right; }
.icon-btn { background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 14px; padding: 4px 6px; border-radius: 6px; }
.icon-btn:hover { color: var(--text); background: var(--card-2); }
.icon-btn.danger:hover { color: var(--danger); }
@media (max-width: 560px) { th:nth-child(3), td:nth-child(3) { display: none; } }

/* ladder */
.ladder { list-style: none; margin: 0; padding: 0; max-height: 520px; overflow: auto; display: grid; gap: 4px; }
.ladder-item { display: grid; grid-template-columns: 34px 1fr auto 76px; align-items: center; gap: 10px; padding: 6px 8px; border-radius: 10px; }
.ladder-item.locked { opacity: .45; }
.ladder-item.current { background: color-mix(in srgb, var(--accent) 16%, transparent); outline: 1px solid color-mix(in srgb, var(--accent) 50%, transparent); }
.ladder-name { font-weight: 600; }
.ladder-min { font-family: 'JetBrains Mono', monospace; font-size: 13px; color: var(--muted); }
.ladder-when { font-size: 12px; text-align: right; }

/* data */
.data p { margin: 0 0 12px; }
.data-actions { display: flex; gap: 10px; flex-wrap: wrap; }

/* toast + rankup */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px);
  background: #1e293b; border: 1px solid var(--line); color: var(--text);
  padding: 10px 16px; border-radius: 12px; font-weight: 600; font-size: 14px;
  opacity: 0; pointer-events: none; transition: .25s; max-width: calc(100% - 32px);
  box-shadow: 0 10px 30px rgba(0,0,0,.4);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.rankup {
  position: fixed; inset: 0; z-index: 50; display: none; place-items: center; padding: 16px;
  background: rgba(5, 8, 15, .72); backdrop-filter: blur(6px);
}
.rankup.show { display: grid; animation: fade .25s ease; }
.rankup-card {
  display: grid; justify-items: center; gap: 14px; text-align: center;
  padding: 32px 40px; border-radius: 22px; max-width: 360px; width: 100%;
  background:
    radial-gradient(300px 200px at 50% 20%, color-mix(in srgb, var(--tier) 55%, transparent), transparent 70%),
    var(--card);
  border: 1px solid color-mix(in srgb, var(--tier-2) 40%, var(--line));
  animation: pop .45s cubic-bezier(.2, 1.4, .4, 1);
}
.rankup-card h2 { margin: 0; font-size: 26px; }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { transform: scale(.7); opacity: 0; } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
