/* ============================================================
   Prediction Market Calculator — Tron/Dark Theme
   Uses CSS custom properties throughout for easy theming.
   ============================================================ */

/* ---- Custom Properties ---- */
:root {
  --bg-base: #0a0e1a;
  --bg-surface: #0f1629;
  --bg-elevated: #162040;
  --bg-header: #090d18;

  --accent: #6ae5fe;
  --accent-dim: #4fa8bb;
  --accent-glow: rgba(115, 229, 252, 0.274);

  --text-primary: #e8f4fd;
  --text-secondary: #a5aeb7;
  --text-muted: #6698c3;
  --text-on-accent: #0a0e1a;

  --positive: var(--accent);
  --negative: #ff4d6d;
  --negative-dim: rgba(255, 77, 109, 0.15);

  --border-dim: #1e2d47;
  --border-accent: rgba(0, 212, 255, 0.4);

  --font-sans: 'Inter', system-ui, -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', 'Menlo', 'Consolas', monospace;

  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;

  --transition: 150ms ease;
}

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

/* ---- Base ---- */
html {
  font-size: 16px;
  scroll-behavior: smooth;
}

body {
  background-color: var(--bg-base);
  color: var(--text-primary);
  font-family: var(--font-sans);
  line-height: 1.6;
  min-height: 100vh;
}

/* ---- Layout ---- */
.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 1.25rem;
}

/* ---- Site Header ---- */
.site-header {
  background: var(--bg-header);
  border-bottom: 1px solid var(--border-dim);
  padding: 2rem 0 1.75rem;
  position: relative;
  overflow: hidden;
}

/* Subtle Tron grid line effect */
.site-header::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(var(--border-dim) 1px, transparent 1px),
    linear-gradient(90deg, var(--border-dim) 1px, transparent 1px);
  background-size: 40px 40px;
  opacity: 0.3;
  pointer-events: none;
}

.site-header .container {
  position: relative;
}

.site-header h1 {
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -0.04em;
  color: var(--accent);
  text-shadow: 0 0 24px var(--accent-glow);
}

.site-header h2 {
  font-size: 1rem;
  font-weight: 400;
  color: var(--text-secondary);
  margin-top: 0.25rem;
}

.intro {
  margin-top: 0.875rem;
  max-width: 680px;
  font-size: 0.9rem;
  color: var(--text-secondary);
  line-height: 1.7;
}

/* ---- Ad Banner ---- */
.ad-banner {
  margin: 1.25rem 0;
  min-height: 90px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.ad-placeholder {
  width: 100%;
  height: 90px;
  border: 1px dashed var(--border-dim);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 0.75rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

/* ---- Buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.5rem 1rem;
  font-family: var(--font-sans);
  font-size: 0.875rem;
  font-weight: 500;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  transition:
    background-color var(--transition),
    color var(--transition),
    border-color var(--transition),
    box-shadow var(--transition);
  white-space: nowrap;
  user-select: none;
}

.btn--primary {
  background: var(--accent);
  color: var(--text-on-accent);
  border-color: var(--accent);
}
.btn--primary:hover {
  background: var(--accent-dim);
  border-color: var(--accent-dim);
  box-shadow: 0 0 12px var(--accent-glow);
}

.btn--ghost {
  background: transparent;
  color: var(--text-secondary);
  border-color: var(--border-dim);
}
.btn--ghost:hover {
  color: var(--text-primary);
  border-color: var(--accent);
  background: var(--bg-elevated);
}

.btn--outline {
  background: transparent;
  color: var(--accent);
  border-color: var(--border-accent);
}
.btn--outline:hover {
  background: var(--accent-glow);
}

.btn--icon {
  padding: 0.375rem;
  background: transparent;
  border-color: transparent;
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  line-height: 1;
}
.btn--icon:hover {
  color: var(--negative);
  background: var(--negative-dim);
}

/* ---- Inputs ---- */
.input {
  background: var(--bg-base);
  border: 1px solid var(--border-dim);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 0.875rem;
  padding: 0.4rem 0.6rem;
  transition:
    border-color var(--transition),
    box-shadow var(--transition);
  outline: none;
  -moz-appearance: textfield;
  width: 100%;
}
.input::-webkit-inner-spin-button,
.input::-webkit-outer-spin-button {
  -webkit-appearance: none;
}
.input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-glow);
}

