* { box-sizing: border-box; }
:root {
  --bg-dark: #0f1419;
  --panel-olive: #2f3a2e;
  --panel-olive-2: #384635;
  --accent-khaki: #c2b280;
  --accent-brass: #b08d57;
  --accent-red: #f85149;
  --accent-green: #2ea043;
  --text: #e6edf3;
  --muted: #8b949e;
  --line: #30363d;
  --bg-elev: #0e1318;
}

html, body { height: 100%; margin: 0; font-family: Inter, system-ui, Segoe UI, Arial, sans-serif; color: var(--text); }

#app { display: flex; height: 100%; }
#left { flex: 0 0 auto; padding: 12px; background: #0b0f13; }
#right { flex: 1 1 auto; padding: 14px 18px; overflow-y: auto; background: var(--bg-dark); }

#gameCanvas { border: 1px solid var(--line); background: #0d1117; image-rendering: pixelated; border-radius: 10px; box-shadow: 0 6px 24px rgba(0,0,0,0.35), inset 0 0 0 1px rgba(255,255,255,0.02); }

h1 { margin: 4px 0 8px; font-size: 20px; letter-spacing: 0.5px; text-transform: uppercase; }
h2 { margin: 10px 0 6px; font-size: 15px; font-weight: 600; color: var(--accent-khaki); }
#status div { margin: 4px 0; }
#unitPanel div { margin: 4px 0; }
#unitPanel div { margin: 4px 0; }

