/* ── Spökspelet — Theme ──────────────────────────────────── */
@import url('https://fonts.googleapis.com/css2?family=Creepster&family=Inter:wght@400;500;600&display=swap');

:root {
  --bg: #07070d;
  --bg-board: #0e0e1a;
  --bg-cell: #151525;
  --bg-cell-hover: #1c1c35;
  --bg-widget: #111119;
  --border: #1e1e30;
  --border-cell: #252540;

  --text: #c8c8d8;
  --text-dim: #555570;
  --text-bright: #e8e8f4;

  --color-good: #4a9eff;
  --color-evil: #ff4757;
  --color-ghost: #9090a8;
  --color-exit: #2ecc71;
  --color-selected: #ffd700;
  --color-valid: rgba(46, 204, 113, 0.35);
  --color-valid-capture: rgba(255, 71, 87, 0.35);
  --color-accent: #7c5cbf;

  --glow-good: 0 0 12px rgba(74, 158, 255, 0.5);
  --glow-evil: 0 0 12px rgba(255, 71, 87, 0.5);
  --glow-selected: 0 0 16px rgba(255, 215, 0, 0.6);
  --glow-exit: 0 0 10px rgba(46, 204, 113, 0.4);

  --font-display: 'Creepster', cursive;
  --font-body: 'Inter', system-ui, sans-serif;

  --board-max: min(90vw, 500px);
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  display: flex;
  justify-content: center;
  align-items: center;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

#app {
  width: 100%;
  height: 100%;
  position: relative;
}

/* ── Screens ─────────────────────────────────────────────── */
.screen {
  display: none;
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
}

.screen.active {
  display: flex;
  align-items: center;
  justify-content: center;
}

.hidden { display: none !important; }

/* ── Lobby ───────────────────────────────────────────────── */
.lobby-content {
  text-align: center;
  padding: 2rem;
  max-width: 400px;
  width: 100%;
}

.title-area {
  margin-bottom: 3rem;
  position: relative;
}

.ghost-bg-icon {
  font-size: 6rem;
  opacity: 0.15;
  position: absolute;
  top: -2rem;
  left: 50%;
  transform: translateX(-50%);
  animation: float 3s ease-in-out infinite;
  filter: blur(1px);
}

.game-title {
  font-family: var(--font-display);
  font-size: clamp(2.5rem, 8vw, 4rem);
  color: var(--text-bright);
  letter-spacing: 0.15em;
  text-shadow: 0 0 30px rgba(124, 92, 191, 0.4), 0 0 60px rgba(124, 92, 191, 0.15);
  position: relative;
  z-index: 1;
}

.subtitle {
  font-size: 0.9rem;
  color: var(--text-dim);
  margin-top: 0.5rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
}

.lobby-section {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  align-items: center;
}

.code-input {
  font-family: var(--font-display);
  font-size: 2rem;
  text-align: center;
  letter-spacing: 0.5em;
  padding: 0.5rem 1rem;
  background: var(--bg-widget);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-bright);
  width: 200px;
  outline: none;
  text-transform: uppercase;
  transition: border-color 0.2s;
}

.code-input:focus {
  border-color: var(--color-accent);
}

.room-code-display {
  font-family: var(--font-display);
  font-size: 3rem;
  letter-spacing: 0.5em;
  color: var(--color-accent);
  text-shadow: 0 0 20px rgba(124, 92, 191, 0.5);
  padding: 0.5rem;
}

.info-text {
  color: var(--text);
  font-size: 0.9rem;
}

.info-text.dim {
  color: var(--text-dim);
  font-size: 0.8rem;
}

.waiting-dots {
  display: flex;
  gap: 0.3em;
  justify-content: center;
  font-size: 2rem;
  color: var(--text-dim);
}

.waiting-dots span {
  animation: blink 1.4s infinite;
}

.waiting-dots span:nth-child(2) { animation-delay: 0.2s; }
.waiting-dots span:nth-child(3) { animation-delay: 0.4s; }

/* ── Buttons ─────────────────────────────────────────────── */
.btn {
  font-family: var(--font-body);
  font-size: 0.95rem;
  font-weight: 500;
  padding: 0.75rem 2rem;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
  min-width: 160px;
}

.btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--color-accent);
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  background: #6a4dab;
  box-shadow: 0 0 20px rgba(124, 92, 191, 0.3);
}

.btn-secondary {
  background: var(--bg-widget);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover:not(:disabled) {
  border-color: var(--color-accent);
}

.btn-ghost {
  background: transparent;
  color: var(--text-dim);
}

.btn-ghost:hover {
  color: var(--text);
}

/* ── Game Layout ─────────────────────────────────────────── */
.game-layout {
  display: flex;
  flex-direction: column;
  align-items: center;
  height: 100%;
  padding: 0.75rem;
  gap: 0.5rem;
  justify-content: center;
}

.game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: var(--board-max);
  max-width: 100%;
}

