/* ─── Design tokens ──────────────────────────────────────────── */
:root {
  --ink:           #1a1510;
  --parchment:     #f0e8d4;
  --gold:          #c9a227;
  --gold-dim:      #8a6e1a;
  --gold-pale:     #f0d888;
  --rust:          #8b3a2a;
  --stone:         #5c5040;
  --stone-lt:      #8a7a68;
  --panel:         #1e1a14;
  --panel2:        #2a2418;
  --panel3:        #332e22;
  --border:        rgba(201,162,39,0.22);
  --border-bright: rgba(201,162,39,0.55);
  --text-main:     #e8dcc4;
  --text-dim:      #a89878;
  --text-faint:    #6a5c48;
  --shadow-gold:   0 0 24px rgba(201,162,39,0.12);
  --radius:        2px;
  --font-display:  'Cinzel', 'Trajan Pro', serif;
  --font-body:     'Crimson Pro', 'Palatino Linotype', Georgia, serif;
}

/* ─── Reset ──────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { height: 100%; }

body {
  font-family: var(--font-body);
  background: var(--ink);
  color: var(--text-main);
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background-image:
    radial-gradient(ellipse at 20% 0%,   rgba(201,162,39,0.055) 0%, transparent 55%),
    radial-gradient(ellipse at 80% 100%, rgba(139,58,42,0.07)   0%, transparent 55%);
}

/* ─── Scrollbar ──────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--panel); }
::-webkit-scrollbar-thumb { background: var(--gold-dim); border-radius: 3px; }

/* ─── Header ─────────────────────────────────────────────────── */
header {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(42,36,24,0.98) 0%, rgba(30,26,20,0.98) 100%);
  position: relative;
  z-index: 10;
}
header::after {
  content: '';
  position: absolute;
  bottom: -1px; left: 0; right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--gold-dim), transparent);
}

.header-logo {
  display: flex;
  align-items: center;
  gap: 12px;
}
.logo-img {
  width: 40px;
  height: 40px;
  object-fit: contain;
  filter: drop-shadow(0 0 6px rgba(201,162,39,0.4));
}
.logo-fallback {
  width: 40px; height: 40px;
  border: 1px solid var(--border-bright);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px;
  color: var(--gold);
  background: var(--panel2);
  flex-shrink: 0;
}
.logo-text { display: flex; flex-direction: column; }
.logo-title {
  font-family: var(--font-display);
  font-size: 16px; font-weight: 700;
  color: var(--gold);
  letter-spacing: 0.06em;
  line-height: 1;
}
.logo-sub {
  font-size: 10px; color: var(--text-dim);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  margin-top: 3px;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 16px;
}
.header-meta {
  font-size: 12px;
  color: var(--text-faint);
  letter-spacing: 0.06em;
  font-style: italic;
}
.btn-dashboard {
  font-family: var(--font-display);
  font-size: 9px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  padding: 6px 14px;
  border: 1px solid var(--border-bright);
  background: transparent;
  color: var(--gold-dim);
  cursor: pointer;
  border-radius: var(--radius);
  text-decoration: none;
  transition: all 0.15s;
  display: none;  /* shown by JS when logged in */
}
.btn-dashboard:hover {
  background: var(--panel3);
  color: var(--gold);
  border-color: var(--gold);
}
.btn-dashboard.visible { display: inline-flex; }

.signature {
  font-size: 9px; color: var(--text-faint);
  letter-spacing: 0.1em; text-transform: uppercase;
  margin-top: 4px;
}

/* ─── App layout ─────────────────────────────────────────────── */
.app {
  flex: 1;
  display: flex;
  overflow: hidden;
}

/* ─── Civ rail ───────────────────────────────────────────────── */
.civ-rail {
  flex-shrink: 0;
  width: 80px;
  background: var(--panel);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  padding: 6px 0;
}
.civ-rail-label {
  font-family: var(--font-display);
  font-size: 7.5px;
  letter-spacing: 0.14em;
  color: var(--text-faint);
  text-align: center;
  padding: 6px 0 10px;
  text-transform: uppercase;
}

.civ-btn {
  display: flex; flex-direction: column; align-items: center;
  gap: 5px; padding: 8px 4px;
  cursor: pointer;
  border: none; background: transparent;
  color: var(--text-dim);
  transition: background 0.15s, color 0.15s;
  position: relative;
  border-radius: var(--radius);
  margin: 1px 4px;
}
.civ-btn:hover  { background: var(--panel2); color: var(--text-main); }
.civ-btn.active { background: var(--panel3); color: var(--gold); }
.civ-btn.active::before {
  content: '';
  position: absolute; left: 0; top: 4px; bottom: 4px;
  width: 2px; background: var(--gold);
  border-radius: 0 2px 2px 0;
}

