/* main.css - Modern Responsive Layout for Mobile & iPad */

:root {
  --bg-primary: #070b14;
  --bg-secondary: #0f172a;
  --panel-bg: rgba(19, 26, 43, 0.85);
  --accent-gold: #f59e0b;
  --accent-blue: #38bdf8;
  --accent-green: #10b981;
  --accent-red: #ef4444;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

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

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;
  user-select: none;
  -webkit-user-select: none;
}

/* App Header */
.app-header {
  padding: calc(var(--safe-top) + 6px) 12px 6px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(11, 15, 25, 0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  position: sticky;
  top: 0;
  z-index: 100;
}

.logo-section {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}

.app-icon {
  font-size: 1.35rem;
}

.app-title {
  font-size: 1.08rem;
  font-weight: 800;
  letter-spacing: 0.5px;
  background: linear-gradient(135deg, #fef3c7, #f59e0b);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.coin-badge {
  display: flex;
  align-items: center;
  gap: 4px;
  background: rgba(245, 158, 11, 0.18);
  border: 1px solid rgba(245, 158, 11, 0.5);
  border-radius: 20px;
  padding: 4px 8px;
  font-size: 0.8rem;
  font-weight: 800;
  color: #fef3c7;
  cursor: pointer;
  transition: transform 0.15s, background 0.15s;
}

.coin-badge:hover {
  background: rgba(245, 158, 11, 0.28);
  transform: scale(1.05);
}

.icon-btn {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--text-main);
  width: 35px;
  height: 35px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.05rem;
  cursor: pointer;
  transition: all 0.15s ease;
  flex-shrink: 0;
}

.icon-btn:hover {
  background: rgba(255, 255, 255, 0.16);
  transform: translateY(-1px);
}

.icon-btn.active {
  background: var(--accent-gold);
  color: #0f172a;
  border-color: var(--accent-gold);
}

/* Main Content Area */
.game-layout {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 4px 10px calc(var(--safe-bottom) + 8px) 10px;
  max-width: 900px;
  margin: 0 auto;
  width: 100%;
}

/* Player & Opponent Bars - Ultra-compact to give board max space */
.player-bar {
  width: 100%;
  max-width: min(98vw, 640px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 2px 8px;
  background: var(--panel-bg);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  margin: 2px 0;
  height: 38px;
  min-height: 38px;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.player-bar.active-turn {
  border-color: var(--accent-gold);
  box-shadow: 0 0 14px rgba(245, 158, 11, 0.22);
}

.player-details {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  flex: 1;
}

.player-avatar {
  font-size: 1.15rem;
  width: 26px;
  height: 26px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.08);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.player-text {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 6px;
  position: relative;
  min-width: 0;
  overflow: hidden;
}

/* In-game Emote Speech Bubble */
.emote-bubble {
  position: absolute;
  top: -30px;
  left: 20px;
  background: rgba(15, 23, 42, 0.95);
  border: 1px solid var(--accent-gold);
  border-radius: 12px;
  padding: 3px 8px;
  font-size: 0.74rem;
  font-weight: 700;
  color: #fef3c7;
  white-space: nowrap;
  box-shadow: 0 4px 12px rgba(0,0,0,0.5);
  pointer-events: none;
  opacity: 0;
  transform: translateY(6px);
  transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  z-index: 50;
}

.emote-bubble.show {
  opacity: 1;
  transform: translateY(0);
}

.emote-bubble::after {
  content: '';
  position: absolute;
  bottom: -6px;
  left: 14px;
  border-width: 6px 6px 0 6px;
  border-style: solid;
  border-color: rgba(15, 23, 42, 0.95) transparent transparent transparent;
}

.player-name {
  font-weight: 700;
  font-size: 0.84rem;
  display: flex;
  align-items: center;
  gap: 3px;
  white-space: nowrap;
}

.player-sub {
  font-size: 0.68rem;
  color: var(--text-muted);
  white-space: nowrap;
  opacity: 0.85;
}

.captured-tray {
  display: flex;
  gap: 1px;
  font-size: 0.78rem;
  color: #cbd5e1;
  margin-left: 4px;
  white-space: nowrap;
  overflow: hidden;
}

.timer-group {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.btn-time-extend {
  background: linear-gradient(135deg, rgba(245, 158, 11, 0.25), rgba(217, 119, 6, 0.35));
  border: 1px solid var(--accent-gold);
  color: #fef3c7;
  font-weight: 800;
  font-size: 0.7rem;
  padding: 3px 6px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.btn-time-extend:hover {
  background: var(--accent-gold);
  color: #0f172a;
  transform: scale(1.05);
}

.timer-box {
  background: rgba(11, 15, 25, 0.9);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  padding: 3px 8px;
  font-family: monospace;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-main);
  min-width: 52px;
  text-align: center;
}

.timer-box.low-time {
  color: var(--accent-red);
  animation: pulseLowTime 1s infinite alternate;
}

@keyframes pulseLowTime {
  from { opacity: 1; }
  to { opacity: 0.45; }
}

/* In-game Floating Controls - Compact Single-Row Toolbar */
.game-controls {
  width: 100%;
  max-width: min(98vw, 640px);
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  justify-content: center;
  margin-top: 4px;
  gap: 4px;
}

.control-btn {
  flex: 1 1 0;
  min-width: 48px;
  max-width: 110px;
  padding: 7px 3px;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 10px;
  color: var(--text-main);
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
  transition: all 0.15s;
  white-space: nowrap;
}

.control-btn:hover {
  background: rgba(255, 255, 255, 0.14);
}

.control-btn.highlight {
  background: linear-gradient(135deg, rgba(245, 158, 11, 0.3), rgba(217, 119, 6, 0.3));
  border-color: var(--accent-gold);
}

.control-btn.btn-coach-hint {
  background: linear-gradient(135deg, rgba(56, 189, 248, 0.25), rgba(14, 165, 233, 0.25));
  border-color: #38bdf8;
  color: #7dd3fc;
  font-weight: 700;
}

.control-btn.btn-undo-action {
  background: linear-gradient(135deg, rgba(245, 158, 11, 0.2), rgba(217, 119, 6, 0.2));
  border-color: #f59e0b;
  color: #fbbf24;
  font-weight: 700;
}

.control-btn.btn-emote-action {
  background: linear-gradient(135deg, rgba(168, 85, 247, 0.22), rgba(147, 51, 234, 0.22));
  border-color: #c084fc;
  color: #e9d5ff;
  font-weight: 700;
}

.control-btn.btn-time-action {
  background: linear-gradient(135deg, rgba(245, 158, 11, 0.22), rgba(217, 119, 6, 0.22));
  border-color: #f59e0b;
  color: #fde68a;
  font-weight: 700;
}

/* Battle Chess Combat Comic Action Banner */
.combat-banner {
  position: fixed;
  top: 42%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.5);
  background: linear-gradient(135deg, rgba(220, 38, 38, 0.96), rgba(185, 28, 28, 0.96));
  border: 3px solid #fef08a;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.85), 0 0 24px rgba(239, 68, 68, 0.8);
  color: #ffffff;
  padding: 14px 28px;
  border-radius: 16px;
  font-size: 1.35rem;
  font-weight: 900;
  letter-spacing: 1px;
  text-transform: uppercase;
  z-index: 9999;
  pointer-events: none;
  opacity: 0;
  transition: transform 0.22s cubic-bezier(0.175, 0.885, 0.32, 1.275), opacity 0.22s;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.6);
}

.combat-banner.show {
  transform: translate(-50%, -50%) scale(1.06);
  opacity: 1;
}

/* Status Toast */
.status-banner {
  position: fixed;
  bottom: calc(var(--safe-bottom) + 20px);
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: rgba(15, 23, 42, 0.95);
  border: 1px solid var(--accent-gold);
  border-radius: 30px;
  padding: 10px 22px;
  font-size: 0.9rem;
  font-weight: 600;
  color: #fef3c7;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.7);
  z-index: 900;
  opacity: 0;
  transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  pointer-events: none;
}

.status-banner.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

/* Landscape & Rotation Optimization for Mobile Phones & iPads (2x Board Scale) */
@media (orientation: landscape) {
  .app-header {
    padding: calc(var(--safe-top) + 2px) 12px 2px 12px;
    height: 36px;
  }
  .app-icon { font-size: 1.1rem; }
  .app-title { font-size: 0.9rem; }
  .coin-badge { padding: 2px 6px; font-size: 0.72rem; }
  .icon-btn { width: 28px; height: 28px; font-size: 0.9rem; border-radius: 7px; }

  .game-layout {
    display: grid !important;
    grid-template-columns: minmax(105px, 130px) 1fr auto !important;
    grid-template-rows: 1fr 1fr !important;
    grid-template-areas:
      "opp   board ctrl"
      "user  board ctrl" !important;
    height: calc(100vh - 38px) !important;
    max-width: 100vw !important;
    padding: 2px 8px calc(var(--safe-bottom) + 2px) 8px !important;
    gap: 4px 10px !important;
    align-items: stretch !important;
    justify-items: stretch !important;
    overflow: hidden !important;
  }

  /* Compact left column for Player and Opponent Bars */
  #opponentBar {
    grid-area: opp !important;
    align-self: end !important;
    width: 100% !important;
    max-width: 130px !important;
    height: auto !important;
    min-height: 46px !important;
    flex-direction: column !important;
    align-items: flex-start !important;
    padding: 3px 6px !important;
    margin: 0 !important;
    gap: 2px !important;
  }

  #playerBar {
    grid-area: user !important;
    align-self: start !important;
    width: 100% !important;
    max-width: 130px !important;
    height: auto !important;
    min-height: 46px !important;
    flex-direction: column !important;
    align-items: flex-start !important;
    padding: 3px 6px !important;
    margin: 0 !important;
    gap: 2px !important;
  }

  .player-bar .player-details {
    width: 100%;
    gap: 5px;
  }

  .player-bar .player-text {
    flex-direction: column;
    align-items: flex-start;
    gap: 1px;
    width: 100%;
  }

  .player-bar .player-name {
    font-size: 0.74rem;
  }

  .player-bar .player-sub {
    font-size: 0.64rem;
    display: block;
  }

  .player-bar .timer-group {
    width: 100%;
    justify-content: center;
  }

  .player-bar .timer-box {
    font-size: 0.86rem;
    padding: 2px 4px;
    width: 100%;
    text-align: center;
  }

  /* In landscape, hide redundant +5m button inside player-bar */
  .player-bar .btn-time-extend {
    display: none !important;
  }

  /* Perfectly Square Chess Board in Landscape: 1:1 Aspect Ratio with zero distortion */
  .game-layout #boardContainer,
  #boardContainer,
  .board-container {
    grid-area: board !important;
    --board-size: min(calc(100vh - 42px), calc(100vw - 230px), 640px);
    width: var(--board-size) !important;
    height: var(--board-size) !important;
    max-width: var(--board-size) !important;
    max-height: var(--board-size) !important;
    aspect-ratio: 1 / 1 !important;
    justify-self: center !important;
    align-self: center !important;
    flex-shrink: 0 !important;
    margin: auto !important;
  }

  .chess-board-2d {
    width: 100% !important;
    height: 100% !important;
    aspect-ratio: 1 / 1 !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
  }

  .board-grid-2d {
    width: 100% !important;
    height: 100% !important;
    aspect-ratio: 1 / 1 !important;
    max-width: 100% !important;
    max-height: 100% !important;
  }

  /* Right column: Action Controls */
  .game-controls {
    grid-area: ctrl;
    width: 54px;
    min-width: 50px;
    max-width: 56px;
    flex-direction: column;
    margin-top: 0;
    gap: 4px;
    flex-shrink: 0;
  }

  .control-btn {
    width: 100%;
    max-width: 100%;
    padding: 5px 2px;
    font-size: 0.66rem;
    border-radius: 8px;
    flex-direction: column;
    gap: 2px;
    text-align: center;
  }
}
