/* =============================================================================
   Kingdom of Valor — Main Stylesheet
   Dark-wood-and-gold design system. All color decisions derive from the locked
   identity: #14110f near-black, #d4af37 gold, contextual red/blue accents.
   ============================================================================= */

/* --- Google Fonts (loaded in HTML head) ------------------------------------
   Display: Cinzel (medieval serif, headings + UI labels)
   Body:    Inter (clean, legible at small sizes for resource bars/stats)
   Mono:    JetBrains Mono (battle log replay, config keys)
   --------------------------------------------------------------------------- */

/* --- CSS Variables --------------------------------------------------------- */
:root {
  /* Core palette */
  --gold:           #d4af37;
  --gold-dim:       #c9912f;
  --gold-muted:     #a07828;
  --gold-faint:     rgba(212, 175, 55, 0.12);
  --gold-border:    rgba(212, 175, 55, 0.30);

  --bg-void:        #0e0c09;
  --bg-deep:        #14110f;
  --bg-dark:        #1c1814;
  --bg-mid:         #251f18;
  --bg-raised:      #2e2620;
  --bg-hover:       #352d24;

  --border-dark:    rgba(255,255,255,0.06);
  --border-mid:     rgba(255,255,255,0.10);
  --border-gold:    var(--gold-border);

  --text-primary:   #f0e8d8;
  --text-secondary: #9a8a78;
  --text-muted:     #5a4e42;

  --red:            #d65c5c;
  --red-dim:        #b8413a;
  --red-faint:      rgba(214, 92, 92, 0.12);
  --red-border:     rgba(214, 92, 92, 0.30);

  --blue:           #5c9fd6;
  --blue-dim:       #3d6fa8;
  --blue-faint:     rgba(92, 159, 214, 0.12);
  --blue-border:    rgba(92, 159, 214, 0.30);

  --green:          #4a9d6f;
  --green-faint:    rgba(74, 157, 111, 0.12);
  --green-border:   rgba(74, 157, 111, 0.30);

  /* Typography */
  --font-display:   'Cinzel', 'Palatino Linotype', 'Book Antiqua', Georgia, serif;
  --font-body:      'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono:      'JetBrains Mono', 'Consolas', 'Monaco', 'Courier New', monospace;

  /* Spacing */
  --space-1:  4px;
  --space-2:  8px;
  --space-3:  12px;
  --space-4:  16px;
  --space-5:  20px;
  --space-6:  24px;
  --space-8:  32px;
  --space-10: 40px;
  --space-12: 48px;

  /* Radius */
  --radius-sm:  4px;
  --radius-md:  8px;
  --radius-lg:  12px;
  --radius-xl:  16px;
  --radius-pill:99px;

  /* Shadows */
  --shadow-panel:  0 4px 24px rgba(0,0,0,0.5);
  --shadow-modal:  0 8px 48px rgba(0,0,0,0.7);
  --shadow-gold:   0 0 0 1px var(--gold-border), 0 4px 16px rgba(212,175,55,0.10);
  --shadow-inset:  inset 0 1px 3px rgba(0,0,0,0.4);

  /* Transitions */
  --ease:       cubic-bezier(0.16, 1, 0.3, 1);
  --trans-fast: 120ms var(--ease);
  --trans-mid:  220ms var(--ease);
}

/* --- Reset ----------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-body);
  background: var(--bg-deep);
  color: var(--text-primary);
  min-height: 100dvh;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

img { display: block; max-width: 100%; }
a   { color: var(--gold); text-decoration: none; }
a:hover { text-decoration: underline; }

/* --- Typography scale ------------------------------------------------------ */
.display      { font-family: var(--font-display); font-size: 2rem;   font-weight: 700; letter-spacing: 0.04em; color: var(--gold); }
.heading-lg   { font-family: var(--font-display); font-size: 1.25rem; font-weight: 600; letter-spacing: 0.03em; }
.heading-md   { font-family: var(--font-display); font-size: 1rem;   font-weight: 600; letter-spacing: 0.03em; }
.heading-sm   { font-family: var(--font-display); font-size: 0.8125rem; font-weight: 600; letter-spacing: 0.05em; text-transform: uppercase; }
.label        { font-size: 0.6875rem; font-weight: 500; color: var(--text-secondary); letter-spacing: 0.06em; text-transform: uppercase; }
.body-sm      { font-size: 0.8125rem; }
.body-xs      { font-size: 0.75rem; }
.mono         { font-family: var(--font-mono); font-size: 0.75rem; }

