﻿:root {
  --cell-size: 32px;
  --gap: 2px;
  --primary: #2563eb;
  --primary-dark: #1e40af;
  --success: #10b981;
  --danger: #ef4444;
  --text: #111827;
  --text-light: #6b7280;
  --bg: #ffffff;
  --bg-secondary: #f3f4f6;
  --border: #e5e7eb;
  --wall: #1f2937;
  --path: #f0f0f0;
}

@media (prefers-color-scheme: dark) {
  :root {
    --text: #f9fafb;
    --text-light: #d1d5db;
    --bg: #0f1226;
    --bg-secondary: #1a1f3a;
    --border: #2d3748;
    --wall: #0f0f0f;
    --path: #2a2a2a;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

html[dir="rtl"] body {
  direction: rtl;
}

#wrap {
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-height: 100dvh;
  padding-top: max(10px, env(safe-area-inset-top));
  padding-bottom: max(10px, env(safe-area-inset-bottom));
  padding-left: max(10px, env(safe-area-inset-left));
  padding-right: max(10px, env(safe-area-inset-right));
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0;
  gap: 12px;
  border-bottom: 1px solid var(--border);
}

.back-hub {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  border-radius: 8px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  text-decoration: none;
  color: var(--text);
  cursor: pointer;
  transition: background 0.2s;
}

.back-hub:active {
  background: var(--border);
}

.brand {
  flex: 1;
  font-size: 18px;
  font-weight: bold;
  text-align: center;
}

.brand b {
  color: var(--primary);
}

.hchips {
  display: flex;
  gap: 8px;
}

.chip {
  padding: 4px 10px;
  border-radius: 6px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  font-size: 13px;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 6px;
}

.torch-toggle {
  padding: 0 !important;
}

.torch-toggle input {
  display: none;
}

.torch-toggle label {
  padding: 4px 10px;
  cursor: pointer;
  border-radius: 6px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  font-size: 16px;
  display: block;
  transition: all 0.2s;
}

.torch-toggle input:checked + label {
  background: var(--primary);
  border-color: var(--primary-dark);
  color: white;
}

.hud {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  padding: 8px 0;
}

.board-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  padding: 8px 0;
}

#board {
  display: grid;
  gap: var(--gap);
  grid-template-columns: repeat(auto-fit, var(--cell-size));
  justify-content: center;
  align-content: center;
  user-select: none;
  -webkit-user-select: none;
}

.cell {
  width: var(--cell-size);
  height: var(--cell-size);
  border-radius: 2px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  user-select: none;
  -webkit-user-select: none;
}

.cell.wall {
  background: var(--wall);
  border: 1px solid var(--text-light);
}

.cell.path {
  background: var(--path);
  border: 1px solid var(--border);
}

.cell.player {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  border: 2px solid var(--primary);
  animation: pulse-player 1s infinite;
  z-index: 10;
}

.cell.goal {
  background: linear-gradient(135deg, var(--success), #059669);
  border: 2px solid var(--success);
  animation: pulse-goal 1s infinite;
  z-index: 9;
}

.cell.visible {
  opacity: 1;
}

.cell.hidden {
  opacity: 0.1;
  background: var(--bg-secondary);
}

@keyframes pulse-player {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.15); }
}

@keyframes pulse-goal {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.1); }
}

.controls {
  display: flex;
  gap: 10px;
  padding: 8px 0;
  justify-content: center;
}

.btn-control {
  padding: 8px 16px;
  border-radius: 6px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s;
  touch-action: manipulation;
}

.btn-control:active {
  background: var(--border);
}

footer {
  padding: 8px 0;
  font-size: 12px;
  color: var(--text-light);
  text-align: center;
  border-top: 1px solid var(--border);
}

.overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.overlay.show {
  display: flex;
}

.card {
  background: var(--bg);
  border-radius: 12px;
  padding: 24px;
  max-width: 90%;
  max-height: 90%;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  text-align: center;
}

.card.home {
  max-width: 320px;
}

.logo {
  font-size: 48px;
  font-weight: bold;
  margin-bottom: 12px;
}

.logo b {
  color: var(--primary);
}

.sub {
  font-size: 14px;
  color: var(--text-light);
  margin-bottom: 24px;
}

.stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 24px;
  padding: 16px;
  background: var(--bg-secondary);
  border-radius: 8px;
}

.stat {
  text-align: center;
}

.lbl {
  font-size: 12px;
  color: var(--text-light);
  margin-bottom: 4px;
}

.val {
  font-size: 20px;
  font-weight: bold;
  color: var(--primary);
}

.big {
  font-size: 48px;
  font-weight: bold;
  margin: 24px 0;
  color: var(--primary);
}

.btn-primary, .btn-ghost, .btn-share {
  width: 100%;
  padding: 12px 16px;
  border-radius: 6px;
  border: none;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  margin-bottom: 10px;
  touch-action: manipulation;
}

.btn-primary {
  background: var(--primary);
  color: white;
}

.btn-primary:active {
  background: var(--primary-dark);
  transform: scale(0.98);
}

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

.btn-ghost:active {
  background: var(--border);
}

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

.btn-share:active {
  background: var(--border);
}

.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 12px 24px;
  border-radius: 6px;
  font-size: 14px;
  z-index: 200;
  opacity: 0;
  transition: opacity 0.3s;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
}

@media (max-width: 480px) {
  :root {
    --cell-size: 28px;
  }
  
  .card {
    margin: 20px;
    padding: 16px;
  }
  
  .logo {
    font-size: 36px;
  }
  
  .big {
    font-size: 36px;
  }
}
