:root {
  --bg: #f0f4f8;
  --surface: #ffffff;
  --panel: #e2eaf4;
  --accent: #d63251;
  --accent2: #0d9488;
  --text: #1e293b;
  --muted: #64748b;
  --border: #cbd5e1;
  --success: #0d9488;
  --warn: #b45309;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Segoe UI', 'Microsoft JhengHei', sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

header {
  background: var(--surface);
  border-bottom: 2px solid var(--panel);
  padding: 16px 32px;
  display: flex;
  align-items: center;
  gap: 16px;
}
header h1 { font-size: 1.4rem; color: var(--accent2); letter-spacing: 2px; }
header .subtitle { font-size: 0.85rem; color: var(--muted); }

.main-layout {
  display: flex;
  flex: 1;
  min-height: 0;
  gap: 0;
  overflow: hidden;
}

/* ── Left Panel (Config) ────────────────────────────────── */
.config-panel {
  width: 320px;
  min-width: 280px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  overflow-y: auto;
}

.panel-title {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 2px;
  color: var(--muted);
  margin-bottom: 4px;
}

.field-group { display: flex; flex-direction: column; gap: 6px; }

label { font-size: 0.85rem; color: var(--text); }
.label-hint { display: block; font-size: 0.75rem; color: var(--muted); margin-top: 2px; }

select, input[type=number], input[type=text] {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 8px 12px;
  font-size: 0.95rem;
  width: 100%;
  outline: none;
  transition: border-color 0.2s;
}
select:focus, input:focus { border-color: var(--accent2); }

.stripe-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}
.stripe-btn {
  padding: 8px 0;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--panel);
  color: var(--muted);
  cursor: pointer;
  font-size: 0.9rem;
  text-align: center;
  transition: all 0.15s;
}
.stripe-btn:hover { border-color: var(--accent2); color: var(--text); }
.stripe-btn.selected {
  background: var(--accent2);
  color: #ffffff;
  border-color: var(--accent2);
  font-weight: bold;
}

.run-btn {
  padding: 12px;
  border-radius: 8px;
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 1rem;
  font-weight: bold;
  cursor: pointer;
  letter-spacing: 1px;
  transition: opacity 0.2s;
}
.run-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.run-btn:not(:disabled):hover { opacity: 0.85; }

.status-text {
  font-size: 0.82rem;
  color: var(--warn);
  text-align: left;
  min-height: 1.2em;
  white-space: pre-wrap;
  line-height: 1.6;
}

/* ── Right Panel (Results) ──────────────────────────────── */
.results-panel {
  flex: 1;
  padding: 24px 28px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 36px;
}

/* Progress */
.progress-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 20px;
}
.progress-row {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 0.88rem;
  color: var(--muted);
}
.progress-title { white-space: nowrap; flex-shrink: 0; }
.progress-bar-outer {
  flex: 1;
  background: var(--panel);
  border-radius: 999px;
  height: 8px;
  overflow: hidden;
}
.progress-bar-inner {
  height: 100%;
  background: linear-gradient(90deg, var(--accent2), #00b4d8);
  border-radius: 999px;
  transition: width 0.3s ease;
  width: 0%;
}
.progress-pct {
  white-space: nowrap;
  flex-shrink: 0;
  color: var(--accent2);
  font-weight: bold;
  min-width: 48px;
  text-align: right;
}
.progress-elapsed {
  white-space: nowrap;
  flex-shrink: 0;
  min-width: 80px;
  text-align: right;
}

/* Results section inner layout */
#resultsSection {
  display: flex;
  flex-direction: column;
  gap: 36px;
}

/* Stats section: 4 flex rows */
.stats-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.stat-row {
  display: flex;
  gap: 10px;
}
.stat-row .stat-card {
  flex: 1;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
}
.stat-card .label { font-size: 0.72rem; color: var(--muted); margin-bottom: 4px; text-align: center; }
.stat-card .value { font-size: 1.1rem; color: var(--accent2); font-weight: bold; text-align: center; }

