/* ============================================
   PALWORLD BASE PLANNER — Design System
   ============================================ */

/* --- Custom Properties / Tokens --- */
:root {
  /* Background layers */
  --bg-base: #0b0e17;
  --bg-surface: #111827;
  --bg-elevated: #1e2538;
  --bg-card: rgba(22, 30, 48, 0.72);
  --bg-card-hover: rgba(30, 40, 62, 0.85);
  --bg-glass: rgba(255, 255, 255, 0.04);

  /* Accent palette */
  --accent-primary: #6d9fff;
  --accent-primary-dim: rgba(109, 159, 255, 0.15);
  --accent-warm: #f5a623;
  --accent-warm-dim: rgba(245, 166, 35, 0.12);
  --accent-success: #34d399;
  --accent-danger: #f87171;

  /* Text */
  --text-primary: #e8ecf4;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;

  /* Borders */
  --border-subtle: rgba(148, 163, 184, 0.1);
  --border-active: rgba(109, 159, 255, 0.5);

  /* Shadows */
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.45);
  --shadow-lg: 0 8px 30px rgba(0, 0, 0, 0.55);
  --shadow-glow: 0 0 20px rgba(109, 159, 255, 0.15);

  /* Radii */
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-pill: 100px;

  /* Transitions */
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --transition-fast: 0.18s var(--ease-out);
  --transition-normal: 0.3s var(--ease-out);
  --transition-slow: 0.5s var(--ease-out);

  /* Layout */
  --container-max: 1220px;
  --header-height: 72px;
}

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

html {
  font-size: 16px;
  scroll-behavior: smooth;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: "Inter", system-ui, -apple-system, sans-serif;
  background: var(--bg-base);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  overflow-x: hidden;
  position: relative;
}

/* Subtle radial gradient behind the page */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse 80% 60% at 50% -10%, rgba(109, 159, 255, 0.08), transparent 60%),
    radial-gradient(ellipse 60% 50% at 80% 90%, rgba(245, 166, 35, 0.06), transparent 50%);
  pointer-events: none;
  z-index: 0;
}

/* --- Container --- */
.container {
  width: 100%;
  max-width: var(--container-max);
  margin: 0 auto;
  padding: 0 24px;
}

/* ============================================
   FLOATING PARTICLES
   ============================================ */
.particles {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}

.particle {
  position: absolute;
  bottom: -10px;
  border-radius: 50%;
  opacity: 0;
  animation: floatUp linear infinite;
}

@keyframes floatUp {
  0% {
    transform: translateY(0) scale(1);
    opacity: 0;
  }
  10% {
    opacity: 0.6;
  }
  90% {
    opacity: 0.3;
  }
  100% {
    transform: translateY(-100vh) scale(0.4);
    opacity: 0;
  }
}

/* ============================================
   HEADER
   ============================================ */
.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--header-height);
  display: flex;
  align-items: center;
  background: rgba(11, 14, 23, 0.82);
  backdrop-filter: blur(18px) saturate(1.4);
  -webkit-backdrop-filter: blur(18px) saturate(1.4);
  border-bottom: 1px solid var(--border-subtle);
}

.header-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  width: 100%;
}

.logo-group {
  display: flex;
  align-items: center;
  gap: 14px;
}

.logo-icon {
  font-size: 2rem;
  line-height: 1;
  filter: drop-shadow(0 0 6px rgba(109, 159, 255, 0.4));
}

.logo-group h1 {
  font-size: 1.35rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, var(--text-primary), var(--accent-primary));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.subtitle {
  font-size: 0.78rem;
  color: var(--text-muted);
  font-weight: 400;
  letter-spacing: 0.02em;
}

/* Reset Button */
.reset-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 18px;
  background: rgba(248, 113, 113, 0.1);
  color: var(--accent-danger);
  border: 1px solid rgba(248, 113, 113, 0.2);
  border-radius: var(--radius-pill);
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition:
    background var(--transition-fast),
    border-color var(--transition-fast),
    transform var(--transition-fast);
  white-space: nowrap;
}

.reset-btn:hover {
  background: rgba(248, 113, 113, 0.2);
  border-color: rgba(248, 113, 113, 0.4);
  transform: scale(1.04);
}

.reset-btn:active {
  transform: scale(0.97);
}

/* ============================================
   TAB NAVIGATION
   ============================================ */
.tabs-nav {
  display: flex;
  gap: 8px;
  padding: 24px 0 16px;
  overflow-x: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
  position: relative;
  z-index: 1;
}

.tabs-nav::-webkit-scrollbar {
  display: none;
}

