/* ============================================
   DESIGN TOKENS
   ============================================ */

:root {
  /* Type Scale */
  --text-xs:   clamp(0.75rem,  0.7rem  + 0.25vw, 0.875rem);
  --text-sm:   clamp(0.875rem, 0.8rem  + 0.35vw, 1rem);
  --text-base: clamp(1rem,     0.95rem + 0.25vw, 1.125rem);
  --text-lg:   clamp(1.125rem, 1rem    + 0.75vw, 1.5rem);
  --text-xl:   clamp(1.5rem,   1.2rem  + 1.25vw, 2.25rem);
  --text-2xl:  clamp(2rem,     1.2rem  + 2.5vw,  3.5rem);

  /* Spacing */
  --space-1:  0.25rem;
  --space-2:  0.5rem;
  --space-3:  0.75rem;
  --space-4:  1rem;
  --space-5:  1.25rem;
  --space-6:  1.5rem;
  --space-8:  2rem;
  --space-10: 2.5rem;
  --space-12: 3rem;
  --space-16: 4rem;
  --space-20: 5rem;
  --space-24: 6rem;
  --space-32: 8rem;

  /* Radius */
  --radius-sm: 0.375rem;
  --radius-md: 0.5rem;
  --radius-lg: 0.75rem;
  --radius-xl: 1rem;

  /* Transitions */
  --transition-interactive: 180ms cubic-bezier(0.16, 1, 0.3, 1);

  /* Fonts */
  --font-body: 'Space Grotesk', 'Helvetica Neue', sans-serif;
  --font-mono: 'Space Mono', 'Courier New', monospace;

  /* Content widths */
  --content-default: 960px;
  --content-wide: 1200px;
}

/* DARK (default) */
:root, [data-theme="dark"] {
  --color-bg:             #0d0f0e;
  --color-surface:        #151816;
  --color-surface-2:      #1b1e1c;
  --color-surface-offset: #1f2220;
  --color-border:         #2e3230;
  --color-divider:        #262a28;

  --color-text:           #d4d6d2;
  --color-text-muted:     #808580;
  --color-text-faint:     #525753;

  --color-primary:        #8ab464;
  --color-primary-hover:  #a0c87e;
  --color-primary-muted:  rgba(138, 180, 100, 0.12);

  --color-accent:         #c9a84c;
  --color-accent-muted:   rgba(201, 168, 76, 0.10);

  --color-bar-bg:         #1f2220;
  --color-bar-fill:       #8ab464;

  --shadow-sm: 0 1px 2px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.4);
  --shadow-lg: 0 12px 32px rgba(0,0,0,0.5);
}

/* LIGHT */
[data-theme="light"] {
  --color-bg:             #f4f3ef;
  --color-surface:        #ffffff;
  --color-surface-2:      #fafaf8;
  --color-surface-offset: #eceae4;
  --color-border:         #d4d1ca;
  --color-divider:        #dcd9d5;

  --color-text:           #1a1d1a;
  --color-text-muted:     #6b6e68;
  --color-text-faint:     #a0a39d;

  --color-primary:        #4a7a2e;
  --color-primary-hover:  #3d6624;
  --color-primary-muted:  rgba(74, 122, 46, 0.10);

  --color-accent:         #9a7b2e;
  --color-accent-muted:   rgba(154, 123, 46, 0.08);

  --color-bar-bg:         #e8e6e0;
  --color-bar-fill:       #4a7a2e;

  --shadow-sm: 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
  --shadow-lg: 0 12px 32px rgba(0,0,0,0.12);
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme]) {
    --color-bg:             #f4f3ef;
    --color-surface:        #ffffff;
    --color-surface-2:      #fafaf8;
    --color-surface-offset: #eceae4;
    --color-border:         #d4d1ca;
    --color-divider:        #dcd9d5;
    --color-text:           #1a1d1a;
    --color-text-muted:     #6b6e68;
    --color-text-faint:     #a0a39d;
    --color-primary:        #4a7a2e;
    --color-primary-hover:  #3d6624;
    --color-primary-muted:  rgba(74, 122, 46, 0.10);
    --color-accent:         #9a7b2e;
    --color-accent-muted:   rgba(154, 123, 46, 0.08);
    --color-bar-bg:         #e8e6e0;
    --color-bar-fill:       #4a7a2e;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.06);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
    --shadow-lg: 0 12px 32px rgba(0,0,0,0.12);
  }
}

/* ============================================
   LAYOUT
   ============================================ */

main {
  max-width: var(--content-default);
  margin: 0 auto;
  padding: 0 var(--space-6);
}

/* ============================================
   HEADER
   ============================================ */

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-5) 0;
}

.logo {
  color: var(--color-primary);
}

.site-header button {
  color: var(--color-text-muted);
  padding: var(--space-2);
  border-radius: var(--radius-sm);
}
.site-header button:hover {
  color: var(--color-text);
  background: var(--color-primary-muted);
}

/* ============================================
   HERO
   ============================================ */

.hero {
  padding: var(--space-16) 0 var(--space-10);
}

.hero h1 {
  font-family: var(--font-body);
  font-size: var(--text-2xl);
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--color-text);
  margin-bottom: var(--space-4);
}

.subtitle {
  font-size: var(--text-base);
  color: var(--color-text-muted);
  max-width: 52ch;
  line-height: 1.7;
}

