/* PackWeight RPG - Main Stylesheet */
:root {
  --bg: #1a1612;
  --bg-card: #231e18;
  --bg-surface: #2d261e;
  --bg-input: #1e1a14;
  --text: #e8e0d4;
  --text-muted: #9a8e7e;
  --text-dim: #6b6054;
  --accent: #c9a84c;
  --accent-light: #e0c47a;
  --accent-dark: #8a6d2b;
  --danger: #c44;
  --success: #4a8;
  --warning: #da6;
  --border: #3d3428;
  --border-light: #4a3f30;
  --radius: 8px;
  --radius-sm: 4px;
  --shadow: 0 2px 12px rgba(0,0,0,0.4);
  --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
  --font-mono: 'SF Mono', 'Fira Code', monospace;
  --max-width: 1200px;
  --header-height: 60px;
}

.light-mode {
  --bg: #f5f0e8;
  --bg-card: #fffbf5;
  --bg-surface: #ede6d8;
  --bg-input: #fff;
  --text: #2a2418;
  --text-muted: #6b5e48;
  --text-dim: #9a8e74;
  --border: #d4c8b4;
  --border-light: #e0d6c4;
  --shadow: 0 2px 12px rgba(0,0,0,0.1);
}

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

html { scroll-behavior: smooth; scroll-padding-top: calc(var(--header-height) + 16px); }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.skip-link {
  position: absolute;
  top: -100%;
  left: 16px;
  background: var(--accent);
  color: var(--bg);
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  z-index: 1000;
  font-weight: 600;
  text-decoration: none;
}
.skip-link:focus { top: 8px; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  border: 0;
}

/* Header */
.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  height: var(--header-height);
}

.header-inner {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 20px;
  height: 100%;
  display: flex;
  align-items: center;
  gap: 24px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  color: var(--text);
  flex-shrink: 0;
}

.logo-icon { color: var(--accent); }
.logo-text { font-size: 1.2rem; font-weight: 700; letter-spacing: 0.5px; }
.logo-accent { color: var(--accent); }

.main-nav {
  display: flex;
  gap: 4px;
  margin-left: auto;
}

.nav-link {
  color: var(--text-muted);
  text-decoration: none;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  transition: color 0.2s, background 0.2s;
}

.nav-link:hover, .nav-link.active {
  color: var(--accent);
  background: var(--bg-surface);
}

.theme-toggle {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  cursor: pointer;
  font-size: 1.1rem;
  transition: background 0.2s;
}
.theme-toggle:hover { background: var(--border); }

/* Hero */
.hero {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 60px 20px 40px;
  display: grid;
  grid-template-columns: 1fr 300px;
  gap: 40px;
  align-items: center;
}

.hero-content h1 {
  font-size: 2.8rem;
  font-weight: 800;
  line-height: 1.15;
  margin-bottom: 16px;
  background: linear-gradient(135deg, var(--text), var(--accent-light));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.hero-sub {
  font-size: 1.15rem;
  color: var(--text-muted);
  margin-bottom: 28px;
  max-width: 520px;
}

.hero-actions { display: flex; gap: 12px; flex-wrap: wrap; }

.hero-visual { display: flex; justify-content: center; }

.encumbrance-preview {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  width: 220px;
}

.preview-bar {
  height: 12px;
  background: var(--bg-surface);
  border-radius: 6px;
  overflow: hidden;
  margin-bottom: 8px;
}

.preview-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--success), var(--warning));
  border-radius: 6px;
  transition: width 0.5s ease;
}

.preview-label {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  text-decoration: none;
  transition: all 0.2s;
  font-family: var(--font);
}

.btn-primary {
  background: var(--accent);
  color: var(--bg);
}
.btn-primary:hover { background: var(--accent-light); }

.btn-ghost {
  background: var(--bg-surface);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-ghost:hover { background: var(--border); }

.btn-danger:hover { background: rgba(204,68,68,0.15); border-color: var(--danger); color: var(--danger); }

.btn-add { padding: 10px 16px; white-space: nowrap; }
.btn-sm { padding: 4px 10px; font-size: 0.85rem; }

/* Sections */
.section-title {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 20px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--border);
}

/* Tracker Layout */
.tracker-section {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 20px;
}

.tracker-layout {
  display: grid;
  grid-template-columns: 1fr 300px;
  gap: 32px;
  align-items: start;
}