.input--sm {
  width: 80px;
}

/* ---- Control Bar ---- */
.control-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
  padding: 0.875rem 1rem;
  background: var(--bg-surface);
  border: 1px solid var(--border-dim);
  border-radius: var(--radius-md);
  margin-bottom: 0.75rem;
}

.control-bar__left {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.control-bar__divider {
  width: 1px;
  height: 24px;
  background: var(--border-dim);
  flex-shrink: 0;
}

/* ---- Calculator Section ---- */
.calculator {
  background: var(--bg-surface);
  border: 1px solid var(--border-dim);
  border-radius: var(--radius-md);
  overflow: hidden;
}

/* ---- Table Header ---- */
.table-header {
  display: grid;
  grid-template-columns: var(--row-grid);
  gap: 0.5rem;
  padding: 0.5rem 0.875rem;
  background: var(--bg-header);
  border-bottom: 1px solid var(--border-dim);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
  user-select: none;
}

/* ---- Contract Row ---- */
:root {
  /* cols: made-check | cost | price | fee | arrow | payout | profit | correct-check | delete */
  /* rem used for text-driven columns so they scale with user font-size preference */
  --row-grid: 2.5rem 1fr 1fr 80px 20px 100px 100px 5rem 32px;
}

.row {
  display: grid;
  grid-template-columns: var(--row-grid);
  gap: 0.5rem;
  align-items: center;
  padding: 0.45rem 0.875rem;
  border-bottom: 1px solid var(--border-dim);
  cursor: default;
  transition: background-color var(--transition);
  user-select: none;
}

.row:last-child {
  border-bottom: none;
}

.row:hover {
  background: var(--bg-elevated);
}

.row--selected {
  background: var(--bg-elevated);
  box-shadow: inset 3px 0 0 0 var(--accent);
}

.row--grayed {
  opacity: 0.4;
}

/* ---- Row columns ---- */
.col-check {
  display: flex;
  align-items: center;
  justify-content: center;
}

.col-arrow {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 0.75rem;
}

.col-label {
  font-size: 0.72rem;
  padding-inline: 0.25rem;
}

.col-label--right {
  text-align: right;
}

.col-delete {
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ---- Value display (payout, profit) ---- */
.value {
  font-family: var(--font-mono);
  font-size: 0.875rem;
  font-weight: 500;
  text-align: right;
  letter-spacing: -0.01em;
  transition: color var(--transition);
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.value--positive {
  color: var(--positive);
}

.value--negative {
  color: var(--negative);
}

.value--muted {
  color: var(--text-muted);
  text-decoration: line-through;
}

.value--empty {
  color: var(--text-muted);
}

/* ---- Checkbox styling ---- */
.checkbox {
  appearance: none;
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border: 1.5px solid var(--border-dim);
  border-radius: 3px;
  background: var(--bg-base);
  cursor: pointer;
  position: relative;
  transition:
    border-color var(--transition),
    background-color var(--transition);
  flex-shrink: 0;
}

.checkbox:hover {
  border-color: var(--accent);
}

.checkbox:checked {
  background: var(--accent);
  border-color: var(--accent);
}

.checkbox:checked::after {
  content: '';
  position: absolute;
  left: 4px;
  top: 1px;
  width: 5px;
  height: 9px;
  border: 2px solid var(--text-on-accent);
  border-top: none;
  border-left: none;
  transform: rotate(45deg);
}

/* ---- Totals ---- */
.totals {
  display: flex;
  gap: 0;
  border-top: 2px solid var(--border-dim);
}

.totals__item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  padding: 0.875rem 1rem;
  border-right: 1px solid var(--border-dim);
}

.totals__item:last-child {
  border-right: none;
}

.totals__label {
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 0.25rem;
}

.totals__value {
  font-family: var(--font-mono);
  font-size: 1.25rem;
  font-weight: 500;
  color: var(--text-primary);
}

.totals__value--profit {
  /* color set dynamically by JS */
}

/* ---- Explainer Section ---- */
.explainer {
  margin: 2rem 0;
}

.explainer h2 {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border-dim);
}

.explainer__grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
}

