@font-face {
  font-family: "InterLocal";
  src: url("/assets/vendor/fonts/Inter-Variable.ttf") format("truetype");
  font-display: swap;
}

@font-face {
  font-family: "VazirLocal";
  src: url("/assets/vendor/fonts/Vazirmatn-Regular.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "VazirLocal";
  src: url("/assets/vendor/fonts/Vazirmatn-Bold.woff2") format("woff2");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

:root {
  --bg-app: #f4f7f8;
  --text-primary: #172026;
  --text-secondary: #5a6974;
  --text-muted: #4a5a65;
  --surface: #ffffff;
  --surface-soft: #f9fbfc;
  --surface-elevated: #f7fafc;
  --border: #dce4ea;
  --border-strong: #c8d4de;
  --accent: #1396e0;
  --accent-strong: #0f7fc0;
  --success-bg: #d7f6e6;
  --success-text: #0b6c3d;
  --danger-bg: #fbe3e3;
  --danger-text: #9b1d1d;
  --clock-face: #ffffff;
  --clock-ring: #c4d2dc;
  --clock-tick: #6a7c89;
  --clock-hand: #1e2a32;
  --clock-second: #b52323;
  --tooltip-bg: rgba(25, 33, 40, 0.95);
  --tooltip-text: #f6f9fb;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg-app: #0f1418;
    --text-primary: #e5edf3;
    --text-secondary: #a4b3bf;
    --text-muted: #91a2af;
    --surface: #161d23;
    --surface-soft: #1b252d;
    --surface-elevated: #1e2932;
    --border: #2d3b46;
    --border-strong: #3a4b59;
    --accent: #3fb1ff;
    --accent-strong: #2f9ceb;
    --success-bg: rgba(13, 108, 61, 0.22);
    --success-text: #71d6a2;
    --danger-bg: rgba(155, 29, 29, 0.24);
    --danger-text: #f19696;
    --clock-face: #141d25;
    --clock-ring: #324452;
    --clock-tick: #8da0ad;
    --clock-hand: #dce6ec;
    --clock-second: #ef7a7a;
    --tooltip-bg: rgba(10, 13, 16, 0.96);
    --tooltip-text: #f3f7fa;
  }
}

html,
body {
  color-scheme: light dark;
}

body {
  margin: 0;
  background: var(--bg-app);
  color: var(--text-primary);
  font-family: "VazirLocal", "InterLocal", "Segoe UI", sans-serif;
  font-feature-settings: "tnum" 1, "ss01" 1;
  text-align: start;
}

html[data-lang="en"] body,
html[data-lang="fr"] body,
html[data-lang="de"] body,
html[data-lang="es"] body,
html[data-lang="tr"] body,
html[data-lang="it"] body {
  font-family: "InterLocal", "Segoe UI", sans-serif;
}

html[data-lang="fa"] body,
html[data-lang="ar"] body {
  font-family: "VazirLocal", "InterLocal", "Segoe UI", sans-serif;
}

[v-cloak] {
  display: none;
}

.container {
  max-width: 1260px;
  margin: 0 auto;
  padding: 1.5rem;
}

.hero {
  margin-bottom: 1.5rem;
}

.hero h1 {
  margin-bottom: 0.25rem;
}

.hero p {
  margin-top: 0;
}

.presence-strip {
  position: sticky;
  top: 0.55rem;
  z-index: 40;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.65rem;
  margin-bottom: 1rem;
  padding: 0.5rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: color-mix(in srgb, var(--bg-app) 94%, transparent);
  backdrop-filter: blur(5px);
}

.lang-selector {
  display: flex;
  align-items: center;
  gap: 0.28rem;
  margin-inline-start: auto;
}

.lang-buttons {
  display: flex;
  align-items: center;
  gap: 0.28rem;
}

.lang-btn {
  padding: 0.22rem 0.52rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  font-size: 0.76rem;
  font-family: "InterLocal", "Segoe UI", sans-serif;
  font-weight: 500;
  cursor: pointer;
  line-height: 1.4;
  letter-spacing: 0.03em;
  transition: border-color 0.14s, background 0.14s, color 0.14s;
}

.lang-btn:hover {
  border-color: var(--text-secondary);
  color: var(--text-primary);
}

.lang-btn.active {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 14%, var(--surface));
  color: var(--accent-strong);
  font-weight: 700;
}

