:root {
  --bg: #0f1620;
  --panel: #1a2533;
  --panel-light: #233044;
  --accent: #4fd1c5;
  --accent-dark: #2ca39a;
  --text: #eef3f8;
  --text-dim: #9fb0c2;
  --correct: #4ade80;
  --incorrect: #f87171;
  --highlight: #f6ad55;

  --left: #4fd1c5;
  --right: #c084fc;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
}

#app {
  max-width: 1040px;
  margin: 0 auto;
  padding: 20px;
  min-height: 100vh;
}

.hidden { display: none !important; }

.screen { display: none; }
.screen.active { display: block; }

h1 {
  text-align: center;
  font-size: 2.2rem;
  margin-bottom: 4px;
  letter-spacing: 1px;
}

.subtitle {
  text-align: center;
  color: var(--text-dim);
  margin-top: 0;
  margin-bottom: 28px;
}

/* ---------- Start screen ---------- */

.setup-group { margin-bottom: 22px; }

.setup-group h2 {
  font-size: 1.05rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 1.5px;
  margin-bottom: 10px;
  font-weight: 600;
}

.options-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}
.options-grid.three { grid-template-columns: repeat(3, 1fr); }

.option-btn {
  background: var(--panel);
  border: 2px solid transparent;
  border-radius: 10px;
  padding: 14px 16px;
  text-align: left;
  cursor: pointer;
  color: var(--text);
  display: flex;
  flex-direction: column;
  gap: 4px;
  font: inherit;
  transition: border-color 0.15s, background 0.15s, transform 0.1s;
}
.option-btn:hover { background: var(--panel-light); transform: translateY(-1px); }
.option-btn.selected { border-color: var(--accent); background: var(--panel-light); }

.opt-title { font-weight: 700; font-size: 1.05rem; }
.opt-desc { font-size: 0.82rem; color: var(--text-dim); }

.primary-btn {
  display: block;
  width: 100%;
  margin-top: 8px;
  padding: 14px;
  font-size: 1.1rem;
  font-weight: 700;
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: #06231f;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s, opacity 0.15s;
}
.primary-btn:hover:not(:disabled) { background: var(--accent-dark); }
.primary-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.primary-btn.secondary { background: var(--panel-light); color: var(--text); }
.primary-btn.secondary:hover:not(:disabled) { background: #2d3d55; }

.back-link { text-align: center; margin-top: 16px; font-size: 0.9rem; }
.back-link a { color: var(--text-dim); text-decoration: none; }
.back-link a:hover { color: var(--accent); }

.how-to {
  border: 1px solid var(--panel-light);
  border-radius: 8px;
  margin: 20px auto 0;
  background: var(--panel);
  max-width: 560px;
  width: 100%;
  text-align: left;
}
.how-to-summary {
  display: block;
  padding: 10px 14px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 1px;
  cursor: pointer;
  list-style: none;
  user-select: none;
}
.how-to-summary::-webkit-details-marker { display: none; }
.how-to-summary::before {
  content: "\25B8";
  display: inline-block;
  margin-right: 8px;
  transition: transform 0.2s;
}
details.how-to[open] > .how-to-summary::before { transform: rotate(90deg); }
.how-to-summary:hover { color: var(--text); }
.how-to-body { padding: 0 16px 12px; }
.how-to-body p {
  font-size: 0.9rem;
  color: var(--text-dim);
  line-height: 1.55;
  margin: 0 0 10px;
}
.how-to-body p:last-child { margin-bottom: 0; }
.how-to-body strong { color: var(--text); }

.text-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 0.95rem;
  text-decoration: underline;
  font-family: inherit;
}
.text-btn:hover { color: var(--text); }

/* ---------- HUD ---------- */

.game-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}
.hud-item {
  background: var(--panel);
  border: 1px solid var(--panel-light);
  border-radius: 8px;
  padding: 6px 12px;
  font-weight: 600;
}

.stat-banner { text-align: center; margin-bottom: 16px; }
.stat-kicker {
  font-size: 0.8rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 2px;
}
.stat-banner h2 { margin: 2px 0 0; font-size: 1.8rem; color: var(--highlight); }

/* ---------- Board ---------- */

.board {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  align-items: stretch;
}

.zone {
  background: var(--panel);
  border: 2px solid var(--panel-light);
  border-radius: 12px;
  padding: 10px;
  min-height: 260px;
  display: flex;
  flex-direction: column;
  transition: border-color 0.15s, background 0.15s;
}
.zone.left { border-top: 4px solid var(--left); }
.zone.right { border-top: 4px solid var(--right); }
.zone.pool { border-style: dashed; }
.zone.pool.empty { opacity: 0.55; }
.board.revealed { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.board.revealed .zone.pool { display: none; }
.zone.drop-target { border-color: var(--accent); background: var(--panel-light); }
.zone.right.drop-target { border-color: var(--right); }

.zone-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  font-size: 0.85rem;
  color: var(--text-dim);
  margin: 0 4px 8px;
}
.zone.left .zone-head > span:first-child { color: var(--left); }
.zone.right .zone-head > span:first-child { color: var(--right); }
.zone-total { color: var(--text); letter-spacing: 0; text-transform: none; font-size: 0.95rem; }
.board.revealed .zone-total { font-size: 1.1rem; color: var(--highlight); }