.turn-indicator {
  font-size: 0.9rem;
  font-weight: 600;
  padding: 0.3rem 0.8rem;
  border-radius: 4px;
  background: var(--bg-widget);
  border: 1px solid var(--border);
}

.turn-indicator.your-turn {
  color: var(--color-exit);
  border-color: var(--color-exit);
  text-shadow: 0 0 8px rgba(46, 204, 113, 0.4);
}

.turn-indicator.opponent-turn {
  color: var(--text-dim);
}

.move-counter {
  font-size: 0.8rem;
  color: var(--text-dim);
}

/* ── Captures ────────────────────────────────────────────── */
.captures-area {
  width: var(--board-max);
  max-width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
  min-height: 2.5rem;
}

.captures-label {
  font-size: 0.7rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.captures-row {
  display: flex;
  gap: 0.3rem;
  flex-wrap: wrap;
  justify-content: center;
}

.captured-ghost {
  width: 28px;
  height: 32px;
  position: relative;
}

.captured-ghost svg {
  width: 100%;
  height: 100%;
}

/* ── Setup ───────────────────────────────────────────────── */
#setup-overlay {
  width: var(--board-max);
  max-width: 100%;
  text-align: center;
}

#setup-overlay h2 {
  font-family: var(--font-display);
  font-size: 1.5rem;
  color: var(--text-bright);
  margin-bottom: 0.25rem;
}

#setup-overlay p {
  font-size: 0.85rem;
  color: var(--text-dim);
}

.text-good { color: var(--color-good); }
.text-evil { color: var(--color-evil); }

.setup-counter {
  font-size: 0.9rem;
  font-weight: 600;
  margin-top: 0.5rem;
  padding: 0.3rem 1rem;
  background: var(--bg-widget);
  border-radius: 4px;
  display: inline-block;
}

/* ── Board ───────────────────────────────────────────────── */
.board-wrapper {
  width: var(--board-max);
  max-width: 100%;
}

.game-board {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 2px;
  background: var(--border-cell);
  border: 2px solid var(--border-cell);
  border-radius: 6px;
  overflow: hidden;
}

.cell {
  aspect-ratio: 1;
  background: var(--bg-cell);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: default;
  position: relative;
  transition: background 0.15s;
}

.cell.playable {
  cursor: pointer;
}

.cell.playable:hover {
  background: var(--bg-cell-hover);
}

.cell.corner {
  background: var(--bg);
  cursor: default;
}

.cell.exit {
  background: #0d1a10;
  cursor: default;
}

.cell.exit::after {
  content: 'EXIT';
  font-family: var(--font-display);
  font-size: 0.55rem;
  color: var(--color-exit);
  opacity: 0.5;
  letter-spacing: 0.1em;
  position: absolute;
}

.cell.selected {
  background: rgba(255, 215, 0, 0.1);
  box-shadow: inset 0 0 0 2px var(--color-selected);
}

.cell.valid-move {
  background: var(--color-valid);
  cursor: pointer;
}

.cell.valid-move::before {
  content: '';
  width: 30%;
  height: 30%;
  background: var(--color-exit);
  border-radius: 50%;
  opacity: 0.6;
  animation: pulse 1.5s ease-in-out infinite;
}

.cell.valid-capture {
  background: var(--color-valid-capture);
  cursor: pointer;
}

.cell.valid-escape {
  background: rgba(46, 204, 113, 0.25);
  cursor: pointer;
}

.cell.last-move-from {
  background: rgba(124, 92, 191, 0.08);
  box-shadow: inset 0 0 0 1px rgba(124, 92, 191, 0.3);
}

.cell.last-move-from::after {
  content: '';
  position: absolute;
  inset: 15%;
  border: 1px dashed rgba(124, 92, 191, 0.3);
  border-radius: 50%;
  animation: lastMovePulse 2s ease-in-out infinite;
}

.cell.last-move-to {
  background: rgba(124, 92, 191, 0.12);
  box-shadow: inset 0 0 0 2px rgba(124, 92, 191, 0.4);
}

.ghost-piece.ghost-arriving {
  animation: ghostArrive 0.35s ease-out !important;
}

.cell.last-move-to.valid-capture {
  animation: captureFlash 0.5s ease-out;
}

.cell.valid-escape::before {
  content: '';
  width: 40%;
  height: 40%;
  background: var(--color-exit);
  border-radius: 50%;
  opacity: 0.7;
  animation: pulse 1s ease-in-out infinite;
}

/* ── Ghost Pieces ────────────────────────────────────────── */
.ghost-piece {
  width: 75%;
  height: 85%;
  position: relative;
  z-index: 2;
  transition: transform 0.15s;
  animation: float 3s ease-in-out infinite;
}

