/* ============================================
   TopLanet v3.0 - Stylesheet
   ============================================ */

/* === CSS Variables === */
:root {
  --primary: #1a73e8;
  --primary-dark: #1557b0;
  --secondary: #34a853;
  --danger: #ea4335;
  --warning: #fbbc04;
  --bg-dark: #1a1a2e;
  --bg-card: #16213e;
  --bg-light: #0f3460;
  --text-light: #ffffff;
  --text-muted: #a0a0a0;
  --card-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  --radius: 12px;
  --radius-lg: 24px;
}

/* === Reset & Base === */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Poppins', -apple-system, BlinkMacSystemFont, sans-serif;
  background: linear-gradient(135deg, var(--bg-dark), var(--bg-card), var(--bg-light));
  background-attachment: fixed;
  color: var(--text-light);
  min-height: 100vh;
  overflow-x: hidden;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.hidden {
  display: none !important;
}

/* === Animations === */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes slideIn {
  from { transform: translateX(-100%); }
  to { transform: translateX(0); }
}

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

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-8px); }
  75% { transform: translateX(8px); }
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

@keyframes glow {
  0%, 100% { box-shadow: 0 0 10px var(--primary); }
  50% { box-shadow: 0 0 25px var(--primary), 0 0 40px var(--primary); }
}

/* === Buttons === */
button {
  padding: 12px 24px;
  border: none;
  border-radius: var(--radius);
  font-weight: 600;
  font-size: 1rem;
  font-family: inherit;
  cursor: pointer;
  transition: var(--transition);
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: white;
  box-shadow: 0 4px 15px rgba(26, 115, 232, 0.4);
}

.btn-primary:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(26, 115, 232, 0.6);
}

.btn-secondary {
  background: var(--bg-light);
  color: var(--text-light);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--bg-card);
}

.btn-danger {
  background: linear-gradient(135deg, var(--danger), #c5221f);
  color: white;
}

.btn-danger:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(234, 67, 53, 0.4);
}

.btn-small {
  padding: 8px 16px;
  font-size: 0.9rem;
}

.btn-team {
  width: 100%;
  margin-top: 10px;
  background: var(--secondary);
  color: white;
}

.btn-send, .btn-voice {
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 1.1rem;
}

.btn-send {
  background: var(--primary);
  color: white;
}

.btn-voice {
  background: var(--secondary);
  color: white;
}

.btn-voice.recording {
  background: var(--danger);
  animation: pulse 1s infinite;
}

.btn-link {
  background: transparent;
  color: var(--text-muted);
  padding: 8px;
  text-decoration: underline;
}

.btn-link:hover {
  color: var(--text-light);
}

/* === Right Side Buttons Container === */
.right-buttons {
  position: fixed;
  top: 20px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 100;
}

.control-btn {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  background: var(--bg-card);
  font-size: 1.5rem;
  box-shadow: var(--card-shadow);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: var(--transition);
}

.control-btn:hover {
  transform: scale(1.1);
}

.settings-btn:hover {
  transform: scale(1.1) rotate(90deg);
}

.history-btn.active {
  background: var(--primary);
}

/* === Connection Status === */
.connection-status {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--danger);
  color: white;
  padding: 12px 24px;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  gap: 12px;
  z-index: 1000;
  box-shadow: var(--card-shadow);
  animation: fadeIn 0.3s;
}

.connection-spinner {
  width: 20px;
  height: 20px;
  border: 3px solid rgba(255, 255, 255, 0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

/* === Overlays & Boxes === */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.9);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 500;
  animation: fadeIn 0.3s;
  padding: 20px;
}

.box {
  background: var(--bg-card);
  padding: 40px;
  border-radius: var(--radius-lg);
  box-shadow: var(--card-shadow);
  animation: fadeIn 0.5s;
  max-width: 95vw;
  max-height: 90vh;
  overflow-y: auto;
}

