/* ==========================================================================
   HEXON Style Sheet
   Glassmorphism Sci-Fi Theme with Neon Accents
   Ultra-Compact Viewport Optimized Layout
   ========================================================================== */

:root {
  --bg-dark: #070a13;
  --bg-card: rgba(15, 23, 42, 0.75);
  --bg-card-border: rgba(99, 102, 241, 0.25);
  
  --color-primary: #6366f1;
  --color-primary-glow: rgba(99, 102, 241, 0.4);
  --color-accent: #06b6d4;
  --color-gold: #f59e0b;
  --color-purple: #a855f7;
  --color-black-token: #c084fc;
  --color-white-token: #fef08a;

  --text-main: #f8fafc;
  --text-muted: #94a3b8;

  --font-heading: 'Outfit', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'Space Grotesk', monospace;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-full: 9999px;

  --shadow-glow: 0 0 20px rgba(99, 102, 241, 0.35);
  --transition-fast: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-normal: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
  font-family: var(--font-heading);
  background-color: var(--bg-dark);
  background-image: 
    radial-gradient(circle at 15% 15%, rgba(99, 102, 241, 0.15) 0%, transparent 40%),
    radial-gradient(circle at 85% 85%, rgba(168, 85, 247, 0.15) 0%, transparent 40%),
    radial-gradient(circle at 50% 50%, rgba(6, 182, 212, 0.08) 0%, transparent 60%);
  color: var(--text-main);
  height: 100vh;
  max-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Landscape phones / very short windows: the fixed 100vh layout cannot fit
   the stacked UI, so allow vertical scrolling instead of clipping the board. */
body.scroll-fallback {
  height: auto;
  max-height: none;
  overflow-y: auto;
  overflow-x: hidden;
}

body.scroll-fallback .app-container {
  overflow: visible;
}

body.scroll-fallback .screen.active {
  height: auto;
  min-height: 0;
}

/* Header */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 16px;
  background: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--bg-card-border);
  z-index: 100;
  flex-shrink: 0;
}