/* --- Layout ---------------------------------------------------------------- */
.page-wrap {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 var(--space-4);
}

/* --- Resource top bar ------------------------------------------------------ */
.resource-bar {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--bg-deep);
  border-bottom: 1px solid var(--border-dark);
  padding: var(--space-2) var(--space-4);
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.resource-bar__profile {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  cursor: pointer;
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-md);
  transition: background var(--trans-fast);
  flex-shrink: 0;
}
.resource-bar__profile:hover { background: var(--bg-raised); }

.th-badge {
  width: 32px; height: 32px;
  background: var(--gold-faint);
  border: 1px solid var(--gold-border);
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-display);
  font-size: 0.6875rem; font-weight: 700;
  color: var(--gold);
}

.resource-bar__name {
  font-size: 0.8125rem;
  font-weight: 500;
  max-width: 100px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.resource-pills {
  display: flex;
  gap: var(--space-2);
  flex: 1;
  overflow-x: auto;
  scrollbar-width: none;
}
.resource-pills::-webkit-scrollbar { display: none; }

.resource-pill {
  display: flex;
  align-items: center;
  gap: 5px;
  background: var(--bg-mid);
  border: 1px solid var(--border-dark);
  border-radius: var(--radius-pill);
  padding: 4px 10px 4px 6px;
  white-space: nowrap;
  flex-shrink: 0;
}
.resource-pill__icon {
  width: 18px; height: 18px;
  object-fit: contain;
  flex-shrink: 0;
}
.resource-pill__amount {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-primary);
}

.resource-bar__vp {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-shrink: 0;
}
.vp-badge {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  background: var(--gold-faint);
  border: 1px solid var(--gold-border);
  border-radius: var(--radius-pill);
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--gold);
}

.shield-countdown {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  background: var(--blue-faint);
  border: 1px solid var(--blue-border);
  border-radius: var(--radius-pill);
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--blue);
}
.shield-countdown[hidden] { display: none; }

/* --- Bottom navigation ----------------------------------------------------- */
.bottom-nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 100;
  background: var(--bg-deep);
  border-top: 1px solid var(--border-dark);
  display: flex;
  align-items: stretch;
  height: 60px;
  padding-bottom: env(safe-area-inset-bottom);
}

.bottom-nav__item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  cursor: pointer;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.625rem;
  font-family: var(--font-display);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  transition: color var(--trans-fast);
  position: relative;
  padding: 0;
}
.bottom-nav__item.active,
.bottom-nav__item:hover { color: var(--gold); }

.bottom-nav__icon {
  width: 22px; height: 22px;
  object-fit: contain;
  opacity: 0.5;
  transition: opacity var(--trans-fast);
}
.bottom-nav__item.active .bottom-nav__icon,
.bottom-nav__item:hover  .bottom-nav__icon { opacity: 1; }

.nav-badge {
  position: absolute;
  top: 6px; right: calc(50% - 18px);
  min-width: 16px; height: 16px;
  background: var(--red);
  border-radius: var(--radius-pill);
  font-size: 0.625rem;
  font-weight: 700;
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  padding: 0 4px;
}
.nav-badge[hidden] { display: none; }

/* --- Panels & cards -------------------------------------------------------- */
.panel {
  background: var(--bg-dark);
  border: 1px solid var(--border-dark);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
}

.panel--gold {
  border-color: var(--gold-border);
  background: var(--bg-dark);
  box-shadow: var(--shadow-gold);
}

