﻿:root {
  --tile-size: 48px;
  --gap: 8px;
  --primary: #2563eb;
  --primary-dark: #1e40af;
  --success: #10b981;
  --text: #111827;
  --text-light: #6b7280;
  --bg: #ffffff;
  --bg-secondary: #f3f4f6;
  --border: #e5e7eb;
}

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

* {
  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;
}

.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: 12px 0;
}

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

.tile {
  width: var(--tile-size);
  height: var(--tile-size);
  background: linear-gradient(135deg, #f5f1e8, #e8e3d8);
  border: 2px solid #c9bfb0;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  cursor: pointer;
  transition: all 0.15s;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  touch-action: manipulation;
}

.tile:active {
  transform: scale(0.95);
}

.tile.selected {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.3);
  animation: pulse 0.4s;
}

@keyframes pulse {
  0% { transform: scale(1); }
  50% { transform: scale(1.05); }
  100% { transform: scale(1); }
}

.tile.empty {
  background: transparent;
  border: none;
  box-shadow: none;
  cursor: default;
}

@media (prefers-color-scheme: dark) {
  .tile {
    background: linear-gradient(135deg, #2a2620, #1f1c18);
    border-color: #3d3a36;
  }
}

.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 {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 1000;
  align-items: center;
  justify-content: center;
}

.overlay.show {
  display: flex;
}

.card {
  background: var(--bg);
  border-radius: 12px;
  padding: 24px;
  max-width: 320px;
  width: 90%;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.card h2 {
  margin: 0;
  text-align: center;
  font-size: 22px;
}

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

.logo {
  font-size: 40px;
  font-weight: bold;
  margin-bottom: 8px;
}

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

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

.big {
  font-size: 48px;
  font-weight: bold;
  color: var(--primary);
  text-align: center;
}

.stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin: 16px 0;
}

.stat {
  padding: 12px;
  border-radius: 8px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
}

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

.val {
  font-size: 24px;
  font-weight: bold;
}

button {
  padding: 12px;
  border-radius: 8px;
  border: none;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  touch-action: manipulation;
}

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

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

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

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

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

.btn-share:active {
  background: #059669;
}

.toast {
  display: none;
  position: fixed;
  bottom: 20px;
  left: 20px;
  right: 20px;
  background: rgba(0, 0, 0, 0.8);
  color: white;
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 14px;
  z-index: 2000;
  animation: slideUp 0.3s;
}

.toast.show {
  display: block;
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 480px) {
  :root {
    --tile-size: 40px;
    --gap: 6px;
  }
  
  #wrap {
    padding-top: max(8px, env(safe-area-inset-top));
    padding-bottom: max(8px, env(safe-area-inset-bottom));
    padding-left: max(8px, env(safe-area-inset-left));
    padding-right: max(8px, env(safe-area-inset-right));
  }
  
  header {
    padding: 6px 0;
  }
  
  .chip {
    font-size: 12px;
    padding: 3px 8px;
  }
  
  .card {
    padding: 20px;
  }
}