/* ─── Reset & Base ────────────────────────────────────────────────────────── */
* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: #111827;
  color: #f3f4f6;
  font-family: system-ui, -apple-system, sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 16px;
  gap: 12px;
}

/* ─── Main layout: board + side log ─────────────────────────────────────────── */
#layout {
  width: 100%;
  max-width: 1200px;
  display: flex;
  flex-direction: row;
  align-items: stretch;
  gap: 16px;
}

nav {
  width: 100%;
  max-width: 1200px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px 20px;
  justify-content: space-between;
  align-items: center;
  font-size: 0.95rem;
}
nav a { color: #93c5fd; text-decoration: none; }
nav a:hover { text-decoration: underline; }

/* ─── Game Board ──────────────────────────────────────────────────────────── */
#game-board {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* ─── Game history (side panel) ─────────────────────────────────────────────── */
#history-panel {
  width: 280px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: #1f2937;
  border: 1px solid #374151;
  border-radius: 12px;
  overflow: hidden;
  max-height: min(85vh, 720px);
}
.history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  background: #111827;
  border-bottom: 1px solid #374151;
}
.history-header h2 {
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #9ca3af;
}
.btn-history-clear {
  padding: 4px 10px;
  font-size: 0.72rem;
  font-weight: 600;
  color: #9ca3af;
  background: transparent;
  border: 1px solid #4b5563;
  border-radius: 6px;
  cursor: pointer;
}
.btn-history-clear:hover {
  color: #f3f4f6;
  border-color: #6b7280;
}
#history-list {
  flex: 1;
  min-height: 120px;
  overflow-y: auto;
  padding: 8px 10px 12px;
  font-size: 0.78rem;
  line-height: 1.45;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.history-entry {
  padding: 6px 8px;
  border-radius: 6px;
  border-left: 3px solid transparent;
  word-break: break-word;
}
.history-entry.history-player {
  background: rgba(22, 163, 74, 0.12);
  border-left-color: #22c55e;
  color: #d1fae5;
}
.history-entry.history-cpu {
  background: rgba(59, 130, 246, 0.12);
  border-left-color: #3b82f6;
  color: #dbeafe;
}
.history-entry.history-system {
  background: rgba(107, 114, 128, 0.2);
  border-left-color: #6b7280;
  color: #d1d5db;
  font-style: italic;
  font-size: 0.74rem;
}

@media (max-width: 900px) {
  #layout {
    flex-direction: column;
    max-width: 900px;
  }
  #history-panel {
    width: 100%;
    max-height: 220px;
    order: 2;
  }
  #game-board {
    order: 1;
  }
}

/* Score bar */
#score-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 14px;
  background: #1f2937;
  border-radius: 8px;
  font-size: 0.88rem;
  color: #9ca3af;
}
#score-bar strong { color: #f9fafb; font-size: 1rem; }
#series-status { font-size: 0.78rem; color: #6b7280; }

/* CPU area */
#cpu-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 4px 0 0;
}
#cpu-hand {
  width: 100%;
  display: flex;
  justify-content: center;
  overflow-x: auto;
  padding: 4px 0 6px;
}
#cpu-info { font-size: 0.8rem; color: #6b7280; }

/* Trick area — dark felt */
#trick-area {
  background: linear-gradient(145deg, #14532d 0%, #166534 60%, #15803d 100%);
  border-radius: 14px;
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  min-height: 148px;
  box-shadow: inset 0 2px 20px rgba(0, 0, 0, 0.55), 0 1px 3px rgba(0, 0, 0, 0.4);
}
#trick-label {
  font-size: 0.8rem;
  color: #86efac;
  letter-spacing: 0.04em;
  text-align: center;
}
#current-trick {
  display: flex;
  justify-content: center;
  align-items: flex-end;
  min-height: 75px;
}

/* Turn indicator pill */
#turn-indicator {
  align-self: center;
  padding: 3px 18px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  transition: background 0.25s;
}
#turn-indicator.your-turn { background: #166534; color: #bbf7d0; }
#turn-indicator.cpu-turn  { background: #78350f; color: #fde68a; }

/* Player area */
#player-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}
#player-hand {
  width: 100%;
  display: flex;
  justify-content: center;
  overflow-x: auto;
  padding: 24px 0 4px; /* top padding = room for selected lift + hover */
}

/* Controls */
#controls {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: center;
  padding-bottom: 4px;
}