.lang-dropdown-label {
  display: none;
}

.lang-dropdown {
  display: none;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text-primary);
  font-size: 0.8rem;
  font-family: inherit;
  line-height: 1.4;
  padding: 0.22rem 1.9rem 0.22rem 0.65rem;
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--text-secondary) 50%),
    linear-gradient(135deg, var(--text-secondary) 50%, transparent 50%);
  background-position:
    calc(100% - 0.95rem) calc(50% - 2px),
    calc(100% - 0.7rem) calc(50% - 2px);
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
}

.presence-pill {
  min-width: 170px;
  display: inline-flex;
  align-items: baseline;
  gap: 0.45rem;
  padding: 0.38rem 0.6rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
}

.presence-label {
  font-size: 0.78rem;
  color: var(--text-secondary);
}

.presence-value {
  font-size: 1rem;
  color: var(--text-primary);
}

.grid.two {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
  margin-bottom: 1rem;
}

.grid.two > .card {
  width: 100%;
  min-width: 0;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem;
}

html[dir="rtl"] .card {
  text-align: right;
}

.alert-toggle {
  min-height: 2rem;
  border: 1px solid var(--border-strong);
  background: var(--surface-elevated);
  border-radius: 999px;
  padding: 0.28rem 0.5rem;
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  cursor: pointer;
  color: var(--text-primary);
}

.alert-toggle:hover {
  border-color: var(--text-secondary);
}

.alert-toggle:focus-visible {
  outline: 2px solid #2c7fcc;
  outline-offset: 2px;
}

.alert-toggle-label {
  font-size: 0.82rem;
}

.alert-toggle-track {
  width: 38px;
  height: 20px;
  border-radius: 999px;
  background: var(--border-strong);
  position: relative;
  transition: background-color 0.18s ease;
}

.alert-toggle-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--surface);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
  position: absolute;
  top: 2px;
  left: 2px;
  transition: transform 0.18s ease;
}

.alert-toggle-state {
  font-size: 0.75rem;
  color: var(--text-secondary);
  min-width: 2.2ch;
  text-align: center;
}

.alert-toggle.is-on {
  border-color: color-mix(in srgb, var(--accent) 55%, var(--border));
  background: color-mix(in srgb, var(--accent) 14%, var(--surface));
}

.alert-toggle.is-on .alert-toggle-track {
  background: var(--accent-strong);
}

.alert-toggle.is-on .alert-toggle-thumb {
  transform: translateX(18px);
}

.alert-toggle.is-on .alert-toggle-state {
  color: var(--accent-strong);
}

.status-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  margin-bottom: 0.45rem;
}

.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.status {
  display: inline-block;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  font-size: 0.85rem;
  letter-spacing: 0.04em;
}

.status-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.status-clock-panel {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
}

.status-clock {
  width: 56px;
  height: 56px;
  border-radius: 50%;
}

.status-time-info {
  display: inline-flex;
  flex-direction: column;
  gap: 0.1rem;
}

.status-countdown {
  min-width: 3ch;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.status-clock-time {
  font-size: 0.82rem;
  color: var(--text-secondary);
}

#next-connection-estimate {
  word-break: break-word;
}

.status.online {
  background: var(--success-bg);
  color: var(--success-text);
}

.status.offline {
  background: var(--danger-bg);
  color: var(--danger-text);
}

table.primary {
  width: 100%;
  font-size: 0.9rem;
  min-width: 420px;
}

table.primary th,
table.primary td {
  padding: 0.45rem 0.4rem;
  border-bottom: 1px solid var(--border);
  text-align: start;
}

table.primary tbody tr:nth-child(even) {
  background: var(--surface-soft);
}

.row-live {
  font-weight: 600;
  color: var(--success-text);
}

.timeline-list {
  display: grid;
  gap: 0.45rem;
}

.timeline-row {
  display: grid;
  grid-template-columns: 56px 1fr 58px;
  align-items: center;
  gap: 0.5rem;
}

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