.cell.playable:hover .ghost-piece {
  transform: scale(1.08);
}

.ghost-piece svg {
  width: 100%;
  height: 100%;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.5));
}

.ghost-piece.good svg {
  fill: var(--color-good);
  filter: drop-shadow(0 0 8px rgba(74, 158, 255, 0.4));
}

.ghost-piece.evil svg {
  fill: var(--color-evil);
  filter: drop-shadow(0 0 8px rgba(255, 71, 87, 0.4));
}

.ghost-piece.opponent svg {
  fill: var(--color-ghost);
  filter: drop-shadow(0 0 6px rgba(144, 144, 168, 0.3));
}

.ghost-piece.selected svg {
  filter: drop-shadow(0 0 12px rgba(255, 215, 0, 0.7));
}

.ghost-piece.setup-unset svg {
  fill: #555;
  opacity: 0.5;
}

/* ── Controls ────────────────────────────────────────────── */
.controls {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  justify-content: center;
}

/* ── Overlays ────────────────────────────────────────────── */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(4px);
}

.overlay-content {
  background: var(--bg-widget);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 2rem;
  text-align: center;
  max-width: 360px;
  width: 90%;
}

.overlay-content p {
  margin-bottom: 1.5rem;
  line-height: 1.6;
}

.overlay-buttons {
  display: flex;
  gap: 0.75rem;
  justify-content: center;
}

.rules-content {
  max-width: 420px;
  text-align: left;
  max-height: 85vh;
  overflow-y: auto;
}

.rules-content h2 {
  font-family: var(--font-display);
  font-size: 1.8rem;
  text-align: center;
  color: var(--text-bright);
  margin-bottom: 1rem;
}

.rules-section {
  margin-bottom: 1rem;
}

.rules-section h3 {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--color-accent);
  margin-bottom: 0.3rem;
}

.rules-section p {
  font-size: 0.85rem;
  line-height: 1.5;
  color: var(--text);
  margin-bottom: 0;
}

.rules-section ul {
  list-style: none;
  padding: 0;
  font-size: 0.85rem;
  line-height: 1.6;
}

.rules-section ul li {
  padding-left: 1.2em;
  position: relative;
  color: var(--text);
}

.rules-section ul li::before {
  content: '👻';
  position: absolute;
  left: 0;
  font-size: 0.75em;
}

.rules-content .btn {
  display: block;
  margin: 1.2rem auto 0;
}

.gameover-content h2 {
  font-family: var(--font-display);
  font-size: 2rem;
  margin-bottom: 0.5rem;
}

.gameover-content .win { color: var(--color-exit); text-shadow: 0 0 20px rgba(46, 204, 113, 0.5); }
.gameover-content .lose { color: var(--color-evil); text-shadow: 0 0 20px rgba(255, 71, 87, 0.5); }

.gameover-stats {
  font-size: 0.85rem;
  color: var(--text-dim);
  margin: 1rem 0;
}

/* ── Toast ───────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-widget);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.6rem 1.5rem;
  border-radius: 8px;
  font-size: 0.85rem;
  z-index: 200;
  animation: toastIn 0.3s ease;
}

/* ── Animations ──────────────────────────────────────────── */
@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-3px); }
}

@keyframes ghostArrive {
  0% { transform: scale(0.4) translateY(-12px); opacity: 0.2; }
  50% { transform: scale(1.1) translateY(2px); opacity: 1; }
  100% { transform: scale(1) translateY(0); opacity: 1; }
}

@keyframes lastMovePulse {
  0%, 100% { opacity: 0.4; }
  50% { opacity: 0.8; }
}

@keyframes captureFlash {
  0% { box-shadow: inset 0 0 25px rgba(255, 71, 87, 0.5); }
  100% { box-shadow: none; }
}

@keyframes pulse {
  0%, 100% { opacity: 0.4; transform: scale(0.8); }
  50% { opacity: 0.8; transform: scale(1.1); }
}

@keyframes blink {
  0%, 100% { opacity: 0.2; }
  50% { opacity: 1; }
}

@keyframes toastIn {
  from { opacity: 0; transform: translateX(-50%) translateY(10px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ── Responsive ──────────────────────────────────────────── */
@media (max-height: 700px) {
  .game-layout { gap: 0.25rem; padding: 0.5rem; }
  .captures-area { min-height: 2rem; }
  .captures-label { font-size: 0.6rem; }
  #setup-overlay h2 { font-size: 1.2rem; }
  #setup-overlay p { font-size: 0.75rem; }
}

@media (max-width: 400px) {
  .btn { min-width: 120px; padding: 0.6rem 1.2rem; font-size: 0.85rem; }
  .game-title { font-size: 2.5rem; }
}
