/* Martingale Machine – playful, slightly grim */

:root {
  --bg: #0f0f12;
  --surface: #18181c;
  --surface2: #222228;
  --text: #e8e6e3;
  --muted: #8b8685;
  --accent: #c9a227;
  --accent-dim: #8b7322;
  --win: #4a7c59;
  --loss: #a04545;
  --radius: 12px;
  --font-sans: 'Outfit', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
}

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

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.5;
}

.app {
  max-width: 560px;
  margin: 0 auto;
  padding: 2rem 1.5rem;
}

.header {
  text-align: center;
  margin-bottom: 2rem;
}

.header h1 {
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  margin: 0 0 0.25rem;
}

.tagline {
  color: var(--muted);
  font-size: 0.95rem;
  margin: 0;
}

.card {
  background: var(--surface);
  border: 1px solid var(--surface2);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  margin-bottom: 1.5rem;
}

.settings h2,
.game.card > h3,
.game .log h3,
.game .graph h3,
.estimate h3 {
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin: 0 0 1rem;
}

.settings-row {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 0.75rem;
}

.settings-row label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.settings-row label span {
  font-size: 0.8rem;
  color: var(--muted);
}

.settings-row input {
  width: 100%;
  min-width: 80px;
  padding: 0.5rem 0.65rem;
  background: var(--surface2);
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 0.95rem;
}

.settings-row input:focus {
  outline: none;
  border-color: var(--accent-dim);
}

.settings-hint {
  font-size: 0.8rem;
  color: var(--muted);
  margin: 0;
}

/* Stats */
.stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1rem;
  margin-bottom: 2rem;
}

.stat {
  background: var(--surface2);
  padding: 0.75rem 1rem;
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.stat-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.stat-value {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 1.1rem;
}

.stat-status {
  font-family: var(--font-sans);
  font-weight: 400;
  font-size: 0.9rem;
}

/* Coin */
.coin-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  margin-bottom: 2rem;
  perspective: 400px;
}

.coin {
  --size: 140px;
  width: var(--size);
  height: var(--size);
  border-radius: 50%;
  background: linear-gradient(145deg, #d4af37 0%, #a68b2a 50%, #8b7322 100%);
  border: 4px solid #5c4a18;
  box-shadow:
    inset 0 2px 4px rgba(255, 255, 255, 0.25),
    inset 0 -2px 4px rgba(0, 0, 0, 0.3),
    0 8px 24px rgba(0, 0, 0, 0.4);
  cursor: pointer;
  position: relative;
  overflow: hidden;
  transition: transform 0.1s ease, box-shadow 0.2s ease;
  font-family: var(--font-mono);
  font-size: 2.5rem;
  font-weight: 700;
  color: #2a2416;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  transform-style: preserve-3d;
}

.coin:hover:not(:disabled) {
  transform: scale(1.03);
  box-shadow:
    inset 0 2px 4px rgba(255, 255, 255, 0.3),
    0 10px 28px rgba(0, 0, 0, 0.45);
}

.coin:active:not(:disabled) {
  transform: scale(0.98);
}

.coin:disabled {
  cursor: not-allowed;
  opacity: 0.7;
}

.coin-face {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  backface-visibility: hidden;
}

.coin .coin-heads {
  transform: rotateY(0deg);
}

.coin .coin-tails {
  transform: rotateY(180deg);
}

/* Resting: show both faces in a neutral “edge” view – we use one face as default */
.coin.land-heads {
  transform: rotateY(0deg);
}

.coin.land-tails {
  transform: rotateY(180deg);
}

/* Flip animation: spin whole coin to outcome */
.coin.flipping.flip-heads {
  animation: coin-to-heads 0.65s ease-out forwards;
}

.coin.flipping.flip-tails {
  animation: coin-to-tails 0.65s ease-out forwards;
}

@keyframes coin-to-heads {
  0% {
    transform: rotateY(0deg);
  }
  100% {
    transform: rotateY(360deg);
  }
}

@keyframes coin-to-tails {
  0% {
    transform: rotateY(0deg);
  }
  100% {
    transform: rotateY(180deg);
  }
}

.bet-on {
  font-size: 0.9rem;
  color: var(--muted);
  margin: 0;
}

.bet-on strong {
  color: var(--text);
}

/* Buttons */
.actions {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 2rem;
}

.btn {
  padding: 0.65rem 1.25rem;
  border-radius: 8px;
  font-family: var(--font-sans);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: background 0.2s, transform 0.1s;
}

.btn:disabled {
  cursor: not-allowed;
  opacity: 0.5;
  filter: grayscale(0.4);
  pointer-events: none;
}

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

.btn-primary:hover:not(:disabled) {
  background: #d4af37;
}

.btn-secondary {
  background: var(--surface2);
  color: var(--text);
}

.btn-secondary:hover:not(:disabled) {
  background: #2a2a32;
}

/* Log */
.log-entries {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  max-height: 240px;
  overflow-y: auto;
}

.log-entry {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  padding: 0.35rem 0.5rem;
  border-radius: 4px;
}

.log-win {
  background: rgba(74, 124, 89, 0.15);
  color: #6b9b7a;
}

.log-loss {
  background: rgba(160, 69, 69, 0.15);
  color: #c45c5c;
}

.log-empty {
  color: var(--muted);
  font-style: italic;
}

/* Bankroll graph */
.graph-container {
  width: 100%;
  overflow: hidden;
  border-radius: 8px;
  background: var(--surface2);
  padding: 10px;
}

.graph-container canvas {
  display: block;
  width: 100%;
  height: auto;
  max-height: 200px;
}

/* Estimate flips to failure */
.estimate .estimate-hint {
  font-size: 0.9rem;
  color: var(--muted);
  margin: 0 0 0.75rem;
  line-height: 1.5;
}

.estimate .btn {
  margin-bottom: 1rem;
}

.estimate-result {
  margin: 0;
}

.estimate-result .estimate-stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.75rem;
  margin-bottom: 0.5rem;
}

