:root {
  --bg: #0f1a14;
  --panel: #17251d;
  --text: #e8efe9;
  --muted: #9fb3a6;
  --human: #4aa8ff;
  --bot: #ff6b5e;
  --accent: #7be08c;
  color-scheme: dark;
}

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

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

.app {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* Top bar */
.bar {
  flex: none;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px 6px;
}

button {
  font: inherit;
  color: var(--text);
  background: var(--panel);
  border: 1px solid #2d4235;
  border-radius: 12px;
  cursor: pointer;
}
button:disabled { opacity: 0.35; cursor: default; }
button[hidden] { display: none; }

.icon {
  width: 40px;
  height: 40px;
  font-size: 20px;
  line-height: 1;
  padding: 0;
  flex: none;
}

/* Opponent badge in the bar */
.opponent {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 3px 10px 3px 3px;
  border-radius: 24px;
  text-align: left;
}
.opponent:disabled { opacity: 1; }
.opp-text { display: flex; flex-direction: column; min-width: 0; }
.opp-name {
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.face { display: inline-block; flex: none; width: 36px; height: 36px; }
.face svg { display: block; width: 100%; height: 100%; }
.face.mid { width: 56px; height: 56px; }
.face.big { width: 110px; height: 110px; margin: 0 auto 10px; display: block; }
.face.big.beaten { animation: dizzy 0.9s ease-in-out 2; }
@keyframes dizzy { 25% { transform: rotate(-12deg); } 75% { transform: rotate(12deg); } }

.status {
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.status.human { color: var(--human); }
.status.thinking { color: var(--muted); }

.score {
  flex: none;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  font-size: 15px;
}
.score .h { color: var(--human); }
.score .b { color: var(--bot); }

/* Board */
.board-wrap {
  flex: 1;
  min-height: 0;
  position: relative;
  padding: 0 6px 8px;
}

#board {
  display: block;
  width: 100%;
  height: 100%;
  cursor: pointer;
}

.pitch { fill: #2f7a45; }
.zone { opacity: 0.25; }
.zone-bot { fill: var(--bot); }
.zone-human { fill: var(--human); }
.grid line { stroke: rgba(255, 255, 255, 0.28); stroke-width: 1; }
.goal-line { stroke-width: 4; stroke-linecap: round; }
.goal-bot { stroke: var(--bot); }
.goal-human { stroke: var(--human); }
.center-dot { fill: rgba(255, 255, 255, 0.5); }

.man { stroke: rgba(0, 0, 0, 0.5); stroke-width: 1; transition: opacity 0.15s; }
.man.doomed { opacity: 0.35; }
.last { fill: #ffd34d; pointer-events: none; }
.ball { filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.45)); }
.ball-icon { display: inline-block; width: 1.15em; height: 1.15em; vertical-align: -0.2em; }
.ghost { fill: rgba(15, 18, 24, 0.4); stroke: rgba(255, 255, 255, 0.35); stroke-dasharray: 3 3; pointer-events: none; }

.hint {
  fill: rgba(123, 224, 140, 0.18);
  stroke: var(--accent);
  stroke-width: 2.5;
  animation: pulse 1.4s ease-in-out infinite;
}
.hint.win { stroke: #fff; fill: rgba(74, 168, 255, 0.5); }
.hint.lose { stroke: var(--bot); fill: rgba(255, 107, 94, 0.25); }
@keyframes pulse { 50% { stroke-opacity: 0.4; } }

.trail polyline {
  fill: none;
  stroke: #ffd34d;
  stroke-width: 3;
  stroke-dasharray: 6 5;
  stroke-linejoin: round;
  opacity: 0.85;
}
.jump-line { stroke: #fff; stroke-width: 2; stroke-dasharray: 4 4; opacity: 0.7; }

/* Floating end-turn button */
.end-turn {
  position: absolute;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%);
  padding: 12px 22px;
  font-weight: 700;
  background: var(--accent);
  color: #0d1f12;
  border-color: var(--accent);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.45);
}

/* Overlays: result and opponent picker */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(8, 14, 10, 0.6);
}
.overlay[hidden] { display: none; }
.card {
  width: min(340px, 100%);
  background: var(--panel);
  border-radius: 20px;
  padding: 22px 20px;
  text-align: center;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
}
.result-text { font-size: 24px; font-weight: 800; }
.result-text.win { color: var(--accent); }
.result-text.lose { color: var(--bot); }
.result-sub { min-height: 1.2em; margin: 8px 0 16px; color: var(--muted); font-size: 15px; }
.actions { display: flex; gap: 10px; justify-content: center; }
.actions button { padding: 12px 18px; font-weight: 600; }
.primary {
  background: var(--accent);
  color: #0d1f12;
  border-color: var(--accent);
  font-weight: 700;
  padding: 12px 26px;
}

.picker-title { font-size: 20px; font-weight: 800; margin-bottom: 14px; }
.picker-list { display: flex; flex-direction: column; gap: 10px; margin-bottom: 14px; }
.pick {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 14px 8px 8px;
  border-radius: 16px;
  text-align: left;
}
.pick.current { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.pick.locked { opacity: 1; }
.pick.locked .face { filter: grayscale(1) brightness(0.45); }
.pick.locked .pick-text { opacity: 0.45; }
.pick-text { flex: 1; display: flex; flex-direction: column; }
.pick-name { font-size: 17px; font-weight: 700; }
.pick-level { font-size: 13px; color: var(--muted); }
.pick-mark { font-size: 20px; color: var(--accent); }
#pickerClose { padding: 10px 22px; }
#rulesOpen { padding: 10px 22px; }

/* Player avatar (Pikabu account) */
.me {
  border-radius: 50%;
  overflow: hidden;
  color: var(--human);
  border-color: var(--human);
}
.me img { display: block; width: 100%; height: 100%; object-fit: cover; }
.me svg { display: block; width: 24px; height: 24px; margin: auto; }
.me.guest { color: var(--muted); border-color: #2d4235; }

/* Rules popup */
.c-human { color: var(--human); }
.c-bot { color: var(--bot); }
.rules-card { text-align: left; }
.rules-card .picker-title { text-align: center; }
.rules-list {
  margin: 0 0 18px;
  padding-left: 18px;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.45;
}
.rules-list li + li { margin-top: 8px; }
.rules-list b { color: var(--text); }
.rules-list b.c-human { color: var(--human); }
.rules-list b.c-bot { color: var(--bot); }
.rules-card .primary { display: block; width: 100%; }

@media (max-width: 380px) {
  .bar { gap: 6px; padding: 8px 6px 6px; }
  .icon { width: 36px; height: 36px; font-size: 18px; }
}
