/* 🐷 Pig Dice Game - Mobile-First PWA Stylesheet */

:root {
  --bg-primary: #090d16;
  --bg-secondary: #131b2e;
  --bg-card: #1e293b;
  --bg-card-active: #27354f;
  --border-color: #334155;
  --accent-purple: #6366f1;
  --accent-purple-glow: rgba(99, 102, 241, 0.45);
  --accent-emerald: #10b981;
  --accent-emerald-glow: rgba(16, 185, 129, 0.4);
  --accent-rose: #f43f5e;
  --accent-amber: #f59e0b;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --dice-size: 88px;
  --die-bg: #f8fafc;
  --die-border: #cbd5e1;
  --pip-color: #1e293b;
  --pip-bust-color: #ef4444;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-main);
  min-height: 100vh;
  min-height: -webkit-fill-available;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  padding-top: max(12px, env(safe-area-inset-top));
  padding-bottom: max(12px, env(safe-area-inset-bottom));
  padding-left: max(16px, env(safe-area-inset-left));
  padding-right: max(16px, env(safe-area-inset-right));
  touch-action: manipulation;
}

/* App Container */
.app-container {
  max-width: 460px;
  margin: 0 auto;
  width: 100%;
  display: flex;
  flex-direction: column;
  flex: 1;
  gap: 12px;
  position: relative;
  z-index: 2;
}

/* Confetti Canvas */
#confetti-canvas {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 100;
}

/* Top App Header */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 0 8px 0;
}

.logo-area {
  display: flex;
  align-items: center;
  gap: 8px;
}

.logo-pig {
  font-size: 1.8rem;
  line-height: 1;
}

.app-title {
  font-size: 1.25rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, #f43f5e 0%, #a855f7 50%, #6366f1 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.header-controls {
  display: flex;
  gap: 6px;
}

.icon-btn {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  font-size: 1.1rem;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s ease;
}

.icon-btn:active {
  transform: scale(0.92);
  background: var(--border-color);
}

/* Scoreboard */
.scoreboard {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.player-card {
  background: var(--bg-card);
  border: 2px solid transparent;
  border-radius: 16px;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  position: relative;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
}

.player-card.active-turn {
  background: var(--bg-card-active);
  border-color: var(--accent-purple);
  box-shadow: 0 0 18px var(--accent-purple-glow);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.player-name {
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.turn-pill {
  font-size: 0.65rem;
  font-weight: 800;
  text-transform: uppercase;
  background: var(--accent-purple);
  color: #fff;
  padding: 2px 7px;
  border-radius: 8px;
  animation: pulse 1.8s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.75; transform: scale(0.96); }
}

.card-score-row {
  display: flex;
  align-items: baseline;
  gap: 6px;
}

.score-number {
  font-size: 2.2rem;
  font-weight: 900;
  line-height: 1;
  color: #fff;
  font-variant-numeric: tabular-nums;
}

.potential-score {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--accent-emerald);
}

.progress-track {
  width: 100%;
  height: 6px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #6366f1, #10b981);
  border-radius: 999px;
  transition: width 0.4s ease-out;
}

/* Banner Alert */
.status-banner {
  min-height: 38px;
  padding: 8px 14px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-size: 0.88rem;
  font-weight: 600;
  transition: all 0.25s ease;
}

.banner-info {
  background: rgba(99, 102, 241, 0.15);
  border: 1px solid rgba(99, 102, 241, 0.3);
  color: #c7d2fe;
}

.banner-roll {
  background: rgba(59, 130, 246, 0.15);
  border: 1px solid rgba(59, 130, 246, 0.3);
  color: #93c5fd;
}

.banner-bust {
  background: rgba(244, 63, 94, 0.2);
  border: 1px solid rgba(244, 63, 94, 0.5);
  color: #fda4af;
  animation: shake 0.4s ease-in-out;
}

.banner-hold {
  background: rgba(16, 185, 129, 0.2);
  border: 1px solid rgba(16, 185, 129, 0.4);
  color: #a7f3d0;
}

.banner-win {
  background: linear-gradient(135deg, rgba(245, 158, 11, 0.3), rgba(236, 72, 153, 0.3));
  border: 1px solid #f59e0b;
  color: #fef08a;
  font-weight: 800;
  font-size: 0.95rem;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-6px); }
  40%, 80% { transform: translateX(6px); }
}

