:root {
  --bg: #0f1218;
  --bg-2: #151a22;
  --panel: #1a2029;
  --panel-2: #212835;
  --line: #2c3442;
  --text: #e8e3d6;
  --muted: #9aa3b2;
  --gold: #d8b25a;
  --gold-2: #f0cf7e;
  --gold-ink: #1b1608;
  --ok: #5fbf83;
  --warn: #e3a144;
  --bad: #e06a5f;
  --blue: #6aa6e8;
  --radius: 12px;
  --shadow: 0 10px 30px rgba(0, 0, 0, .35);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: radial-gradient(1200px 500px at 50% -200px, #2a2414 0%, transparent 70%), var(--bg);
  color: var(--text);
  font: 15px/1.5 Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  min-height: 100vh;
}
h1, h2, h3, .brand { font-family: Cinzel, Georgia, serif; letter-spacing: .02em; }
h1 { font-size: 26px; margin: 0 0 4px; }
h2 { font-size: 18px; margin: 0 0 12px; color: var(--gold-2); }
h3 { font-size: 15px; margin: 18px 0 8px; color: var(--text); }
a { color: var(--gold-2); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.hidden { display: none !important; }

/* ---- top bar ---- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 16px; border-bottom: 1px solid var(--line);
  background: rgba(15, 18, 24, .85); backdrop-filter: blur(6px);
  position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 10px; font-size: 18px; font-weight: 700; color: var(--gold-2); text-decoration: none; }
.brand .crest {
  width: 32px; height: 32px; border-radius: 8px; display: grid; place-items: center;
  background: linear-gradient(160deg, var(--gold-2), #9c7a2c); color: var(--gold-ink); font-size: 13px; font-weight: 800;
}
.topbar nav { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }

.wrap { max-width: 860px; margin: 0 auto; padding: 20px 16px 60px; }
.wrap.wide { max-width: none; }

.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; margin-bottom: 16px; box-shadow: var(--shadow);
}

/* ---- controls ---- */
button, .btn {
  font: inherit; border: 1px solid var(--line); background: var(--panel-2); color: var(--text);
  border-radius: 9px; padding: 8px 14px; cursor: pointer; text-decoration: none; display: inline-flex;
  align-items: center; gap: 8px; justify-content: center; white-space: nowrap;
}
button:hover, .btn:hover { border-color: #3d475a; background: #263042; }
button:disabled { opacity: .5; cursor: default; }
.btn-gold { background: linear-gradient(180deg, var(--gold-2), var(--gold)); color: var(--gold-ink); border-color: #b08f3f; font-weight: 600; }
.btn-gold:hover { background: linear-gradient(180deg, #f6dc98, #e2bd68); }
.btn-ghost { background: transparent; }
.btn-danger { color: var(--bad); }
.btn-sm { padding: 4px 10px; font-size: 13px; border-radius: 7px; }
.btn-google { background: #fff; color: #222; border-color: #ddd; font-weight: 600; }
.btn-google:hover { background: #f1f1f1; }
.btn-discord { background: #5865f2; color: #fff; border-color: #4752c4; font-weight: 600; }
.btn-discord:hover { background: #4f5bdc; }

label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
input, select {
  font: inherit; width: 100%; padding: 9px 11px; border-radius: 9px; border: 1px solid var(--line);
  background: var(--bg-2); color: var(--text);
}
input:focus, select:focus { outline: 2px solid rgba(216, 178, 90, .45); border-color: var(--gold); }

.grid { display: grid; gap: 12px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
@media (max-width: 560px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }

.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }

.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; }
.seg button { border: 0; border-radius: 0; background: var(--bg-2); padding: 8px 14px; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: var(--gold); color: var(--gold-ink); font-weight: 600; }

.msg { padding: 10px 12px; border-radius: 9px; margin-bottom: 12px; font-size: 14px; }
.msg.error { background: rgba(224, 106, 95, .12); border: 1px solid rgba(224, 106, 95, .4); color: #ffb3ab; }
.msg.ok { background: rgba(95, 191, 131, .12); border: 1px solid rgba(95, 191, 131, .4); color: #a9e6c0; }

.status { font-size: 13px; color: var(--muted); min-height: 1em; }
.status.ok { color: var(--ok); }
.status.err { color: var(--bad); }

/* ---- login ---- */
.login { max-width: 400px; margin: 40px auto; }
.login .hero { text-align: center; margin-bottom: 18px; }
.login .hero .crest-lg {
  width: 64px; height: 64px; margin: 0 auto 10px; border-radius: 16px; display: grid; place-items: center;
  background: linear-gradient(160deg, var(--gold-2), #9c7a2c); color: var(--gold-ink); font: 800 22px Cinzel, serif;
}
.oauth { display: grid; gap: 8px; margin-bottom: 14px; }
.divider { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13px; margin: 14px 0; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.tabs { display: flex; gap: 4px; margin-bottom: 14px; }
.tabs button { flex: 1; }
.tabs button.on { border-color: var(--gold); color: var(--gold-2); }

/* ---- battle banner ---- */
.banner {
  display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 16px 18px; border-radius: var(--radius); margin-bottom: 16px;
  background: linear-gradient(135deg, #2b2312, #1a1f29 70%); border: 1px solid #4a3d1d;
}
.banner .when { font-size: 14px; color: var(--muted); }
.pill { display: inline-block; font-size: 12px; padding: 2px 8px; border-radius: 99px; border: 1px solid var(--line); color: var(--muted); }
.pill.gold { border-color: #8a6f30; color: var(--gold-2); }
.pill.ok { border-color: rgba(95, 191, 131, .5); color: var(--ok); }

/* ---- availability slots ---- */
.slots { display: grid; grid-template-columns: repeat(10, minmax(0, 1fr)); gap: 6px; }
@media (max-width: 640px) { .slots { grid-template-columns: repeat(5, minmax(0, 1fr)); } }
.slot {
  display: flex; flex-direction: column; align-items: center; padding: 10px 2px; border-radius: 9px;
  background: var(--bg-2); border: 1px solid var(--line); color: var(--muted); user-select: none; touch-action: manipulation;
}
.slot b { color: var(--text); font-size: 14px; }
.slot span { font-size: 11px; }
.slot.on { background: rgba(95, 191, 131, .18); border-color: var(--ok); }
.slot.on b { color: #c9f2d8; }

/* ---- assignment ---- */
.timeline { display: grid; gap: 8px; }
.shift {
  display: grid; grid-template-columns: 150px 1fr; gap: 12px; align-items: center;
  padding: 12px 14px; border-radius: 10px; background: var(--bg-2); border: 1px solid var(--line);
}
.shift.lead { border-color: var(--gold); background: rgba(216, 178, 90, .1); }
.shift.now { box-shadow: 0 0 0 2px rgba(95, 191, 131, .6); }
.shift .time { font-weight: 600; font-variant-numeric: tabular-nums; }
.shift .time small { display: block; font-weight: 400; color: var(--muted); font-size: 12px; }
.shift .who { font-size: 16px; }
.swap { text-align: center; font-size: 12px; color: var(--warn); letter-spacing: .04em; }
@media (max-width: 480px) { .shift { grid-template-columns: 1fr; gap: 4px; } }

/* ---- stats form ---- */
.troops { width: 100%; border-collapse: collapse; }
.troops th, .troops td { padding: 6px 4px; text-align: left; }
.troops th { font-size: 13px; color: var(--muted); font-weight: 500; }
.troops td:first-child { font-weight: 600; width: 34%; }
.skills { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; }

table.list { width: 100%; border-collapse: collapse; }
table.list th, table.list td { padding: 9px 8px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
table.list th { color: var(--muted); font-size: 13px; font-weight: 500; }

.toast {
  position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); z-index: 100;
  background: var(--panel-2); border: 1px solid var(--line); padding: 10px 16px; border-radius: 10px; box-shadow: var(--shadow);
}

.joinbox { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-bottom: 12px; }
.joinbox > div { background: var(--bg-2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; display: grid; gap: 2px; }
.joinbox b { font-size: 17px; color: var(--gold-2); }
@media (max-width: 520px) { .joinbox { grid-template-columns: 1fr; } }

/* ---- troop icons & formation bars ---- */
:root { --inf: #6aa6e8; --cav: #e0776a; --arc: #b98ae6; }
.ti { display: inline-flex; width: 1.15em; height: 1.15em; vertical-align: -0.2em; }
.ti svg { width: 100%; height: 100%; }
.ti.inf { color: var(--inf); } .ti.cav { color: var(--cav); } .ti.arc { color: var(--arc); }
.tt { display: inline-flex; align-items: center; gap: 3px; white-space: nowrap; }
.fbar { display: grid; gap: 5px; }
.fbar-track { display: flex; height: 10px; border-radius: 5px; overflow: hidden; background: #2a3140; gap: 2px; }
.fbar-track i { display: block; height: 100%; }
.fbar-track i.inf, .mini-bar i.inf { background: var(--inf); }
.fbar-track i.cav, .mini-bar i.cav { background: var(--cav); }
.fbar-track i.arc, .mini-bar i.arc { background: var(--arc); }
.fbar-lbl { display: flex; gap: 12px; font-size: 13px; font-variant-numeric: tabular-nums; }
.fbar-lbl span { display: inline-flex; align-items: center; gap: 4px; font-weight: 600; }
.fbar-lbl span.zero { opacity: .4; }
.fbar.compact { gap: 2px; margin-top: 3px; }
.fbar.compact .fbar-track { height: 5px; gap: 1px; }
.fbar.compact .fbar-lbl { display: none; }
.joinbox .jb-form .fbar { margin-top: 4px; }

/* ---- sign-up checklist ---- */
.todo { border-color: #8a6f30; background: linear-gradient(180deg, rgba(216,178,90,.12), var(--panel) 70%); display: grid; gap: 8px; }
.todo h2 { margin-bottom: 6px; }
.todo-step { display: flex; gap: 12px; align-items: center; padding: 10px 12px; border-radius: 10px; background: var(--bg-2); border: 1px solid var(--line); color: var(--text); text-decoration: none; }
.todo-step:hover { border-color: var(--gold); }
.todo-step small { display: block; color: var(--muted); font-size: 13px; }
.todo-step .tick { width: 24px; height: 24px; flex: none; border-radius: 50%; border: 2px solid var(--gold); display: grid; place-items: center; font-weight: 700; color: var(--gold-ink); }
.todo-step.done .tick { background: var(--ok); border-color: var(--ok); }
.todo-step.done b { color: var(--muted); text-decoration: line-through; }
input.need, select.need { border-color: var(--warn); box-shadow: 0 0 0 1px rgba(227,161,68,.4); }
#profile-form, #slots-card { scroll-margin-top: 80px; }

/* alliance tags */
.ally { display: inline-block; font-size: 10px; font-weight: 700; padding: 0 5px; border-radius: 4px; margin-right: 5px; vertical-align: 1px; letter-spacing: .02em; background: #34405a; color: #dfe6f3; }
.ally-2nd { background: #3b5ea8; } .ally-hrd { background: #a8473b; } .ally-pxl { background: #7a4ab0; } .ally-718 { background: #9c7a2c; color: #fff6dc; }

/* rally manager */
:root { --mgr: #4fd1c5; }
.pill.mgr { border-color: var(--mgr); color: var(--mgr); font-weight: 600; }

.shift.free { opacity: .6; }
