/* === RESET & BASE === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; background: #1a1a2e; color: #e0e0e0; overflow-x: hidden; }

/* === VIEWS === */
.view { display: none; }
.view.active { display: flex; }

/* === BUTTONS === */
.btn { padding: 12px 24px; border: none; border-radius: 6px; cursor: pointer; font-size: 17px; font-weight: 600; transition: all 0.2s; text-decoration: none; display: inline-block; }
.btn-primary { background: #4361ee; color: #fff; }
.btn-primary:hover { background: #3a56d4; }
.btn-danger { background: #e74c3c; color: #fff; }
.btn-danger:hover { background: #c0392b; }
.btn-success { background: #27ae60; color: #fff; }
.btn-success:hover { background: #219a52; }
.btn-sm { padding: 8px 16px; font-size: 15px; }
.btn-suit { padding: 14px 24px; font-size: 28px; border-radius: 8px; background: #2d2d44; color: #fff; border: 2px solid #444; }
.btn-suit:hover { border-color: #4361ee; background: #3a3a55; }
.btn-suit.hearts, .btn-suit.diamonds { color: #e74c3c; }
.btn-suit.clubs, .btn-suit.spades { color: #ecf0f1; }

/* === LOGIN === */
#loginView { justify-content: center; align-items: center; min-height: calc(100vh - 160px); }
.login-container { background: #16213e; padding: 48px 40px; border-radius: 16px; text-align: center; box-shadow: 0 8px 32px rgba(0,0,0,0.4); max-width: 380px; width: 90%; }
.login-container h1 { font-size: 36px; margin-bottom: 4px; color: #fff; }
.subtitle { color: #888; margin-bottom: 28px; font-size: 14px; }
.login-container form { display: flex; flex-direction: column; gap: 12px; }
.login-container input { padding: 12px 16px; border-radius: 8px; border: 1px solid #333; background: #0f1a30; color: #e0e0e0; font-size: 15px; outline: none; }
.login-container input:focus { border-color: #4361ee; }
.help-link { display: block; margin-top: 20px; color: #4361ee; font-size: 13px; text-decoration: none; }
.help-link:hover { text-decoration: underline; }

/* === LOBBY === */
#lobbyView { flex-direction: column; min-height: calc(100vh - 160px); padding: 20px; }
.lobby-container { max-width: 700px; width: 100%; margin: 0 auto; }
.lobby-header { display: flex; align-items: center; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.lobby-header h2 { flex: 1; font-size: 24px; color: #fff; }
.player-badge { background: #4361ee; color: #fff; padding: 4px 14px; border-radius: 20px; font-size: 13px; font-weight: 600; }
#createTableBtn { margin-bottom: 20px; width: 100%; }
.table-list { display: flex; flex-direction: column; gap: 10px; }
.empty-msg { text-align: center; color: #666; padding: 40px 0; }

.table-card { background: #16213e; border-radius: 10px; padding: 16px 20px; display: flex; align-items: center; gap: 16px; border: 1px solid #2a2a44; }
.table-card .table-id { font-weight: 700; font-size: 14px; color: #4361ee; min-width: 80px; }
.table-card .table-players { flex: 1; font-size: 13px; color: #aaa; }
.table-card .table-players span { display: inline-block; background: #222; padding: 2px 10px; border-radius: 12px; margin: 2px 4px; font-size: 12px; }
.table-card .seat-count { font-size: 13px; color: #888; min-width: 50px; text-align: center; }

/* === GAME LAYOUT === */
#gameView { flex-direction: column; height: calc(100vh - 160px); }
.game-layout { display: flex; flex-direction: column; flex: 1; overflow: hidden; }

/* Info Bar */
.info-bar { display: flex; align-items: center; justify-content: space-between; padding: 8px 16px; background: #16213e; border-bottom: 1px solid #2a2a44; flex-wrap: wrap; gap: 8px; }
.score-display { display: flex; gap: 16px; align-items: center; font-size: 18px; }
.team-score { padding: 4px 12px; border-radius: 6px; }
.team-a { background: #1a3a5c; }
.team-b { background: #5c1a1a; }
.vs { color: #666; font-size: 12px; }
.info-bar-actions { display: flex; gap: 8px; align-items: center; }

/* Table Area */
.table-area { flex: 1; position: relative; background: #1b5e20; background: radial-gradient(ellipse at center, #2e7d32 0%, #1b5e20 60%, #14451a 100%); border-radius: 12px; margin: 8px; min-height: 300px; overflow: hidden; }

/* Trump Indicator */
.trump-indicator { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); font-size: 180px; opacity: 0.25; pointer-events: none; z-index: 0; text-shadow: 0 0 40px currentColor, 0 0 80px currentColor; animation: trumpPulse 3s ease-in-out infinite; }
.trump-indicator.hidden { display: none; }
@keyframes trumpPulse { 0%, 100% { opacity: 0.2; text-shadow: 0 0 40px currentColor, 0 0 80px currentColor; } 50% { opacity: 0.35; text-shadow: 0 0 60px currentColor, 0 0 120px currentColor; } }

/* Seats */
.seat { position: absolute; text-align: center; z-index: 2; }
.seat-label { font-size: 12px; text-transform: uppercase; color: rgba(255,255,255,0.5); letter-spacing: 1px; }
.seat-name { font-size: 17px; font-weight: 700; color: #fff; padding: 5px 14px; border-radius: 6px; background: rgba(0,0,0,0.35); min-width: 90px; display: inline-block; }
.seat-name.active-turn { box-shadow: 0 0 12px #ffd700, 0 0 4px #ffd700; border: 1px solid #ffd700; }
.seat-name.empty-seat { color: #666; font-weight: 400; cursor: pointer; }
.seat-name.empty-seat:hover { background: rgba(67,97,238,0.3); }
.seat-cards { margin-top: 4px; display: flex; gap: 2px; justify-content: center; }

.seat-top { top: 8px; left: 50%; transform: translateX(-50%); }
.seat-left { left: 8px; top: 50%; transform: translateY(-50%); }
.seat-right { right: 8px; top: 50%; transform: translateY(-50%); }
.seat-bottom { bottom: 8px; left: 50%; transform: translateX(-50%); }

/* Play Area (center trick) */
.play-area { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); display: flex; gap: 8px; z-index: 3; }

/* Flip display */
.flip-display { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; z-index: 5; background: rgba(0,0,0,0.6); padding: 20px; border-radius: 12px; max-width: 80%; }
.flip-display.hidden { display: none; }

/* Run display */
.run-display { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); z-index: 10; background: rgba(0,0,0,0.85); padding: 24px; border-radius: 12px; text-align: center; }
.run-display.hidden { display: none; }
.run-display h3 { color: #ffd700; margin-bottom: 12px; font-size: 18px; }
.run-display .run-cards { display: flex; gap: 8px; justify-content: center; }

/* === CARD STYLES === */
.card { width: 65px; height: 95px; background: #fff; border-radius: 7px; display: inline-flex; flex-direction: column; align-items: center; justify-content: center; font-weight: 700; border: 1px solid #ccc; position: relative; user-select: none; flex-shrink: 0; }
.card.red { color: #c0392b; }
.card.black { color: #2c3e50; }
.card .card-rank { font-size: 20px; line-height: 1; }
.card .card-suit { font-size: 22px; line-height: 1; }
.card.small { width: 42px; height: 62px; font-size: 14px; }
.card.small .card-rank { font-size: 14px; }
.card.small .card-suit { font-size: 16px; }
.card-back { width: 42px; height: 62px; background: linear-gradient(135deg, #4361ee 25%, #3a56d4 25%, #3a56d4 50%, #4361ee 50%, #4361ee 75%, #3a56d4 75%); background-size: 8px 8px; border-radius: 7px; border: 2px solid #fff; flex-shrink: 0; }
.card.greyed { opacity: 0.4; }

/* Player hand cards */
.player-hand { display: flex; justify-content: center; gap: 4px; padding: 8px 16px; flex-wrap: wrap; }
.player-hand .card { width: 75px; height: 110px; cursor: pointer; transition: transform 0.15s, box-shadow 0.15s; }
.player-hand .card .card-rank { font-size: 22px; }
.player-hand .card .card-suit { font-size: 27px; }
.player-hand .card:hover { transform: translateY(-8px); box-shadow: 0 6px 16px rgba(0,0,0,0.4); }
.player-hand .card.valid-play { border: 2px solid #ffd700; }
.player-hand .card.invalid-play { opacity: 0.45; cursor: not-allowed; }
.player-hand .card.dragging { opacity: 0.4; }

/* Face-down cards area */
.hand-area { text-align: center; min-height: 100px; padding-bottom: 4px; }
.face-down-cards { display: flex; justify-content: center; gap: 4px; margin-bottom: 6px; }
.face-down-cards.hidden { display: none; }
.face-down-card { width: 70px; height: 102px; background: linear-gradient(135deg, #4361ee 25%, #3a56d4 25%, #3a56d4 50%, #4361ee 50%, #4361ee 75%, #3a56d4 75%); background-size: 10px 10px; border-radius: 7px; border: 2px solid #9ab; display: inline-block; }

/* Action Area */
.action-area { display: flex; justify-content: center; gap: 10px; padding: 8px 16px; min-height: 50px; flex-wrap: wrap; align-items: center; }

/* === LEGEND PANEL === */
.legend-panel { position: fixed; right: 0; top: 50%; transform: translateY(-50%); z-index: 50; }
.legend-toggle { writing-mode: vertical-rl; background: #16213e; padding: 12px 8px; border-radius: 8px 0 0 8px; cursor: pointer; font-size: 13px; border: 1px solid #333; border-right: none; user-select: none; }
.legend-content { display: none; position: absolute; right: 36px; top: 50%; transform: translateY(-50%); background: #16213e; border: 1px solid #333; border-radius: 10px; padding: 16px; min-width: 160px; box-shadow: -4px 0 16px rgba(0,0,0,0.4); }
.legend-panel.open .legend-content { display: block; }
.legend-content h4 { color: #4361ee; font-size: 13px; margin: 10px 0 4px; }
.legend-content h4:first-child { margin-top: 0; }
.legend-content table { width: 100%; font-size: 13px; border-collapse: collapse; }
.legend-content td { padding: 2px 8px; }
.legend-content td:last-child { text-align: right; color: #ffd700; font-weight: 600; }

/* === SYSTEM MESSAGES === */
.system-messages { position: fixed; bottom: 0; left: 0; right: 0; background: #0d1117; border-top: 1px solid #2a2a44; max-height: 160px; z-index: 100; display: flex; flex-direction: column; }
.sys-msg-header { padding: 6px 16px; font-size: 11px; text-transform: uppercase; letter-spacing: 1px; color: #666; background: #0d1117; border-bottom: 1px solid #1a1a2e; cursor: pointer; user-select: none; }
.msg-log { flex: 1; overflow-y: auto; padding: 8px 16px; font-size: 15px; line-height: 1.6; }
.msg-log .msg { color: #aaa; }
.msg-log .msg::before { content: '› '; color: #4361ee; }

/* === ANIMATIONS === */
@keyframes cardDealIn { from { opacity: 0; transform: translateY(-40px) scale(0.7); } to { opacity: 1; transform: translateY(0) scale(1); } }
.card.deal-anim { animation: cardDealIn 0.35s ease-out both; }
.face-down-card.deal-anim { animation: cardDealIn 0.35s ease-out both; }
.card-back.deal-anim { animation: cardDealIn 0.35s ease-out both; }

@keyframes flipCardIn { from { opacity: 0; transform: rotateY(90deg) scale(0.8); } to { opacity: 1; transform: rotateY(0deg) scale(1); } }
.card.flip-anim { animation: flipCardIn 0.4s ease-out both; }

@keyframes cutSlice { 0% { transform: translateX(0); } 30% { transform: translateX(30px) translateY(-10px); } 60% { transform: translateX(-30px) translateY(10px); } 100% { transform: translateX(0); } }
.cut-anim { animation: cutSlice 0.8s ease-in-out; }

/* Scoring Panel */
.scoring-overlay { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); z-index: 20; background: rgba(0,0,0,0.92); border-radius: 14px; padding: 24px 32px; min-width: 500px; max-width: 90%; max-height: 80%; overflow-y: auto; border: 2px solid #ffd700; }
.scoring-overlay.hidden { display: none; }
.scoring-overlay h3 { text-align: center; color: #ffd700; font-size: 20px; margin-bottom: 16px; }
.scoring-teams { display: flex; gap: 24px; justify-content: center; }
.scoring-team { flex: 1; min-width: 200px; }
.scoring-team h4 { text-align: center; font-size: 16px; margin-bottom: 10px; padding-bottom: 6px; border-bottom: 1px solid #444; }
.scoring-team .scoring-cards { display: flex; flex-wrap: wrap; gap: 4px; justify-content: center; min-height: 100px; }
.scoring-team .scoring-total { text-align: center; font-size: 22px; font-weight: 700; color: #ffd700; margin-top: 12px; padding-top: 8px; border-top: 1px solid #444; }
.scoring-team.team-0 h4 { color: #5dade2; }
.scoring-team.team-1 h4 { color: #e74c3c; }

/* Cut visual overlay */
.cut-overlay { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); z-index: 15; display: flex; gap: 16px; }
.cut-overlay.hidden { display: none; }
.cut-half { display: flex; flex-direction: column; align-items: center; }
.deck-stack { width: 70px; height: 100px; background: linear-gradient(135deg, #4361ee 25%, #3a56d4 25%, #3a56d4 50%, #4361ee 50%, #4361ee 75%, #3a56d4 75%); background-size: 10px 10px; border-radius: 7px; border: 3px solid #fff; box-shadow: 3px 3px 8px rgba(0,0,0,0.5); }

/* === RESPONSIVE === */
@media (max-width: 600px) {
  .table-area { min-height: 250px; }
  .player-hand .card { width: 56px; height: 82px; }
  .player-hand .card .card-rank { font-size: 17px; }
  .player-hand .card .card-suit { font-size: 20px; }
  .card { width: 50px; height: 72px; }
  .card .card-rank { font-size: 16px; }
  .card .card-suit { font-size: 18px; }
  .seat-name { font-size: 14px; padding: 4px 10px; }
  .info-bar { font-size: 15px; }
  .legend-panel { display: none; }
  .scoring-overlay { min-width: unset; width: 95%; padding: 16px; }
}