/* Play Arena */
.play-arena {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 20px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.turn-stats {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.turn-badge {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.turn-score-callout {
  font-size: 2.8rem;
  font-weight: 900;
  color: #38bdf8;
  line-height: 1;
  text-shadow: 0 0 20px rgba(56, 189, 248, 0.3);
}

.potential-callout {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 500;
}

/* 3D Dice Stage */
.dice-scene {
  width: var(--dice-size);
  height: var(--dice-size);
  perspective: 700px;
  margin: 10px 0;
}

.dice-cube {
  width: 100%;
  height: 100%;
  position: relative;
  transform-style: preserve-3d;
  transition: transform 0.6s cubic-bezier(0.2, 0.9, 0.3, 1.15);
}

.dice-cube.rolling {
  transition: transform 0.6s cubic-bezier(0.25, 1, 0.5, 1);
}

.die-face {
  position: absolute;
  width: var(--dice-size);
  height: var(--dice-size);
  background: var(--die-bg);
  border: 2px solid var(--die-border);
  border-radius: 16px;
  box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.06), 0 8px 18px rgba(0, 0, 0, 0.35);
  display: grid;
  padding: 10px;
}

/* 3D Face Offsets */
.die-face.face-1 { transform: rotateY(0deg) translateZ(calc(var(--dice-size) / 2)); }
.die-face.face-6 { transform: rotateY(180deg) translateZ(calc(var(--dice-size) / 2)); }
.die-face.face-2 { transform: rotateX(90deg) translateZ(calc(var(--dice-size) / 2)); }
.die-face.face-5 { transform: rotateX(-90deg) translateZ(calc(var(--dice-size) / 2)); }
.die-face.face-3 { transform: rotateY(90deg) translateZ(calc(var(--dice-size) / 2)); }
.die-face.face-4 { transform: rotateY(-90deg) translateZ(calc(var(--dice-size) / 2)); }

/* Pips */
.pip {
  display: block;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--pip-color);
  justify-self: center;
  align-self: center;
  box-shadow: inset 0 2px 3px rgba(0, 0, 0, 0.5);
}

/* Face 1: Large Red Pip (Pig Out alert) */
.die-face.face-1 {
  display: flex;
  align-items: center;
  justify-content: center;
}
.die-face.face-1 .pip {
  width: 22px;
  height: 22px;
  background: var(--pip-bust-color);
  box-shadow: 0 0 8px rgba(239, 68, 68, 0.6);
}

/* Face 2 */
.die-face.face-2 {
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
}
.die-face.face-2 .pip:nth-child(1) { grid-column: 2; grid-row: 1; }
.die-face.face-2 .pip:nth-child(2) { grid-column: 1; grid-row: 2; }

/* Face 3 */
.die-face.face-3 {
  grid-template-columns: 1fr 1fr 1fr;
  grid-template-rows: 1fr 1fr 1fr;
}
.die-face.face-3 .pip:nth-child(1) { grid-column: 3; grid-row: 1; }
.die-face.face-3 .pip:nth-child(2) { grid-column: 2; grid-row: 2; }
.die-face.face-3 .pip:nth-child(3) { grid-column: 1; grid-row: 3; }

/* Face 4 */
.die-face.face-4 {
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
}

/* Face 5 */
.die-face.face-5 {
  grid-template-columns: 1fr 1fr 1fr;
  grid-template-rows: 1fr 1fr 1fr;
}
.die-face.face-5 .pip:nth-child(1) { grid-column: 1; grid-row: 1; }
.die-face.face-5 .pip:nth-child(2) { grid-column: 3; grid-row: 1; }
.die-face.face-5 .pip:nth-child(3) { grid-column: 2; grid-row: 2; }
.die-face.face-5 .pip:nth-child(4) { grid-column: 1; grid-row: 3; }
.die-face.face-5 .pip:nth-child(5) { grid-column: 3; grid-row: 3; }

/* Face 6 */
.die-face.face-6 {
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr 1fr;
}

/* Action Buttons (Thumb reachable) */
.action-buttons {
  display: grid;
  grid-template-columns: 1.35fr 1fr;
  gap: 12px;
  width: 100%;
}

.btn-game {
  border: none;
  border-radius: 16px;
  padding: 16px 12px;
  font-size: 1.15rem;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  transition: transform 0.1s ease, filter 0.2s ease, opacity 0.2s ease;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.35);
}

.btn-game:active:not(:disabled) {
  transform: scale(0.96);
}

.btn-game:disabled {
  opacity: 0.38;
  cursor: not-allowed;
  filter: grayscale(0.5);
  box-shadow: none;
}

.btn-roll {
  background: linear-gradient(135deg, #6366f1 0%, #4f46e5 100%);
  color: #fff;
}

.btn-hold {
  background: linear-gradient(135deg, #10b981 0%, #059669 100%);
  color: #fff;
}

/* Log Drawer */
.log-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  padding: 10px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: auto;
}

.log-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.toggle-log-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
  padding: 4px 6px;
}

.log-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 110px;
  overflow-y: auto;
  font-size: 0.78rem;
  color: var(--text-muted);
  -webkit-overflow-scrolling: touch;
}

.log-container.collapsed .log-list {
  display: none;
}

.log-list li {
  padding: 3px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.log-list li.log-bust {
  color: var(--accent-rose);
  font-weight: 600;
}
.log-list li.log-win {
  color: #fde047;
  font-weight: 700;
}
.log-list li.log-hold {
  color: var(--accent-emerald);
}

/* Modals */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
  transition: opacity 0.2s ease;
}

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

.modal-dialog {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 20px;
  max-width: 400px;
  width: 100%;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.6);
  max-height: 85vh;
  overflow-y: auto;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-header h3 {
  font-size: 1.2rem;
  font-weight: 800;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
}

.select-input {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: #fff;
  padding: 12px;
  border-radius: 12px;
  font-size: 0.95rem;
  font-weight: 600;
  outline: none;
}

.btn-primary {
  background: var(--accent-purple);
  color: #fff;
  border: none;
  padding: 14px;
  border-radius: 14px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: opacity 0.15s ease;
}

.btn-secondary {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  padding: 14px;
  border-radius: 14px;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s ease;
}

.btn-secondary:hover {
  background: var(--border-color);
  color: #fff;
}

/* Stats Modal */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.stat-box {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 14px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.stat-val {
  font-size: 1.6rem;
  font-weight: 900;
  color: #38bdf8;
  line-height: 1.1;
}

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

.rules-body {
  font-size: 0.88rem;
  line-height: 1.5;
  color: #cbd5e1;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.rules-body ul {
  padding-left: 20px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.hidden {
  display: none !important;
}

