/* Hex Castles - Scoped strictly to #game-app and .modal-backdrop */

#game-app, .modal-backdrop {
  --bg-board: #fdf6ea;
  --board-border: #000000;
  --text-main: #222222;
  --text-muted: #555555;
  --accent-blue: #3a7ede;
  --accent-yellow: #f7e55f;
  --match-green: #589a56;
  --coral: #ec8d6f;
  --pink: #ec96c4;
}

#game-app, #game-app *, #game-app *::before, #game-app *::after,
.modal-backdrop, .modal-backdrop *, .modal-backdrop *::before, .modal-backdrop *::after {
  box-sizing: border-box;
}

#game-app {
  width: 100%;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  font-family: "Comic Relief", system-ui, sans-serif;
  color: var(--text-main);
}

/* Header & Controls - Standard Giraffian Centered Header */
#game-app .game-header {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  width: 100%;
  padding: 8px 12px;
  margin-bottom: 8px;
  gap: 8px 12px;
}

#game-app .title-group {
  display: contents;
}

#game-app .title-group h1 {
  flex-basis: 100%;
  margin: 0 0 6px;
  font-size: 2em;
  text-align: center;
  font-weight: 700;
  color: #000;
}

#game-app .level-badge {
  font-size: 0.95rem;
  padding: 4px 14px;
  cursor: default;
}

#game-app .header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

#game-app button.icon-btn, #game-app .icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  min-width: 44px;
  min-height: 44px;
  padding: 0 !important;
  border: 2px solid #000;
  border-radius: 50% !important;
  cursor: pointer;
  flex-shrink: 0;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.08);
  transition: transform 0.1s ease, background-color 0.1s;
}

#game-app button.icon-btn svg, #game-app .icon-btn svg {
  display: block;
  flex-shrink: 0;
  pointer-events: none;
}

#game-app .icon-btn:hover {
  transform: translateY(-1px);
}

#game-app .icon-btn:active {
  transform: translateY(1px);
}

#game-app .game-instructions {
  font-size: 0.95rem;
  color: var(--text-muted);
  text-align: center;
  margin: 0 0 8px;
  max-width: 680px;
  line-height: 1.4;
}

/* Status Bar matching standard Giraffian game pattern */
#game-app .status-bar {
  display: flex;
  justify-content: space-around;
  align-items: center;
  width: 100%;
  max-width: 600px;
  background: rgba(255, 255, 255, 0.7);
  border: 2px solid #000;
  border-radius: 12px;
  padding: 6px 14px;
  margin-bottom: 8px;
  font-size: 0.92rem;
  font-weight: 600;
  flex-wrap: wrap;
  gap: 8px;
}

#game-app .status-bar strong {
  color: #000;
}

#game-app .text-green { color: #2e7d32; }
#game-app .text-coral { color: #d84315; }

/* Playfield & Board */
#game-app .playfield-container {
  width: 100%;
  display: flex;
  justify-content: center;
  margin-bottom: 8px;
}

#game-app .board-frame {
  width: 100%;
  border: 2px solid #000;
  border-radius: 16px;
  background-color: #3a7ede;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='64' height='20' viewBox='0 0 64 20'%3E%3Cpath d='M-16 10 Q-8 4 0 10 T16 10 T32 10 T48 10 T64 10 T80 10' fill='none' stroke='%23ffffff' stroke-opacity='.3' stroke-width='1.5'/%3E%3C/svg%3E");
  overflow: hidden;
  position: relative;
  touch-action: manipulation;
}

#game-app .hex-board {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 680 / 460;
}

/* SVG Hex Tiles (Strict 2px rule) */
.hex-tile {
  cursor: pointer;
  stroke: #ffffff;
  stroke-width: 2px;
  transition: filter 0.1s ease;
}

.hex-tile:hover {
  filter: brightness(1.08);
}

.hex-tile.mountain {
  fill: #8e9ca8;
  cursor: default;
}

.hex-tile.neutral {
  fill: #d8ccaa;
}

.hex-tile.yellow { fill: #f7e55f; }
.hex-tile.coral  { fill: #ec8d6f; }
.hex-tile.green  { fill: #589a56; }
.hex-tile.pink { fill: #ec96c4; }

/* Selected / Target Outlines */
.hex-selected {
  stroke: #000000 !important;
  stroke-width: 2px !important;
  filter: brightness(1.15) !important;
}

.hex-move-target {
  stroke: #2e7d32 !important;
  stroke-width: 2px !important;
  stroke-dasharray: 4 2;
  cursor: pointer;
}

.hex-attack-target {
  stroke: #d84315 !important;
  stroke-width: 2px !important;
  stroke-dasharray: 4 2;
  cursor: pointer;
}

.hex-ai-acting {
  stroke: #ffffff !important;
  stroke-width: 2px !important;
  animation: pulseAi 0.4s ease alternate infinite;
}

@keyframes pulseAi {
  from { filter: brightness(1); }
  to { filter: brightness(1.3); }
}

.castle-glyph, .unit-glyph {
  pointer-events: none;
  font-family: "Comic Relief", system-ui, sans-serif;
  user-select: none;
}

.castle-glyph {
  pointer-events: visiblePainted;
  cursor: pointer;
}

#game-app .castle-upgrade-popover {
  position: absolute;
  z-index: 2;
  width: 232px;
  max-width: calc(100% - 16px);
  padding: 10px;
  border: 2px solid #bec6ce;
  border-radius: 12px;
  background: #ffffff;
  text-align: center;
}

#game-app #castle-upgrade-title {
  display: block;
  margin: 0 24px 8px;
  font-size: .82rem;
  font-weight: 700;
}

#game-app .castle-upgrade-popover .castle-btn {
  width: 100%;
  justify-content: center;
  white-space: normal;
}

#game-app .castle-close {
  position: absolute;
  top: 3px;
  right: 3px;
  width: 30px;
  height: 30px;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: #ffffff;
  color: #222222;
  font: inherit;
  font-size: 1.3rem;
  cursor: pointer;
}

