:root {
  --bg: #070912;
  --panel: rgba(13, 18, 36, 0.92);
  --line: rgba(28, 36, 64, 0.85);
  --cyan: #00e5ff;
  --magenta: #ff2fb8;
  --amber: #ffd60a;
  --text: #dbe4ff;
  --muted: #7d8ab3;
  --accent: #3b82f6;
  --win: rgba(45, 255, 154, 0.35);
}

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

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background:
    radial-gradient(ellipse at 15% 85%, rgba(45, 255, 154, 0.1) 0%, transparent 42%),
    radial-gradient(ellipse at 85% 15%, rgba(123, 92, 255, 0.12) 0%, transparent 40%),
    radial-gradient(ellipse at 50% 0%, rgba(0, 229, 255, 0.08) 0%, transparent 45%),
    linear-gradient(180deg, #0a1020 0%, var(--bg) 55%, #04060f 100%);
  color: var(--text);
  font-family: "Vazirmatn", Tahoma, system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

.screen {
  width: 100%;
  height: 100%;
  max-width: 960px;
  margin: 0 auto;
  padding: 14px 12px 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.screen.is-hidden,
.is-hidden {
  display: none !important;
}

.menu-screen {
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.game-screen {
  overflow: hidden;
}

.dooz-head h1 {
  font-size: clamp(1.25rem, 4vw, 1.65rem);
  font-weight: 800;
  background: linear-gradient(135deg, var(--cyan), var(--magenta));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.game-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  flex-wrap: wrap;
  flex-shrink: 0;
}

.game-head p {
  color: var(--muted);
  font-size: 0.82rem;
  margin-top: 4px;
}

.dooz-status {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px 14px;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--cyan);
}

.dooz-turn {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px 14px;
  flex-shrink: 0;
}

.dooz-turn-label {
  color: var(--muted);
  font-size: 0.82rem;
}

.dooz-turn-mark {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 1rem;
  flex-shrink: 0;
}

.dooz-turn-name {
  font-weight: 700;
  font-size: 0.95rem;
}

.dooz-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px;
  display: grid;
  gap: 12px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
}

.dooz-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.85rem;
  color: var(--muted);
}

.dooz-field span {
  font-weight: 600;
}

.dooz-field select {
  background: rgba(20, 26, 52, 0.95);
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--text);
  padding: 10px 12px;
  font-family: inherit;
  font-size: 0.95rem;
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 18px) calc(50% - 3px), calc(100% - 12px) calc(50% - 3px);
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
}

[dir="rtl"] .dooz-field select {
  background-position: 18px calc(50% - 3px), 12px calc(50% - 3px);
}

.dooz-field select:disabled {
  opacity: 0.55;
}

.dooz-custom {
  display: grid;
  gap: 10px;
  padding: 10px;
  border: 1px dashed var(--line);
  border-radius: 12px;
}

.dooz-btn {
  border: 1px solid var(--line);
  background: rgba(20, 26, 52, 0.95);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 16px;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
}

.dooz-btn.primary {
  background: linear-gradient(135deg, var(--cyan), var(--accent));
  border: none;
  color: #04121a;
}

.dooz-btn.ghost {
  background: transparent;
  color: var(--muted);
}

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

.dooz-stats {
  font-size: 0.82rem;
  color: var(--muted);
  line-height: 1.7;
}

.dooz-layout {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(120px, 180px) 1fr;
  gap: 12px;
  min-height: 0;
  overflow: hidden;
}

.dooz-board-col {
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  gap: 8px;
}

.dooz-board-toolbar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex-shrink: 0;
}

.dooz-zoom-btn {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(20, 26, 52, 0.95);
  color: var(--cyan);
  font-size: 1.2rem;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  touch-action: manipulation;
}

.dooz-zoom-val {
  min-width: 48px;
  text-align: center;
  font-size: 0.82rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.dooz-players {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

.dooz-player {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px;
  border-radius: 10px;
  border: 1px solid transparent;
  font-size: 0.82rem;
}

.dooz-player.active {
  border-color: var(--cyan);
  background: rgba(0, 229, 255, 0.08);
}

.dooz-player .mark {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 0.95rem;
  flex-shrink: 0;
}

.dooz-player .tag {
  color: var(--muted);
  font-size: 0.72rem;
}

.dooz-board-wrap {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 10px;
  overflow: auto;
  flex: 1;
  min-height: 120px;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  touch-action: pan-x pan-y pinch-zoom;
}

.dooz-board {
  display: grid;
  gap: 3px;
  margin: 0 auto;
}

.dooz-cell {
  aspect-ratio: 1;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(8, 12, 24, 0.85);
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: clamp(0.75rem, 2.5vw, 1.35rem);
  cursor: pointer;
  user-select: none;
  touch-action: manipulation;
}

.dooz-cell:hover:not(.taken):not(:disabled) {
  background: rgba(0, 229, 255, 0.08);
}

.dooz-cell.taken {
  cursor: default;
}

.dooz-cell.win {
  background: var(--win);
  box-shadow: 0 0 0 2px rgba(45, 255, 154, 0.55);
}

.dooz-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  flex-shrink: 0;
}

.dooz-actions.center {
  margin-top: 8px;
}

.dooz-overlay {
  position: fixed;
  inset: 0;
  background: rgba(4, 6, 15, 0.88);
  display: grid;
  place-items: center;
  z-index: 20;
  padding: 16px;
}

.dooz-overlay.is-hidden {
  display: none !important;
}

.dooz-overlay-box {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 24px;
  text-align: center;
  min-width: min(92vw, 320px);
}

.dooz-overlay-box h2 {
  font-size: 1.4rem;
  color: var(--magenta);
  margin-bottom: 8px;
}

.dooz-overlay-box p {
  color: var(--muted);
  margin-bottom: 12px;
}

@media (max-width: 720px) {
  .dooz-layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }

  .dooz-players {
    flex-direction: row;
    flex-wrap: wrap;
    max-height: 88px;
  }

  .dooz-player {
    flex: 1 1 calc(50% - 8px);
  }
}

@media (orientation: landscape) and (max-height: 520px) {
  .game-screen {
    padding: 8px 10px 10px;
    gap: 8px;
  }

  .dooz-layout {
    grid-template-columns: minmax(100px, 130px) 1fr;
  }

  .dooz-head h1 {
    font-size: 1.1rem;
  }

  .game-head p {
    display: none;
  }

  .dooz-players {
    flex-direction: column;
    max-height: none;
  }
}

@media (orientation: portrait) {
  .dooz-board-wrap {
    min-height: 180px;
  }
}