.zone-cards { display: flex; flex-direction: column; gap: 6px; flex: 1; }

.card {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--panel-light);
  border-radius: 8px;
  padding: 6px;
  cursor: grab;
  user-select: none;
  touch-action: none;
  border-left: 4px solid transparent;
}
.card.side-L { border-left-color: var(--left); }
.card.side-R { border-left-color: var(--right); }
.card.locked { cursor: default; }
.card.dragging { opacity: 0.3; }
.card.ghost {
  position: fixed;
  z-index: 50;
  pointer-events: none;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  cursor: grabbing;
}

.flag {
  width: 30px;
  height: 20px;
  object-fit: cover;
  border-radius: 3px;
  flex-shrink: 0;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.12);
}
.card-name {
  flex: 1;
  min-width: 0;
  font-weight: 600;
  font-size: 0.95rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.card-val { font-weight: 700; color: var(--highlight); font-size: 0.9rem; white-space: nowrap; }

.arrow {
  flex-shrink: 0;
  width: 30px;
  height: 30px;
  border: none;
  border-radius: 6px;
  background: var(--panel);
  color: var(--text-dim);
  cursor: pointer;
  font-size: 0.8rem;
}
.arrow.left:hover:not(:disabled) { background: var(--left); color: #06231f; }
.arrow.right:hover:not(:disabled) { background: var(--right); color: #1e0b33; }
.arrow:disabled { visibility: hidden; }
.card.locked .arrow { display: none; }

.controls { margin-top: 14px; }

/* ---------- Result ---------- */

.result-panel {
  margin-top: 16px;
  background: var(--panel);
  border: 1px solid var(--panel-light);
  border-radius: 12px;
  padding: 18px 20px;
  text-align: center;
  animation: pop 0.3s ease;
}
@keyframes pop { from { transform: scale(0.97); opacity: 0; } to { transform: none; opacity: 1; } }

.balance-bar {
  position: relative;
  display: flex;
  height: 18px;
  border-radius: 9px;
  overflow: hidden;
  background: var(--panel-light);
}
.bar-l { background: var(--left); transition: width 0.5s ease; }
.bar-r { background: var(--right); transition: width 0.5s ease; }
.bar-mid {
  position: absolute;
  left: 50%;
  top: -2px;
  bottom: -2px;
  width: 2px;
  margin-left: -1px;
  background: var(--bg);
}
.bar-labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  font-weight: 700;
  margin-top: 4px;
}
.bar-labels span:first-child { color: var(--left); }
.bar-labels span:last-child { color: var(--right); }

.result-line { font-size: 1.3rem; margin: 10px 0 4px; }
.pts { font-weight: 800; }
.pts.great { color: var(--correct); }
.pts.good { color: var(--highlight); }
.pts.meh { color: var(--incorrect); }
.best-line { color: var(--text-dim); margin: 0 0 14px; }

.end-btns { display: flex; gap: 12px; }
.end-btns .primary-btn { margin-top: 0; }

/* ---------- End screen ---------- */

.final-score { text-align: center; font-size: 2.6rem; font-weight: 800; color: var(--accent); margin: 10px 0 4px; }
.summary {
  background: var(--panel);
  border-radius: 12px;
  padding: 8px 14px;
  margin-bottom: 18px;
}
.sum-row {
  display: grid;
  grid-template-columns: 28px 1fr auto 44px;
  gap: 10px;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--panel-light);
}
.sum-row:last-child { border-bottom: none; }
.sum-n { color: var(--text-dim); }
.sum-gap small { color: var(--text-dim); }
.sum-pts { text-align: right; font-weight: 800; color: var(--highlight); }

@media (max-width: 720px) {
  #app { padding: 16px; }
  .options-grid, .options-grid.three { grid-template-columns: 1fr; }
  h1 { font-size: 1.6rem; }
  .stat-banner h2 { font-size: 1.4rem; }
  .board { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .zone.pool { grid-column: 1 / -1; order: -1; min-height: 0; }
  .zone.pool .zone-cards { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .zone { padding: 8px; }
  .zone.side { min-height: 180px; }
  .board.revealed .zone.side { min-height: 0; }
  .card { padding: 5px; gap: 6px; }
  .card-name { font-size: 0.85rem; }
  .flag { width: 24px; height: 16px; }
  .arrow { width: 26px; height: 26px; }
  .card-val { font-size: 0.8rem; }
  .board.revealed .card .flag { display: none; }
}