.tab-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 20px;
  background: var(--bg-glass);
  color: var(--text-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-pill);
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition:
    background var(--transition-fast),
    color var(--transition-fast),
    border-color var(--transition-fast),
    box-shadow var(--transition-fast),
    transform var(--transition-fast);
}

.tab-btn:hover {
  background: var(--accent-primary-dim);
  color: var(--text-primary);
  border-color: rgba(109, 159, 255, 0.25);
}

.tab-btn.active {
  background: linear-gradient(135deg, rgba(109, 159, 255, 0.2), rgba(109, 159, 255, 0.08));
  color: var(--accent-primary);
  border-color: var(--border-active);
  box-shadow: var(--shadow-glow);
  font-weight: 600;
}

.tab-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  background: var(--accent-primary);
  color: var(--bg-base);
  border-radius: var(--radius-pill);
  font-size: 0.72rem;
  font-weight: 700;
  line-height: 1;
}

/* ============================================
   BUILDINGS GRID
   ============================================ */
.buildings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
  gap: 16px;
  padding-bottom: 32px;
  position: relative;
  z-index: 1;
}

/* ============================================
   BUILDING CARD
   ============================================ */
.building-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  transition:
    background var(--transition-fast),
    border-color var(--transition-fast),
    box-shadow var(--transition-normal),
    transform var(--transition-fast);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.building-card:hover {
  background: var(--bg-card-hover);
  border-color: rgba(148, 163, 184, 0.18);
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

.building-card.selected {
  border-color: var(--border-active);
  box-shadow: var(--shadow-glow), var(--shadow-md);
  background: linear-gradient(
    170deg,
    rgba(109, 159, 255, 0.08) 0%,
    var(--bg-card) 40%
  );
}

/* Card Top — Icon + Info */
.card-top {
  display: flex;
  align-items: center;
  gap: 14px;
}

.card-image {
  width: 56px;
  height: 56px;
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  overflow: hidden;
  border: 1px solid var(--border-subtle);
}

.card-image img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  padding: 4px;
}

.card-info {
  flex: 1;
  min-width: 0;
}

.card-name {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.3;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-tech {
  display: inline-block;
  margin-top: 4px;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--accent-warm);
  background: var(--accent-warm-dim);
  padding: 2px 10px;
  border-radius: var(--radius-pill);
  letter-spacing: 0.03em;
}

/* Card Materials */
.card-materials {
  min-height: 0;
}

.material-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.material-tag {
  display: inline-block;
  font-size: 0.73rem;
  font-weight: 500;
  color: var(--text-secondary);
  background: var(--bg-glass);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 3px 9px;
  white-space: nowrap;
}

/* Card Controls */
.card-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-top: 4px;
  border-top: 1px solid var(--border-subtle);
}

.qty-control {
  display: flex;
  align-items: center;
  gap: 0;
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.qty-btn {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  color: var(--text-secondary);
  border: none;
  font-family: inherit;
  font-size: 1.1rem;
  font-weight: 700;
  cursor: pointer;
  transition:
    background var(--transition-fast),
    color var(--transition-fast);
  user-select: none;
}

.qty-btn:hover {
  background: var(--accent-primary-dim);
  color: var(--accent-primary);
}

.qty-btn:active {
  transform: scale(0.92);
}

.qty-btn.minus:hover {
  background: rgba(248, 113, 113, 0.12);
  color: var(--accent-danger);
}

.qty-value {
  width: 44px;
  height: 36px;
  text-align: center;
  background: transparent;
  border: none;
  border-left: 1px solid var(--border-subtle);
  border-right: 1px solid var(--border-subtle);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.92rem;
  font-weight: 700;
  outline: none;
  -moz-appearance: textfield;
}

.qty-value::-webkit-outer-spin-button,
.qty-value::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.qty-value:focus {
  background: rgba(109, 159, 255, 0.06);
}

.card-total {
  font-size: 0.82rem;
  color: var(--text-muted);
}

.card-total strong {
  color: var(--accent-primary);
  font-weight: 700;
}

.total-label {
  color: var(--text-muted);
  font-weight: 400;
}

/* ============================================
   SUMMARY PANEL
   ============================================ */
.summary-panel {
  position: sticky;
  bottom: 0;
  z-index: 50;
  background: rgba(17, 24, 39, 0.92);
  backdrop-filter: blur(20px) saturate(1.3);
  -webkit-backdrop-filter: blur(20px) saturate(1.3);
  border: 1px solid var(--border-subtle);
  border-bottom: none;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  box-shadow: 0 -4px 30px rgba(0, 0, 0, 0.4);
  margin-top: 16px;
  overflow: hidden;
  transition: box-shadow var(--transition-normal);
}

.summary-panel.has-items {
  border-color: var(--border-active);
  box-shadow:
    0 -4px 30px rgba(0, 0, 0, 0.4),
    0 0 30px rgba(109, 159, 255, 0.08);
}

/* Summary Header (toggle) */
.summary-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 24px;
  cursor: pointer;
  user-select: none;
  transition: background var(--transition-fast);
}

