/* ============ تايغا — آخر حيوان ============ */

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

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

body {
  font-family: 'Tajawal', 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: #E7EDEF;
  color: #2B2F33;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

.hidden { display: none !important; }

button, .joystick, .animal-card {
  -webkit-user-select: none;
  user-select: none;
  font-family: inherit;
}

/* ---------- الهيكل ---------- */
.app {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  min-height: 0;
  background: #F2F4F3;
  overflow: hidden;
}

/* ---------- شريط المعلومات ---------- */
.hud {
  flex: 0 0 auto;
  padding: 6px 8px 0;
  background: #F7F9F9;
  border-bottom: 1px solid #D5DFE3;
  z-index: 5;
}

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

.hud-cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-width: 0;
  padding: 2px 4px 3px;
  background: #FFFFFF;
  border: 1px solid #2B2F33;
  border-radius: 4px;
}

.hud-label {
  font-size: 9px;
  line-height: 1.3;
  font-weight: 500;
  color: #6C777E;
  white-space: nowrap;
}

.hud-val {
  display: flex;
  align-items: baseline;
  gap: 1px;
  font-size: 16px;
  font-weight: 800;
  line-height: 1.05;
  color: #2B2F33;
}

.hud-val i {
  font-style: normal;
  font-size: 10px;
  font-weight: 500;
  color: #8A959B;
}

.hp-strip {
  height: 5px;
  margin: 4px 1px 5px;
  background: #E2E9EC;
  border-radius: 3px;
  overflow: hidden;
}

.hp-fill {
  height: 100%;
  width: 100%;
  background: #6FA8B8;
  border-radius: 3px;
  transition: width .16s linear, background-color .2s linear;
}

.hp-fill.low { background: #B4674E; }

/* ---------- الساحة ---------- */
.stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  background: #F2F4F3;
}

#game {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

/* ---------- منطقة التحكم ---------- */
.dock {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 16px 8px;
  background: #F7F9F9;
  border-top: 1px solid #D5DFE3;
  z-index: 5;
}

.dock-group {
  display: flex;
  align-items: center;
  gap: 10px;
}

.dock-end { justify-content: flex-end; }

.joystick {
  position: relative;
  width: clamp(58px, min(13vh, 25vw), 100px);
  height: clamp(58px, min(13vh, 25vw), 100px);
  border-radius: 50%;
  background: rgba(255, 255, 255, .9);
  border: 2px solid #2B2F33;
  box-shadow: 0 2px 0 rgba(43, 47, 51, .12);
  touch-action: none;
  cursor: grab;
  transition: border-color .16s ease, background-color .16s ease;
}

.joystick.active {
  border-color: #6FA8B8;
  background: rgba(232, 242, 246, .95);
}

.joystick-cross {
  position: absolute;
  inset: 22%;
  border-radius: 50%;
  border: 1px dashed rgba(43, 47, 51, .18);
}

.joystick-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 42%;
  height: 42%;
  border-radius: 50%;
  background: #6FA8B8;
  border: 2px solid #2B2F33;
  transform: translate(-50%, -50%);
  transition: transform .1s ease-out;
  will-change: transform;
}

.joystick.active .joystick-knob { transition: none; }

.dock-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  min-width: 62px;
  min-height: 52px;
  padding: 6px 12px;
  border-radius: 4px;
  border: 2px solid #2B2F33;
  background: #FFFFFF;
  color: #2B2F33;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  transition: transform .1s ease, background-color .16s ease;
}

.dock-btn:active {
  transform: translateY(1px);
  background: #E8F2F6;
}

.dock-btn:focus-visible {
  outline: 3px solid #6FA8B8;
  outline-offset: 2px;
}