.tracker-main { min-width: 0; }
.tracker-sidebar {
  position: sticky;
  top: calc(var(--header-height) + 20px);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.sidebar-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.sidebar-card h3 {
  font-size: 0.95rem;
  color: var(--accent);
  margin-bottom: 8px;
}

.sidebar-card p, .sidebar-card li {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.sidebar-card ul { padding-left: 16px; }
.sidebar-card li { margin-bottom: 4px; }

/* System Selector */
.system-selector {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 20px;
}

.system-option { cursor: pointer; }
.system-option input { position: absolute; opacity: 0; }

.system-card {
  display: block;
  padding: 12px;
  background: var(--bg-card);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  text-align: center;
  transition: all 0.2s;
}

.system-option input:checked + .system-card {
  border-color: var(--accent);
  background: var(--bg-surface);
}

.system-card strong { display: block; font-size: 0.9rem; }
.system-card small { font-size: 0.75rem; color: var(--text-muted); }

/* Fields */
.field-row {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr;
  gap: 12px;
  margin-bottom: 16px;
}

.field { display: flex; flex-direction: column; gap: 4px; }
.field label { font-size: 0.8rem; color: var(--text-muted); font-weight: 600; }
.field input {
  padding: 8px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.95rem;
  font-family: var(--font);
}
.field input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px rgba(201,168,76,0.2); }
.field-grow { flex: 1; }
.field-sm { max-width: 80px; }

.character-panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}

.add-item-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

/* Quick Add */
.quick-add {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.quick-add-label { font-size: 0.8rem; color: var(--text-muted); font-weight: 600; }
.quick-add-chips { display: flex; gap: 6px; flex-wrap: wrap; }

.chip {
  padding: 4px 10px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 0.8rem;
  cursor: pointer;
  color: var(--text);
  transition: all 0.2s;
  font-family: var(--font);
}
.chip:hover { background: var(--border); border-color: var(--accent); }

/* Inventory Table */
.inventory-table-wrap {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 20px;
}

.inventory-table {
  width: 100%;
  border-collapse: collapse;
}

.inventory-table th {
  text-align: left;
  padding: 10px 12px;
  font-size: 0.8rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
}

.inventory-table td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}

.inventory-table tr:last-child td { border-bottom: none; }
.inventory-table tfoot td { background: var(--bg-surface); border-top: 2px solid var(--border); }

.col-qty { width: 60px; }
.col-wt { width: 80px; }
.col-total { width: 80px; }
.col-action { width: 40px; text-align: center; }

.inventory-table input {
  width: 100%;
  padding: 4px 6px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.85rem;
  font-family: var(--font);
}
.inventory-table input:focus { outline: none; border-color: var(--accent); }

.btn-remove {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 1.1rem;
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  transition: color 0.2s;
}
.btn-remove:hover { color: var(--danger); }

.empty-state {
  padding: 32px;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* Encumbrance Meter */
.encumbrance-meter {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 20px;
}

.meter-labels {
  display: flex;
  justify-content: space-between;
  margin-bottom: 8px;
}

.meter-labels span:first-child {
  font-weight: 700;
  font-size: 1rem;
}

.meter-labels span:last-child {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

.meter-bar {
  height: 20px;
  background: var(--bg-surface);
  border-radius: 10px;
  overflow: hidden;
  position: relative;
}

.meter-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--success), var(--warning), var(--danger));
  border-radius: 10px;
  transition: width 0.4s ease, background 0.4s;
  width: 0%;
}

.meter-thresholds {
  display: flex;
  justify-content: space-between;
  margin-top: 6px;
  font-size: 0.7rem;
  color: var(--text-dim);
}

.meter-penalty {
  margin-top: 8px;
  font-size: 0.85rem;
  color: var(--warning);
  font-weight: 600;
  min-height: 1.2em;
}

/* Actions */
.actions-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 40px;
}

/* Reference Section */
.reference-section { margin-top: 40px; }

.ref-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
}

.ref-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

.ref-card h3 {
  color: var(--accent);
  margin-bottom: 8px;
  font-size: 1rem;
}

