:root {
  /* Visual System Tokens (Tabletop / Ink Outline) */
  --bg-app: #cfb48e;       /* warm sand */
  --bg-app-2: #e3d1b3;     /* lighter sand */
  --bg-panel: #f3eadb;     /* cream */
  --bg-panel-2: #efe3cf;   /* alt cream */
  --ink: #1a1a1a;          /* outline/text */
  --ink-2: #2f2f2f;        /* secondary text */
  --muted: rgba(26,26,26,0.55);
  
  /* Accents (small usage) */
  --accent: #d85b2a;       /* terra */
  --accent-2: #2f7d73;     /* jade */
  --focus: #1b6edc;

  /* Shape */
  --stroke: 2px;
  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 18px;
  --radius-pill: 999px;
  
  /* Depth */
  --shadow-color: rgba(26,26,26,0.15);
  --shadow-ink: rgba(26,26,26,0.85);
  --shadow-offset: 4px;
  --shadow-card: 4px 4px 0 var(--shadow-color);
  --shadow-btn: 3px 3px 0 var(--ink);

  /* Typography */
  --font-display: "Fraunces", "Noto Serif SC", "Noto Serif JP", serif;
  --font-ui: "Nunito", "Noto Sans SC", "Noto Sans JP", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  
  /* Motion */
  --ease-out: cubic-bezier(.2,.8,.2,1);
  --dur-fast: 120ms;
}

/* Reset / Base */
body {
  background-color: var(--bg-app);
  background-image: repeating-linear-gradient(
    45deg,
    transparent,
    transparent 10px,
    rgba(0, 0, 0, 0.03) 10px,
    rgba(0, 0, 0, 0.03) 20px
  );
  color: var(--ink);
  font-family: var(--font-ui);
  margin: 0;
  padding: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Layout Skeleton */
.main-layout {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* Header */
.app-header {
  height: 64px;
  background: rgba(243, 234, 219, 0.85); /* semi-transparent cream */
  border-bottom: var(--stroke) solid var(--ink);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
  flex: 0 0 auto;
  z-index: 10;
  backdrop-filter: blur(4px);
}

.logo {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  text-decoration: none;
  color: var(--ink);
}

.logo-icon {
  border: var(--stroke) solid var(--ink);
  border-radius: 8px;
  background: #fff;
  padding: 2px;
}

.logo-text {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.4rem;
  letter-spacing: -0.02em;
}

/* Header Controls */
.header-controls {
  display: flex;
  gap: 1rem;
  align-items: center;
}

.pill-group {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.pill-label {
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--ink-2);
}

/* Buttons / Pills */
.pill-selector, .btn-action {
  background: #fff;
  border: var(--stroke) solid var(--ink);
  border-radius: var(--radius-pill);
  padding: 0.3rem 1rem;
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--ink);
  text-decoration: none;
  cursor: pointer;
  box-shadow: 2px 2px 0 var(--ink);
  transition: transform var(--dur-fast), box-shadow var(--dur-fast);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 40px;
}

.pill-selector:hover, .btn-action:hover {
  transform: translate(-1px, -1px);
  box-shadow: 3px 3px 0 var(--ink);
  background: #fffdf5;
}

.pill-selector:active, .btn-action:active,
.pill-selector.dropdown-toggle.show {
  transform: translate(1px, 1px);
  box-shadow: 1px 1px 0 var(--ink);
}

.btn-action--primary {
  background: var(--ink);
  color: #fff;
  border-color: var(--ink);
}
.btn-action--primary:hover {
  background: #333;
}

/* Dropdown Menu Override */
.dropdown-menu {
  background: var(--bg-panel);
  border: var(--stroke) solid var(--ink);
  box-shadow: 4px 4px 0 var(--ink);
  border-radius: var(--radius-md);
  padding: 0.5rem;
  margin-top: 8px !important;
}
.dropdown-item {
  border-radius: var(--radius-sm);
  font-weight: 600;
  padding: 0.4rem 1rem;
}
.dropdown-item:active, .dropdown-item.active {
  background-color: var(--ink);
  color: #fff;
}

#vs-choice {
  display: none !important;
}

/* Game Area */
.game-container {
  flex: 1;
  display: flex;
  padding: 1.5rem;
  gap: 1.5rem;
  overflow: hidden;
  align-items: stretch;
  max-width: 1400px;
  margin: 0 auto;
  width: 100%;
}

/* Panels */
.panel-card {
  background: var(--bg-panel);
  border: var(--stroke) solid var(--ink);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
}

/* Board Panel */
.board-panel {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden; /* prevents layout blowout */
  background-image: radial-gradient(var(--bg-panel-2) 15%, transparent 16%);
  background-size: 20px 20px;
  min-height: 0; /* Important for flex child scrolling/sizing */
}

