* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #1a1a2e;
  color: #e0e0e0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* ---- Views ---- */
.view {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 100vh;
}

.view.hidden {
  display: none;
}

/* ---- Home / Stage Select ---- */
.home {
  text-align: center;
  padding: 2rem 1rem;
  width: 100%;
  max-width: 500px;
}

.home-title {
  font-family: 'Playfair Display', Georgia, 'Times New Roman', serif;
  font-weight: 900;
  font-size: 3.5rem;
  letter-spacing: 0.15em;
  color: #d4af37;
  margin-bottom: 0.25rem;
  margin-top: 1.5rem;
  text-shadow: 0 2px 8px rgba(0,0,0,0.5);
}

.home-subtitle {
  color: #888;
  font-size: 0.95rem;
  margin-bottom: 2rem;
  letter-spacing: 0.05em;
}

/* Stage list */
.stage-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  text-align: left;
}

.stage-card {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.85rem 1rem;
  background: #16213e;
  border: 1px solid #0f3460;
  border-radius: 10px;
  transition: all 0.2s;
}

.stage-card.unlocked {
  cursor: pointer;
}

.stage-card.unlocked:hover {
  background: #1a3a5c;
  border-color: #d4af37;
}

.stage-card.locked {
  opacity: 0.45;
  cursor: default;
}

.stage-number {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: #d4af37;
  color: #1a1a2e;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.9rem;
  flex-shrink: 0;
}

.stage-number.locked-number {
  background: #444;
  color: #888;
}

.stage-info {
  flex: 1;
  min-width: 0;
}

.stage-name {
  font-weight: 600;
  font-size: 1rem;
  color: #e0e0e0;
}

.stage-desc {
  font-size: 0.8rem;
  color: #888;
  margin-top: 0.15rem;
}

.locked-desc {
  font-style: italic;
  color: #666;
}

.stage-arrow {
  font-size: 1.5rem;
  color: #d4af37;
  flex-shrink: 0;
}

.stage-lock {
  font-size: 1.1rem;
  flex-shrink: 0;
}

/* Stage progress bar */
.stage-progress {
  height: 4px;
  background: #0f3460;
  border-radius: 2px;
  margin-top: 0.4rem;
  overflow: hidden;
}

.stage-progress-bar {
  height: 100%;
  background: #d4af37;
  border-radius: 2px;
  transition: width 0.3s;
}

.stage-stats-row {
  display: flex;
  gap: 1rem;
  font-size: 0.7rem;
  color: #666;
  margin-top: 0.25rem;
}

/* Reset button */
.reset-btn {
  margin-top: 2rem;
  padding: 0.5rem 1.25rem;
  background: transparent;
  border: 1px solid #444;
  border-radius: 6px;
  color: #666;
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.2s;
}

.reset-btn:hover {
  border-color: #c62828;
  color: #c62828;
}

/* ---- Practice page header ---- */
header {
  width: 100%;
  background: #16213e;
  padding: 0.75rem 1rem;
  border-bottom: 2px solid #0f3460;
}

.header-row {
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
}

.home-link {
  font-family: 'Playfair Display', Georgia, 'Times New Roman', serif;
  font-weight: 700;
  font-size: 1.3rem;
  color: #d4af37;
  text-decoration: none;
  letter-spacing: 0.1em;
}

.back-btn {
  position: absolute;
  left: 0;
  padding: 0.35rem 0.75rem;
  background: transparent;
  border: 1px solid #d4af37;
  border-radius: 6px;
  color: #d4af37;
  font-size: 1rem;
  cursor: pointer;
  transition: all 0.2s;
}

.back-btn:hover {
  background: rgba(212, 175, 55, 0.15);
}

.chart-btn {
  position: absolute;
  right: 0;
  padding: 0.35rem 0.85rem;
  background: transparent;
  border: 1px solid #d4af37;
  border-radius: 6px;
  color: #d4af37;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.2s;
}

.chart-btn:hover {
  background: rgba(212, 175, 55, 0.15);
}

.chart-btn.hidden {
  display: none;
}

/* ---- Game area ---- */
.container {
  width: 100%;
  max-width: 700px;
  padding: 1.5rem;
  flex: 1;
}

.table {
  background: #1b5e20;
  border-radius: 16px;
  padding: 2rem 1.5rem;
  margin-bottom: 1.5rem;
  box-shadow: inset 0 2px 8px rgba(0,0,0,0.4);
}

.table.hidden {
  display: none;
}