/* ─── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
  padding: 9px 20px;
  border: none;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s, background 0.15s;
  color: #fff;
  white-space: nowrap;
}
.btn:disabled { opacity: 0.35; cursor: not-allowed; }
.btn:not(:disabled):hover { opacity: 0.82; }

.btn-green  { background: #16a34a; }
.btn-gray   { background: #4b5563; }
.btn-indigo { background: #4f46e5; }
.btn-invalid { background: #dc2626 !important; }

/* ─── Card Fan Layout ─────────────────────────────────────────────────────── */
.hand-fan {
  display: flex;
  align-items: flex-end;
}
.hand-fan .card + .card { margin-left: -28px; }

.trick-cards {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 6px;
}

/* ─── Cards ───────────────────────────────────────────────────────────────── */
.card {
  position: relative;
  width: 70px;
  height: 98px;
  border-radius: 8px;
  background: #ffffff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.45);
  cursor: pointer;
  transition: transform 0.14s ease, box-shadow 0.14s ease, z-index 0s;
  flex-shrink: 0;
  user-select: none;
  color: #111827;
}

/* Hover: subtle lift for unselected cards */
.hand-fan .card:hover:not(.selected):not(.card-back) {
  transform: translateY(-8px);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.5);
  z-index: 6;
}

/* Selected: gold glow + lift */
.card.selected {
  transform: translateY(-18px);
  box-shadow: 0 0 0 2px #fbbf24, 0 10px 24px rgba(251, 191, 36, 0.35), 0 6px 16px rgba(0, 0, 0, 0.5);
  z-index: 10;
}

/* Small cards used in the trick area */
.card-small {
  width: 54px;
  height: 75px;
  cursor: default;
  border-radius: 6px;
}
.card-small:hover { transform: none !important; box-shadow: 0 2px 8px rgba(0,0,0,0.45) !important; }

/* Corner rank + suit labels */
.corner {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.1;
}
.corner .r { font-size: 0.88rem; font-weight: 800; }
.corner .s { font-size: 0.6rem;  font-weight: 700; line-height: 1; }

.tl { top: 4px; left: 5px; }
.br { bottom: 4px; right: 5px; transform: rotate(180deg); }

/* Center suit symbol */
.center-suit {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 1.55rem;
  line-height: 1;
  pointer-events: none;
}

/* Small card overrides */
.card-small .corner .r { font-size: 0.72rem; }
.card-small .corner .s { font-size: 0.5rem;  }
.card-small .center-suit { font-size: 1.2rem; }

/* Red suits */
.card.red { color: #dc2626; }

/* CPU face-down card back */
.card-back {
  background: linear-gradient(135deg, #1e3a8a 0%, #2563eb 50%, #1e3a8a 100%);
  border: 2px solid #3b82f6;
  cursor: default;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
}
.card-back::after {
  content: '';
  position: absolute;
  inset: 5px;
  border: 1px solid rgba(147, 197, 253, 0.35);
  border-radius: 4px;
}
.card-back:hover { transform: none !important; box-shadow: 0 2px 8px rgba(0,0,0,0.5) !important; }

/* ─── Overlay ─────────────────────────────────────────────────────────────── */
#overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
}
#overlay.hidden { display: none; }

#overlay-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.78);
}

#overlay-content {
  position: relative;
  background: #1f2937;
  border: 1px solid #374151;
  border-radius: 16px;
  padding: 32px 28px;
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 18px;
  box-shadow: 0 8px 48px rgba(0, 0, 0, 0.7);
}

.overlay-title {
  font-size: 2.2rem;
  font-weight: 800;
  text-align: center;
  color: #f9fafb;
  line-height: 1.1;
}
.rules-page-title { font-size: 1.6rem; }

.overlay-sub {
  text-align: center;
  color: #d1d5db;
  font-size: 0.95rem;
  line-height: 1.5;
}
.overlay-sub strong { color: #f9fafb; }

.overlay-scores {
  display: flex;
  justify-content: space-around;
  align-items: center;
  padding: 12px 16px;
  background: #111827;
  border-radius: 8px;
  font-size: 0.9rem;
  color: #9ca3af;
  flex-wrap: wrap;
  gap: 8px;
}
.overlay-scores strong { color: #f9fafb; font-size: 1.05rem; }
.series-note { font-size: 0.78rem; color: #6b7280; }

.overlay-btns {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}
.overlay-btns .btn { padding: 11px 28px; font-size: 1rem; }

/* Rules content */
.rules-text {
  color: #d1d5db;
  font-size: 0.88rem;
  line-height: 1.75;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.rules-text h3 {
  color: #e5e7eb;
  font-size: 0.9rem;
  margin-top: 2px;
}
.rules-text ul {
  padding-left: 18px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.rules-text strong { color: #f3f4f6; }
.rules-text em { color: #fca5a5; font-style: normal; font-weight: 600; }