.panel__title {
  font-family: var(--font-display);
  font-size: 0.8125rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--gold);
  margin-bottom: var(--space-3);
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

/* --- Buttons --------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: 9px 18px;
  border-radius: var(--radius-md);
  font-family: var(--font-display);
  font-size: 0.8125rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  cursor: pointer;
  border: none;
  transition: background var(--trans-fast), opacity var(--trans-fast), transform var(--trans-fast);
  white-space: nowrap;
  line-height: 1;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }

.btn--gold     { background: var(--gold);     color: var(--bg-deep); }
.btn--gold:hover:not(:disabled) { background: var(--gold-dim); }

.btn--ghost    { background: transparent; color: var(--text-secondary); border: 1px solid var(--border-mid); }
.btn--ghost:hover:not(:disabled) { background: var(--bg-raised); color: var(--text-primary); }

.btn--red      { background: var(--red);      color: #fff; }
.btn--red:hover:not(:disabled) { background: var(--red-dim); }

.btn--blue     { background: var(--blue-dim); color: #fff; }
.btn--blue:hover:not(:disabled) { background: var(--blue); }

.btn--sm { padding: 6px 12px; font-size: 0.75rem; }
.btn--lg { padding: 13px 28px; font-size: 0.9375rem; }
.btn--full { width: 100%; }

/* --- Form inputs ----------------------------------------------------------- */
.input {
  width: 100%;
  background: var(--bg-mid);
  border: 1px solid var(--border-mid);
  border-radius: var(--radius-md);
  padding: 9px 12px;
  font-family: var(--font-body);
  font-size: 0.9375rem;
  color: var(--text-primary);
  outline: none;
  transition: border-color var(--trans-fast);
}
.input::placeholder { color: var(--text-muted); }
.input:focus { border-color: var(--gold-muted); }
.input:disabled { opacity: 0.5; cursor: not-allowed; }

.field { margin-bottom: var(--space-4); }
.field__label {
  display: block;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: var(--space-2);
  letter-spacing: 0.04em;
}
.field__error {
  font-size: 0.75rem;
  color: var(--red);
  margin-top: var(--space-1);
}

.select {
  width: 100%;
  background: var(--bg-mid);
  border: 1px solid var(--border-mid);
  border-radius: var(--radius-md);
  padding: 9px 12px;
  font-family: var(--font-body);
  font-size: 0.9375rem;
  color: var(--text-primary);
  outline: none;
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%239a8a78' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
}
.select:focus { border-color: var(--gold-muted); }

/* --- HP & progress bars ---------------------------------------------------- */
.hp-bar-wrap {
  position: relative;
  height: 8px;
  background: var(--bg-mid);
  border-radius: var(--radius-pill);
  overflow: hidden;
}
.hp-bar-fill {
  height: 100%;
  border-radius: var(--radius-pill);
  transition: width 0.5s var(--ease);
}
.hp-bar-fill--gold   { background: var(--gold); }
.hp-bar-fill--red    { background: var(--red); }
.hp-bar-fill--blue   { background: var(--blue); }
.hp-bar-fill--green  { background: var(--green); }

/* Threshold marker (50% line in Battle View) */
.hp-bar-marker {
  position: absolute;
  top: 0; bottom: 0;
  width: 2px;
  background: rgba(255,255,255,0.4);
}