.civ-emblem {
  width: 40px; height: 40px;
  object-fit: cover;
  border-radius: 50%;
  border: 1px solid transparent;
  transition: border-color 0.15s;
  opacity: 0.8;
}
.civ-btn:hover .civ-emblem,
.civ-btn.active .civ-emblem { border-color: var(--gold-dim); opacity: 1; }
.civ-name {
  font-family: var(--font-display);
  font-size: 7.5px; text-align: center;
  line-height: 1.2; letter-spacing: 0.04em;
}

/* ─── Roster ─────────────────────────────────────────────────── */
.roster {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.welcome {
  flex: 1;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 14px; color: var(--text-faint);
  text-align: center; padding: 40px;
}
.welcome-icon { font-size: 52px; opacity: 0.25; }
.welcome h2 {
  font-family: var(--font-display);
  font-size: 22px; color: var(--text-dim); font-weight: 400;
}
.welcome p {
  font-size: 15px; font-style: italic;
  max-width: 340px; line-height: 1.7;
}

.civ-header { display: flex; align-items: baseline; gap: 12px; margin-bottom: 2px; }
.civ-header h1 {
  font-family: var(--font-display);
  font-size: 26px; font-weight: 700;
  color: var(--gold); letter-spacing: 0.04em;
}
.unit-count { font-size: 13px; color: var(--text-faint); font-style: italic; }
.civ-divider {
  height: 1px;
  background: linear-gradient(90deg, var(--gold-dim), transparent);
  margin-bottom: 18px;
}

.category-block { display: flex; flex-direction: column; gap: 10px; }
.category-title {
  font-family: var(--font-display);
  font-size: 9.5px; letter-spacing: 0.18em;
  text-transform: uppercase; color: var(--text-faint);
  display: flex; align-items: center; gap: 8px;
}
.category-title::after {
  content: ''; flex: 1; height: 1px; background: var(--border);
}
.cat-icon { font-size: 12px; opacity: 0.65; }

.unit-grid { display: flex; flex-wrap: wrap; gap: 8px; }

/* ─── Unit card ──────────────────────────────────────────────── */
.unit-card {
  width: 88px;
  display: flex; flex-direction: column;
  align-items: center; gap: 5px;
  padding: 8px 6px 10px;
  background: var(--panel2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color 0.14s, background 0.14s, transform 0.14s, box-shadow 0.14s;
  position: relative; overflow: hidden;
  animation: fadeUp 0.22s ease both;
}
.unit-card::before {
  content: '';
  position: absolute; inset: 0;
  background: linear-gradient(135deg, rgba(201,162,39,0.03) 0%, transparent 60%);
  pointer-events: none;
}
.unit-card:hover {
  border-color: var(--gold-dim);
  background: var(--panel3);
  transform: translateY(-2px);
  box-shadow: var(--shadow-gold);
}
.unit-card.selected {
  border-color: var(--gold);
  background: var(--panel3);
  box-shadow: 0 0 0 1px var(--gold-dim), var(--shadow-gold);
}
.unit-card.selected::after {
  content: '';
  position: absolute; top: 0; left: 0; right: 0;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--gold), transparent);
}

.unit-portrait {
  width: 62px; height: 62px;
  object-fit: cover;
  border-radius: 1px;
  background: var(--panel3);
  border: 1px solid var(--border);
}
.unit-portrait-fallback {
  width: 62px; height: 62px;
  display: flex; align-items: center; justify-content: center;
  font-size: 26px; color: var(--text-faint);
  background: var(--panel3);
  border: 1px solid var(--border);
  border-radius: 1px;
}
.unit-name {
  font-size: 10.5px; text-align: center;
  line-height: 1.3; color: var(--text-main);
  font-style: italic;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.unit-class {
  font-family: var(--font-display);
  font-size: 7.5px; color: var(--text-faint);
  letter-spacing: 0.08em; text-align: center;
  text-transform: uppercase;
}
.evo-pip {
  position: absolute; top: 5px; right: 5px;
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--gold); opacity: 0.7;
}