.explainer__card {
  background: var(--bg-surface);
  border: 1px solid var(--border-dim);
  border-radius: var(--radius-md);
  padding: 1rem 1.125rem;
}

.explainer__card h3 {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 0.5rem;
}

.explainer__card p {
  font-size: 0.82rem;
  color: var(--text-secondary);
  line-height: 1.65;
}

.explainer__card code {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--accent);
  background: var(--bg-elevated);
  padding: 0.1em 0.35em;
  border-radius: 3px;
}

/* ---- Site Footer ---- */
.site-footer {
  margin-top: 2.5rem;
  border-top: 1px solid var(--border-dim);
  padding: 1.5rem 0;
  background: var(--bg-header);
}

.site-footer p {
  font-size: 0.78rem;
  color: var(--text-muted);
  text-align: center;
  line-height: 1.7;
}

.footer__keywords {
  margin-top: 0.25rem;
}

/* ---- Empty state ---- */
.empty-state {
  text-align: center;
  padding: 2.5rem 1rem;
  color: var(--text-muted);
  font-size: 0.875rem;
}

.empty-state strong {
  display: block;
  font-size: 1rem;
  color: var(--text-secondary);
  margin-bottom: 0.375rem;
}

/* ---- Custom value tooltip ---- */
.value-tooltip {
  display: none;
  position: fixed;
  z-index: 1000;
  background: var(--bg-elevated);
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 0.8rem;
  font-weight: 500;
  padding: 0.25rem 0.5rem;
  border: 1px solid var(--border-dim);
  border-radius: var(--radius-sm);
  white-space: nowrap;
  pointer-events: none;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

/* ---- Header checkbox (table-header "Made?" column) ---- */
.checkbox--header {
  border-color: var(--text-muted);
}
.checkbox--header:indeterminate {
  background: var(--accent);
  border-color: var(--accent);
  opacity: 0.5;
}
.checkbox--header:indeterminate::after {
  content: '';
  position: absolute;
  left: 3px;
  top: 6px;
  width: 8px;
  height: 2px;
  background: var(--text-on-accent);
  border: none;
  transform: none;
}

/* ---- Trash icon SVG (inline) ---- */
.icon-trash {
  width: 15px;
  height: 15px;
  display: block;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ---- Responsive ---- */
@media (max-width: 780px) {
  :root {
    --row-grid: 2.5rem 80px 80px 80px 20px 80px 80px 5rem 28px;
  }

  .site-header h1 {
    font-size: 1.5rem;
  }

  .control-bar {
    flex-direction: column;
    align-items: stretch;
  }

  .control-bar__left {
    justify-content: flex-start;
  }

  .control-bar__divider {
    display: none;
  }

  .totals {
    flex-direction: column;
  }

  .totals__item {
    align-items: flex-start;
    border-right: none;
    border-bottom: 1px solid var(--border-dim);
    padding: 0.75rem 1rem;
  }

  .totals__item:last-child {
    border-bottom: none;
  }
}

@media (max-width: 560px) {
  .table-header {
    display: none;
  }

  :root {
    --row-grid: 28px 1fr 1fr 56px 14px 72px 44px 28px;
  }

  .row .col-profit {
    display: none;
  }
}