/* Faction Standings Bar */
#game-app .faction-bar {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  width: 100%;
  max-width: 820px;
  margin-bottom: 6px;
}

@media (max-width: 650px) {
  #game-app .faction-bar {
    grid-template-columns: repeat(2, 1fr);
  }
}

#game-app .faction-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  border: 2px solid #bec6ce;
  border-radius: 10px;
  background: #fffaf0;
  font-size: 0.82rem;
  font-weight: 600;
  transition: border-color 0.15s ease, background 0.15s ease;
}

#game-app .faction-pill.active {
  border-color: #000;
  background: #ffffff;
}

#game-app .faction-pill.defeated {
  opacity: 0.35;
  text-decoration: line-through;
}

#game-app .faction-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 2px solid #000;
  display: inline-block;
  flex-shrink: 0;
}

#game-app .faction-yellow .faction-dot { background: #f7e55f; }
#game-app .faction-coral .faction-dot  { background: #ec8d6f; }
#game-app .faction-green .faction-dot  { background: #589a56; }
#game-app .faction-pink .faction-dot { background: #ec96c4; }

#game-app .faction-name {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#game-app .faction-hexes {
  color: #666;
  font-size: 0.78rem;
}

/* Action Hint Bar */
#game-app .action-hint-bar {
  background: #ffffff;
  border: 2px solid #bec6ce;
  border-radius: 10px;
  padding: 6px 12px;
  font-size: 0.85rem;
  color: #333;
  text-align: center;
  min-height: 18px;
  width: 100%;
  max-width: 820px;
  margin-bottom: 6px;
  font-weight: 500;
}

/* Command Bar */
#game-app .command-bar {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  max-width: 820px;
  background: #fffaf0;
  border: 2px solid #000;
  border-radius: 14px;
  padding: 6px 10px;
  margin-bottom: 10px;
}

#game-app .command-group {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

#game-app .group-label {
  font-size: 0.68rem;
  font-weight: 700;
  color: #666;
  text-transform: uppercase;
}

#game-app .button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  align-items: center;
}

#game-app .recruit-btn {
  padding: 4px 8px;
  font-size: 0.8rem;
  display: flex;
  align-items: center;
  gap: 3px;
  cursor: pointer;
}

#game-app .btn-badge {
  background: #ffffff;
  border: 2px solid #000;
  border-radius: 6px;
  font-size: 0.65rem;
  padding: 0 3px;
  font-weight: 700;
}

#game-app .castle-btn {
  display: flex;
  align-items: center;
  gap: 3px;
  padding: 5px 10px;
  font-size: 0.82rem;
  cursor: pointer;
}

#game-app .troop-icon {
  display: block;
  flex-shrink: 0;
  object-fit: contain;
}

#game-app .end-turn-group {
  display: flex;
  align-items: center;
  margin-left: auto;
}

#game-app .end-turn-btn {
  padding: 7px 14px;
  font-size: 0.95rem;
  font-weight: 700;
  white-space: nowrap;
  cursor: pointer;
}

#game-app button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

@media (max-width: 768px) {
  #game-app .command-bar {
    flex-direction: column;
    align-items: stretch;
  }
  #game-app .end-turn-group {
    margin-left: 0;
    width: 100%;
  }
  #game-app .end-turn-btn {
    width: 100%;
  }
}

#game-app .artwork-preview {
  width: 100%;
  min-width: 0;
  padding: 12px 0;
  margin-bottom: 10px;
  background: #ffffff;
}

#game-app .artwork-preview h2 {
  margin: 0 0 8px;
  font-size: 1rem;
  text-align: center;
}

#game-app .artwork-strip {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  padding: 8px 4px 12px;
  background: #ffffff;
  touch-action: pan-x pan-y;
}

#game-app .artwork-strip figure {
  flex: 0 0 100px;
  margin: 0;
  text-align: center;
}

#game-app .artwork-strip a {
  display: block;
  background: #ffffff;
}

#game-app .artwork-strip .preview-sprite,
#game-app .artwork-strip .preview-prop {
  display: block;
  width: 100px;
  height: 110px;
  object-fit: contain;
}

#game-app .artwork-strip figcaption {
  margin-top: 6px;
  font-size: .75rem;
  color: #222222;
}

/* Modals matching site standard pattern */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 16px;
}

.modal-backdrop.hidden {
  display: none !important;
}

.modal-card {
  background: #ffffff;
  border: 2px solid #000000;
  border-radius: 20px;
  max-width: 540px;
  width: 100%;
  padding: 24px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  max-height: 85vh;
  overflow-y: auto;
  font-family: "Comic Relief", system-ui, sans-serif;
}

.modal-card h2 {
  margin-top: 0;
  margin-bottom: 12px;
  font-size: 1.5rem;
  color: #000;
}

.modal-card h3 {
  margin-top: 14px;
  margin-bottom: 4px;
  font-size: 1.05rem;
  color: #000;
}

.modal-card p, .modal-card ul {
  font-size: 0.9rem;
  line-height: 1.45;
  color: #333;
  margin: 6px 0;
}

.modal-card ul {
  padding-left: 20px;
}

.modal-card .setting-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 14px 0;
  gap: 12px;
}

.modal-card select {
  font-family: inherit;
  font-size: 0.95rem;
  padding: 6px 12px;
  border: 2px solid #000;
  border-radius: 12px;
  background: #fff;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
}

.text-center {
  text-align: center;
}

.hidden {
  display: none !important;
}