.timeline-track {
  position: relative;
  height: 14px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--surface-soft) 70%, var(--border));
  overflow: hidden;
}

.timeline-bar {
  position: absolute;
  top: 0;
  height: 100%;
  border-radius: 999px;
  background: var(--accent);
}

.timeline-total {
  text-align: end;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.chart-wrap {
  position: relative;
  min-height: 240px;
}

.heatmap-grid {
  display: grid;
  grid-template-columns: 28px repeat(7, minmax(0, 1fr));
  gap: 4px;
  font-size: 0.68rem;
  width: 100%;
}

.heatmap-wrap {
  width: 100%;
  overflow: hidden;
  -webkit-overflow-scrolling: touch;
}

.heatmap-head {
  text-align: center;
  color: var(--text-muted);
  padding-bottom: 2px;
  white-space: nowrap;
}

.heatmap-hour {
  color: var(--text-muted);
  text-align: end;
  padding-inline-end: 4px;
  line-height: 14px;
}

.heatmap-cell {
  height: 14px;
  border-radius: 3px;
  background: var(--surface-soft);
}

.heatmap-tooltip {
  position: fixed;
  z-index: 1100;
  pointer-events: none;
  max-width: 280px;
  padding: 0.35rem 0.5rem;
  border-radius: 6px;
  background: var(--tooltip-bg);
  color: var(--tooltip-text);
  font-family: inherit;
  font-size: 0.8rem;
  line-height: 1.35;
  direction: inherit;
  unicode-bidi: plaintext;
  white-space: nowrap;
}

.offline-game-cta {
  border: 1px solid color-mix(in srgb, var(--accent) 55%, var(--border));
  background: color-mix(in srgb, var(--accent) 14%, var(--surface));
  color: color-mix(in srgb, var(--accent-strong) 80%, var(--text-primary));
  border-radius: 999px;
  padding: 0.36rem 0.68rem;
  font-size: 0.82rem;
  cursor: pointer;
}

.offline-game-cta:hover {
  border-color: color-mix(in srgb, var(--accent) 78%, var(--border));
  background: color-mix(in srgb, var(--accent) 22%, var(--surface));
}

.offline-game-card {
  margin-bottom: 1rem;
  border-color: var(--border);
}

.offline-game-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.8rem;
}

.offline-game-head h3 {
  margin: 0;
}

.offline-game-subtitle {
  margin: 0.25rem 0 0;
  color: var(--text-secondary);
  font-size: 0.85rem;
}

.offline-game-toggle,
.offline-game-reset {
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--surface-elevated);
  color: var(--text-primary);
  padding: 0.35rem 0.6rem;
  font-size: 0.82rem;
  cursor: pointer;
}

.offline-game-toggle:hover,
.offline-game-reset:hover {
  border-color: var(--text-secondary);
}

.offline-game-body {
  margin-top: 0.75rem;
}

.offline-game-stats {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-bottom: 0.7rem;
}

.offline-game-stat {
  position: relative;
  background: #bbada0;
  color: #fff;
  border-radius: 6px;
  padding: 0.35rem 0.65rem;
  min-width: 72px;
  text-align: center;
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}

.offline-game-stat span {
  font-size: 0.7rem;
  text-transform: uppercase;
  color: #eee4da;
  font-weight: 700;
}

.offline-game-stat strong {
  font-size: 1.1rem;
}

.game-score-addition {
  position: absolute;
  bottom: 0;
  inset-inline: 0;
  color: rgba(119, 110, 101, 0.9);
  font-weight: 700;
  font-size: 1.1rem;
  z-index: 100;
  animation: score-float-up 0.6s ease-out;
  animation-fill-mode: both;
  pointer-events: none;
}

@keyframes score-float-up {
  0% { transform: translateY(0); opacity: 1; }
  100% { transform: translateY(-30px); opacity: 0; }
}