.estimate-stat {
  background: var(--surface2);
  border-radius: 8px;
  padding: 0.75rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  border: 1px solid transparent;
}

.estimate-stat-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}

.estimate-stat-tooltip-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.estimate-stat-tooltip-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1rem;
  height: 1rem;
  border-radius: 50%;
  background: var(--muted);
  color: var(--bg);
  font-size: 0.65rem;
  font-weight: 600;
  line-height: 1rem;
  padding: 0;
  cursor: help;
  text-transform: none;
  letter-spacing: 0;
  box-sizing: border-box;
}

.estimate-stat-tooltip-wrap:hover .estimate-stat-tooltip-icon {
  background: var(--text);
}

.estimate-stat-tooltip {
  position: absolute;
  bottom: calc(100% + 0.5rem);
  left: 50%;
  transform: translateX(-50%);
  width: 12rem;
  padding: 0.5rem 0.65rem;
  font-size: 0.75rem;
  font-weight: 400;
  line-height: 1.4;
  text-transform: none;
  letter-spacing: 0;
  color: var(--text);
  background: var(--surface2);
  border: 1px solid var(--surface);
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  white-space: normal;
  visibility: hidden;
  opacity: 0;
  transition: visibility 0.15s, opacity 0.15s;
  z-index: 10;
  pointer-events: none;
}

.estimate-stat-tooltip-wrap:hover .estimate-stat-tooltip {
  visibility: visible;
  opacity: 1;
}

.estimate-stat-value {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 1.1rem;
  color: var(--text);
}

.estimate-stat-bankrupt .estimate-stat-value {
  color: var(--loss);
}

.estimate-stat-wall-black .estimate-stat-value {
  color: var(--win);
}

.estimate-stat-wall-red .estimate-stat-value {
  color: var(--loss);
}

/* Explainer: why Martingale fails */
.explainer h2 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  margin: 0 0 0.75rem;
}

.explainer h3 {
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin: 1.25rem 0 0.5rem;
}

.explainer h3:first-of-type {
  margin-top: 0;
}

.explainer p {
  margin: 0 0 0.75rem;
  font-size: 0.9rem;
  line-height: 1.6;
  color: var(--text);
}

.explainer p:last-child {
  margin-bottom: 0;
}

.explainer .formula {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  padding: 0.5rem 0.75rem;
  background: var(--surface2);
  border-radius: 6px;
  margin: 0.5rem 0 0.75rem;
}

.footer {
  text-align: center;
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 1rem;
}

.footer p {
  margin: 0;
}