/* ─── Detail panel ───────────────────────────────────────────── */
.detail-panel {
  flex-shrink: 0; width: 310px;
  background: var(--panel);
  border-left: 1px solid var(--border);
  overflow-y: auto;
  display: flex; flex-direction: column;
}
.detail-empty {
  flex: 1; display: flex;
  align-items: center; justify-content: center;
  color: var(--text-faint); font-style: italic;
  font-size: 14px; text-align: center; padding: 24px;
}

.detail-header {
  padding: 18px 18px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--panel2);
  position: relative;
  animation: slideLeft 0.2s ease both;
}
.detail-header::after {
  content: '';
  position: absolute; bottom: -1px; left: 18px; right: 18px;
  height: 1px;
  background: linear-gradient(90deg, var(--gold-dim), transparent);
}

.detail-rank-tabs { display: flex; gap: 4px; margin-bottom: 12px; }
.rank-tab {
  font-family: var(--font-display);
  font-size: 8.5px; letter-spacing: 0.09em;
  padding: 4px 10px;
  border: 1px solid var(--border);
  background: transparent; color: var(--text-faint);
  cursor: pointer; border-radius: var(--radius);
  transition: all 0.14s;
}
.rank-tab:hover { border-color: var(--gold-dim); color: var(--text-main); }
.rank-tab.active {
  background: var(--panel3); border-color: var(--gold); color: var(--gold);
}

.detail-unit-row { display: flex; gap: 12px; align-items: flex-start; }
.detail-portrait {
  width: 76px; height: 76px; object-fit: cover;
  border: 1px solid var(--border-bright);
  border-radius: var(--radius); flex-shrink: 0;
  background: var(--panel3);
}
.detail-names { flex: 1; min-width: 0; }
.detail-specific {
  font-family: var(--font-display);
  font-size: 14px; font-weight: 600;
  color: var(--gold); line-height: 1.2; margin-bottom: 3px;
}
.detail-generic {
  font-size: 12.5px; color: var(--text-dim); font-style: italic; margin-bottom: 5px;
}
.detail-tooltip {
  font-size: 11.5px; color: var(--rust); font-style: italic; line-height: 1.4;
}
.detail-classes { display: flex; flex-wrap: wrap; gap: 3px; margin-top: 7px; }
.class-tag {
  font-family: var(--font-display);
  font-size: 7.5px; letter-spacing: 0.07em;
  padding: 2px 6px;
  border: 1px solid var(--border); border-radius: 1px;
  color: var(--text-faint); background: var(--panel3);
}

.detail-body {
  flex: 1; padding: 14px 18px;
  display: flex; flex-direction: column; gap: 15px;
  animation: slideLeft 0.2s ease both;
}

/* Stat sections */
.stat-section { display: flex; flex-direction: column; gap: 7px; }
.stat-section-title {
  font-family: var(--font-display);
  font-size: 8.5px; letter-spacing: 0.18em;
  text-transform: uppercase; color: var(--gold-dim);
  padding-bottom: 5px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 5px;
}
.stat-section-title .si { font-size: 12px; }
.stat-row {
  display: flex; justify-content: space-between; align-items: baseline;
  font-size: 13px;
}
.stat-label { color: var(--text-dim); }
.stat-val { color: var(--text-main); font-weight: 600; letter-spacing: 0.02em; }
.stat-val.gold  { color: var(--gold-pale); }

.cost-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 5px; }
.cost-item {
  display: flex; align-items: center; gap: 6px;
  background: var(--panel2); padding: 5px 8px;
  border-radius: var(--radius); border: 1px solid var(--border);
}
.cost-icon { font-size: 13px; width: 16px; text-align: center; }
.cost-label { font-size: 10.5px; color: var(--text-dim); }
.cost-val { font-size: 13.5px; font-weight: 600; color: var(--text-main); margin-left: auto; }
.cost-val.zero { color: var(--text-faint); }