/* === Login Screen === */
.login-overlay {
  background: radial-gradient(ellipse at center, #1a2a3a 0%, #0d1520 100%);
  overflow: hidden;
}

.login-cards-decoration {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}

.floating-card {
  position: absolute;
  width: 60px;
  height: 85px;
  background: white;
  border-radius: 8px;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 1.4rem;
  font-weight: 700;
  color: #333;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
  animation: floatCard 8s ease-in-out infinite;
  opacity: 0.6;
}

.floating-card:nth-child(odd) {
  color: var(--danger);
}

.card-1 { top: 10%; left: 5%; animation-delay: 0s; }
.card-2 { top: 20%; right: 8%; animation-delay: -1s; }
.card-3 { top: 60%; left: 3%; animation-delay: -2s; }
.card-4 { top: 70%; right: 5%; animation-delay: -3s; }
.card-5 { top: 40%; left: 8%; animation-delay: -4s; }
.card-6 { top: 85%; right: 15%; animation-delay: -5s; }

@keyframes floatCard {
  0%, 100% { transform: translateY(0) rotate(-5deg); }
  50% { transform: translateY(-20px) rotate(5deg); }
}

.login-box {
  text-align: center;
  min-width: min(400px, 90vw);
  position: relative;
  z-index: 10;
  background: rgba(22, 33, 62, 0.95);
  backdrop-filter: blur(10px);
}

.logo {
  margin-bottom: 24px;
}

.logo-cards {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-bottom: 12px;
}

.logo-card {
  width: 40px;
  height: 55px;
  background: white;
  border-radius: 6px;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 1.8rem;
  color: #333;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
  animation: cardPop 0.5s ease-out backwards;
}

.logo-card:nth-child(1) { animation-delay: 0.1s; }
.logo-card:nth-child(2) { animation-delay: 0.2s; }
.logo-card:nth-child(3) { animation-delay: 0.3s; }
.logo-card:nth-child(4) { animation-delay: 0.4s; }

.logo-card.red {
  color: var(--danger);
}

@keyframes cardPop {
  from { transform: scale(0) rotate(-20deg); opacity: 0; }
  to { transform: scale(1) rotate(0); opacity: 1; }
}

.logo h1 {
  font-size: clamp(2.5rem, 10vw, 4rem);
  font-weight: 700;
  background: linear-gradient(135deg, #ffd700, #ffaa00, #ff8c00);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  text-shadow: 0 0 30px rgba(255, 215, 0, 0.3);
  letter-spacing: 2px;
}

.btn-play {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  font-size: 1.2rem;
  padding: 16px 40px;
  background: linear-gradient(135deg, #ffd700, #ff8c00);
  color: #1a1a2e;
  font-weight: 700;
}

.btn-play:hover {
  transform: translateY(-3px) scale(1.02);
  box-shadow: 0 8px 25px rgba(255, 215, 0, 0.4);
}

.btn-icon {
  font-size: 1.4rem;
}

/* === Inputs === */
input[type="text"] {
  width: 100%;
  padding: 16px;
  margin: 12px 0;
  background: var(--bg-light);
  border: 2px solid transparent;
  border-radius: var(--radius);
  color: white;
  font-size: 1rem;
  font-family: inherit;
  transition: var(--transition);
}

input[type="text"]:focus {
  outline: none;
  border-color: var(--primary);
  background: var(--bg-dark);
}

input[type="text"]::placeholder {
  color: var(--text-muted);
}

/* === Menu === */
.menu-box {
  min-width: min(700px, 95vw);
}

.player-info {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px;
  background: var(--bg-light);
  border-radius: var(--radius);
  margin-bottom: 24px;
  flex-wrap: wrap;
  gap: 12px;
}

.menu-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.menu-card {
  background: var(--bg-light);
  padding: 24px;
  border-radius: var(--radius);
  text-align: center;
  border: 2px solid transparent;
  transition: var(--transition);
}

.menu-card:hover {
  border-color: var(--primary);
  transform: translateY(-4px);
  box-shadow: 0 10px 30px rgba(26, 115, 232, 0.3);
}

.card-icon {
  font-size: 2.5rem;
  display: block;
  margin-bottom: 12px;
}

.menu-card h3 {
  font-size: 1.1rem;
  margin-bottom: 4px;
}

.menu-card p {
  color: var(--text-muted);
  font-size: 0.85rem;
}

/* === Menu Tabs === */
.menu-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 20px;
  background: var(--bg-light);
  border-radius: var(--radius);
  padding: 4px;
}

.menu-tab {
  flex: 1;
  padding: 12px 20px;
  background: transparent;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 1rem;
  border-radius: 8px;
  transition: var(--transition);
}

.menu-tab:hover {
  color: var(--text-light);
}

.menu-tab.active {
  background: var(--primary);
  color: white;
  box-shadow: 0 2px 8px rgba(26, 115, 232, 0.4);
}

.tab-content {
  animation: fadeIn 0.3s;
}

.btn-new-mp-game {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-bottom: 20px;
  padding: 14px 24px;
  font-size: 1.05rem;
}

/* === Single Player Section === */
.sp-section {
  margin-bottom: 20px;
}

.sp-section h3 {
  margin-bottom: 12px;
  font-size: 0.95rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.sp-difficulty-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.sp-mode-select {
  display: flex;
  gap: 12px;
}

.sp-rounds-select {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 12px;
  padding: 12px;
  background: var(--bg-light);
  border-radius: 8px;
}

.rounds-buttons {
  display: flex;
  gap: 8px;
}

.rounds-btn {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  background: var(--bg-dark);
  color: var(--text-light);
  font-weight: 700;
  font-size: 1.1rem;
  border: 2px solid transparent;
  transition: var(--transition);
}

.rounds-btn:hover {
  border-color: var(--primary);
}

.rounds-btn.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

.btn-start-sp {
  width: 100%;
  padding: 16px;
  font-size: 1.1rem;
}

/* === Game Mode Info Display === */
.game-mode-info {
  text-align: center;
  padding: 6px 12px;
  background: var(--bg-light);
  border-radius: 6px;
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.game-mode-info strong {
  color: var(--primary);
}

/* === Room List === */
.room-list-section h3 {
  margin-bottom: 12px;
}

.scroll-list {
  list-style: none;
  max-height: 250px;
  overflow-y: auto;
  background: var(--bg-light);
  border-radius: var(--radius);
  padding: 8px;
}

.scroll-list li {
  padding: 12px 16px;
  margin-bottom: 8px;
  background: var(--bg-card);
  border-radius: 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  transition: var(--transition);
}

.scroll-list li:last-child {
  margin-bottom: 0;
}

.scroll-list li:hover {
  background: var(--bg-dark);
}

.empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: 24px;
}

/* === Online Players === */
.online-players-section {
  margin-top: 24px;
}

.online-players-section h3 {
  margin-bottom: 8px;
}

.online-players-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.online-player-chip {
  display: inline-block;
  background: var(--bg-light);
  color: var(--text-secondary);
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 0.8rem;
  font-weight: 500;
}

.online-player-chip.is-me {
  background: var(--secondary);
  color: #fff;
  font-weight: 600;
}

/* === Logout Button === */
.btn-logout {
  background: var(--danger);
  color: white;
}

.btn-logout:hover {
  background: #c5221f;
}

/* === Mode Switch === */
.mode-switch {
  display: flex;
  gap: 16px;
  margin: 20px 0;
}

.radio-card {
  flex: 1;
  cursor: pointer;
}

.radio-card input[type="radio"] {
  display: none;
}

.radio-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 20px;
  background: var(--bg-light);
  border: 2px solid transparent;
  border-radius: var(--radius);
  transition: var(--transition);
}

.radio-card input:checked + .radio-content {
  border-color: var(--primary);
  background: var(--bg-dark);
}

.radio-icon {
  font-size: 2rem;
  margin-bottom: 8px;
}

.button-group {
  display: flex;
  gap: 12px;
  margin-top: 20px;
}

.button-group button {
  flex: 1;
}

/* === Waiting Room === */
.room-box {
  min-width: min(600px, 95vw);
}

.room-code {
  text-align: center;
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.status-text {
  text-align: center;
  padding: 12px;
  background: var(--bg-light);
  border-radius: 8px;
  margin-bottom: 20px;
}

.teams-container {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
  margin: 20px 0;
}

.team-box {
  background: var(--bg-light);
  padding: 20px;
  border-radius: var(--radius);
  border: 2px solid transparent;
  transition: var(--transition);
}

.team-box:hover {
  border-color: var(--primary);
}

.team-box h3 {
  text-align: center;
  margin-bottom: 12px;
}

.team-list {
  list-style: none;
  min-height: 60px;
}

.team-list li {
  padding: 10px;
  margin-bottom: 6px;
  background: var(--bg-dark);
  border-radius: 6px;
  animation: slideIn 0.3s;
}

.empty-slot {
  opacity: 0.5;
  text-align: center;
}

/* === Chat === */
.room-chat, .game-chat {
  margin: 16px 0;
  background: var(--bg-light);
  padding: 16px;
  border-radius: var(--radius);
}

.room-chat h4, .game-chat h4 {
  margin-bottom: 10px;
  font-size: 0.95rem;
}

.chat-messages {
  height: 120px;
  overflow-y: auto;
  background: var(--bg-dark);
  border-radius: 8px;
  padding: 8px;
  margin-bottom: 8px;
}

/* Expanded chat when history is removed */
.game-chat.expanded .chat-messages {
  height: 200px;
}

.chat-message {
  padding: 4px 8px;
  margin-bottom: 4px;
  background: var(--bg-card);
  border-radius: 4px;
  animation: fadeIn 0.2s;
  word-break: break-word;
  font-size: 0.8rem;
  line-height: 1.3;
}

.chat-message.system {
  background: transparent;
  color: var(--text-muted);
  font-style: italic;
  font-size: 0.75rem;
  padding: 2px 8px;
}

.chat-message .sender {
  font-weight: 600;
  color: var(--primary);
  margin-right: 4px;
  font-size: 0.75rem;
}

.voice-player {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
}

.voice-player audio {
  flex: 1;
  height: 32px;
}

.chat-input-group {
  display: flex;
  gap: 6px;
}

.chat-input-group input {
  flex: 1;
  margin: 0;
  padding: 10px 12px;
  font-size: 0.9rem;
  min-width: 0; /* Allow shrinking */
}

.room-actions {
  display: flex;
  gap: 12px;
  margin-top: 20px;
}

.room-actions button {
  flex: 1;
}

/* === Game Layout === */
.main-layout {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

.sidebar {
  width: 280px;
  background: var(--bg-card);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  border-right: 2px solid var(--bg-dark);
  overflow-y: auto;
  flex-shrink: 0;
}

/* === Timer === */
.timer-box {
  background: linear-gradient(135deg, var(--danger), #c5221f);
  padding: 20px;
  border-radius: var(--radius);
  text-align: center;
}

.timer-label {
  font-size: 0.85rem;
  opacity: 0.9;
}

.timer-value {
  font-size: 2.5rem;
  font-weight: 700;
  margin: 8px 0;
}

.timer-bar {
  height: 6px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 3px;
  overflow: hidden;
}

.timer-progress {
  height: 100%;
  background: white;
  transition: width 1s linear;
}

.timer-progress.reduced {
  background: var(--warning);
}

/* === Score === */
.score-section h3, .log-section h3 {
  font-size: 0.95rem;
  margin-bottom: 10px;
}

.score-container {
  background: white;
  color: #333;
  border-radius: var(--radius);
  padding: 8px;
  overflow: hidden;
}

#score-table {
  width: 100%;
  border-collapse: collapse;
}

#score-table th {
  background: var(--bg-light);
  color: white;
  padding: 8px;
  font-weight: 600;
  font-size: 0.85rem;
}

#score-table td {
  padding: 8px;
  text-align: center;
  border-bottom: 1px solid #eee;
}

#score-table tfoot td {
  background: var(--warning);
  font-weight: 700;
  font-size: 1.1rem;
}

.team-mine {
  background: var(--secondary) !important;
}

.score-details {
  background: var(--bg-light);
  padding: 12px;
  border-radius: var(--radius);
  margin-top: 12px;
}

.score-details h4 {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.detail-grid {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.detail-item {
  display: flex;
  justify-content: space-between;
  padding: 6px 8px;
  background: var(--bg-dark);
  border-radius: 4px;
  font-size: 0.85rem;
}

.detail-label {
  color: var(--text-muted);
}

.projected-score {
  display: flex;
  justify-content: space-between;
  padding: 10px 8px;
  margin-top: 8px;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  border-radius: 6px;
  font-weight: 600;
}

.projected-score .detail-label {
  color: rgba(255, 255, 255, 0.8);
}

.projected-score .projected {
  color: white;
  font-size: 1.1rem;
}

/* === Log === */
#game-log {
  list-style: none;
  flex: 1;
  overflow-y: auto;
  background: var(--bg-light);
  border-radius: var(--radius);
  padding: 8px;
  max-height: 150px;
}

#game-log li {
  padding: 6px 8px;
  margin-bottom: 4px;
  background: var(--bg-dark);
  border-radius: 4px;
  border-left: 3px solid var(--primary);
  font-size: 0.8rem;
  animation: slideIn 0.2s;
}

.game-chat {
  margin: 0;
}

.game-chat .chat-messages {
  height: 80px;
}

.btn-leave {
  margin-top: auto;
}

/* === Game Board === */
.game-board {
  flex: 1;
  display: grid;
  grid-template-columns: 100px 1fr 100px;
  grid-template-rows: 120px 1fr 140px;
  gap: 10px;
  padding: 16px;
  background: var(--bg-dark);
  min-width: 0;
}

.player-area {
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  border-radius: var(--radius);
  transition: var(--transition);
  background: rgba(255, 255, 255, 0.02);
}

.player-area.active-turn {
  background: rgba(52, 168, 83, 0.15);
  box-shadow: 0 0 20px rgba(52, 168, 83, 0.4);
  animation: pulse 2s infinite;
}

.name-tag {
  background: var(--bg-card);
  padding: 6px 14px;
  border-radius: 6px;
  font-weight: 600;
  font-size: 0.9rem;
  position: absolute;
  z-index: 10;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  white-space: nowrap;
}

.my-name {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
}

.active-turn .name-tag {
  background: var(--secondary);
}

/* Player Positions */
.top {
  grid-column: 2;
  grid-row: 1;
  flex-direction: column;
}

.top .name-tag {
  top: 8px;
}

.bottom {
  grid-column: 2;
  grid-row: 3;
  flex-direction: column-reverse;
}

.bottom-info {
  position: absolute;
  bottom: 8px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 12px;
  align-items: center;
  z-index: 10;
}

.action-hint {
  font-size: 0.85rem;
  color: var(--text-muted);
  background: var(--bg-card);
  padding: 6px 12px;
  border-radius: 6px;
  white-space: nowrap;
}

.action-hint.my-turn {
  color: var(--secondary);
  animation: glow 2s infinite;
}

.left {
  grid-column: 1;
  grid-row: 2;
}

.left .name-tag {
  left: 8px;
  writing-mode: vertical-rl;
  transform: rotate(180deg);
}

.right {
  grid-column: 3;
  grid-row: 2;
}

.right .name-tag {
  right: 8px;
  writing-mode: vertical-rl;
}

/* Center Table */
.center-table {
  grid-column: 2;
  grid-row: 2;
  background: linear-gradient(135deg, rgba(26, 115, 232, 0.1), rgba(52, 168, 83, 0.1));
  border-radius: var(--radius-lg);
  display: flex;
  justify-content: center;
  align-items: center;
  border: 3px solid rgba(255, 255, 255, 0.1);
  position: relative;
  min-height: 200px;
}

.table-cards {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  padding: 16px;
}

.table-hint {
  position: absolute;
  font-size: 1.5rem;
  color: var(--secondary);
  animation: pulse 2s infinite;
}

/* Card Rows/Columns */
.cards-row {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: center;
}

.cards-column {
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: center;
}

.left .cards-column .card {
  transform: rotate(90deg);
  margin: 12px 0;
}

.right .cards-column .card {
  transform: rotate(-90deg);
  margin: 12px 0;
}

/* === Cards === */
.card {
  width: 60px;
  height: 85px;
  background: white;
  border-radius: 8px;
  display: flex;
  justify-content: center;
  align-items: center;
  font-weight: 700;
  font-size: 1.1rem;
  color: black;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.3);
  transition: var(--transition);
  cursor: pointer;
  flex-shrink: 0;
}