/* --- Modal overlay --------------------------------------------------------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: var(--space-4);
  backdrop-filter: blur(2px);
}
@media (min-width: 640px) {
  .modal-overlay { align-items: center; }
}
.modal-overlay[hidden] { display: none; }

.modal {
  background: var(--bg-dark);
  border: 1px solid var(--border-gold);
  border-radius: var(--radius-xl);
  width: 100%;
  max-width: 480px;
  max-height: 90dvh;
  overflow-y: auto;
  box-shadow: var(--shadow-modal);
  position: relative;
}

.modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--border-dark);
}
.modal__title { font-family: var(--font-display); font-size: 1rem; font-weight: 600; color: var(--gold); }
.modal__close {
  width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  font-size: 1.25rem;
  transition: color var(--trans-fast), background var(--trans-fast);
}
.modal__close:hover { color: var(--text-primary); background: var(--bg-raised); }

.modal__body  { padding: var(--space-5); }
.modal__footer {
  padding: var(--space-4) var(--space-5);
  border-top: 1px solid var(--border-dark);
  display: flex;
  gap: var(--space-3);
  justify-content: flex-end;
}

/* --- Stat row (used in building detail, battle panels) --------------------- */
.stat-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-2) 0;
  border-bottom: 1px solid var(--border-dark);
  font-size: 0.8125rem;
}
.stat-row:last-child { border-bottom: none; }
.stat-row__label  { color: var(--text-secondary); }
.stat-row__value  { font-weight: 600; }
.stat-row__next   { color: var(--gold); font-size: 0.75rem; }

/* --- Trophy tier badges ---------------------------------------------------- */
.tier-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: var(--radius-pill);
  font-size: 0.6875rem;
  font-weight: 600;
  font-family: var(--font-display);
  letter-spacing: 0.04em;
}
.tier-badge--none     { background: var(--bg-raised);  color: var(--text-muted); }
.tier-badge--bronze   { background: rgba(184,115,50,0.15); color: #cd7f32; border: 1px solid rgba(184,115,50,0.3); }
.tier-badge--silver   { background: rgba(170,170,170,0.12); color: #b0b0b0; border: 1px solid rgba(170,170,170,0.25); }
.tier-badge--gold     { background: var(--gold-faint);  color: var(--gold);   border: 1px solid var(--gold-border); }
.tier-badge--platinum { background: rgba(188,224,255,0.10); color: #a8d4f5; border: 1px solid rgba(188,224,255,0.20); }
.tier-badge--diamond  { background: rgba(168,240,255,0.10); color: #88eeff; border: 1px solid rgba(168,240,255,0.20); }

/* --- Toast notifications --------------------------------------------------- */
.toast-stack {
  position: fixed;
  top: var(--space-4);
  right: var(--space-4);
  z-index: 500;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  pointer-events: none;
}
.toast {
  background: var(--bg-raised);
  border: 1px solid var(--border-mid);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4);
  font-size: 0.8125rem;
  color: var(--text-primary);
  box-shadow: var(--shadow-panel);
  max-width: 300px;
  pointer-events: auto;
  animation: toast-in 220ms var(--ease);
}
.toast--success { border-color: var(--green-border); }
.toast--error   { border-color: var(--red-border); color: var(--red); }
.toast--gold    { border-color: var(--gold-border); color: var(--gold); }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(-8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* --- Loading spinner ------------------------------------------------------- */
.spinner {
  width: 24px; height: 24px;
  border: 2px solid var(--border-mid);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: spin 700ms linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* --- Utility classes ------------------------------------------------------- */
.text-gold    { color: var(--gold); }
.text-red     { color: var(--red); }
.text-blue    { color: var(--blue); }
.text-green   { color: var(--green); }
.text-muted   { color: var(--text-secondary); }
.text-center  { text-align: center; }
.text-right   { text-align: right; }

.flex         { display: flex; }
.flex-col     { display: flex; flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2        { gap: var(--space-2); }
.gap-3        { gap: var(--space-3); }
.gap-4        { gap: var(--space-4); }

.mt-2         { margin-top: var(--space-2); }
.mt-3         { margin-top: var(--space-3); }
.mt-4         { margin-top: var(--space-4); }
.mt-6         { margin-top: var(--space-6); }
.mb-3         { margin-bottom: var(--space-3); }
.mb-4         { margin-bottom: var(--space-4); }

.hidden       { display: none !important; }
.sr-only      { position:absolute; width:1px; height:1px; overflow:hidden; clip:rect(0,0,0,0); }

/* --- Reduced motion -------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* --- Scrollbar styling ----------------------------------------------------- */
::-webkit-scrollbar       { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--bg-raised); border-radius: 3px; }