/* ---------- الأزرار العامة ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 48px;
  padding: 10px 18px;
  border-radius: 4px;
  border: 2px solid #2B2F33;
  background: #FFFFFF;
  color: #2B2F33;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  transition: transform .1s ease, background-color .16s ease, box-shadow .16s ease;
  box-shadow: 0 2px 0 rgba(43, 47, 51, .14);
}

.btn:active { transform: translateY(2px); box-shadow: 0 0 0 rgba(43,47,51,.14); }

.btn:focus-visible {
  outline: 3px solid #6FA8B8;
  outline-offset: 2px;
}

.btn-primary {
  background: #6FA8B8;
  color: #10303A;
}

.btn-primary:hover { background: #7FB6C5; }

.btn-ghost {
  background: transparent;
  box-shadow: none;
  border-color: #B9C6CC;
  color: #4A5157;
  font-weight: 500;
}

.btn-ghost:hover { border-color: #2B2F33; color: #2B2F33; }

.btn-lg { font-size: 18px; min-height: 54px; }

.btn-small {
  min-height: 42px;
  font-size: 13px;
  font-weight: 700;
  box-shadow: 0 2px 0 rgba(43, 47, 51, .1);
}

.btn[disabled] {
  opacity: .5;
  cursor: not-allowed;
  transform: none;
}

/* ---------- الشاشات ---------- */
.menu {
  position: absolute;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  overflow: auto;
  background: rgba(228, 235, 238, .86);
  -webkit-backdrop-filter: blur(7px);
  backdrop-filter: blur(7px);
  animation: menuIn .22s ease-out;
}

@keyframes menuIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

#menuOver { align-items: center; }

@media (min-height: 560px) {
  #menuOver { align-items: flex-start; padding-top: 118px; }
}

.sheet {
  width: 100%;
  max-width: 420px;
  margin: auto;
  padding: 20px;
  background: rgba(255, 255, 255, .94);
  border: 2px solid #2B2F33;
  border-radius: 6px;
  box-shadow: 0 8px 0 rgba(43, 47, 51, .1);
}

.sheet-tight { max-width: 340px; }

.sheet-title {
  margin: 0 0 6px;
  font-size: 24px;
  font-weight: 800;
  line-height: 1.35;
  color: #2B2F33;
}

.muted {
  margin: 0 0 16px;
  font-size: 14px;
  line-height: 1.6;
  color: #6C777E;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 14px;
}

/* ---------- البداية ---------- */
.brand { text-align: center; margin-bottom: 16px; }

.kicker {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .06em;
  color: #6FA8B8;
  padding: 3px 10px;
  border: 1px solid #C9D6DD;
  border-radius: 4px;
  background: #F5FAFB;
}

.brand h1 {
  margin: 10px 0 6px;
  font-size: 34px;
  font-weight: 800;
  line-height: 1.15;
  color: #2B2F33;
}

.brand-sub {
  margin: 0;
  font-size: 13px;
  line-height: 1.65;
  color: #6C777E;
}

.section-label {
  font-size: 12px;
  font-weight: 700;
  color: #4A5157;
  margin: 0 0 8px;
}

.roster {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 2px 2px 8px;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}

.roster::-webkit-scrollbar { display: none; }

.animal-card {
  position: relative;
  flex: 0 0 auto;
  width: 74px;
  padding: 6px 4px 7px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  border: 2px solid #C9D6DD;
  border-radius: 4px;
  background: #FFFFFF;
  color: #2B2F33;
  cursor: pointer;
  transition: border-color .16s ease, background-color .16s ease, transform .1s ease;
}

.animal-card:active { transform: translateY(1px); }

.animal-card:focus-visible {
  outline: 3px solid #6FA8B8;
  outline-offset: 2px;
}

.animal-card.sel {
  border-color: #2B2F33;
  background: #EDF5F7;
  box-shadow: inset 0 -3px 0 #6FA8B8;
}

.animal-card.locked {
  opacity: .58;
  cursor: not-allowed;
  background: #F4F7F8;
}

.animal-card canvas {
  width: 44px;
  height: 44px;
  display: block;
}

.animal-card .an-name {
  font-size: 11px;
  font-weight: 700;
  line-height: 1.3;
}

.animal-card .an-lock {
  font-size: 9px;
  font-weight: 500;
  color: #8A959B;
  line-height: 1.2;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 10px 0 14px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 9px;
  border-radius: 4px;
  background: #F2F6F7;
  border: 1px solid #DCE5E8;
  font-size: 11px;
  font-weight: 500;
  color: #5B666C;
}

.chip b {
  font-size: 12px;
  font-weight: 800;
  color: #2B2F33;
}

.unlock {
  padding: 11px 12px;
  border-radius: 4px;
  border: 1px solid #DCE5E8;
  background: #F7FAFA;
  margin-bottom: 14px;
}

.unlock-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  font-size: 12px;
  font-weight: 700;
  color: #4A5157;
}

.unlock-count {
  font-size: 12px;
  font-weight: 800;
  color: #2B2F33;
  font-variant-numeric: tabular-nums;
}

