:root {
  --bg: #0d0f0e;
  --panel: #171a18;
  --panel-2: #1e211f;
  --panel-3: #252925;
  --text: #f3efe5;
  --muted: #969b94;
  --line: #30352f;
  --accent: #d84a2b;
  --accent-bright: #f0643f;
  --gold: #d6ad62;
  --green: #63a774;
  --red: #c9574d;
  --radius: 14px;
  --shadow: 0 18px 45px rgba(0, 0, 0, .23);
}

* { box-sizing: border-box; }
html { color-scheme: dark; scroll-behavior: smooth; }
body {
  margin: 0;
  min-width: 320px;
  background:
    radial-gradient(circle at 78% -10%, rgba(216, 74, 43, .12), transparent 32rem),
    var(--bg);
  color: var(--text);
  font: 15px/1.5 Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
.app-shell { min-height: 100vh; display: grid; grid-template-columns: 246px minmax(0, 1fr); }
.sidebar {
  position: sticky; top: 0; height: 100vh; padding: 28px 20px 22px;
  display: flex; flex-direction: column; border-right: 1px solid var(--line);
  background: rgba(15, 17, 16, .94); backdrop-filter: blur(18px);
}
.brand { color: inherit; text-decoration: none; display: flex; align-items: center; gap: 12px; padding: 0 7px 28px; }
.brand-mark {
  width: 42px; height: 42px; display: grid; place-items: center; border: 1px solid #713524;
  border-radius: 11px; background: linear-gradient(145deg, #442319, #201714); color: #ff896b;
  font: 700 20px/1 Georgia, serif; box-shadow: inset 0 0 18px rgba(216, 74, 43, .18);
}
.brand strong { display: block; font: 700 20px/1.1 Georgia, serif; letter-spacing: .02em; }
.brand small, .sidebar-foot small { color: var(--muted); display: block; font-size: 11px; margin-top: 4px; }
.nav { display: grid; gap: 7px; }
.nav-item {
  border: 0; border-radius: 10px; background: transparent; color: #b7bbb5;
  padding: 11px 12px; display: flex; gap: 12px; align-items: center; text-align: left;
}
.nav-item span { width: 21px; color: #81867f; font-size: 19px; text-align: center; }
.nav-item:hover { color: var(--text); background: var(--panel); }
.nav-item.active { color: #fff; background: linear-gradient(90deg, rgba(216,74,43,.22), rgba(216,74,43,.06)); box-shadow: inset 3px 0 var(--accent); }
.nav-item.active span { color: var(--accent-bright); }
.nav-subitem { margin-left: 32px; padding: 8px 12px; font-size: 12px; }
.nav-subitem span { font-size: 15px; }
.sidebar-foot { margin-top: auto; display: flex; gap: 10px; align-items: center; padding: 14px 8px 0; border-top: 1px solid var(--line); font-size: 12px; }
.sidebar-foot strong { display: block; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: #61bc77; box-shadow: 0 0 0 4px rgba(97,188,119,.11); }
.main { min-width: 0; padding: 34px clamp(22px, 4vw, 60px) 70px; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-bottom: 28px; }
.admin-actions { display: flex; align-items: center; gap: 8px; }
.admin-label { color: #91d59f; font-size: 10px; font-weight: 750; letter-spacing: .08em; text-transform: uppercase; }
.eyebrow { margin: 0 0 5px; color: var(--accent-bright); text-transform: uppercase; letter-spacing: .15em; font-size: 10px; font-weight: 750; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 0; font: 700 clamp(27px, 3vw, 38px)/1.1 Georgia, serif; letter-spacing: -.02em; }
h2 { font: 700 21px/1.2 Georgia, serif; margin-bottom: 4px; }
h3 { font-size: 15px; margin-bottom: 5px; }
.subtle { color: var(--muted); }
.tiny { font-size: 11px; }
.view { display: none; animation: reveal .22s ease; }
.view.active { display: block; }
@keyframes reveal { from { opacity: 0; transform: translateY(5px); } }
.grid { display: grid; gap: 18px; }
.stats-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.two-col { grid-template-columns: minmax(0, 1.35fr) minmax(280px, .8fr); }
.dashboard-grid { grid-template-columns: minmax(0, 1.25fr) minmax(290px, .75fr); margin-top: 18px; }
.card { border: 1px solid var(--line); border-radius: var(--radius); background: linear-gradient(145deg, rgba(29,32,30,.97), rgba(21,24,22,.98)); box-shadow: var(--shadow); }
.card-pad { padding: 20px; }
.section-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 18px; }
.section-head p { margin: 0; color: var(--muted); font-size: 12px; }
.stat-card { padding: 17px 18px; min-height: 112px; position: relative; overflow: hidden; }
.stat-card::after { content: ""; position: absolute; width: 72px; height: 72px; border-radius: 50%; background: rgba(216,74,43,.06); right: -24px; top: -24px; }
.stat-label { color: var(--muted); text-transform: uppercase; letter-spacing: .1em; font-size: 10px; font-weight: 700; }
.stat-value { font: 700 31px/1.15 Georgia, serif; margin: 7px 0 3px; }
.stat-note { color: var(--muted); font-size: 11px; }
.button {
  border: 1px solid var(--line); border-radius: 9px; padding: 10px 15px; background: var(--panel-3);
  color: var(--text); font-weight: 700; transition: .16s ease; display: inline-flex; justify-content: center; align-items: center; gap: 7px;
}
.button:hover { transform: translateY(-1px); border-color: #555c54; }
.button.primary { background: linear-gradient(135deg, var(--accent-bright), #ad351f); border-color: #e36040; color: #fff; box-shadow: 0 8px 22px rgba(216,74,43,.2); }
.button.ghost { background: transparent; }
.button.danger { color: #e9867d; background: rgba(201,87,77,.08); border-color: rgba(201,87,77,.28); }
.button.compact { padding: 8px 12px; font-size: 12px; }
.button:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.field { display: grid; gap: 6px; }
.field label, .field-label { color: #c3c7c0; font-size: 11px; font-weight: 750; letter-spacing: .04em; }
input, select, textarea {
  min-width: 0; width: 100%; border: 1px solid #353a35; border-radius: 9px; padding: 10px 11px;
  background: #111412; color: var(--text); outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(216,74,43,.1); }
textarea { resize: vertical; min-height: 86px; }
.form-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.form-row.three { grid-template-columns: 1fr 1fr 1fr; }
.player-stack { display: grid; gap: 14px; }
.player-card { border: 1px solid var(--line); border-radius: 12px; background: #131614; overflow: hidden; }
.player-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px; border-bottom: 1px solid var(--line); background: rgba(255,255,255,.015); }
.player-number { display: flex; align-items: center; gap: 9px; font-weight: 750; }
.number-dot { width: 25px; height: 25px; border-radius: 50%; display: grid; place-items: center; background: rgba(216,74,43,.15); color: #ff8061; font-size: 11px; }
.icon-button { border: 0; background: transparent; color: var(--muted); padding: 5px; }
.icon-button:hover { color: #fff; }
.player-body { padding: 14px; display: grid; gap: 13px; }
.score-boxes { display: grid; grid-template-columns: 1fr 1fr auto; gap: 10px; align-items: end; }
.score-total { min-width: 76px; height: 42px; border-radius: 9px; display: grid; place-items: center; background: rgba(214,173,98,.1); color: var(--gold); border: 1px solid rgba(214,173,98,.18); font: 700 19px Georgia, serif; }
.performance { border-top: 1px solid var(--line); padding-top: 12px; }
details > summary { cursor: pointer; color: #c8cbc6; font-size: 12px; font-weight: 700; }
.performance-list { display: grid; gap: 7px; margin-top: 10px; }
.performance-row { display: grid; grid-template-columns: minmax(130px, 1fr) 88px minmax(150px, 1.2fr); gap: 8px; align-items: center; }
.performance-row span { font-size: 11px; color: #c6cac3; }
.performance-row input, .performance-row select { padding: 7px 8px; font-size: 11px; }
.form-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; }
.notice { display: none; position: fixed; z-index: 20; right: 24px; top: 22px; max-width: 380px; padding: 12px 15px; border-radius: 10px; color: #fff; background: #2c5d39; border: 1px solid #4a8a5c; box-shadow: var(--shadow); }
.notice.show { display: block; animation: reveal .2s ease; }
.notice.error { background: #642c27; border-color: #974a42; }
.modal { display: none; position: fixed; inset: 0; z-index: 40; place-items: center; padding: 18px; background: rgba(4,5,4,.78); backdrop-filter: blur(8px); }
.modal.show { display: grid; }
.modal-card { width: min(420px, 100%); position: relative; display: grid; gap: 15px; padding: 26px; border: 1px solid var(--line); border-radius: 16px; background: var(--panel); box-shadow: var(--shadow); }
.modal-card h2, .modal-card p { margin-bottom: 0; }
.modal-close { position: absolute; right: 12px; top: 12px; border: 0; background: transparent; color: var(--muted); }
.default-hint { margin: 0; padding: 9px 10px; border-radius: 8px; color: #d6bd8e; background: rgba(214,173,98,.08); border: 1px solid rgba(214,173,98,.18); font-size: 11px; }
.login-error { display: none; margin: 0; padding: 9px 10px; border-radius: 8px; color: #ffaaa2; background: rgba(201,87,77,.1); border: 1px solid rgba(201,87,77,.35); font-size: 12px; }
.login-error:not(:empty) { display: block; }
.empty { padding: 32px 18px; text-align: center; color: var(--muted); border: 1px dashed #363b36; border-radius: 11px; }
.empty strong { color: var(--text); display: block; margin-bottom: 5px; }
.bar-list { display: grid; gap: 14px; }
.bar-label { display: flex; justify-content: space-between; gap: 12px; font-size: 12px; margin-bottom: 6px; }
.bar-label span:last-child { color: var(--muted); font-variant-numeric: tabular-nums; }
.bar-track { height: 8px; border-radius: 20px; background: #0e110f; overflow: hidden; display: flex; }
.bar-win { height: 100%; background: linear-gradient(90deg, #477e55, #68ad78); }
.bar-loss { height: 100%; background: linear-gradient(90deg, #9d3f36, #ca5c51); }
.bar-draw { height: 100%; background: #6d716d; }
.matchups { display: grid; gap: 9px; }
.matchup { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 12px; align-items: center; padding: 11px 12px; border-radius: 9px; background: rgba(255,255,255,.025); border: 1px solid #2c312c; }
.matchup strong { font-size: 12px; display: block; }
.matchup small { color: var(--muted); }
.record { white-space: nowrap; font: 700 13px Georgia, serif; color: var(--gold); }
.badge { display: inline-flex; align-items: center; border: 1px solid #3b413b; background: #202420; color: #c7cbc5; border-radius: 20px; padding: 3px 8px; font-size: 9px; text-transform: uppercase; letter-spacing: .06em; font-weight: 700; }
.badge.win { color: #91d59f; border-color: rgba(99,167,116,.35); background: rgba(99,167,116,.1); }
.badge.loss { color: #e38c84; border-color: rgba(201,87,77,.35); background: rgba(201,87,77,.1); }
.badge.draw { color: #c5c8c3; }
.roster-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.roster-card { overflow: hidden; }
.roster-accent { height: 4px; background: linear-gradient(90deg, var(--accent), var(--gold)); }
.roster-top { padding: 18px 18px 13px; }
.roster-meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 11px; }
.roster-points { font: 700 18px Georgia, serif; color: var(--gold); }
.roster-title-row { display: flex; justify-content: space-between; gap: 12px; }
.unit-table { width: 100%; border-collapse: collapse; font-size: 11px; }
.unit-table th { color: var(--muted); text-align: left; font-size: 9px; text-transform: uppercase; letter-spacing: .08em; padding: 8px 18px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.unit-table td { padding: 7px 18px; border-bottom: 1px solid rgba(48,53,47,.55); }
.unit-table td:last-child, .unit-table th:last-child { text-align: right; }
.roster-actions { padding: 12px 18px 16px; display: flex; justify-content: space-between; align-items: center; }
.enhancement { display: block; color: var(--gold); margin-top: 2px; font-size: 9px; }
.upload-card { padding: 20px; margin-bottom: 18px; display: grid; grid-template-columns: 1fr minmax(220px, .65fr) auto; gap: 12px; align-items: end; }
.upload-copy p { margin: 3px 0 0; color: var(--muted); font-size: 11px; }
.game-list { display: grid; gap: 13px; }
.game-card { padding: 18px; }
.game-card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.game-card-head p { color: var(--muted); font-size: 11px; margin: 4px 0 0; }
.game-players { display: grid; gap: 6px; }
.game-player { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; align-items: center; gap: 12px; padding: 10px 11px; border-radius: 9px; background: rgba(255,255,255,.024); }
.game-player strong { display: block; font-size: 12px; }
.game-player small { color: var(--muted); }
.score { font: 700 20px Georgia, serif; min-width: 42px; text-align: right; }
.score-split { color: var(--muted); font-size: 10px; white-space: nowrap; }
.unit-notes { margin: 12px 0 0; border-top: 1px solid var(--line); padding-top: 10px; color: var(--muted); font-size: 11px; }
.photo-picker { margin-top: 14px; padding: 13px; border: 1px dashed #3c423c; border-radius: 10px; background: rgba(255,255,255,.015); }
.photo-gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 9px; margin-top: 14px; }
.photo { position: relative; aspect-ratio: 4 / 3; overflow: hidden; border-radius: 10px; border: 1px solid var(--line); background: #0b0d0c; }
.photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo .icon-button { position: absolute; right: 6px; top: 6px; width: 28px; height: 28px; border-radius: 50%; color: #fff; background: rgba(90,25,19,.88); }
.viewer-callout { padding: 34px; text-align: center; }
.viewer-callout .brand-mark { margin: 0 auto 15px; }
.recommend-box { min-height: 190px; }
.recommend-lead { padding: 12px; border-radius: 10px; background: rgba(216,74,43,.08); border: 1px solid rgba(216,74,43,.18); margin-bottom: 10px; }
.recommend-lead strong { color: #ff896b; }
.signal-list { display: grid; gap: 7px; }
.signal { display: flex; justify-content: space-between; gap: 12px; font-size: 11px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.signal span:last-child { color: var(--gold); white-space: nowrap; }
.detachment-groups, .unit-rating-groups { display: grid; gap: 18px; }
.detachment-group h3, .unit-rating-group h3 { margin: 0 0 7px; color: var(--gold); font: 700 15px/1.2 Georgia, serif; }
.detachment-group + .detachment-group, .unit-rating-group + .unit-rating-group { padding-top: 17px; border-top: 1px solid var(--line); }
.profile-toolbar { display: flex; justify-content: space-between; align-items: end; gap: 18px; margin-bottom: 18px; }
.profile-toolbar h2 { margin-bottom: 3px; }
.profile-toolbar p { margin: 0; color: var(--muted); font-size: 12px; }
.profile-toolbar .field { width: min(330px, 100%); }
.profile-hero { display: grid; grid-template-columns: auto minmax(180px, 1fr) minmax(390px, .9fr); align-items: center; gap: 18px; padding: 22px; overflow: hidden; position: relative; }
.profile-hero::after { content: ""; position: absolute; width: 220px; height: 220px; right: -90px; top: -120px; border-radius: 50%; background: rgba(216,74,43,.07); pointer-events: none; }
.profile-avatar { width: 62px; height: 62px; display: grid; place-items: center; border-radius: 16px; background: linear-gradient(145deg, #4a261b, #221714); border: 1px solid #713524; color: #ff896b; font: 700 21px Georgia, serif; }
.profile-hero.army .profile-avatar { color: var(--gold); border-color: rgba(214,173,98,.4); background: rgba(214,173,98,.08); }
.profile-hero h2 { font-size: 27px; margin-bottom: 4px; }
.profile-hero p { margin: 0; color: var(--muted); font-size: 12px; }
.profile-metrics { display: grid; grid-template-columns: repeat(4, minmax(70px, 1fr)); gap: 7px; position: relative; z-index: 1; }
.profile-metrics div { padding: 10px; border: 1px solid var(--line); border-radius: 10px; background: rgba(10,12,11,.36); text-align: center; }
.profile-metrics strong { display: block; color: var(--gold); font: 700 20px Georgia, serif; }
.profile-metrics span { display: block; margin-top: 2px; color: var(--muted); font-size: 9px; text-transform: uppercase; letter-spacing: .07em; }
.profile-grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); margin-top: 18px; align-items: start; }
.profile-details, .profile-matchups { display: grid; gap: 8px; }
.profile-detail { border: 1px solid var(--line); border-radius: 10px; background: rgba(255,255,255,.018); overflow: hidden; }
.profile-detail > summary { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 11px 12px; list-style: none; }
.profile-detail > summary::-webkit-details-marker { display: none; }
.profile-detail > summary strong, .profile-detail > summary small { display: block; }
.profile-detail > summary small { color: var(--muted); font-size: 10px; margin-top: 2px; }
.usage-list { display: grid; max-height: 390px; overflow: auto; border-top: 1px solid var(--line); }
.usage-list > div { display: flex; justify-content: space-between; gap: 12px; padding: 8px 12px; border-bottom: 1px solid rgba(48,53,47,.55); font-size: 11px; }
.usage-list > div:last-child { border-bottom: 0; }
.usage-list strong { color: var(--gold); white-space: nowrap; font-size: 10px; }
.unit-profile-stats { display: grid; justify-items: end; gap: 1px; }
.unit-profile-stats small { color: var(--muted); white-space: nowrap; font-size: 9px; }
.profile-matchup { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 12px; align-items: center; padding: 10px 11px; border: 1px solid #2c312c; border-radius: 9px; background: rgba(255,255,255,.024); }
.profile-matchup strong, .profile-matchup small { display: block; }
.profile-matchup strong { font-size: 12px; }
.profile-matchup small { color: var(--muted); margin-top: 2px; }
.army-profile-grid { align-items: stretch; }
.mobile-nav { display: none; }
.loading { min-height: 240px; display: grid; place-items: center; color: var(--muted); }

@media (max-width: 1050px) {
  .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dashboard-grid, .two-col, .profile-grid { grid-template-columns: 1fr; }
  .profile-hero { grid-template-columns: auto 1fr; }
  .profile-metrics { grid-column: 1 / -1; }
}
@media (max-width: 760px) {
  .app-shell { display: block; }
  .sidebar { display: none; }
  .main { padding: 24px 15px 92px; }
  .topbar { margin-bottom: 22px; }
  .topbar .button { display: none; }
  .topbar .admin-actions .button { display: inline-flex; }
  .admin-label { display: none; }
  .stats-grid, .roster-grid { grid-template-columns: 1fr; }
  #dashboard-view.active { display: flex; flex-direction: column; gap: 18px; }
  #dashboard-view .dashboard-grid { display: contents; }
  #dashboard-view .faction-record-card { order: -2; }
  #dashboard-view .stats-grid { order: -1; }
  .mobile-nav { position: fixed; z-index: 10; bottom: 0; left: 0; right: 0; width: 100%; height: 68px; display: flex; flex-wrap: nowrap; background: rgba(17,20,18,.97); border-top: 1px solid var(--line); backdrop-filter: blur(14px); }
  .mobile-nav button { width: 25%; min-width: 0; height: 100%; flex: 0 0 25%; border: 0; background: transparent; color: var(--muted); display: grid; place-content: center; gap: 1px; padding: 0; font-size: 9px; white-space: nowrap; }
  .mobile-nav button span { font-size: 20px; }
  .mobile-nav button.active { color: #ff7a59; }
  .form-row, .form-row.three { grid-template-columns: 1fr; }
  .score-boxes { grid-template-columns: 1fr 1fr; }
  .score-total { grid-column: 1 / -1; width: 100%; }
  .performance-row { grid-template-columns: 1fr 78px; }
  .performance-row input { grid-column: 1 / -1; }
  .upload-card { grid-template-columns: 1fr; }
  .game-player { grid-template-columns: minmax(0, 1fr) auto; }
  .score-split { grid-column: 1 / -1; }
  .notice { left: 15px; right: 15px; top: 15px; max-width: none; }
  .profile-toolbar { display: grid; }
  .profile-toolbar .field { width: 100%; }
  .profile-hero { grid-template-columns: auto 1fr; padding: 17px; }
  .profile-metrics { grid-template-columns: repeat(2, 1fr); }
}