.attack-block {
  background: var(--panel2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 9px 11px;
  display: flex; flex-direction: column; gap: 5px;
}
.attack-type-name {
  font-family: var(--font-display);
  font-size: 9px; color: var(--gold-dim); letter-spacing: 0.07em; margin-bottom: 3px;
}
.dmg-bars { display: flex; flex-direction: column; gap: 4px; }
.dmg-row { display: flex; align-items: center; gap: 7px; }
.dmg-name { font-size: 11px; color: var(--text-dim); width: 40px; flex-shrink: 0; }
.dmg-bar-wrap {
  flex: 1; height: 5px;
  background: var(--panel3); border-radius: 2px; overflow: hidden;
}
.dmg-bar { height: 100%; border-radius: 2px; transition: width 0.3s ease; }
.dmg-val { font-size: 11.5px; color: var(--text-main); font-weight: 600; width: 28px; text-align: right; }
.bonus-tag { font-size: 11px; color: var(--rust); font-style: italic; }
.attack-timing {
  display: flex; gap: 10px; margin-top: 3px;
  font-size: 10.5px; color: var(--text-dim);
}
.timing-item { display: flex; gap: 3px; }
.timing-val { color: var(--text-main); }

.resist-grid { display: flex; gap: 5px; }
.resist-item {
  flex: 1; background: var(--panel2);
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 7px; text-align: center;
}
.resist-type { font-size: 9.5px; color: var(--text-dim); margin-bottom: 3px; }
.resist-val  { font-size: 16px; font-weight: 600; color: var(--text-main); }

.speed-bar-wrap {
  flex: 1; height: 4px;
  background: var(--panel3); border-radius: 2px; overflow: hidden;
}
.speed-bar { height: 100%; border-radius: 2px; }
.speed-row { display: flex; align-items: center; gap: 8px; margin-top: -2px; }

/* ─── Login page ─────────────────────────────────────────────── */
.login-page {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  background: var(--ink);
  background-image:
    radial-gradient(ellipse at 30% 20%, rgba(201,162,39,0.07) 0%, transparent 50%),
    radial-gradient(ellipse at 70% 80%, rgba(139,58,42,0.08) 0%, transparent 50%);
  font-family: var(--font-body);
}
.login-card {
  width: 360px;
  background: var(--panel2);
  border: 1px solid var(--border-bright);
  border-radius: 3px;
  padding: 40px 36px;
  box-shadow: 0 8px 48px rgba(0,0,0,0.5), var(--shadow-gold);
  position: relative;
}
.login-card::before {
  content: '';
  position: absolute; top: 0; left: 20px; right: 20px; height: 1px;
  background: linear-gradient(90deg, transparent, var(--gold), transparent);
}
.login-logo {
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  margin-bottom: 28px;
}
.login-logo img {
  width: 52px; height: 52px; object-fit: contain;
  filter: drop-shadow(0 0 8px rgba(201,162,39,0.5));
}
.login-logo-fallback {
  width: 52px; height: 52px; border-radius: 50%;
  border: 1px solid var(--border-bright);
  display: flex; align-items: center; justify-content: center;
  font-size: 26px; color: var(--gold); background: var(--panel3);
}
.login-title {
  font-family: var(--font-display);
  font-size: 20px; color: var(--gold);
  letter-spacing: 0.06em; text-align: center;
}
.login-sub {
  font-size: 11px; color: var(--text-faint);
  letter-spacing: 0.12em; text-transform: uppercase;
  text-align: center;
}
.login-field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; }
.login-label {
  font-family: var(--font-display);
  font-size: 9px; letter-spacing: 0.14em;
  color: var(--text-dim); text-transform: uppercase;
}
.login-input {
  background: var(--panel3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  font-family: var(--font-body);
  font-size: 15px;
  color: var(--text-main);
  outline: none;
  transition: border-color 0.15s;
}
.login-input:focus { border-color: var(--gold-dim); }
.login-btn {
  width: 100%; margin-top: 8px;
  font-family: var(--font-display);
  font-size: 11px; letter-spacing: 0.12em;
  text-transform: uppercase;
  padding: 12px;
  background: linear-gradient(135deg, var(--gold-dim), var(--gold));
  border: none; border-radius: var(--radius);
  color: var(--ink); font-weight: 700;
  cursor: pointer; transition: opacity 0.15s, transform 0.1s;
}
.login-btn:hover   { opacity: 0.9; transform: translateY(-1px); }
.login-btn:active  { transform: translateY(0); }
.login-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.login-error {
  margin-top: 10px;
  font-size: 13px; color: #e06050;
  font-style: italic; text-align: center;
  min-height: 20px;
}
.back-link {
  display: block; text-align: center;
  margin-top: 18px; font-size: 12px;
  color: var(--text-faint); text-decoration: none;
  font-style: italic; transition: color 0.15s;
}
.back-link:hover { color: var(--text-dim); }

/* ─── Animations ─────────────────────────────────────────────── */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(5px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes slideLeft {
  from { opacity: 0; transform: translateX(10px); }
  to   { opacity: 1; transform: translateX(0); }
}

/* ─── Responsive ─────────────────────────────────────────────── */
@media (max-width: 900px) {
  .detail-panel { width: 275px; }
  .civ-rail { width: 68px; }
}
@media (max-width: 640px) {
  .detail-panel { display: none; }
}