.unlock-track {
  height: 8px;
  margin: 8px 0 0;
  border-radius: 4px;
  background: #E1EAED;
  overflow: hidden;
}

.unlock-fill {
  height: 100%;
  width: 0%;
  background: #6FA8B8;
  border-radius: 4px;
  transition: width .35s ease-out;
}

.unlock-hint {
  margin: 7px 0 0;
  font-size: 11px;
  line-height: 1.5;
  color: #7A858B;
}

.menu-links {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 10px;
}

.bestline {
  margin: 14px 0 0;
  text-align: center;
  font-size: 12px;
  color: #7A858B;
}

.bestline b {
  color: #2B2F33;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

/* ---------- النهاية ---------- */
.over-head { text-align: center; margin-bottom: 12px; }

.over-tag {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 4px;
  background: #F5FAFB;
  border: 1px solid #C9D6DD;
  color: #6FA8B8;
}

#overTitle {
  margin: 10px 0 4px;
  font-size: 28px;
  font-weight: 800;
  line-height: 1.25;
  color: #2B2F33;
}

#overTitle.win { color: #3E7B8C; }

.score-block {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
  padding: 12px 0 14px;
  border-top: 1px solid #E3EAED;
  border-bottom: 1px solid #E3EAED;
  margin-bottom: 12px;
}

.score-label {
  font-size: 11px;
  font-weight: 700;
  color: #8A959B;
}

.score-big {
  font-size: 44px;
  font-weight: 800;
  line-height: 1.1;
  color: #2B2F33;
  font-variant-numeric: tabular-nums;
}

.score-best {
  font-size: 11px;
  color: #8A959B;
  margin-top: 2px;
}

.score-best b {
  color: #4A5157;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.breakdown {
  list-style: none;
  margin: 0 0 12px;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.breakdown li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 13px;
  color: #5B666C;
  padding: 6px 10px;
  background: #F7FAFA;
  border-radius: 4px;
}

.breakdown li b {
  color: #2B2F33;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.breakdown li.total {
  background: #EDF5F7;
  border: 1px solid #C9D6DD;
  color: #2B2F33;
  font-weight: 700;
}

/* ---------- لوحة الصدارة ---------- */
.board-body {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 46vh;
  overflow: auto;
  margin-bottom: 4px;
}

.board-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 4px;
  background: #F7FAFA;
  border: 1px solid #E3EAED;
  font-size: 13px;
}

.board-row.you {
  background: #EDF5F7;
  border-color: #6FA8B8;
}

.board-rank {
  font-weight: 800;
  color: #6FA8B8;
  min-width: 22px;
  font-variant-numeric: tabular-nums;
}

.board-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: #2B2F33;
  font-weight: 500;
}

.board-pts {
  font-weight: 800;
  color: #2B2F33;
  font-variant-numeric: tabular-nums;
}

.board-note {
  font-size: 11px;
  line-height: 1.6;
  color: #8A959B;
  margin: 8px 0 0;
  text-align: center;
}

.board-empty {
  padding: 22px 12px;
  text-align: center;
  font-size: 13px;
  line-height: 1.7;
  color: #6C777E;
  background: #F7FAFA;
  border: 1px dashed #C9D6DD;
  border-radius: 4px;
}

/* ---------- السيارة ---------- */
.hp-strip.hp-car { background: #F3E7DC; }
.hp-strip.hp-car .hp-fill { background: #C9793F; }

.dock-btn[disabled] {
  opacity: .38;
  cursor: default;
}

.dock-btn[disabled]:active {
  transform: none;
  background: #FFFFFF;
}

.dock-btn.ready {
  border-color: #6FA8B8;
  background: #E8F2F6;
  animation: mountPulse 1.4s ease-in-out infinite;
}

.dock-btn.driving {
  background: #6FA8B8;
  color: #10303A;
}

@keyframes mountPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(111, 168, 184, .55); }
  50% { box-shadow: 0 0 0 6px rgba(111, 168, 184, 0); }
}

@media (max-width: 380px) {
  .brand h1 { font-size: 29px; }
  .sheet { padding: 16px; }
  .hud-val { font-size: 15px; }
  .score-big { font-size: 38px; }
}

@media (prefers-reduced-motion: reduce) {
  .menu { animation: none; }
  .hp-fill, .unlock-fill, .joystick-knob { transition: none; }
  .dock-btn.ready { animation: none; }
}