/* ==========================================================================
   RuleForge — design tokens
   Dark: deep indigo-black forge with an ember/amber accent.
   Light: warm parchment with a deeper amber accent.
   ========================================================================== */

:root {
  --bg: #F5F2EA;
  --surface: #FFFFFF;
  --surface-2: #EFEAE0;
  --border: #DCD5C6;
  --text: #201C16;
  --text-muted: #6B6455;
  --accent: #C4772A;
  --accent-strong: #A8611E;
  --ember: #C4442E;
  --success: #3E7A52;
  --code-bg: #FBF8F1;
  --code-text: #2B2620;
  --shadow: 0 1px 2px rgba(32, 28, 22, 0.06), 0 8px 24px rgba(32, 28, 22, 0.06);
  --radius-sm: 6px;
  --radius-md: 12px;
  --radius-lg: 20px;
  --font-display: "Space Grotesk", "Segoe UI", sans-serif;
  --font-body: "Inter", "Segoe UI", sans-serif;
  --font-mono: "JetBrains Mono", "SFMono-Regular", Consolas, monospace;
}

[data-theme="dark"] {
  --bg: #12121B;
  --surface: #191A26;
  --surface-2: #20212F;
  --border: #2E303F;
  --text: #ECEAE3;
  --text-muted: #9A9AAB;
  --accent: #F2A65A;
  --accent-strong: #F7B96E;
  --ember: #E8674C;
  --success: #5FBE83;
  --code-bg: #0F1017;
  --code-text: #E7E4D8;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 12px 32px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  transition: background-color 0.2s ease, color 0.2s ease;
}

h1, h2, h3, h4 {
  font-family: var(--font-display);
  font-weight: 600;
  letter-spacing: -0.01em;
  margin: 0;
}

a { color: inherit; }

button, input, textarea, select {
  font-family: inherit;
  color: inherit;
}

code, .mono {
  font-family: var(--font-mono);
  font-size: 12px;
  background: var(--surface-2);
  padding: 2px 6px;
  border-radius: 4px;
}

.container {
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 24px;
}

/* ---------------- Header ---------------- */

.site-header {
  position: sticky;
  top: 0;
  z-index: 40;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.site-header .container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 68px;
  gap: 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 700;
  text-decoration: none;
  color: var(--text);
}

.brand-mark {
  width: 30px;
  height: 30px;
  flex-shrink: 0;
}

.brand-mark path { fill: var(--accent); }

nav.main-nav {
  display: flex;
  align-items: center;
  gap: 4px;
}

.nav-link {
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  text-decoration: none;
  color: var(--text-muted);
  font-size: 14.5px;
  font-weight: 500;
  cursor: pointer;
  background: none;
  border: none;
}

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

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.stats-display {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 13px;
  color: var(--text-muted);
}

.stat-item {
  display: flex;
  align-items: center;
  gap: 4px;
}

.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text);
}

.icon-btn:hover { background: var(--surface-2); }
.icon-btn svg { width: 18px; height: 18px; }

/* ---------------- Buttons ---------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  font-size: 14.5px;
  font-weight: 600;
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}

.btn-primary {
  background: var(--accent);
  color: #1A1508;
}
.btn-primary:hover { background: var(--accent-strong); }

.btn-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--text);
}
.btn-ghost:hover { background: var(--surface-2); }

.btn-danger {
  background: transparent;
  border-color: var(--ember);
  color: var(--ember);
}
.btn-danger:hover { background: color-mix(in srgb, var(--ember) 12%, transparent); }

.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-block { width: 100%; }
.btn-sm { padding: 7px 12px; font-size: 13px; }

/* ---------------- Hero ---------------- */

.hero {
  padding: 72px 0 56px;
  border-bottom: 1px solid var(--border);
}

.hero .container {
  display: grid;
  grid-template-columns: 1.1fr 1fr;
  gap: 48px;
  align-items: center;
}

.eyebrow {
  font-family: var(--font-mono);
  font-size: 12.5px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 14px;
  display: block;
}

.hero h1 {
  font-size: clamp(30px, 4vw, 46px);
  line-height: 1.12;
  margin-bottom: 18px;
}