button, .hud-button { background: linear-gradient(180deg, #3c7a3f, #2b6a32); color: white; border: 1px solid #2ea043; border-radius: 10px; padding: 7px 12px; margin: 4px 6px 4px 0; cursor: pointer; transition: transform 120ms ease, filter 120ms ease, box-shadow 120ms ease; box-shadow: 0 2px 0 rgba(0,0,0,0.3); }
button:hover, .hud-button:hover { filter: brightness(1.06); transform: translateY(-1px); box-shadow: 0 6px 14px rgba(0,0,0,0.35); }
button:active, .hud-button:active { transform: translateY(0); }
button:disabled, .hud-button:disabled { background: #30363d; border-color: #30363d; cursor: not-allowed; }

.hint { color: #8b949e; font-size: 12px; margin-top: 6px; }

.legend-row { display: flex; align-items: center; gap: 8px; margin: 4px 0; }
.legend-swatch { display: inline-block; width: 16px; height: 16px; border: 1px solid #30363d; }
.legend-swatch.p1 { background: #58a6ff; }
.legend-swatch.p2 { background: #ffa657; }
.legend-swatch.base { background: #8957e5; }
.legend-swatch.flag { background: #d29922; }
.legend-swatch.spawn { background: rgba(137,87,229,0.28); border-color: #8957e5; }
.legend-swatch.fort { background: #8b949e; }
.legend-swatch.move { background: rgba(88,166,255,0.25); border-color: #58a6ff; }
.legend-swatch.atk { background: rgba(255,101,101,0.25); border-color: #ff6565; }

ul { margin: 6px 0 0 18px; }
li { margin: 4px 0; }

.panel {
  background: linear-gradient(180deg, var(--panel-olive), var(--panel-olive-2));
  border: 1px solid #20261f;
  border-radius: 14px;
  padding: 12px 14px;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.25), 0 10px 24px rgba(0,0,0,0.35);
  position: relative;
}
.panel:before, .panel:after {
  content: "";
  position: absolute; width: 8px; height: 8px; border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, #b8b8b8, #666 60%, #222);
  box-shadow: 0 0 0 1px #111;
}
.panel:before { top: 8px; right: 10px; }
.panel:after { bottom: 8px; left: 10px; }

/* Shop grid */
.shop-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; }
.shop-item { display: flex; align-items: center; gap: 10px; padding: 10px; background: rgba(0,0,0,0.24); border: 1px solid rgba(0,0,0,0.4); border-radius: 12px; cursor: pointer; transition: transform 120ms ease, box-shadow 120ms ease; }
.shop-item:hover { transform: translateY(-1px); box-shadow: 0 10px 24px rgba(0,0,0,0.35); }
.shop-item .thumb { width: 36px; height: 36px; background-size: cover; background-position: center; border-radius: 6px; box-shadow: inset 0 0 0 1px rgba(0,0,0,0.35); }
.shop-item .label { flex: 1; font-size: 13px; }
.shop-item .price { font-size: 12px; color: var(--accent-khaki); }
.shop-section-title { color: var(--accent-khaki); font-weight: 600; letter-spacing: 0.5px; margin: 6px 0; text-transform: uppercase; }

/* Unit panel enhancements */
.stat-row { display: flex; gap: 8px; align-items: center; }
.bar { height: 8px; background: #2a2f24; border-radius: 6px; overflow: hidden; flex: 1; box-shadow: inset 0 0 0 1px rgba(0,0,0,0.45); }
.bar-fill { height: 100%; background: linear-gradient(90deg, #3ba55d, #2ea043); }
.badge { display: inline-block; padding: 2px 6px; font-size: 11px; border: 1px solid #444; border-radius: 999px; background: rgba(0,0,0,0.25); color: var(--accent-khaki); }
.ability { display: inline-block; padding: 2px 6px; margin: 2px 4px 0 0; font-size: 11px; background: rgba(194,178,128,0.15); color: var(--accent-khaki); border: 1px solid rgba(194,178,128,0.35); border-radius: 6px; }

/* Action button polish */
#endTurn { background: linear-gradient(180deg, #b19362, #a17f48); border-color: #8b6b3b; }
#endTurn:hover { filter: brightness(1.07); }

/* Top HUD (mobile-first hidden) */
#hudTop { display: none; align-items: center; gap: 10px; margin: 6px 8px; }
.hud-item { display: flex; align-items: center; gap: 6px; }
.hud-label { font-size: 12px; color: var(--accent-khaki); text-transform: uppercase; letter-spacing: 0.5px; }
.hud-pill { display: inline-block; min-width: 28px; text-align: center; padding: 2px 8px; border-radius: 999px; background: rgba(194,178,128,0.18); color: var(--text); border: 1px solid rgba(194,178,128,0.35); font-weight: 600; }
.hud-spacer { flex: 1; }
.hud-button { background: #b08d57; border: 1px solid #8b6b3b; border-radius: 8px; padding: 6px 12px; color: #fff; cursor: pointer; }
.hud-button:hover { filter: brightness(1.07); }
.hud-button.selected { outline: 2px solid #c2b280; }

/* Opponent status colors */
.hud-pill.connected { background: rgba(46,160,67,0.22); border-color: #2ea043; }
.hud-pill.waiting { background: rgba(194,178,128,0.18); border-color: rgba(194,178,128,0.35); }

/* Banner */
.banner { display: flex; align-items: center; gap: 10px; margin: 6px 8px; padding: 8px 12px; background: linear-gradient(180deg, var(--panel-olive), var(--panel-olive-2)); border: 1px solid #20261f; border-radius: 14px; box-shadow: inset 0 0 0 1px rgba(0,0,0,0.25), 0 10px 24px rgba(0,0,0,0.35); }

/* MP controls */
.mp-grid { display: grid; grid-template-columns: 1fr; gap: 12px; }
.mp-card { background: rgba(0,0,0,0.2); border: 1px solid rgba(0,0,0,0.35); border-radius: 10px; padding: 10px; }
.input { background: #0f1419; color: var(--text); border: 1px solid #30363d; border-radius: 6px; padding: 6px 8px; min-width: 140px; }
.mode-actions { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }
.mode-actions .hud-button { min-width: 180px; text-align: center; }
.mode-logo { display: flex; justify-content: center; align-items: center; margin: 4px 0 8px; }
.mode-logo img { max-width: 200px; width: 40%; height: auto; filter: drop-shadow(0 6px 12px rgba(0,0,0,0.35)); }
.legal-links { margin-top: 10px; font-size: 12px; color: var(--muted); display: flex; gap: 8px; justify-content: center; align-items: center; }
.legal-links a { color: var(--muted); text-decoration: none; }
.legal-links a:hover { text-decoration: underline; color: var(--text); }
.legal-links .sep { color: rgba(255,255,255,0.25); }

/* Center content inside the main menu modal */
#modeModal .mp-grid { justify-items: center; }
#modeModal .mp-card { text-align: center; }
#modeModal .stat-row { justify-content: center; }
#modeModal .stat-row .input { text-align: center; }
#aiControls .stat-row { justify-content: center; gap: 8px; }
#aiControls .ai-diff { min-width: 96px; }

/* Accordion details styling */
details.accordion > summary {
  cursor: pointer; user-select: none; list-style: none; outline: none; padding: 6px 0; color: var(--accent-khaki);
}
details.accordion > summary::-webkit-details-marker { display: none; }
details.accordion[open] > summary { color: var(--text); }
details.accordion > summary::after {
  content: '▸'; display: inline-block; margin-left: 6px; transform: translateY(-1px);
}
details.accordion[open] > summary::after { content: '▾'; }

/* Mobile responsive layout */
@media (max-width: 900px) {
  #app { flex-direction: column; }
  #left { padding: 8px; }
  #right { padding: 8px 10px; }
  #gameCanvas { width: 100%; height: auto; border-width: 1px; }
  #roomBanner { background: transparent !important; border: 0 !important; box-shadow: none !important; padding: 4px 12px; margin: 4px 8px; gap: 6px; border-radius: 0; }
  #roomBanner .banner-left { display: flex; align-items: center; gap: 6px; flex-wrap: nowrap; }
  #roomBanner .hud-label { display: none; }
  #roomBanner .room-label { display: inline-block; font-size: 12px; color: var(--accent-khaki); }
  #roomBanner .room-label { display: inline-block; font-size: 12px; color: var(--accent-khaki); }
  #roomBanner .hud-pill { background: transparent; border: 0; border-radius: 0; color: var(--text); padding: 0 6px; font-weight: 600; }
  #roomBanner #roomCode { flex: 1 1 auto; text-align: center; }
  #roomBanner .hud-button { padding: 4px 8px; font-size: 12px; }
  #roomBanner .hud-spacer { display: block; }
  /* Make shop horizontally scrollable ribbons to reduce vertical space */
  .shop-grid { grid-auto-flow: column; grid-auto-columns: minmax(140px, 1fr); overflow-x: auto; grid-template-columns: none; }
  .shop-item { padding: 10px; }
  button, .shop-item { font-size: 14px; }
  #actions { position: sticky; bottom: 0; z-index: 5; }
  #status { position: sticky; top: 0; z-index: 6; background: var(--panel-olive); border-bottom: 1px solid #20261f; }
  /* Use top HUD on mobile, hide side status/actions to save space */
  #hudTop { display: flex; position: sticky; top: 0; z-index: 7; margin: 0; border-radius: 0; border-left: 0; border-right: 0; }
  #right #status, #right #actions { display: none; }
  #right hr { display: none; }
  #shop.panel { margin-top: 6px; }
  /* Mode actions full-width symmetry on small screens */
  .mode-actions .hud-button { flex: 1 1 48%; min-width: 0; }
}

/* Tutorial overlay */
.tutorial-overlay { position: fixed; inset: 0; pointer-events: none; display: flex; align-items: flex-start; justify-content: center; padding: 12px; z-index: 1003; }
.tutorial-content { pointer-events: auto; max-width: 760px; width: 100%; max-height: 80vh; overflow: auto; }
.tutorial-body { color: var(--text); font-size: 14px; line-height: 1.5; text-align: left; }
.tutorial-body h3 { margin: 8px 0 4px; font-size: 15px; color: var(--accent-khaki); }
.tutorial-body ul { margin: 6px 0 6px 18px; }
.tutorial-body li { margin: 4px 0; }
.tutorial-list { display: flex; flex-direction: column; gap: 8px; margin-top: 6px; }
.tu-row { display: flex; gap: 10px; align-items: flex-start; background: rgba(0,0,0,0.18); border: 1px solid rgba(0,0,0,0.35); border-radius: 10px; padding: 8px 10px; }
.tu-thumb { width: 44px; height: 44px; border-radius: 8px; object-fit: contain; image-rendering: pixelated; background: #0d1117; border: 1px solid var(--line); }
.tu-body { flex: 1; }
.tu-name { font-weight: 600; color: var(--accent-khaki); margin-bottom: 2px; }
.tu-stats { display: flex; flex-wrap: wrap; gap: 10px; font-size: 12px; color: var(--muted); }
.tu-stats .pair { display: inline-flex; gap: 4px; }
.tu-abil { margin-top: 4px; }
.tu-abil .ability { margin-right: 4px; }

/* Modal overlay */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,0.55); display: flex; align-items: center; justify-content: center; z-index: 999; }
.modal { backdrop-filter: blur(4px); }
.modal-content { max-width: 680px; width: 92%; text-align: center; animation: pop 160ms ease-out; }
@keyframes pop { from { transform: scale(0.98); opacity: 0.8; } to { transform: scale(1); opacity: 1; } }

/* Make MP grid two columns when modal is wide enough */
@media (min-width: 540px) {
  .mp-grid { grid-template-columns: repeat(2, minmax(220px, 1fr)); }
}

/* Game log */
.log-list { max-height: 200px; overflow-y: auto; text-align: left; padding: 6px 4px; font-size: 12px; color: var(--muted); border-top: 1px dashed rgba(255,255,255,0.08); margin-top: 6px; }
.log-list .item { margin: 2px 0; }
.log-list .p1 { color: #58a6ff; }
.log-list .p2 { color: #ffa657; }

/* Shop preview tooltip/modal */
.shop-preview {
  position: fixed;
  z-index: 1002;
  min-width: 200px;
  max-width: 260px;
  pointer-events: auto;
  border: 1px solid #20261f;
  box-shadow: 0 10px 24px rgba(0,0,0,0.35);
}
.shop-preview h3 { margin: 0 0 6px; font-size: 14px; }
.shop-preview .row { display: flex; justify-content: space-between; font-size: 12px; margin: 2px 0; }
.shop-preview .abilities { margin-top: 6px; }
.shop-preview .abilities .ability { margin-right: 4px; }
.shop-preview .close { position: absolute; top: 6px; right: 8px; cursor: pointer; font-weight: 700; color: var(--muted); }

/* Reduce redundant headings visually */
#actions > h2 { display:none; }

/* (removed MP Debug overlay styles) */


#hudTop.panel:before, #hudTop.panel:after, #roomBanner.panel:before, #roomBanner.panel:after { display: none; content: none; }


/* Override banner to use dark background consistently */
#roomBanner { background: transparent !important; border: 0 !important; box-shadow: none !important; padding: 4px 12px; margin: 4px 8px; gap: 6px; border-radius: 0; }