.summary-header:hover {
  background: var(--bg-glass);
}

.summary-title-group {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}

.summary-title-group h2 {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-primary);
}

.selected-count {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--accent-primary);
  background: var(--accent-primary-dim);
  padding: 4px 12px;
  border-radius: var(--radius-pill);
}

.chevron {
  color: var(--text-muted);
  transition: transform var(--transition-normal);
  flex-shrink: 0;
}

.summary-panel.collapsed .chevron {
  transform: rotate(180deg);
}

/* Summary Body */
.summary-body {
  max-height: 400px;
  overflow-y: auto;
  padding: 0 24px 20px;
  transition:
    max-height var(--transition-slow),
    padding var(--transition-slow),
    opacity var(--transition-normal);
  scrollbar-width: thin;
  scrollbar-color: var(--accent-primary-dim) transparent;
}

.summary-body::-webkit-scrollbar {
  width: 6px;
}

.summary-body::-webkit-scrollbar-track {
  background: transparent;
}

.summary-body::-webkit-scrollbar-thumb {
  background: var(--accent-primary-dim);
  border-radius: 3px;
}

.summary-panel.collapsed .summary-body {
  max-height: 0;
  padding-top: 0;
  padding-bottom: 0;
  opacity: 0;
  overflow: hidden;
}

/* Empty state */
.summary-empty {
  text-align: center;
  padding: 24px 0;
  color: var(--text-muted);
  font-size: 0.9rem;
  font-style: italic;
}

/* Material list */
.summary-materials {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 8px;
}

.summary-mat-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  background: var(--bg-glass);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  transition:
    background var(--transition-fast),
    border-color var(--transition-fast);
}

.summary-mat-item:hover {
  background: var(--accent-primary-dim);
  border-color: rgba(109, 159, 255, 0.2);
}

.summary-mat-name {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-secondary);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.summary-mat-qty {
  font-size: 0.95rem;
  font-weight: 800;
  color: var(--accent-primary);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

/* ============================================
   FOOTER
   ============================================ */
.site-footer {
  position: relative;
  z-index: 1;
  padding: 28px 0;
  text-align: center;
  border-top: 1px solid var(--border-subtle);
  margin-top: 40px;
}

.site-footer p {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.site-footer a {
  color: var(--accent-primary);
  text-decoration: none;
  font-weight: 500;
  transition: color var(--transition-fast);
}

.site-footer a:hover {
  color: var(--accent-warm);
  text-decoration: underline;
}

/* ============================================
   RESPONSIVE
   ============================================ */
@media (max-width: 768px) {
  :root {
    --header-height: 64px;
    --container-max: 100%;
  }

  .container {
    padding: 0 16px;
  }

  .logo-group h1 {
    font-size: 1.1rem;
  }

  .subtitle {
    display: none;
  }

  .reset-btn span,
  .reset-btn svg + span {
    display: none;
  }

  .tabs-nav {
    padding: 16px 0 12px;
    gap: 6px;
  }

  .tab-btn {
    padding: 8px 14px;
    font-size: 0.82rem;
  }

  .buildings-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .summary-header {
    padding: 14px 16px;
  }

  .summary-body {
    padding: 0 16px 16px;
  }

  .summary-materials {
    grid-template-columns: 1fr;
  }

  .summary-title-group h2 {
    font-size: 0.92rem;
  }
}

@media (max-width: 480px) {
  .logo-icon {
    font-size: 1.5rem;
  }

  .logo-group h1 {
    font-size: 1rem;
  }

  .building-card {
    padding: 14px;
  }

  .card-image {
    width: 44px;
    height: 44px;
  }

  .card-name {
    font-size: 0.88rem;
  }
}

/* ============================================
   SELECTION / FOCUS ACCESSIBILITY
   ============================================ */
:focus-visible {
  outline: 2px solid var(--accent-primary);
  outline-offset: 2px;
}

button:focus:not(:focus-visible) {
  outline: none;
}

/* Subtle entrance animation for cards */
.building-card {
  animation: cardIn 0.35s var(--ease-out) both;
}

@keyframes cardIn {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.97);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}