.ref-card p, .ref-card li {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.ref-card ul { padding-left: 16px; margin: 8px 0; }

.custom-fields {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 12px;
}

.custom-fields .field label { font-size: 0.75rem; }
.custom-fields .field input { padding: 6px 8px; font-size: 0.85rem; }

/* Help Section */
.help-section {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 40px 20px;
}

.help-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.help-item {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.help-item summary {
  padding: 14px 16px;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text);
  list-style: none;
  display: flex;
  align-items: center;
  gap: 8px;
}

.help-item summary::before {
  content: '▸';
  color: var(--accent);
  font-size: 0.8rem;
  transition: transform 0.2s;
}

.help-item[open] summary::before { transform: rotate(90deg); }

.help-item summary:hover { background: var(--bg-surface); }

.help-item p {
  padding: 0 16px 14px;
  font-size: 0.85rem;
  color: var(--text-muted);
  line-height: 1.5;
}

/* Tips Section */
.tips-section {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 20px 20px 60px;
}

.tips-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
}

.tip-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

.tip-card h3 {
  color: var(--accent);
  font-size: 0.95rem;
  margin-bottom: 8px;
}

.tip-card p {
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* Footer */
.site-footer {
  margin-top: auto;
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  padding: 32px 20px;
}

.footer-inner {
  max-width: var(--max-width);
  margin: 0 auto;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 24px;
  align-items: start;
}

.footer-brand p {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 4px;
}

.footer-nav {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
}

.footer-nav a {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.85rem;
  transition: color 0.2s;
}
.footer-nav a:hover { color: var(--accent); }

.footer-copy {
  grid-column: 1 / -1;
  font-size: 0.75rem;
  color: var(--text-dim);
  margin-top: 8px;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--bg-card);
  border: 1px solid var(--accent);
  color: var(--text);
  padding: 12px 20px;
  border-radius: var(--radius);
  font-size: 0.9rem;
  box-shadow: var(--shadow);
  transform: translateY(100px);
  opacity: 0;
  transition: all 0.3s ease;
  z-index: 200;
}

.toast.show {
  transform: translateY(0);
  opacity: 1;
}

/* Print */
@media print {
  .site-header, .site-footer, .hero, .tracker-sidebar, .actions-row, .quick-add, .add-item-row, .system-selector, .character-panel, .help-section, .tips-section, .theme-toggle, .btn-remove, .col-action { display: none !important; }
  body { background: #fff; color: #000; }
  .tracker-section { padding: 0; }
  .inventory-table-wrap { border: 1px solid #000; }
  .inventory-table th, .inventory-table td { border-color: #000; color: #000; }
  .encumbrance-meter { border: 1px solid #000; }
  .meter-fill { background: #ccc !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

/* Responsive */
@media (max-width: 900px) {
  .hero { grid-template-columns: 1fr; text-align: center; }
  .hero-sub { margin: 0 auto 28px; }
  .hero-actions { justify-content: center; }
  .hero-visual { display: none; }
  .tracker-layout { grid-template-columns: 1fr; }
  .tracker-sidebar { position: static; }
  .ref-grid { grid-template-columns: 1fr; }
  .help-grid { grid-template-columns: 1fr; }
  .tips-grid { grid-template-columns: repeat(2, 1fr); }
  .system-selector { grid-template-columns: repeat(2, 1fr); }
  .field-row { grid-template-columns: 1fr; }
  .footer-inner { grid-template-columns: 1fr; }
}

@media (max-width: 600px) {
  .hero-content h1 { font-size: 2rem; }
  .tips-grid { grid-template-columns: 1fr; }
  .system-selector { grid-template-columns: 1fr 1fr; }
  .add-item-row { flex-direction: column; align-items: stretch; }
  .field-sm { max-width: none; }
  .main-nav { display: none; }
  .custom-fields { grid-template-columns: 1fr; }
}

/* Focus styles for accessibility */
*:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Scrollbar */
::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }


/* Factory-injected deployment helpers. The AI owns the site design above this block. */
.ad-unit {
  width: min(100%, 720px);
  min-height: 120px;
  margin: 24px auto;
  display: block;
}

.legal-page {
  width: min(900px, calc(100% - 32px));
  margin: 40px auto;
}

.factory-fallback-nav {
  width: min(900px, calc(100% - 32px));
  margin: 24px auto 0;
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
  align-items: center;
  font-size: 0.95rem;
}

.factory-fallback-nav a {
  color: inherit;
  text-decoration: none;
  border-bottom: 1px solid currentColor;
}