.card:hover {
  transform: translateY(-8px) scale(1.05);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.4);
}

.card.red {
  color: var(--danger);
}

.card.selected {
  border: 3px solid var(--warning);
  transform: translateY(-12px) scale(1.08);
  box-shadow: 0 0 20px var(--warning);
}

.card-back {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: white;
  font-size: 1.5rem;
}

.my-hand .card {
  cursor: pointer;
}

.my-hand .card:hover {
  transform: translateY(-15px) scale(1.1);
}

.empty-hand {
  color: var(--text-muted);
  padding: 20px;
}

.more-cards {
  color: var(--text-muted);
  font-size: 0.8rem;
}

/* === Modals === */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.95);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
  animation: fadeIn 0.3s;
  padding: 20px;
}

.modal-content {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  max-width: 500px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--card-shadow);
}

.modal-large {
  max-width: 700px;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 24px;
  border-bottom: 2px solid var(--bg-light);
}

.modal-header h2 {
  font-size: 1.3rem;
}

.modal-close {
  background: var(--bg-light);
  color: white;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  font-size: 1.3rem;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-close:hover {
  background: var(--danger);
  transform: rotate(90deg);
}

.modal-body {
  padding: 24px;
}

/* Stats Modal */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--bg-light);
  padding: 24px 16px;
  border-radius: var(--radius);
  text-align: center;
}