.hand-label {
  text-align: center;
  font-size: 0.85rem;
  color: rgba(255,255,255,0.6);
  margin-bottom: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.cards-row {
  display: flex;
  justify-content: center;
  gap: 0.75rem;
}

/* Playing cards */
.card {
  width: 70px;
  height: 100px;
  background: #fff;
  border-radius: 8px;
  position: relative;
  box-shadow: 0 2px 6px rgba(0,0,0,0.3);
  font-family: 'Georgia', serif;
}

.card.red { color: #c62828; }
.card.black { color: #212121; }

.card-corner {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1;
}

.card-corner .card-value {
  font-size: 0.95rem;
  font-weight: 700;
}

.card-corner .card-suit {
  font-size: 0.7rem;
}

.top-left { top: 4px; left: 6px; }
.bottom-right { bottom: 4px; right: 6px; transform: rotate(180deg); }

.card-center {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 1.8rem;
}

/* Action buttons */
.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  justify-content: center;
  margin-bottom: 1.5rem;
}

.action-btn {
  padding: 0.75rem 1.5rem;
  border: 2px solid #444;
  border-radius: 8px;
  background: #2a2a4a;
  color: #e0e0e0;
  font-size: 1rem;
  cursor: pointer;
  transition: all 0.15s;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-width: 100px;
  justify-content: center;
}

.action-btn kbd {
  font-size: 0.7rem;
  background: rgba(255,255,255,0.1);
  padding: 2px 6px;
  border-radius: 3px;
  border: 1px solid rgba(255,255,255,0.2);
}

.action-btn:hover:not(:disabled) {
  background: #3a3a6a;
  border-color: #666;
}

.action-btn:disabled {
  cursor: default;
  opacity: 0.7;
}

.action-btn.correct {
  background: #2e7d32;
  border-color: #4caf50;
  opacity: 1;
}

.action-btn.wrong {
  background: #c62828;
  border-color: #ef5350;
  opacity: 1;
}

/* Addition mode buttons */
.action-addition {
  min-width: 70px;
  font-size: 1.1rem;
  font-weight: 700;
}

/* Feedback */
.feedback {
  text-align: center;
  font-size: 1.2rem;
  font-weight: 600;
  min-height: 2rem;
  margin-bottom: 1rem;
  transition: all 0.2s;
}

.feedback.correct { color: #4caf50; }
.feedback.wrong { color: #ef5350; }

/* Stats row (stats + inline chart btn) */
.stats-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
}

/* Inline chart button: hidden on desktop */
.chart-btn-inline {
  display: none;
}

/* Stats */
.stats {
  display: flex;
  justify-content: center;
  gap: 1.5rem;
  flex-wrap: wrap;
}

.stat { text-align: center; }

.stat-value {
  font-size: 1.3rem;
  font-weight: 700;
}

.stat-label {
  font-size: 0.75rem;
  color: #888;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.stat-value.correct-color { color: #4caf50; }
.stat-value.wrong-color { color: #ef5350; }

/* ---- Chart overlay ---- */
.chart-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.75);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.chart-overlay.hidden {
  display: none;
}

.chart-panel {
  background: #1a1a2e;
  border: 1px solid #0f3460;
  border-radius: 12px;
  padding: 1.5rem;
  max-width: 95vw;
  max-height: 90vh;
  overflow: auto;
  position: relative;
}

.chart-close {
  position: absolute;
  top: 0.5rem;
  right: 0.75rem;
  background: none;
  border: none;
  color: #888;
  font-size: 1.5rem;
  cursor: pointer;
  line-height: 1;
}

.chart-close:hover {
  color: #fff;
}

.chart-title {
  color: #d4af37;
  font-size: 1rem;
  margin-bottom: 0.5rem;
  margin-top: 1rem;
}

.chart-title:first-child {
  margin-top: 0;
}

.chart-table {
  border-collapse: collapse;
  font-size: 0.85rem;
  width: 100%;
  margin-bottom: 0.5rem;
}

.chart-table th,
.chart-table td {
  padding: 0.4rem 0.55rem;
  text-align: center;
  border: 1px solid #2a2a4a;
}

.chart-table th {
  background: #16213e;
  color: #ccc;
  font-weight: 600;
}

.chart-table td {
  font-weight: 600;
}

/* Cell colors by action */
.cell-h  { background: #2e7d32; color: #fff; }
.cell-s  { background: #c62828; color: #fff; }
.cell-d  { background: #1565c0; color: #fff; }
.cell-ds { background: #6a1b9a; color: #fff; }
.cell-p  { background: #e65100; color: #fff; }
.cell-rh { background: #4e342e; color: #fff; }
.cell-rs { background: #4e342e; color: #fff; }
.cell-rp { background: #4e342e; color: #fff; }
.cell-none { background: #2a2a3a; color: #555; }

/* Chart legend */
.chart-legend {
  margin-top: 0.5rem;
  margin-bottom: 1rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.25rem;
  font-size: 0.8rem;
  color: #aaa;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.legend-swatch {
  display: inline-block;
  width: 1.8rem;
  text-align: center;
  padding: 0.15rem 0;
  border-radius: 3px;
  font-size: 0.75rem;
  font-weight: 700;
}

/* ---- Unlock notification ---- */
.unlock-notification {
  position: fixed;
  top: 1.5rem;
  left: 50%;
  transform: translateX(-50%) translateY(-100px);
  z-index: 200;
  transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.unlock-notification.show {
  transform: translateX(-50%) translateY(0);
}

.unlock-notification.hidden {
  display: none;
}

.unlock-content {
  background: linear-gradient(135deg, #1a3a5c, #16213e);
  border: 2px solid #d4af37;
  border-radius: 12px;
  padding: 1rem 1.5rem;
  text-align: center;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
}

.unlock-icon {
  font-size: 2rem;
  margin-bottom: 0.25rem;
}

.unlock-text {
  color: #d4af37;
  font-weight: 700;
  font-size: 1.1rem;
}

.unlock-stage-name {
  color: #e0e0e0;
  font-size: 0.9rem;
  margin-top: 0.25rem;
}

/* ---- Responsive ---- */
@media (max-width: 500px) {
  .home-title {
    font-size: 2.5rem;
  }

  /* Practice view: fill viewport, no scroll */
  #practice-view {
    height: 100dvh;
    min-height: auto;
    overflow: hidden;
  }

  #practice-view header {
    padding: 0.4rem 0.75rem;
    flex-shrink: 0;
  }

  #practice-view .container {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    padding: 0.5rem 0.75rem;
    gap: 0.4rem;
  }

  .table {
    flex: 1 1 0;
    padding: 0.5rem 1rem;
    margin-bottom: 0;
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    justify-content: center;
  }

  .hand-label {
    margin-bottom: 0.3rem;
    font-size: 0.75rem;
  }

  .cards-row {
    gap: 0.5rem;
  }

  .card {
    width: 52px;
    height: 74px;
  }

  .card-center {
    font-size: 1.3rem;
  }

  .card-corner .card-value {
    font-size: 0.8rem;
  }

  .card-corner .card-suit {
    font-size: 0.6rem;
  }

  /* Action buttons: 2-row grid, 6-col base for even division */
  .actions {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 0.4rem;
    margin-bottom: 0;
    padding: 0.3rem 0;
    flex-shrink: 0;
  }

  .action-btn {
    padding: 1rem 0.5rem;
    min-width: 0;
    font-size: 1.2rem;
    gap: 0.3rem;
    grid-column: span 2; /* default: 3 per row */
  }

  /* Hit & Stand (first two): each take half the row */
  .action-btn:nth-child(1),
  .action-btn:nth-child(2) {
    grid-column: span 3;
  }

  /* 3 buttons total: row 2 has 1 button, span full width */
  .action-btn:nth-child(3):last-child {
    grid-column: span 6;
  }

  /* 4 buttons total: row 2 has 2 buttons, each span 3 (half width) */
  .action-btn:nth-child(3):nth-last-child(2),
  .action-btn:nth-child(4):last-child:nth-child(4) {
    grid-column: span 3;
  }

  /* Addition mode: 4 equal buttons */
  .action-addition {
    grid-column: span 3;
  }

  .action-btn kbd {
    display: none;
  }

  .feedback {
    font-size: 1rem;
    min-height: 1.4rem;
    margin-bottom: 0;
    padding: 0.1rem 0;
    flex-shrink: 0;
  }

  /* Stats row: compact single line with chart button */
  .stats-row {
    flex-shrink: 0;
    gap: 0.5rem;
    padding: 0.25rem 0;
  }

  .stats {
    gap: 0.5rem;
    flex-wrap: nowrap;
    flex: 1;
  }

  .stat-value {
    font-size: 0.95rem;
  }

  .stat-label {
    font-size: 0.6rem;
  }

  /* Hide header chart button, show inline one */
  .chart-btn {
    display: none !important;
  }

  .chart-btn-inline {
    display: block;
    padding: 0.3rem 0.6rem;
    background: transparent;
    border: 1px solid #d4af37;
    border-radius: 6px;
    color: #d4af37;
    font-size: 0.75rem;
    cursor: pointer;
    flex-shrink: 0;
    white-space: nowrap;
  }

  /* Chart overlay: slide up from bottom */
  .chart-overlay,
  .chart-overlay.hidden {
    display: flex;
    align-items: flex-end;
    padding: 0;
    background: transparent;
    pointer-events: none;
    transition: background 0.3s;
  }

  .chart-overlay.open {
    background: rgba(0,0,0,0.75);
    pointer-events: auto;
  }

  .chart-panel {
    width: 100%;
    max-width: 100vw;
    max-height: 85vh;
    border-radius: 0;
    border: none;
    border-top: 2px solid #0f3460;
    padding: 1rem;
    transform: translateY(100%);
    transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  }

  .chart-overlay.open .chart-panel {
    transform: translateY(0);
  }

  .chart-table {
    font-size: 0.75rem;
  }

  .chart-table th,
  .chart-table td {
    padding: 0.3rem 0.35rem;
  }
}