.offline-game-board {
  --g: 8px;
  --cell: calc((100% - (3 * var(--g))) / 4);
  --step: calc(var(--cell) + var(--g));
  width: min(100%, 360px);
  aspect-ratio: 1 / 1;
  position: relative;
  background: #bbada0;
  border-radius: 12px;
  padding: var(--g);
  touch-action: none;
  user-select: none;
  box-sizing: border-box;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.offline-game-bg {
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--g);
  box-sizing: border-box;
}

.offline-game-bg-cell {
  border-radius: 8px;
  background: rgba(238, 228, 218, 0.35);
}

.offline-game-tiles {
  position: absolute;
  inset: var(--g);
  pointer-events: none;
  --g: 8px;
  --cell: calc((100% - (3 * var(--g))) / 4);
}

.offline-game-cell {
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: clamp(0.95rem, 3.4vw, 1.25rem);
}

.game-tile {
  position: absolute;
  width: var(--cell);
  height: var(--cell);
  left: 0;
  top: 0;
  background: #3c3a32;
  color: #f9f6f2;
  transition: transform 0.1s ease-in-out, background-color 0.1s ease;
  z-index: 10;
  will-change: transform;
}

.tile-128, .tile-256, .tile-512 { font-size: clamp(0.85rem, 3vw, 1.1rem); }
.tile-1024, .tile-2048 { font-size: clamp(0.7rem, 2.5vw, 0.95rem); }
.tile-4096, .tile-8192 { font-size: clamp(0.6rem, 2vw, 0.8rem); }

.tile-new {
  animation: tile-pop-in 0.15s ease-out;
  z-index: 5;
}

.tile-merge {
  animation: tile-merge-pop 0.15s ease-out;
  z-index: 15;
}

@keyframes tile-pop-in {
  0% { transform: translate3d(calc(var(--x) * 100% + var(--x) * var(--g)), calc(var(--y) * 100% + var(--y) * var(--g)), 0) scale(0); opacity: 0; }
  100% { transform: translate3d(calc(var(--x) * 100% + var(--x) * var(--g)), calc(var(--y) * 100% + var(--y) * var(--g)), 0) scale(1); opacity: 1; }
}

@keyframes tile-merge-pop {
  0% { transform: translate3d(calc(var(--x) * 100% + var(--x) * var(--g)), calc(var(--y) * 100% + var(--y) * var(--g)), 0) scale(1); }
  50% { transform: translate3d(calc(var(--x) * 100% + var(--x) * var(--g)), calc(var(--y) * 100% + var(--y) * var(--g)), 0) scale(1.15); }
  100% { transform: translate3d(calc(var(--x) * 100% + var(--x) * var(--g)), calc(var(--y) * 100% + var(--y) * var(--g)), 0) scale(1); }
}