.stat-value {
  font-size: 2rem;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 4px;
}

.stat-label {
  color: var(--text-muted);
  font-size: 0.85rem;
}

/* Tutorial Modal */
.tutorial-steps {
  min-height: 250px;
}

.tutorial-step {
  animation: fadeIn 0.3s;
}

.tutorial-step h3 {
  color: var(--primary);
  margin-bottom: 16px;
}

.tutorial-step ul {
  padding-left: 20px;
}

.tutorial-step li {
  margin-bottom: 8px;
}

.tutorial-example {
  background: var(--bg-light);
  padding: 16px;
  border-radius: var(--radius);
  margin: 16px 0;
}

.example-cards {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 12px 0;
}

.card-preview {
  display: inline-block;
  background: white;
  color: black;
  padding: 4px 8px;
  border-radius: 4px;
  font-family: monospace;
}

.tip {
  color: var(--warning);
  font-style: italic;
  margin-top: 12px;
}

.points-table {
  width: 100%;
  border-collapse: collapse;
}

.points-table td {
  padding: 10px;
  border-bottom: 1px solid var(--bg-light);
}

.points-table td:last-child {
  text-align: right;
  color: var(--secondary);
  font-weight: 600;
}

.tutorial-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 24px;
  padding-top: 16px;
  border-top: 2px solid var(--bg-light);
}

#tutorial-progress {
  color: var(--text-muted);
}

/* Game End Modal */
.game-end-message {
  font-size: 1.2rem;
  text-align: center;
  margin-bottom: 20px;
}

.game-end-scores {
  text-align: center;
  margin-bottom: 24px;
}

/* Stats Preview */
/* === Login Language Selector === */
.login-language-selector {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin-top: 16px;
}

.login-lang-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  background: rgba(255, 255, 255, 0.08);
  border: 2px solid transparent;
  border-radius: 8px;
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
}

.login-lang-btn:hover {
  border-color: var(--primary);
  color: var(--text-light);
}

.login-lang-btn.active {
  border-color: var(--secondary);
  background: rgba(52, 168, 83, 0.2);
  color: var(--text-light);
}

.login-lang-btn .flag {
  font-size: 1.1rem;
}

.stats-preview {
  margin-top: 16px;
}

.stats-mini {
  padding: 12px;
  background: rgba(26, 115, 232, 0.1);
  border-radius: 8px;
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* === History Panel (Floating) === */
.history-panel {
  position: fixed;
  top: 200px;
  right: 20px;
  width: 300px;
  max-height: 400px;
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--card-shadow);
  z-index: 90;
  animation: fadeIn 0.2s;
  display: flex;
  flex-direction: column;
}

.history-panel.hidden {
  display: none;
}

.history-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 2px solid var(--bg-light);
}

.history-header h3 {
  font-size: 0.95rem;
  margin: 0;
}

.history-header .btn-close {
  background: var(--bg-light);
  color: white;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  font-size: 1rem;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

#game-log-panel {
  list-style: none;
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  margin: 0;
}

#game-log-panel li {
  padding: 8px 10px;
  margin-bottom: 6px;
  background: var(--bg-light);
  border-radius: 6px;
  border-left: 3px solid var(--primary);
  font-size: 0.8rem;
  animation: slideIn 0.2s;
}

/* === Last Moves Display === */
.last-moves-display {
  position: absolute;
  bottom: 10px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  max-width: 90%;
}

.last-move-item {
  background: rgba(0, 0, 0, 0.7);
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 0.8rem;
  white-space: nowrap;
  animation: fadeIn 0.3s;
}

.move-player {
  font-weight: 600;
  color: var(--primary);
}

.move-card {
  font-weight: 700;
  background: white;
  color: black;
  padding: 2px 6px;
  border-radius: 4px;
  margin: 0 4px;
}

.move-card.red {
  color: var(--danger);
}

.move-action {
  color: var(--text-muted);
}

/* === Password Modal === */
.modal-small {
  max-width: 350px;
}

#password-input {
  margin: 12px 0;
}

/* === Lock Icon === */
.lock-icon {
  margin-right: 6px;
}