/* ============================================
   INPUT
   ============================================ */

.input-section {
  padding-bottom: var(--space-12);
}

.input-label {
  display: block;
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--color-text-muted);
  margin-bottom: var(--space-3);
}

.input-wrapper {
  display: flex;
  align-items: center;
  background: var(--color-surface);
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-4) var(--space-5);
  max-width: 360px;
  transition: border-color var(--transition-interactive), box-shadow var(--transition-interactive);
}

.input-wrapper:focus-within {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-muted);
}

.input-prefix {
  font-family: var(--font-mono);
  font-size: var(--text-lg);
  font-weight: 700;
  color: var(--color-primary);
  margin-right: var(--space-2);
  user-select: none;
}

#tax-input {
  background: none;
  border: none;
  outline: none;
  font-family: var(--font-mono);
  font-size: var(--text-lg);
  font-weight: 700;
  color: var(--color-text);
  width: 100%;
}

#tax-input::placeholder {
  color: var(--color-text-faint);
}

.input-hint {
  font-size: var(--text-xs);
  color: var(--color-text-faint);
  margin-top: var(--space-3);
}

/* ============================================
   RESULTS GRID
   ============================================ */

.results {
  padding-bottom: var(--space-16);
  min-height: 200px;
}

.results-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: var(--space-4);
}

/* ============================================
   CARD
   ============================================ */

.munition-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  opacity: 0;
  transform: translateY(12px);
  animation: cardIn 0.4s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.card-image {
  width: 100%;
  height: 160px;
  overflow: hidden;
  background: var(--color-surface-offset);
}

.card-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.card-body {
  padding: var(--space-4) var(--space-5) var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

@keyframes cardIn {
  to { opacity: 1; transform: translateY(0); }
}

.card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-3);
}

.card-name {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-primary);
  line-height: 1.3;
  text-decoration: none;
}

.card-name:hover {
  text-decoration: underline;
  color: var(--color-primary-hover);
}

.card-designation {
  font-size: var(--text-xs);
  color: var(--color-text-faint);
  font-family: var(--font-mono);
  white-space: nowrap;
}

.card-cost {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  font-family: var(--font-mono);
}

.card-percent {
  font-family: var(--font-mono);
  font-size: var(--text-xl);
  font-weight: 700;
  color: var(--color-primary);
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.card-percent .unit {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-text-muted);
}

/* Progress bar */
.bar-track {
  width: 100%;
  height: 6px;
  background: var(--color-bar-bg);
  border-radius: 3px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  background: var(--color-bar-fill);
  border-radius: 3px;
  width: 0%;
  transition: width 0.6s cubic-bezier(0.16, 1, 0.3, 1);
}

.card-note {
  font-size: var(--text-xs);
  color: var(--color-text-faint);
  line-height: 1.5;
}

/* High-percent highlight */
.munition-card[data-highlight="true"] .card-percent {
  color: var(--color-accent);
}
.munition-card[data-highlight="true"] .bar-fill {
  background: var(--color-accent);
}

/* Stagger animation */
.munition-card:nth-child(1)  { animation-delay: 0.00s; }
.munition-card:nth-child(2)  { animation-delay: 0.04s; }
.munition-card:nth-child(3)  { animation-delay: 0.08s; }
.munition-card:nth-child(4)  { animation-delay: 0.12s; }
.munition-card:nth-child(5)  { animation-delay: 0.16s; }
.munition-card:nth-child(6)  { animation-delay: 0.20s; }
.munition-card:nth-child(7)  { animation-delay: 0.24s; }
.munition-card:nth-child(8)  { animation-delay: 0.28s; }
.munition-card:nth-child(9)  { animation-delay: 0.32s; }
.munition-card:nth-child(10) { animation-delay: 0.36s; }

/* ============================================
   EMPTY STATE
   ============================================ */

.empty-state {
  text-align: center;
  padding: var(--space-16) var(--space-6);
  color: var(--color-text-faint);
}

.empty-icon {
  font-size: 2.5rem;
  margin-bottom: var(--space-4);
  opacity: 0.4;
}

.empty-state p {
  font-size: var(--text-sm);
  max-width: 36ch;
  margin: 0 auto;
}

/* ============================================
   CONTEXT SECTION
   ============================================ */

.context-section {
  border-top: 1px solid var(--color-divider);
  padding: var(--space-10) 0 var(--space-16);
}

.context-section h2 {
  font-size: var(--text-lg);
  font-weight: 600;
  color: var(--color-text);
  margin-bottom: var(--space-4);
}

.context-section p {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  line-height: 1.7;
  max-width: 65ch;
}

/* ============================================
   FOOTER
   ============================================ */

footer {
  border-top: 1px solid var(--color-divider);
  text-align: center;
  padding: var(--space-8) var(--space-6);
}

footer a {
  font-size: var(--text-xs);
  color: var(--color-text-faint);
  text-decoration: none;
}
footer a:hover {
  color: var(--color-text-muted);
}

/* ============================================
   RESPONSIVE
   ============================================ */

@media (max-width: 600px) {
  .hero {
    padding: var(--space-10) 0 var(--space-8);
  }

  .results-grid {
    grid-template-columns: 1fr;
  }

  .input-wrapper {
    max-width: 100%;
  }
}