/* RTP bar breakdown */
.rtp-breakdown {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px;
}
.rtp-breakdown h3 { font-size: 0.85rem; color: var(--muted); margin-bottom: 14px; text-transform: uppercase; letter-spacing: 1px; }
.rtp-row { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; font-size: 0.88rem; }
.rtp-row .rtp-label { width: 80px; color: var(--muted); }
.rtp-row .rtp-bar-outer { flex: 1; background: var(--panel); border-radius: 999px; height: 8px; }
.rtp-row .rtp-bar-inner { height: 100%; border-radius: 999px; }
.rtp-row .rtp-val { width: 70px; text-align: right; color: var(--text); }

/* RTP + Chart stacked rows */
.rtp-chart-row {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Payout chart */
.chart-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px 20px;
}
.chart-section h3 { font-size: 0.85rem; color: var(--muted); margin-bottom: 0; text-transform: uppercase; letter-spacing: 1px; }
.chart-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.chart-tabs { display: flex; gap: 4px; }
.chart-tab {
  padding: 3px 10px;
  font-size: 0.72rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.chart-tab:hover { border-color: var(--accent2); color: var(--text); }
.chart-tab.active { background: var(--accent2); border-color: var(--accent2); color: #fff; }
canvas { width: 100% !important; }

/* Detail button (above run btn) */
.detail-btn {
  margin-top: auto;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  font-size: 0.9rem;
  cursor: pointer;
  letter-spacing: 0.5px;
  transition: border-color 0.2s, opacity 0.2s;
  width: 100%;
}
.detail-btn:not(:disabled) {
  background: rgba(78, 204, 163, 0.12);
  border-color: var(--accent2);
  color: var(--accent2);
}
.detail-btn:not(:disabled):hover {
  background: rgba(78, 204, 163, 0.25);
}
.detail-btn:disabled { opacity: 0.35; cursor: not-allowed; }

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.modal-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: min(860px, 92vw);
  max-height: 82vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.modal-title {
  font-size: 0.9rem;
  color: var(--accent2);
  font-weight: bold;
  letter-spacing: 1px;
}
.modal-actions { display: flex; align-items: center; gap: 8px; }
.modal-hint { font-size: 0.78rem; background: var(--accent); color: #fff; white-space: nowrap; padding: 4px 10px; border-radius: 4px; }
.modal-btn {
  padding: 6px 14px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  font-size: 0.82rem;
  cursor: pointer;
  transition: border-color 0.15s;
}
.modal-btn:hover { border-color: var(--accent2); }
.modal-btn.close-btn:hover { border-color: var(--accent); color: var(--accent); }
.modal-text {
  font-family: 'Consolas', 'Courier New', monospace;
  font-size: 0.78rem;
  color: var(--muted);
  white-space: pre;
  overflow: auto;
  background: var(--bg);
  padding: 16px 20px;
  flex: 1;
  margin: 0;
}

/* Completion text below progress bar */
.completion-text {
  font-family: 'Consolas', 'Courier New', monospace;
  font-size: 0.78rem;
  color: var(--muted);
  padding-top: 6px;
  padding-left: 2px;
}

/* Symbol / BonusGame stats tables */
.stats-table-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px;
}
.stats-table-section h3 {
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 14px;
  text-transform: uppercase;
  letter-spacing: 1px;
}
.stats-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}
.stats-table th {
  color: var(--muted);
  text-align: left;
  padding: 6px 12px;
  border-bottom: 1px solid var(--border);
  font-weight: normal;
  letter-spacing: 0.5px;
  white-space: nowrap;
}
.stats-table td {
  padding: 5px 12px;
  color: var(--text);
  border-bottom: 1px solid var(--border);
}
.stats-table tr:last-child td { border-bottom: none; }
.stats-table tr.group-sep td { border-top: 1px solid var(--border); }
.stats-table td.no-data { text-align: center; color: var(--muted); padding: 14px; }

.hidden { display: none !important; }

/* scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 999px; }