/* === Reduced Time Warning === */
.timer-value.reduced-time {
  color: var(--warning);
  animation: pulse 1s infinite;
}

/* === Penalty Notification === */
.penalty-notification {
  position: fixed;
  top: 80px;
  left: 50%;
  transform: translateX(-50%);
  background: linear-gradient(135deg, var(--danger), #c5221f);
  color: white;
  padding: 16px 24px;
  border-radius: var(--radius);
  box-shadow: 0 8px 32px rgba(234, 67, 53, 0.5);
  z-index: 1001;
  animation: slideDown 0.3s ease-out;
  display: flex;
  align-items: center;
  gap: 12px;
  font-weight: 600;
}

.penalty-notification.fade-out {
  animation: fadeOut 0.5s ease-out forwards;
}

@keyframes slideDown {
  from { transform: translateX(-50%) translateY(-100%); opacity: 0; }
  to { transform: translateX(-50%) translateY(0); opacity: 1; }
}

@keyframes fadeOut {
  from { opacity: 1; }
  to { opacity: 0; transform: translateX(-50%) translateY(-20px); }
}

.penalty-icon {
  font-size: 1.5rem;
}

.penalty-text strong {
  color: var(--warning);
}

/* === Timer Penalty Display === */
.timer-box.penalty-active {
  background: linear-gradient(135deg, #ff6b35, var(--danger));
  animation: pulse 1.5s infinite;
}

.timer-box.penalty-active .timer-label {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.penalty-badge {
  background: rgba(0, 0, 0, 0.3);
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 700;
}

/* === Action Hint Penalty === */
.action-hint.penalty {
  background: var(--danger);
  color: white;
  animation: pulse 1s infinite;
}

/* === Settings Modal === */
.settings-section {
  margin-bottom: 24px;
}

.settings-section h4 {
  margin-bottom: 12px;
  color: var(--text-muted);
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 1px;
}

/* Language Options in Settings */
.language-options {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.language-option {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  background: var(--bg-light);
  border: 2px solid transparent;
  border-radius: var(--radius);
  cursor: pointer;
  transition: var(--transition);
  font-size: 0.95rem;
}

.language-option:hover {
  border-color: var(--primary);
  transform: translateY(-2px);
}

.language-option.active {
  border-color: var(--secondary);
  background: rgba(52, 168, 83, 0.2);
}

.language-option .flag {
  font-size: 1.3rem;
}

/* Tutorial Button in Settings */
.tutorial-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 14px 20px;
  font-size: 1rem;
}

.tutorial-btn span:first-child {
  font-size: 1.3rem;
}

.theme-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
  gap: 12px;
}

.theme-option {
  background: var(--bg-light);
  border: 2px solid transparent;
  border-radius: var(--radius);
  padding: 8px;
  cursor: pointer;
  transition: var(--transition);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.theme-option:hover {
  border-color: var(--primary);
  transform: translateY(-2px);
}

.theme-option.active {
  border-color: var(--secondary);
  background: rgba(52, 168, 83, 0.2);
}

.theme-preview {
  width: 60px;
  height: 40px;
  border-radius: 6px;
  background-size: cover;
  background-position: center;
}

.theme-preview.classic {
  background: linear-gradient(135deg, rgba(26, 115, 232, 0.3), rgba(52, 168, 83, 0.3));
}

.theme-preview.green {
  background: linear-gradient(135deg, #0d5c2e, #1a8b47);
}

.theme-preview.blue {
  background: linear-gradient(135deg, #0a2463, #1e5f9e);
}

.theme-preview.red {
  background: linear-gradient(135deg, #5c0d0d, #8b1a1a);
}

.theme-preview.purple {
  background: linear-gradient(135deg, #2d0a4e, #5c1a8b);
}

.theme-preview.struga {
  background: url('../images/Struga.png');
  background-size: cover;
  background-position: center;
}

.theme-preview.zhepin {
  background: url('../images/Zhepin.png');
  background-size: cover;
  background-position: center;
}

.theme-option span {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* Music Controls */
.music-controls {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.toggle-switch {
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
}

.toggle-switch input {
  display: none;
}

.toggle-slider {
  width: 50px;
  height: 26px;
  background: var(--bg-light);
  border-radius: 13px;
  position: relative;
  transition: var(--transition);
}

.toggle-slider::after {
  content: '';
  position: absolute;
  width: 20px;
  height: 20px;
  background: white;
  border-radius: 50%;
  top: 3px;
  left: 3px;
  transition: var(--transition);
}

.toggle-switch input:checked + .toggle-slider {
  background: var(--secondary);
}

.toggle-switch input:checked + .toggle-slider::after {
  left: 27px;
}

.toggle-label {
  font-size: 0.9rem;
}

.volume-control {
  display: flex;
  align-items: center;
  gap: 12px;
}

.volume-control input[type="range"] {
  flex: 1;
  height: 6px;
  -webkit-appearance: none;
  background: var(--bg-light);
  border-radius: 3px;
  outline: none;
}

.volume-control input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  background: var(--primary);
  border-radius: 50%;
  cursor: pointer;
}

/* === Table Themes === */
.center-table.theme-classic {
  background: linear-gradient(135deg, rgba(26, 115, 232, 0.1), rgba(52, 168, 83, 0.1));
}

.center-table.theme-green {
  background: linear-gradient(135deg, #0d5c2e, #1a8b47);
  border-color: #2a9d5a;
}

.center-table.theme-blue {
  background: linear-gradient(135deg, #0a2463, #1e5f9e);
  border-color: #3a7fc5;
}

.center-table.theme-red {
  background: linear-gradient(135deg, #5c0d0d, #8b1a1a);
  border-color: #b33030;
}

.center-table.theme-purple {
  background: linear-gradient(135deg, #2d0a4e, #5c1a8b);
  border-color: #8a3cc5;
}

.center-table.theme-struga {
  background: url('../images/Struga.png');
  background-size: cover;
  background-position: center;
  border-color: rgba(255, 255, 255, 0.3);
  image-rendering: -webkit-optimize-contrast;
}

.center-table.theme-zhepin {
  background: url('../images/Zhepin.png');
  background-size: cover;
  background-position: center;
  border-color: rgba(255, 255, 255, 0.3);
  image-rendering: -webkit-optimize-contrast;
}

/* Mobile: Use smaller background for performance */
@media (max-width: 768px) {
  .center-table.theme-struga,
  .center-table.theme-zhepin {
    background-size: cover;
    background-attachment: scroll; /* Disable fixed for mobile performance */
  }
}

/* Overlay for image themes to ensure card visibility */
.center-table.theme-struga::before,
.center-table.theme-zhepin::before {
  content: '';
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.3);
  border-radius: inherit;
  pointer-events: none;
}

/* === Password Input Style === */
input[type="password"] {
  width: 100%;
  padding: 16px;
  margin: 12px 0;
  background: var(--bg-light);
  border: 2px solid transparent;
  border-radius: var(--radius);
  color: white;
  font-size: 1rem;
  font-family: inherit;
  transition: var(--transition);
}

input[type="password"]:focus {
  outline: none;
  border-color: var(--primary);
  background: var(--bg-dark);
}

input[type="password"]::placeholder {
  color: var(--text-muted);
}

/* === Responsive === */
@media (max-width: 1024px) {
  .menu-box, .room-box {
    min-width: 0;
    width: 100%;
  }

  .sidebar {
    width: 240px;
  }

  .game-board {
    grid-template-columns: 80px 1fr 80px;
  }
}

@media (max-width: 768px) {
  .score-section, .log-section {
    display: none;
  }

  .teams-container {
    grid-template-columns: 1fr;
  }

  .mode-switch {
    flex-direction: column;
  }

  .button-group {
    flex-direction: column;
  }

  .floating-card {
    width: 45px;
    height: 65px;
    font-size: 1rem;
  }

  .logo-card {
    width: 30px;
    height: 42px;
    font-size: 1.3rem;
  }

  .history-panel {
    top: 60px;
    right: 10px;
    width: 250px;
    max-height: 300px;
  }
}

@media (max-width: 480px) {
  .box {
    padding: 24px 16px;
  }

  .logo h1 {
    font-size: 2rem;
  }

  .menu-grid {
    grid-template-columns: 1fr;
  }

  .modal-content {
    margin: 10px;
  }
}

/* === Scrollbar === */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: var(--bg-dark);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb {
  background: var(--primary);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--primary-dark);
}

/* === Focus States (Accessibility) === */
button:focus-visible,
input:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

/* === Print === */
@media print {
  .sidebar, .modal {
    display: none;
  }
}

/* === Timer Overlay (mobile - on table) === */
.timer-overlay {
  display: none;
}

@media (max-width: 768px) {
  .timer-overlay {
    display: block;
    position: absolute;
    top: 6px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(234, 67, 53, 0.9);
    color: white;
    padding: 2px 14px;
    border-radius: 12px;
    font-size: 0.85rem;
    font-weight: 700;
    z-index: 20;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
  }
}


/* ============================================
   MOBILE OPTIMIZATION v2
   ============================================ */

/* === Mobile Score Bar (compact score visible on game screen) === */
.mobile-score-bar {
  display: none;
}

@media (max-width: 768px) {
  .mobile-score-bar {
    display: flex;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 40px;
    background: var(--bg-card);
    border-bottom: 1px solid var(--bg-light);
    z-index: 90;
    align-items: center;
    justify-content: center;
    gap: 16px;
    padding: 0 40px;
    font-size: 0.8rem;
    font-weight: 600;
  }

  .mobile-score-bar .score-team {
    display: flex;
    align-items: center;
    gap: 6px;
  }

  .mobile-score-bar .score-value {
    background: var(--bg-light);
    padding: 2px 10px;
    border-radius: 4px;
    font-size: 0.9rem;
    min-width: 30px;
    text-align: center;
  }

  .mobile-score-bar .score-team.mine .score-value {
    background: var(--secondary);
  }

  .mobile-score-bar .score-vs {
    color: var(--text-muted);
    font-size: 0.7rem;
  }

  .mobile-score-bar .mobile-timer {
    display: none;
  }
}

/* === Touch-Optimized Base === */
@media (pointer: coarse) {
  button, .card, .menu-card, .theme-option, .language-option {
    min-height: 44px;
    min-width: 44px;
  }

  .card {
    transition: transform 0.15s ease, box-shadow 0.15s ease;
  }

  .card:active {
    transform: scale(0.95) !important;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3) !important;
  }

  .card.selected:active {
    transform: scale(0.98) translateY(-4px) !important;
  }

  .card:hover {
    transform: none;
  }

  .my-hand .card:hover {
    transform: none;
  }

  .my-hand .card:active {
    transform: translateY(-6px) scale(0.95) !important;
  }
}

/* === Mobile Portrait Layout === */
@media (max-width: 600px) {
  /* Full-screen game layout */
  .main-layout {
    height: 100vh;
    height: 100dvh;
  }

  /* ---- 1v1 Portrait: Single column (left/right hidden by JS) ---- */
  .game-board:not(.mode-2v2) {
    grid-template-columns: 1fr;
    grid-template-rows: 50px 1fr 95px;
    padding: 44px 4px 4px 4px;
    gap: 3px;
    height: 100vh;
    height: 100dvh;
  }

  .game-board:not(.mode-2v2) .player-area.left,
  .game-board:not(.mode-2v2) .player-area.right {
    display: none;
  }

  .game-board:not(.mode-2v2) .player-area.top {
    grid-column: 1;
    grid-row: 1;
  }

  .game-board:not(.mode-2v2) .center-table {
    grid-column: 1;
    grid-row: 2;
  }

  .game-board:not(.mode-2v2) .player-area.bottom {
    grid-column: 1;
    grid-row: 3;
  }

  /* ---- 2v2 Portrait: Browser-like layout with left/right/top ---- */
  .game-board.mode-2v2 {
    grid-template-columns: 40px 1fr 40px;
    grid-template-rows: 50px 1fr 95px;
    padding: 44px 2px 4px 2px;
    gap: 2px;
    height: 100vh;
    height: 100dvh;
  }

  .game-board.mode-2v2 .player-area.top {
    grid-column: 1 / -1;
    grid-row: 1;
  }

  .game-board.mode-2v2 .player-area.left {
    grid-column: 1;
    grid-row: 2;
    display: flex !important;
    visibility: visible !important;
    flex-direction: column;
    align-items: center;
    padding: 2px;
  }

  .game-board.mode-2v2 .player-area.left .name-tag {
    font-size: 0.5rem;
    padding: 2px 3px;
    writing-mode: vertical-rl;
    transform: rotate(180deg);
    left: 1px;
  }

  .game-board.mode-2v2 .player-area.left .cards-column {
    gap: 0;
  }

  .game-board.mode-2v2 .player-area.left .cards-column .card {
    width: 20px;
    height: 28px;
    font-size: 0.45rem;
    border-radius: 3px;
    transform: rotate(90deg);
    margin: 5px 0;
  }

  .game-board.mode-2v2 .center-table {
    grid-column: 2;
    grid-row: 2;
  }

  .game-board.mode-2v2 .player-area.right {
    grid-column: 3;
    grid-row: 2;
    display: flex !important;
    visibility: visible !important;
    flex-direction: column;
    align-items: center;
    padding: 2px;
  }

  .game-board.mode-2v2 .player-area.right .name-tag {
    font-size: 0.5rem;
    padding: 2px 3px;
    writing-mode: vertical-rl;
    right: 1px;
  }

  .game-board.mode-2v2 .player-area.right .cards-column {
    gap: 0;
  }

  .game-board.mode-2v2 .player-area.right .cards-column .card {
    width: 20px;
    height: 28px;
    font-size: 0.45rem;
    border-radius: 3px;
    transform: rotate(-90deg);
    margin: 5px 0;
  }

  .game-board.mode-2v2 .player-area.bottom {
    grid-column: 1 / -1;
    grid-row: 3;
  }

  /* ---- Common portrait mobile styles ---- */

  /* Top opponent bar */
  .player-area.top {
    flex-direction: row;
    justify-content: center;
    align-items: center;
    gap: 4px;
    padding: 2px 6px;
    background: rgba(255, 255, 255, 0.04);
    border-radius: 8px;
    min-height: 0;
  }

  .player-area.top .name-tag {
    position: static;
    font-size: 0.7rem;
    padding: 2px 8px;
  }

  .player-area.top .cards-row {
    gap: 2px;
  }

  .player-area.top .cards-row .card {
    width: 24px;
    height: 34px;
    font-size: 0.55rem;
    border-radius: 3px;
  }

  /* Center table */
  .center-table {
    min-height: 0;
    border-radius: 12px;
    border-width: 2px;
  }

  .table-cards {
    gap: 5px;
    padding: 8px;
    align-content: center;
  }

  .table-cards .card {
    width: 46px;
    height: 66px;
    font-size: 0.95rem;
    border-radius: 6px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
  }

  .table-cards .card.selected {
    transform: translateY(-5px) scale(1.05);
    border-width: 2px;
  }

  .table-hint {
    font-size: 1rem;
  }

  /* Last moves compact */
  .last-moves-display {
    bottom: 2px;
    font-size: 0.6rem;
    max-width: 95%;
  }

  .last-move-item {
    padding: 2px 5px;
    background: rgba(0, 0, 0, 0.6);
    border-radius: 3px;
  }

  /* Bottom player (me) */
  .player-area.bottom {
    flex-direction: column-reverse;
    padding: 0 0 12px 0;
    min-height: 0;
  }

  .bottom-info {
    position: static;
    transform: none;
    flex-direction: row;
    gap: 6px;
    margin-bottom: 2px;
    width: 100%;
    justify-content: center;
  }

  .bottom-info .name-tag {
    position: static;
    font-size: 0.7rem;
    padding: 2px 8px;
  }

  .action-hint {
    font-size: 0.65rem;
    padding: 2px 6px;
  }

  /* My hand - horizontal scroll */
  .my-hand.cards-row {
    overflow-x: auto;
    flex-wrap: nowrap;
    padding: 6px 6px;
    gap: 8px;
    justify-content: center;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  .my-hand.cards-row::-webkit-scrollbar {
    display: none;
  }

  .my-hand .card {
    width: 50px;
    height: 72px;
    font-size: 1rem;
    flex-shrink: 0;
    border-radius: 6px;
    box-shadow: 0 3px 12px rgba(0, 0, 0, 0.4);
  }

  /* General opponent card sizing */
  .card {
    width: 24px;
    height: 34px;
    font-size: 0.55rem;
    border-radius: 3px;
  }

  .name-tag {
    font-size: 0.7rem;
    padding: 2px 6px;
  }
}

/* === Mobile Sidebar as Slide-Out Menu === */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    left: -100%;
    top: 0;
    width: 280px;
    height: 100vh;
    height: 100dvh;
    max-height: none;
    z-index: 200;
    transition: left 0.3s ease;
    flex-direction: column;
    overflow-y: auto;
    border-right: 2px solid var(--bg-light);
    border-bottom: none;
  }

  .sidebar.open {
    left: 0;
  }

  .sidebar.open .score-section,
  .sidebar.open .log-section {
    display: block;
  }

  .main-layout {
    flex-direction: row;
  }

  .game-board {
    width: 100%;
  }

  .sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: 199;
  }

  .sidebar-overlay.active {
    display: block;
  }
}

/* === Menu Button for Mobile === */
.menu-btn {
  display: none;
  position: fixed;
  top: 10px;
  left: 10px;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  font-size: 1.3rem;
  z-index: 150;
  box-shadow: 0 4px 20px rgba(26, 115, 232, 0.5);
  align-items: center;
  justify-content: center;
  padding: 0;
  border: none;
}

.surrender-btn {
  background: var(--danger) !important;
}

@media (max-width: 768px) {
  .menu-btn {
    display: flex;
    top: 4px;
    left: 4px;
    width: 34px;
    height: 34px;
    font-size: 1rem;
  }
}

.menu-btn:active {
  transform: scale(0.95);
}

/* === Mobile Menu Items === */
@media (max-width: 600px) {
  .menu-box {
    padding: 20px 16px;
  }

  .menu-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }

  .menu-card {
    padding: 14px 10px;
  }

  .card-icon {
    font-size: 1.8rem;
    margin-bottom: 6px;
  }

  .menu-card h3 {
    font-size: 0.85rem;
  }

  .menu-card p {
    font-size: 0.7rem;
  }

  .scroll-list {
    max-height: 150px;
  }

  .scroll-list li {
    padding: 10px 12px;
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }

  .scroll-list li button {
    width: 100%;
  }

  .player-info {
    flex-direction: column;
    text-align: center;
    gap: 10px;
  }

  .player-info button {
    width: 100%;
  }
}

/* === Mobile Login === */
@media (max-width: 480px) {
  .login-box {
    padding: 24px 18px;
    min-width: 0;
    width: calc(100% - 24px);
  }

  .logo-cards {
    gap: 6px;
  }

  .logo-card {
    width: 34px;
    height: 48px;
    font-size: 1.4rem;
  }

  .logo h1 {
    font-size: 2rem;
    letter-spacing: 1px;
  }

  .btn-play {
    width: 100%;
    padding: 14px 24px;
    font-size: 1.1rem;
  }

  input[type="text"],
  input[type="password"] {
    padding: 14px;
    font-size: 16px;
  }

  .floating-card {
    width: 36px;
    height: 52px;
    font-size: 0.85rem;
    opacity: 0.3;
  }

  .login-language-selector {
    gap: 8px;
  }

  .login-lang-btn {
    padding: 6px 12px;
    font-size: 0.8rem;
  }
}

/* === Mobile Chat === */
@media (max-width: 600px) {
  .room-chat, .game-chat {
    padding: 12px;
  }

  .chat-messages {
    height: 100px;
  }

  .game-chat.expanded .chat-messages {
    height: 120px;
  }

  .chat-input-group input {
    padding: 12px;
    font-size: 16px;
  }

  .btn-send, .btn-voice {
    width: 44px;
    height: 44px;
    padding: 0;
    font-size: 1.2rem;
  }
}

/* === Mobile Waiting Room === */
@media (max-width: 600px) {
  .room-box {
    padding: 20px 16px;
  }

  .teams-container {
    gap: 12px;
  }

  .team-box {
    padding: 16px;
  }

  .team-box h3 {
    font-size: 1rem;
  }

  .btn-team {
    padding: 10px;
    font-size: 0.9rem;
  }

  .room-actions {
    flex-direction: column;
    gap: 10px;
  }

  .room-actions button {
    width: 100%;
  }
}

/* === Mobile Settings Modal === */
@media (max-width: 600px) {
  .modal-content {
    margin: 8px;
    max-height: calc(100vh - 16px);
  }

  .modal-header {
    padding: 14px;
  }

  .modal-body {
    padding: 14px;
  }

  .theme-grid {
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
  }

  .theme-option {
    padding: 6px;
  }

  .theme-preview {
    width: 45px;
    height: 32px;
  }

  .theme-option span {
    font-size: 0.65rem;
  }

  .language-options {
    flex-direction: column;
  }

  .language-option {
    width: 100%;
    justify-content: center;
  }

  .music-controls {
    gap: 12px;
  }

  .tutorial-btn {
    padding: 12px 16px;
  }
}

/* === Mobile More Button (combined controls) === */
.mobile-more-btn {
  display: none;
}

@media (max-width: 600px) {
  .mobile-more-btn {
    display: flex;
    position: fixed;
    top: 4px;
    right: 4px;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: var(--bg-card);
    color: white;
    font-size: 1.3rem;
    font-weight: 700;
    z-index: 101;
    align-items: center;
    justify-content: center;
    padding: 0;
    border: none;
    box-shadow: var(--card-shadow);
  }

  /* Hide individual buttons by default on mobile */
  .right-buttons {
    display: none !important;
    flex-direction: column;
    position: fixed;
    top: 42px;
    right: 4px;
    gap: 6px;
    z-index: 100;
    background: var(--bg-card);
    padding: 8px;
    border-radius: var(--radius);
    box-shadow: var(--card-shadow);
  }

  /* Show when toggled open */
  .right-buttons.mobile-open {
    display: flex !important;
  }

  .control-btn {
    width: 40px;
    height: 40px;
    font-size: 1.2rem;
  }
}

/* === Mobile History Panel === */
@media (max-width: 600px) {
  .history-panel {
    top: auto;
    bottom: 100px;
    right: 8px;
    left: 8px;
    width: auto;
    max-height: 200px;
  }

  #game-log-panel li {
    padding: 5px 8px;
    font-size: 0.7rem;
  }
}

/* === Prevent Zoom on Input Focus (iOS) === */
@media (max-width: 600px) {
  input[type="text"],
  input[type="password"],
  select,
  textarea {
    font-size: 16px;
  }
}

/* === Safe Area Insets (Notch/Home Indicator) === */
@supports (padding: max(0px)) {
  .main-layout {
    padding-left: max(0px, env(safe-area-inset-left));
    padding-right: max(0px, env(safe-area-inset-right));
  }

  .sidebar {
    padding-bottom: max(16px, env(safe-area-inset-bottom));
  }

  .menu-btn {
    top: max(4px, calc(env(safe-area-inset-top) + 4px));
    left: max(4px, calc(env(safe-area-inset-left) + 4px));
  }

  .mobile-more-btn {
    top: max(4px, calc(env(safe-area-inset-top) + 4px));
    right: max(4px, calc(env(safe-area-inset-right) + 4px));
  }

  .player-area.bottom {
    padding-bottom: max(16px, env(safe-area-inset-bottom));
  }

  @media (max-width: 600px) {
    .mobile-score-bar {
      padding-top: env(safe-area-inset-top);
      height: calc(40px + env(safe-area-inset-top));
    }

    .game-board {
      padding-top: calc(44px + env(safe-area-inset-top));
    }
  }
}


/* === Disable Text Selection on Cards === */
.card {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

/* === Ripple Effect for Touch Feedback === */
.touch-ripple {
  position: relative;
  overflow: hidden;
}

.touch-ripple::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 0;
  height: 0;
  background: rgba(255, 255, 255, 0.3);
  border-radius: 50%;
  transform: translate(-50%, -50%);
  transition: width 0.3s ease, height 0.3s ease, opacity 0.3s ease;
  opacity: 0;
}

.touch-ripple:active::after {
  width: 200%;
  height: 200%;
  opacity: 1;
}

/* === Card Capture Animation === */
@keyframes cardCapture {
  0% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.8; transform: scale(1.15); box-shadow: 0 0 20px gold; }
  100% { opacity: 0; transform: scale(0.3) translateY(-50px); }
}

.card-captured {
  animation: cardCapture 0.8s ease-out forwards;
  pointer-events: none;
}

@keyframes cardPlayed {
  0% { opacity: 0; transform: scale(0.5) translateY(30px); }
  100% { opacity: 1; transform: scale(1) translateY(0); }
}

.card-played {
  animation: cardPlayed 0.3s ease-out;
}

/* === Mobile Tab Adjustments === */
@media (max-width: 600px) {
  .menu-tabs {
    margin-bottom: 14px;
  }

  .menu-tab {
    padding: 10px 12px;
    font-size: 0.9rem;
  }

  .sp-difficulty-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
  }

  .sp-mode-select {
    flex-direction: column;
    gap: 8px;
  }

  .sp-difficulty-grid .radio-content,
  .sp-mode-select .radio-content {
    padding: 12px;
  }

  .sp-difficulty-grid .radio-icon {
    font-size: 1.5rem;
    margin-bottom: 4px;
  }

  .btn-start-sp {
    padding: 14px;
    font-size: 1rem;
  }
}