.hero p.lede {
  font-size: 17px;
  color: var(--text-muted);
  max-width: 46ch;
  margin-bottom: 28px;
}

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

/* Signature element: the rule forge diff */

.forge-demo {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.forge-demo-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-muted);
}

.forge-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--border);
}

.forge-demo-body {
  font-family: var(--font-mono);
  font-size: 13px;
  padding: 18px 20px;
  background: var(--code-bg);
  color: var(--code-text);
  min-height: 220px;
  white-space: pre-wrap;
  word-break: break-word;
}

.forge-line-remove { color: var(--ember); opacity: 0.85; }
.forge-line-add { color: var(--success); }
.forge-cursor {
  display: inline-block;
  width: 7px; height: 15px;
  background: var(--accent);
  vertical-align: text-bottom;
  animation: blink 1s step-end infinite;
}

@keyframes blink { 50% { opacity: 0; } }

@media (prefers-reduced-motion: reduce) {
  .forge-cursor { animation: none; }
}

/* ---------------- Sections ---------------- */

.section {
  padding: 56px 0;
}

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 28px;
  flex-wrap: wrap;
}

.section-head h2 { font-size: 26px; }
.section-head p { color: var(--text-muted); font-size: 14.5px; margin: 4px 0 0; }

/* ---------------- Shop grid ---------------- */

.shop-toolbar {
  display: flex;
  gap: 10px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}

.tag-filter {
  padding: 7px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 13px;
  cursor: pointer;
  color: var(--text-muted);
}

.tag-filter.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #1A1508;
  font-weight: 600;
}

.shop-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 20px;
}

.product-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: var(--shadow);
}

.product-card-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
}

.product-card h3 { font-size: 17px; }

.price-tag {
  font-family: var(--font-mono);
  font-size: 15px;
  font-weight: 700;
  color: var(--accent);
  white-space: nowrap;
}

.product-desc {
  font-size: 14px;
  color: var(--text-muted);
  flex-grow: 1;
}

.tag-row {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.tag-chip {
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-muted);
}

.sample-preview {
  font-family: var(--font-mono);
  font-size: 12px;
  background: var(--code-bg);
  color: var(--code-text);
  border-radius: var(--radius-sm);
  padding: 12px;
  max-height: 110px;
  overflow: hidden;
  position: relative;
  border: 1px solid var(--border);
}

.sample-preview::after {
  content: "";
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 36px;
  background: linear-gradient(to bottom, transparent, var(--code-bg));
}

.card-actions {
  display: flex;
  gap: 8px;
}

.owned-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--success);
}

/* ---------------- Empty / loading states ---------------- */

.empty-state, .loading-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
  border: 1px dashed var(--border);
  border-radius: var(--radius-md);
  font-size: 14.5px;
}

/* ---------------- Modal ---------------- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(10, 9, 6, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 100;
}

.modal {
  background: var(--surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  width: 100%;
  max-width: 520px;
  max-height: 88vh;
  overflow-y: auto;
  padding: 28px;
  box-shadow: var(--shadow);
}

.modal h3 { margin-bottom: 6px; }
.modal .modal-sub { color: var(--text-muted); font-size: 14px; margin-bottom: 20px; }

.field {
  margin-bottom: 16px;
}

.field label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 6px;
}

.field input,
.field textarea,
.field select {
  width: 100%;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 14px;
}

.field textarea { resize: vertical; min-height: 90px; }
.field textarea.mono-field { font-family: var(--font-mono); font-size: 13px; }

.momo-number-container {
  display: flex;
  gap: 8px;
}

.momo-number-container input {
  flex: 1;
  font-family: var(--font-mono);
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.05em;
}

.field-hint { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

.terms-content {
  max-width: 800px;
  margin: 0 auto;
  padding: 24px 0;
}

.terms-content h3 {
  font-size: 18px;
  font-weight: 600;
  margin-top: 32px;
  margin-bottom: 12px;
  color: var(--text);
}

.terms-content h3:first-child {
  margin-top: 0;
}

.terms-content p {
  font-size: 15px;
  line-height: 1.7;
  color: var(--text-muted);
  margin-bottom: 16px;
}

.terms-updated {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 32px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

/* Responsive styles for terms page */
@media (max-width: 768px) {
  .terms-content {
    padding: 16px 0;
  }

  .terms-content h3 {
    font-size: 16px;
    margin-top: 24px;
    margin-bottom: 10px;
  }

  .terms-content p {
    font-size: 14px;
    line-height: 1.6;
    margin-bottom: 14px;
  }

  .terms-updated {
    font-size: 12px;
    margin-top: 24px;
    padding-top: 12px;
  }
}