.logo-container {
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.logo-text {
  font-size: 1.35rem;
  font-weight: 800;
  letter-spacing: 1.5px;
  color: var(--text-main);
}

.logo-text span {
  color: var(--color-primary);
  text-shadow: 0 0 10px var(--color-primary);
}

.tagline {
  font-size: 0.6rem;
  font-family: var(--font-mono);
  color: var(--color-accent);
  letter-spacing: 2px;
}

.header-actions {
  display: flex;
  gap: 8px;
}

/* Glass Card Component */
.glass-card {
  background: var(--bg-card);
  backdrop-filter: blur(16px);
  border: 1px solid var(--bg-card-border);
  border-radius: var(--radius-lg);
  box-shadow: 0 15px 30px rgba(0, 0, 0, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.1);
  padding: 20px;
}

/* Application Container */
.app-container {
  flex: 1;
  max-width: 840px;
  width: 100%;
  margin: 0 auto;
  padding: 10px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Screens */
.screen {
  display: none;
  width: 100%;
  height: 100%;
  flex-direction: column;
  animation: fadeIn 0.3s ease-out;
}

.screen.active {
  display: flex;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Buttons */
.btn {
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 0.85rem;
  padding: 8px 16px;
  border-radius: var(--radius-md);
  border: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: all var(--transition-fast);
  text-transform: uppercase;
  letter-spacing: 0.6px;
}

.btn-primary {
  background: linear-gradient(135deg, #6366f1 0%, #4f46e5 100%);
  color: #fff;
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.4);
}

.btn-primary:hover {
  background: linear-gradient(135deg, #818cf8 0%, #6366f1 100%);
  box-shadow: 0 6px 16px rgba(99, 102, 241, 0.6);
  transform: translateY(-1px);
}

.btn-secondary {
  background: linear-gradient(135deg, #06b6d4 0%, #0891b2 100%);
  color: #fff;
  box-shadow: 0 4px 12px rgba(6, 182, 212, 0.3);
}

.btn-secondary:hover {
  background: linear-gradient(135deg, #22d3ee 0%, #06b6d4 100%);
  transform: translateY(-1px);
}

.btn-outline {
  background: transparent;
  border: 1px solid var(--bg-card-border);
  color: var(--text-main);
}

.btn-outline:hover {
  background: rgba(99, 102, 241, 0.15);
  border-color: var(--color-primary);
}

.btn-lg {
  padding: 12px 22px;
  font-size: 0.95rem;
}

.btn-sm {
  padding: 6px 10px;
  font-size: 0.75rem;
}

.btn.block {
  width: 100%;
}

.icon-btn {
  background: rgba(30, 41, 59, 0.6);
  border: 1px solid var(--bg-card-border);
  color: var(--text-main);
  padding: 6px 10px;
  border-radius: var(--radius-md);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 600;
  font-size: 0.78rem;
  transition: all var(--transition-fast);
}

.icon-btn:hover {
  background: rgba(99, 102, 241, 0.2);
  border-color: var(--color-primary);
}

/* LOBBY SCREEN STYLES */
.main-lobby-card {
  max-width: 480px;
  margin: auto;
  width: 100%;
}

.lobby-title {
  text-align: center;
  font-size: 1.4rem;
  margin-bottom: 16px;
}

.player-name-box {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
}

/* The player name is only relevant for Online PvP and Pass & Play modes */
.player-name-box.hidden {
  display: none;
}

.player-name-box label {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1px;
}

input[type="text"] {
  background: rgba(15, 23, 42, 0.9);
  border: 1px solid var(--bg-card-border);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  color: var(--text-main);
  font-family: var(--font-heading);
  font-size: 0.95rem;
  outline: none;
  transition: border-color var(--transition-fast);
}

input[type="text"]:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 10px var(--color-primary-glow);
}

.mode-tabs {
  display: flex;
  gap: 6px;
  background: rgba(15, 23, 42, 0.8);
  padding: 4px;
  border-radius: var(--radius-md);
  margin-bottom: 16px;
}

.mode-tab {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-muted);
  padding: 8px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.mode-tab.active {
  background: var(--color-primary);
  color: #fff;
  box-shadow: 0 2px 8px var(--color-primary-glow);
}

.mode-config-panel {
  display: none;
  flex-direction: column;
  gap: 12px;
  animation: fadeIn 0.3s ease;
}

.mode-config-panel.active {
  display: flex;
}

.mode-config-panel h3 {
  font-size: 1.1rem;
}

.mode-config-panel p {
  color: var(--text-muted);
  font-size: 0.85rem;
  line-height: 1.3;
}

.difficulty-options {
  display: flex;
  gap: 8px;
  margin-top: 6px;
}

.diff-btn {
  flex: 1;
  background: rgba(30, 41, 59, 0.7);
  border: 1px solid var(--bg-card-border);
  color: var(--text-main);
  padding: 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-weight: 600;
  font-size: 0.85rem;
  transition: all var(--transition-fast);
}

.diff-btn.active {
  background: var(--color-accent);
  color: #000;
  border-color: var(--color-accent);
  font-weight: 700;
  box-shadow: 0 0 10px rgba(6, 182, 212, 0.5);
}

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

.divider-or {
  display: flex;
  align-items: center;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.7rem;
  margin: 4px 0;
}

.divider-or::before, .divider-or::after {
  content: '';
  flex: 1;
  border-bottom: 1px solid var(--bg-card-border);
}

.divider-or span {
  padding: 0 10px;
}

.join-room-box {
  display: flex;
  gap: 8px;
}

.join-room-box input {
  flex: 1;
  text-transform: uppercase;
  letter-spacing: 2px;
  text-align: center;
  font-weight: 700;
}

/* Toast Notice Component */
.toast-notice {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(15, 23, 42, 0.95);
  backdrop-filter: blur(14px);
  border: 1px solid var(--color-purple);
  box-shadow: 0 8px 30px rgba(168, 85, 247, 0.5);
  color: #fff;
  padding: 8px 18px;
  border-radius: var(--radius-full);
  font-weight: 700;
  font-size: 0.88rem;
  z-index: 500;
  display: flex;
  align-items: center;
  gap: 8px;
  animation: slideDownToast 0.35s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.toast-notice.hidden {
  display: none;
}

@keyframes slideDownToast {
  from { opacity: 0; transform: translate(-50%, -15px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

/* IN-GAME SCREEN STYLES */
.game-meta-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
  flex-shrink: 0;
}

.badge {
  background: rgba(99, 102, 241, 0.2);
  border: 1px solid var(--color-primary);
  color: var(--color-primary);
  padding: 2px 8px;
  border-radius: var(--radius-full);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.8px;
}

.room-code-tag {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--color-accent);
  margin-left: 8px;
}

.room-code-tag.hidden {
  display: none;
}

/* Scoreboard */
.scoreboard-container {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
  flex-shrink: 0;
}

.player-card {
  flex: 1;
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid var(--bg-card-border);
  border-radius: var(--radius-md);
  padding: 8px 12px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  position: relative;
  transition: all var(--transition-normal);
}

.player-card.active-turn {
  background: rgba(30, 27, 75, 0.8);
  border-color: var(--color-primary);
  box-shadow: 0 0 16px rgba(99, 102, 241, 0.35);
  transform: scale(1.01);
}

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

.player-name {
  font-size: 0.95rem;
  font-weight: 700;
}

.turn-indicator {
  display: none;
  font-size: 0.6rem;
  background: var(--color-primary);
  color: #fff;
  padding: 1px 6px;
  border-radius: var(--radius-full);
  font-weight: 700;
  letter-spacing: 0.8px;
}

.player-card.active-turn .turn-indicator {
  display: inline-block;
  animation: pulse 1.5s infinite;
}

@keyframes pulse {
  0% { opacity: 0.7; }
  50% { opacity: 1; }
  100% { opacity: 0.7; }
}

.score-box {
  display: flex;
  align-items: baseline;
  gap: 4px;
}

.score-val {
  font-size: 1.5rem;
  font-weight: 800;
  font-family: var(--font-mono);
  color: var(--color-gold);
  line-height: 1;
}

.score-target {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.pending-color-badge {
  font-size: 0.7rem;
  background: rgba(168, 85, 247, 0.25);
  border: 1px solid var(--color-purple);
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  color: #fff;
  font-weight: 700;
}

.pending-color-badge.hidden {
  display: none;
}

.vs-divider {
  font-family: var(--font-mono);
  font-weight: 800;
  color: var(--text-muted);
  font-size: 0.85rem;
}

/* Integrated Compact Turn Banner & Actions */
.turn-decision-banner {
  background: rgba(15, 23, 42, 0.85);
  backdrop-filter: blur(12px);
  border: 1px solid var(--bg-card-border);
  border-radius: var(--radius-lg);
  padding: 6px 12px;
  margin-bottom: 6px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

/* The banner holds only the centered status text since the flanking
   POSITION/COLOR buttons were removed. Without this rule the actions row
   shrink-wraps its content and the text hugs the left edge on wide screens. */
.action-buttons {
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: center;
}

.turn-banner-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  flex: 1;
}

.turn-banner-center h3 {
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--text-main);
  line-height: 1.1;
}

.turn-sub-text {
  font-size: 0.72rem;
  color: var(--text-muted);
}

.btn-action-sm {
  padding: 6px 14px;
  border-radius: var(--radius-md);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
}

.btn-action-sm.hidden {
  display: none !important;
}

.position-btn {
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.25) 0%, rgba(79, 70, 229, 0.35) 100%);
  border: 1px solid var(--color-primary);
  color: #fff;
}

.position-btn:hover {
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.45) 0%, rgba(79, 70, 229, 0.6) 100%);
  box-shadow: 0 0 12px var(--color-primary-glow);
  transform: translateY(-1px);
}

.color-btn {
  background: linear-gradient(135deg, rgba(168, 85, 247, 0.25) 0%, rgba(147, 51, 234, 0.35) 100%);
  border: 1px solid var(--color-purple);
  color: #fff;
}

.color-btn:hover {
  background: linear-gradient(135deg, rgba(168, 85, 247, 0.45) 0%, rgba(147, 51, 234, 0.6) 100%);
  box-shadow: 0 0 12px rgba(168, 85, 247, 0.4);
  transform: translateY(-1px);
}

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

/* Board Color Buttons */
.board-color-buttons {
  position: absolute;
  top: 8px;
  left: 8px;
  right: 8px;
  bottom: 8px;
  pointer-events: none;
  z-index: 120;
}

.color-token {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  pointer-events: auto;
}

.color-token-left {
  left: 8px;
  top: 8px;
}

.color-token-right {
  right: 8px;
  top: 8px;
}

.color-btn-top-left, .color-btn-top-right {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.06);
  background: rgba(15, 23, 42, 0.9);
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  box-shadow: 0 6px 18px rgba(2, 6, 23, 0.6);
  transition: transform 0.14s ease, box-shadow 0.14s ease;
}

.color-btn-top-left:hover, .color-btn-top-right:hover {
  transform: translateY(-4px) scale(1.06);
  box-shadow: 0 12px 24px rgba(2, 6, 23, 0.7);
}

.black-btn {
  background: radial-gradient(circle at 30% 30%, #38bdf8 0%, #581c87 35%, #090d16 100%);
  border-color: rgba(192,132,252,0.9);
}

.white-btn {
  background: radial-gradient(circle at 30% 30%, #ffffff 0%, #fef08a 55%, #d97706 100%);
  border-color: rgba(254,240,138,0.95);
}

.btn-icon {
  font-size: 1.2rem;
  text-shadow: 0 0 5px rgba(0, 0, 0, 0.5);
}

.color-label {
  font-size: 12px;
  color: var(--muted-text, #cbd5e1);
  background: rgba(0,0,0,0.12);
  padding: 3px 8px;
  border-radius: 10px;
  backdrop-filter: blur(4px);
}

/* Canvas Wrapper */
.canvas-wrapper {
  background: rgba(15, 23, 42, 0.8);
  border: 1px solid var(--bg-card-border);
  border-radius: var(--radius-lg);
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 4px;
  margin-bottom: 6px;
  box-shadow: inset 0 0 25px rgba(0, 0, 0, 0.5);
  position: relative;
  flex: 1;
  min-height: 240px;
  width: 100%;
  overflow: hidden;
}

#hexCanvas {
  display: block;
  max-width: 100%;
  cursor: pointer;
}

.tournament-status {
  margin: 10px 0 12px;
  padding: 11px 16px;
  border-radius: 16px;
  background: rgba(79, 70, 229, 0.12);
  border: 1px solid rgba(79, 70, 229, 0.2);
  color: #eef2ff;
  font-size: 0.95rem;
  line-height: 1.4;
}

.btn-content {
  display: flex;
  flex-direction: column;
}

.btn-content strong {
  font-size: 0.95rem;
  letter-spacing: 0.8px;
}

.btn-content span {
  font-size: 0.72rem;
  color: var(--text-muted);
  text-transform: none;
  letter-spacing: 0;
  margin-top: 1px;
}

/* Pending Notice Banner */
.pending-notice {
  background: linear-gradient(135deg, rgba(245, 158, 11, 0.25) 0%, rgba(217, 119, 6, 0.25) 100%);
  border: 1px solid var(--color-gold);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.turn-banner.hidden,
.pending-notice.hidden {
  display: none;
}

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

.notice-text {
  display: flex;
  flex-direction: column;
}

.notice-text strong {
  color: var(--color-gold);
  font-size: 0.9rem;
}

.notice-text span {
  font-size: 0.78rem;
  color: var(--text-muted);
}

/* Modals */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(7, 10, 19, 0.85);
  backdrop-filter: blur(8px);
  display: none;
  justify-content: center;
  align-items: center;
  z-index: 1000;
  padding: 16px;
}

.modal-overlay.active {
  display: flex;
  animation: fadeIn 0.3s ease;
}

.modal-card {
  max-width: 440px;
  width: 100%;
  text-align: center;
}

.modal-title {
  font-size: 1.4rem;
  margin-bottom: 6px;
}

.modal-desc {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 18px;
  line-height: 1.3;
}

.color-choices {
  display: flex;
  gap: 12px;
  margin-bottom: 18px;
}

.color-choice-btn {
  flex: 1;
  background: rgba(30, 41, 59, 0.8);
  border: 1px solid var(--bg-card-border);
  border-radius: var(--radius-md);
  padding: 16px 10px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  transition: all var(--transition-fast);
  color: var(--text-main);
}

.color-choice-btn:hover {
  transform: translateY(-2px);
  border-color: var(--color-primary);
  box-shadow: 0 0 16px var(--color-primary-glow);
}

.color-disc {
  width: 36px;
  height: 36px;
  border-radius: 50%;
}

.black-disc {
  background: radial-gradient(circle at 30% 30%, #38bdf8, #3b0764 40%, #0f172a);
  box-shadow: 0 0 10px rgba(168, 85, 247, 0.8);
}

.white-disc {
  background: radial-gradient(circle at 30% 30%, #ffffff, #fef08a 60%, #d97706);
  box-shadow: 0 0 10px rgba(251, 191, 36, 0.8);
}

/* Victory Modal */
.victory-icon {
  font-size: 3rem;
  margin-bottom: 8px;
}

.final-score-box {
  display: flex;
  justify-content: space-around;
  background: rgba(15, 23, 42, 0.8);
  padding: 12px;
  border-radius: var(--radius-md);
  margin-bottom: 18px;
}

.final-score-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.final-score-item strong {
  font-size: 1.5rem;
  font-family: var(--font-mono);
  color: var(--color-gold);
}

.modal-actions {
  display: flex;
  gap: 10px;
}

.modal-actions button {
  flex: 1;
}

/* Rules Modal (compact) */
.rules-card {
  max-width: 480px;
  text-align: left;
  padding: 14px 16px;
}

.modal-header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

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

.close-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 1.4rem;
  cursor: pointer;
  line-height: 1;
}

.close-btn:hover {
  color: #fff;
}

.rules-body {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 52vh;
  overflow-y: auto;
  margin-bottom: 10px;
  padding-right: 4px;
}

.rule-section h3 {
  color: var(--color-accent);
  font-size: 0.88rem;
  margin-bottom: 2px;
}

.rule-section p, .rule-section li {
  font-size: 0.78rem;
  color: var(--text-muted);
  line-height: 1.3;
}

.rule-section ul {
  padding-left: 16px;
  margin-top: 2px;
}

.rules-card .btn.block {
  padding: 8px 12px;
  font-size: 0.85rem;
}

/* Responsive adjustments */
@media (max-width: 640px) {
  .app-header {
    padding: 6px 12px;
  }
  .logo-text {
    font-size: 1.2rem;
  }
  .tagline {
    display: none;
  }
  .action-buttons-group {
    flex-direction: column;
    gap: 6px;
  }
  .scoreboard-container {
    gap: 6px;
  }
  .player-card {
    padding: 6px 8px;
  }
  .score-val {
    font-size: 1.3rem;
  }
}