#game-app {
  /* Frame for the canvas */
  border: var(--stroke) solid var(--ink);
  border-radius: 4px; /* Phaser canvas usually sharp corners, keep it tight */
  box-shadow: 6px 6px 0 rgba(0,0,0,0.15);
  background: #deb068; /* Fallback board color */
  overflow: hidden;
  /* Ensure it has size even if canvas loads late */
  min-width: 320px;
  min-height: 320px;
  display: block;
}

#game-app canvas {
  display: block; /* remove inline-block gap */
  max-width: 100%;
  height: auto;
}

/* Controls Panel */
.controls-panel {
  flex: 0 0 320px;
  gap: 1.2rem;
  overflow-y: auto;
  min-width: 280px;
}

/* Score Box */
.score-box {
  display: flex;
  gap: 0.8rem;
}

.score-item {
  flex: 1;
  background: #fff;
  border: var(--stroke) solid var(--ink);
  border-radius: var(--radius-md);
  padding: 0.8rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: 2px 2px 0 rgba(0,0,0,0.05);
}

.avatar-wrapper img {
  width: 40px;
  height: auto;
  filter: drop-shadow(1px 1px 0 rgba(0,0,0,0.2));
}

.score-value {
  font-family: var(--font-display);
  font-size: 2rem;
  font-weight: 700;
  line-height: 1;
}

/* Action Groups */
.action-buttons {
  display: flex;
  gap: 0.8rem;
}
.action-buttons .btn-action {
  flex: 1;
}

/* Status / Opponent */
.opp-status {
  background: var(--bg-panel-2);
  border: 2px dashed var(--ink);
  border-radius: var(--radius-md);
  padding: 1rem;
  text-align: center;
  font-weight: 700;
  color: var(--ink-2);
  min-height: 3rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

.form-select {
  border: var(--stroke) solid var(--ink);
  border-radius: var(--radius-md);
  padding: 0.6rem;
  font-weight: 700;
  color: var(--ink);
  background-color: #fff;
  cursor: pointer;
}

/* Rules Section */
#rule {
  background: #fff;
  border-top: var(--stroke) solid var(--ink);
  padding: 3rem 1.5rem;
}

#rule h2 {
  font-family: var(--font-display);
  text-align: center;
  margin-bottom: 2rem;
  font-size: 2rem;
}

/* Rule Cards */
#rule .card {
  background: var(--bg-panel);
  border: var(--stroke) solid var(--ink);
  border-radius: var(--radius-md);
  box-shadow: 3px 3px 0 rgba(0,0,0,0.1);
  overflow: hidden;
  transition: transform 0.2s;
  height: 100%;
}
#rule .card:hover {
  transform: translateY(-2px);
}

#rule .card-body {
  padding: 1rem;
}
#rule .card-title {
  font-family: var(--font-display);
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
  color: var(--accent);
}
#rule .card-text {
  font-size: 0.95rem;
  color: var(--ink-2);
  line-height: 1.5;
}

/* Footer */
.site-footer {
  background: var(--ink);
  color: #fff;
  padding: 2rem 1.5rem;
  font-size: 0.9rem;
}
.footer-padding {
  padding-bottom: 4rem; /* space for iOS home bar */
}
.site-footer h6 {
  color: var(--bg-app);
  opacity: 0.8;
  letter-spacing: 0.05em;
}
.site-footer a {
  color: #fff;
  text-decoration: none;
  opacity: 0.8;
  transition: opacity 0.2s;
  border-bottom: 1px solid transparent;
}
.site-footer a:hover {
  opacity: 1;
  border-bottom-color: #fff;
}

/* Modals (Bootstrap override) */
.modal-content {
  border: var(--stroke) solid var(--ink);
  border-radius: var(--radius-lg);
  box-shadow: 8px 8px 0 var(--ink);
  background: var(--bg-panel);
}
.modal-header, .modal-footer {
  border-color: rgba(0,0,0,0.1);
}

/* Mobile Responsive */
@media (max-width: 768px) {
  .app-header {
    height: 56px;
    padding: 0 1rem;
  }
  
  .game-container {
    flex-direction: column;
    padding: 1rem;
    overflow-y: auto; /* Allow full page scroll on mobile */
    height: auto;
    flex: 0 0 auto;
  }
  
  .board-panel {
    min-height: 360px; /* Ensure board has space */
    padding: 0.5rem;
    width: 100%;
  }
  
  .controls-panel {
    flex: 0 0 auto;
    width: 100%;
    order: 2; /* Ensure it stays below board if flex wraps */
    min-width: 0; /* Allow shrinking */
  }
  
  /* Hide non-critical header items on very small screens? */
  .header-controls .pill-label {
    display: none;
  }
}