.tile-2 { background: #eee4da; color: #776e65; }
.tile-4 { background: #ede0c8; color: #776e65; }
.tile-8 { background: #f2b179; color: #f9f6f2; }
.tile-16 { background: #f59563; color: #f9f6f2; }
.tile-32 { background: #f67c5f; color: #f9f6f2; }
.tile-64 { background: #f65e3b; color: #f9f6f2; }
.tile-128 { background: #edcf72; color: #f9f6f2; box-shadow: 0 0 10px 1px rgba(237, 207, 114, 0.2381), inset 0 0 0 1px rgba(255, 255, 255, 0.28571); }
.tile-256 { background: #edcc61; color: #f9f6f2; box-shadow: 0 0 12px 2px rgba(237, 204, 97, 0.31746), inset 0 0 0 1px rgba(255, 255, 255, 0.38095); }
.tile-512 { background: #edc850; color: #f9f6f2; box-shadow: 0 0 14px 3px rgba(237, 200, 80, 0.39683), inset 0 0 0 1px rgba(255, 255, 255, 0.47619); }
.tile-1024 { background: #edc53f; color: #f9f6f2; box-shadow: 0 0 16px 4px rgba(237, 197, 63, 0.47619), inset 0 0 0 1px rgba(255, 255, 255, 0.57143); }
.tile-2048 { background: #edc22e; color: #f9f6f2; box-shadow: 0 0 18px 5px rgba(237, 194, 46, 0.55556), inset 0 0 0 1px rgba(255, 255, 255, 0.66667); }
.tile-4096 { background: #3c3a32; color: #f9f6f2; }
.tile-8192 { background: #1f1e1a; color: #f9f6f2; }

.game-over-overlay {
  position: absolute;
  inset: 0;
  background: rgba(238, 228, 218, 0.73);
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  animation: fade-in 0.8s ease-in;
  border-radius: 12px;
}

.game-over-overlay p {
  font-size: 2.5rem;
  font-weight: 700;
  color: #776e65;
  margin-bottom: 1.5rem;
}

.game-over-overlay .offline-game-reset {
  padding: 0.8rem 1.6rem;
  font-size: 1.2rem;
  font-weight: 700;
  background: #8f7a66;
  color: #f9f6f2;
  border: none;
  border-radius: 6px;
  cursor: pointer;
}

.game-over-overlay .offline-game-reset:hover {
  background: #7f6a56;
}

@keyframes fade-in {
  0% { opacity: 0; }
  100% { opacity: 1; }
}

.offline-game-help {
  margin: 0.6rem 0 0;
  font-size: 0.8rem;
  color: var(--text-secondary);
}


@media (max-width: 640px) {
  .heatmap-tooltip {
    max-width: calc(100vw - 16px);
    white-space: normal;
    overflow-wrap: anywhere;
  }
}

@media (max-width: 900px) {
  .grid.two {
    grid-template-columns: minmax(0, 1fr);
    width: 100%;
  }

  .grid.two > .card {
    width: 100%;
    box-sizing: border-box;
  }

  .timeline-row {
    grid-template-columns: 48px 1fr 52px;
  }

  .chart-wrap {
    min-height: 220px;
  }
}

@media (min-width: 901px) {
  table.primary {
    min-width: 0;
  }
}

@media (max-width: 640px) {
  .container {
    padding: 0.8rem;
  }

  .presence-strip {
    top: 0.35rem;
    gap: 0.45rem;
    padding: 0.42rem;
  }

  .presence-pill {
    min-width: 0;
    flex: 1 1 auto;
  }

  .lang-selector {
    margin-inline-start: 0;
    margin-inline-end: 0;
  }

  .lang-buttons {
    display: none;
  }

  .lang-dropdown-label {
    display: inline-block;
    font-size: 0.76rem;
    color: var(--text-secondary);
  }

  .lang-dropdown {
    display: inline-block;
    min-width: 72px;
  }

  .hero h1 {
    font-size: 1.4rem;
  }

  .hero p,
  .hero small,
  .card p {
    font-size: 0.88rem;
  }

  .card {
    padding: 0.75rem;
  }

  .grid.two {
    width: 100%;
  }

  .grid.two > .card {
    width: 100%;
  }

  .status-row {
    align-items: flex-start;
    gap: 0.5rem;
  }

  .status-actions {
    gap: 0.45rem;
  }

  .status-clock-panel {
    flex-wrap: wrap;
    max-width: 100%;
  }

  .status-time-info {
    min-width: 0;
  }

  table.primary {
    font-size: 0.82rem;
    min-width: 380px;
  }

  table.primary th,
  table.primary td {
    padding: 0.38rem 0.32rem;
    white-space: nowrap;
  }

  .timeline-row {
    grid-template-columns: 42px 1fr 46px;
    gap: 0.35rem;
  }

  .timeline-track {
    height: 12px;
  }

  .timeline-label,
  .timeline-total {
    font-size: 0.74rem;
  }

  .heatmap-grid {
    grid-template-columns: 34px repeat(7, minmax(36px, 1fr));
    gap: 3px;
    font-size: 0.67rem;
    min-width: 360px;
  }

  .heatmap-wrap {
    overflow-x: auto;
    overflow-y: hidden;
  }

  .heatmap-cell {
    height: 11px;
    border-radius: 2px;
  }

  .chart-wrap {
    min-height: 200px;
  }

  .offline-game-head {
    flex-direction: column;
    align-items: stretch;
  }

  .offline-game-stats {
    gap: 0.35rem;
  }

  .offline-game-stat {
    min-width: 82px;
    padding: 0.32rem 0.48rem;
  }

  .offline-game-board {
    width: min(100%, 320px);
  }
}