@media (max-width: 480px) {
  .terms-content h3 {
    font-size: 15px;
    margin-top: 20px;
    margin-bottom: 8px;
  }

  .terms-content p {
    font-size: 13px;
    line-height: 1.5;
  }
}

.mt-8 {
  margin-top: 32px;
}

.mt-4 {
  margin-top: 16px;
}

.attachments-list {
  margin-top: 12px;
}

.attachment-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
}

.attachment-name {
  font-size: 14px;
  color: var(--text);
  word-break: break-all;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 8px;
}

.form-error {
  background: color-mix(in srgb, var(--ember) 12%, transparent);
  border: 1px solid var(--ember);
  color: var(--ember);
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  margin-bottom: 14px;
}

.form-success {
  background: color-mix(in srgb, var(--success) 12%, transparent);
  border: 1px solid var(--success);
  color: var(--success);
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  margin-bottom: 14px;
}

/* ---------------- Admin table ---------------- */

.admin-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}

table.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}

.admin-table th, .admin-table td {
  text-align: left;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.admin-table th {
  color: var(--text-muted);
  font-weight: 600;
  background: var(--surface-2);
}

.admin-table td.desc-cell {
  white-space: normal;
  max-width: 320px;
  color: var(--text-muted);
}

.status-pill {
  font-size: 11.5px;
  padding: 3px 9px;
  border-radius: 999px;
  font-weight: 600;
}
.status-pill.active { background: color-mix(in srgb, var(--success) 18%, transparent); color: var(--success); }
.status-pill.inactive { background: color-mix(in srgb, var(--text-muted) 18%, transparent); color: var(--text-muted); }

/* ---------------- Auth panel ---------------- */

.auth-card {
  max-width: 400px;
  margin: 0 auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 32px;
  box-shadow: var(--shadow);
}

.auth-toggle {
  display: flex;
  gap: 4px;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: 4px;
  margin-bottom: 22px;
}

.auth-toggle button {
  flex: 1;
  padding: 8px;
  border-radius: 4px;
  border: none;
  background: none;
  cursor: pointer;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-muted);
}

.auth-toggle button.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

/* ---------------- Footer ---------------- */

.site-footer {
  border-top: 1px solid var(--border);
  padding: 32px 0;
  color: var(--text-muted);
  font-size: 13px;
}

.site-footer .container {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
}

.footer-links a {
  color: var(--text-muted);
  text-decoration: none;
  transition: color 0.2s;
}

.footer-links a:hover {
  color: var(--text);
}

@media (max-width: 768px) {
  .site-footer .container {
    flex-direction: column;
    text-align: center;
    gap: 8px;
  }
}

/* ---------------- Toast ---------------- */

#toast-region {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  font-size: 13.5px;
  max-width: 320px;
}

.toast.err { border-color: var(--ember); }
.toast.ok { border-color: var(--success); }

/* ---------------- Utility ---------------- */

.hidden { display: none !important; }
.text-muted { color: var(--text-muted); }
.mt-8 { margin-top: 8px; }
.flex-row { display: flex; align-items: center; gap: 8px; }

/* ---------------- Responsive ---------------- */

@media (max-width: 900px) {
  .hero .container { grid-template-columns: 1fr; }
  .shop-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 640px) {
  .site-header .container { height: auto; padding: 12px 16px; flex-wrap: wrap; }
  nav.main-nav { order: 3; width: 100%; overflow-x: auto; }
  .hero { padding: 40px 0 36px; }
  .hero-actions { flex-direction: column; align-items: stretch; }
  .shop-grid { grid-template-columns: 1fr; }
  .container { padding: 0 16px; }
  .section { padding: 40px 0; }
  .admin-table th, .admin-table td { padding: 10px; }
}
