/**
 * Modal tải game — tấm kính sáng, kiểu Apple Liquid Glass
 */

:root {
  --tt-blue: #007aff;
  --tt-blue-deep: #0066d6;
  --tt-ink: #1d1d1f;
  --tt-muted: #6e6e73;
  --tt-tertiary: #86868b;
  --tt-danger: #ff3b30;
}

html.tt-modal-open,
body.tt-modal-open {
  overflow: hidden !important;
}

.tt-modal-backdrop {
  position: fixed;
  inset: 0;
  width: auto;
  height: auto;
  background: rgba(15, 23, 42, 0.28);
  backdrop-filter: blur(6px) saturate(120%);
  -webkit-backdrop-filter: blur(6px) saturate(120%);
  z-index: 999999;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.28s ease, visibility 0.28s ease;
  padding: 18px;
  box-sizing: border-box;
  overflow: hidden;
}

.tt-modal-backdrop.is-active {
  opacity: 1;
  visibility: visible;
}

.tt-modal-dialog {
  position: relative;
  width: min(640px, 100%);
  max-width: 640px;
  margin: 0 auto;
  border-radius: 28px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.96) 0%, rgba(255, 255, 255, 0.92) 100%);
  border: 1px solid rgba(255, 255, 255, 0.78);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.95),
    inset 0 -1px 0 rgba(20, 40, 80, 0.05),
    0 24px 70px rgba(20, 40, 80, 0.18),
    0 2px 8px rgba(20, 40, 80, 0.06);
  color: var(--tt-ink);
  overflow: hidden;
  transform: translateY(18px) scale(0.985);
  opacity: 0;
  transition: transform 0.38s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.28s ease;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI Variable Display", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.tt-modal-backdrop.is-active .tt-modal-dialog {
  transform: translateY(0) scale(1);
  opacity: 1;
}

.tt-modal-dialog::before {
  content: "";
  position: absolute;
  left: 14%;
  right: 14%;
  top: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.98), transparent);
  pointer-events: none;
  z-index: 4;
}

.tt-modal-dialog::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: 72px;
  border-radius: 28px 28px 0 0;
  pointer-events: none;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.35), rgba(255, 255, 255, 0));
  z-index: 1;
}

.tt-sheet-grabber {
  position: absolute;
  top: 8px;
  left: 50%;
  width: 36px;
  height: 5px;
  margin-left: -18px;
  border-radius: 999px;
  background: rgba(60, 60, 67, 0.28);
  z-index: 6;
}

.tt-modal-close,
.tt-modal-header,
.tt-modal-body,
.tt-modal-footer {
  position: relative;
  z-index: 2;
}

.tt-modal-close {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: rgba(120, 120, 128, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.55);
  color: var(--tt-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 8;
  padding: 0;
  transition: background 0.2s ease, color 0.2s ease, transform 0.2s ease;
}

.tt-modal-close svg {
  width: 14px;
  height: 14px;
}

.tt-modal-close:hover {
  background: rgba(120, 120, 128, 0.2);
  color: var(--tt-ink);
  transform: scale(1.04);
}

.tt-modal-header {
  padding: 28px 56px 14px;
  text-align: center;
}

.tt-modal-title {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--tt-ink);
  line-height: 1.2;
}

.tt-modal-subtitle {
  margin: 6px 0 0;
  font-size: 13px;
  color: var(--tt-muted);
  letter-spacing: -0.01em;
}

.tt-modal-body {
  padding: 6px 16px 16px;
  max-height: calc(85vh - 180px);
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(0, 122, 255, 0.35) transparent;
}

.tt-modal-body::-webkit-scrollbar { width: 8px; }

.tt-modal-body::-webkit-scrollbar-thumb {
  background: rgba(0, 122, 255, 0.28);
  border-radius: 999px;
}

.tt-modal-loader {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 42px 20px;
  gap: 14px;
}

.tt-spinner {
  width: 36px;
  height: 36px;
  border: 3px solid rgba(0, 122, 255, 0.15);
  border-top-color: var(--tt-blue);
  border-radius: 50%;
  animation: ttSpin 0.75s linear infinite;
}

@keyframes ttSpin {
  to { transform: rotate(360deg); }
}

.tt-loader-text {
  font-size: 14px;
  color: var(--tt-muted);
  font-weight: 500;
}

.tt-download-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.tt-list-empty {
  text-align: center;
  padding: 28px 16px;
  color: var(--tt-danger);
  font-size: 14px;
  font-weight: 600;
}

.tt-download-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 12px 12px 14px;
  background: rgba(255, 255, 255, 0.48);
  border: 1px solid rgba(255, 255, 255, 0.72);
  border-radius: 18px;
  text-decoration: none;
  color: inherit;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.85);
  transition: background 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease;
}

.tt-download-card:hover {
  background: rgba(255, 255, 255, 0.78);
  transform: translateY(-1px);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.95),
    0 10px 24px rgba(28, 55, 110, 0.08);
}

.tt-card-left {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
  min-width: 0;
}

.tt-card-icon {
  width: 46px;
  height: 46px;
  border-radius: 14px;
  background: rgba(0, 122, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: var(--tt-blue);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.7);
  transition: background 0.2s ease, color 0.2s ease, transform 0.2s ease;
}

.tt-download-card--android .tt-card-icon {
  color: #248a3d;
  background: rgba(52, 199, 89, 0.14);
}

.tt-download-card--google-play .tt-card-icon {
  color: #1a73e8;
  background: rgba(26, 115, 232, 0.12);
}

.tt-download-card--apple .tt-card-icon,
.tt-download-card--testflight .tt-card-icon {
  color: #1d1d1f;
  background: rgba(255, 255, 255, 0.7);
}

.tt-download-card--windows .tt-card-icon {
  color: #0078d4;
  background: rgba(0, 120, 212, 0.12);
}

.tt-download-card:hover .tt-card-icon {
  transform: scale(1.04);
}

.tt-card-icon svg {
  width: 22px;
  height: 22px;
  fill: currentColor;
}

.tt-card-info { flex: 1; min-width: 0; }

.tt-card-title-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.tt-card-title {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--tt-ink);
}

.tt-card-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(0, 122, 255, 0.1);
  color: var(--tt-blue);
}

.tt-card-desc {
  margin: 2px 0 0;
  font-size: 12.5px;
  color: var(--tt-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tt-card-meta {
  margin-top: 3px;
  font-size: 11px;
  color: var(--tt-tertiary);
  display: flex;
  align-items: center;
  gap: 6px;
}

.tt-card-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(0, 122, 255, 0.12);
  border: 1px solid rgba(0, 122, 255, 0.08);
  color: var(--tt-blue);
  font-size: 13px;
  font-weight: 700;
  flex-shrink: 0;
  white-space: nowrap;
  transition: background 0.2s ease, color 0.2s ease, box-shadow 0.2s ease;
}

.tt-card-btn svg {
  width: 14px;
  height: 14px;
  fill: currentColor;
}

.tt-download-card:hover .tt-card-btn {
  background: linear-gradient(180deg, #3d9bff 0%, #007aff 100%);
  color: #fff;
  border-color: transparent;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.35), 0 6px 14px rgba(0, 122, 255, 0.28);
}

.tt-download-card.is-disabled {
  opacity: 0.65;
  cursor: not-allowed;
}

.tt-download-card.is-disabled:hover {
  background: rgba(255, 255, 255, 0.48);
  transform: none;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.85);
}

.tt-download-card.is-disabled .tt-card-btn {
  background: rgba(120, 120, 128, 0.12);
  border-color: rgba(120, 120, 128, 0.2);
  color: var(--tt-muted);
  box-shadow: none;
}

.tt-download-card.is-disabled:hover .tt-card-btn {
  background: rgba(120, 120, 128, 0.15);
  color: var(--tt-muted);
  box-shadow: none;
}

.tt-download-card.is-disabled .tt-card-badge {
  background: rgba(120, 120, 128, 0.12);
  color: var(--tt-muted);
}

.tt-modal-error {
  text-align: center;
  padding: 32px 16px;
}

.tt-modal-error-msg {
  color: var(--tt-danger);
  font-size: 14px;
  margin-bottom: 14px;
}

.tt-modal-retry-btn {
  padding: 9px 18px;
  background: var(--tt-blue);
  color: #fff;
  border: none;
  border-radius: 999px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.35);
}

.tt-modal-retry-btn:hover { filter: brightness(1.05); }

.tt-modal-footer {
  padding: 12px 18px 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 6px;
  font-size: 12.5px;
  color: var(--tt-muted);
}

.tt-modal-footer a {
  color: var(--tt-blue);
  text-decoration: none;
  font-weight: 600;
}

.tt-modal-footer a:hover { text-decoration: underline; }

.tt-modal-close:focus-visible,
.tt-download-card:focus-visible,
.tt-modal-retry-btn:focus-visible {
  outline: 2px solid var(--tt-blue);
  outline-offset: 2px;
}

@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .tt-modal-backdrop { background: rgba(232, 238, 246, 0.92); }
  .tt-modal-dialog { background: rgba(255, 255, 255, 0.96); }
}

@media (max-width: 640px) {
  .tt-modal-backdrop {
    padding: 12px;
  }

  .tt-modal-dialog {
    width: 100%;
    max-width: 100%;
    border-radius: 22px;
  }

  .tt-modal-close {
    top: 12px;
    right: 12px;
    width: 30px;
    height: 30px;
  }

  .tt-modal-header {
    padding: 22px 36px 10px;
  }

  .tt-modal-title {
    font-size: 19px;
  }

  .tt-modal-subtitle {
    font-size: 12.5px;
    margin-top: 4px;
    line-height: 1.4;
  }

  .tt-modal-body {
    padding: 4px 10px 14px;
    max-height: calc(85vh - 135px);
    scrollbar-width: thin;
  }

  .tt-modal-body::-webkit-scrollbar {
    width: 4px;
  }

  .tt-modal-body::-webkit-scrollbar-thumb {
    background: rgba(0, 122, 255, 0.2);
    border-radius: 999px;
  }

  .tt-download-list {
    gap: 10px;
  }

  /* Card tải game trên mobile: Bố cục 2 tầng (Icon + Thông tin ở trên, Nút tải rộng ở dưới) */
  .tt-download-card {
    flex-direction: column;
    align-items: stretch;
    padding: 12px 14px;
    gap: 10px;
    border-radius: 16px;
  }

  .tt-card-left {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    min-width: 0;
  }

  .tt-card-icon {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    margin-top: 0;
    flex-shrink: 0;
  }

  .tt-card-icon svg {
    width: 20px;
    height: 20px;
  }

  .tt-card-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
  }

  .tt-card-title-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
    width: 100%;
  }

  .tt-card-title {
    font-size: 14.5px;
    font-weight: 700;
    line-height: 1.3;
    color: var(--tt-ink);
  }

  .tt-card-badge {
    font-size: 10px;
    padding: 2px 7px;
    flex-shrink: 0;
  }

  .tt-card-desc {
    font-size: 12px;
    line-height: 1.35;
    color: var(--tt-muted);
    white-space: normal;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    margin-top: 2px;
  }

  .tt-card-meta {
    margin-top: 4px;
    font-size: 11px;
    color: var(--tt-tertiary);
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
  }

  /* Nút bấm tải game trên mobile: Rộng 100%, to rõ, chuẩn ngón tay cái */
  .tt-card-btn {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 10px 14px;
    font-size: 13px;
    font-weight: 700;
    border-radius: 11px;
    box-sizing: border-box;
    gap: 6px;
  }

  .tt-modal-footer {
    padding: 10px 14px 14px;
    font-size: 12px;
    gap: 4px;
  }
}

@media (max-width: 375px) {
  .tt-modal-backdrop {
    padding: 8px;
  }
  .tt-modal-header {
    padding: 18px 28px 8px;
  }
  .tt-modal-title {
    font-size: 17.5px;
  }
  .tt-card-title {
    font-size: 13.5px;
  }
}


@media (prefers-reduced-motion: reduce) {
  .tt-modal-dialog,
  .tt-download-card,
  .tt-spinner {
    transition: none;
    animation: none;
  }
}

/* Thẻ tải game bị vô hiệu hóa khi CDN chưa cho tải */
.tt-download-card.is-disabled {
  opacity: 0.62;
  filter: grayscale(0.85);
  cursor: not-allowed;
}

.tt-download-card.is-disabled:hover {
  transform: none;
  background: rgba(255, 255, 255, 0.48);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.85);
}

.tt-download-card.is-disabled .tt-card-btn {
  background: #9ca3af;
  color: #fff;
  box-shadow: none;
}

/* Toast Notification Thông Báo Tải Game (Chống spam, iOS Glassmorphism) */
.tt-toast {
  position: fixed;
  top: 24px;
  left: 50%;
  transform: translate(-50%, -120%);
  z-index: 999999;
  opacity: 0;
  pointer-events: none;
  transition: transform 0.35s cubic-bezier(0.175, 0.885, 0.32, 1.275), opacity 0.25s ease;
  max-width: min(92vw, 440px);
  width: max-content;
}

.tt-toast.is-visible {
  transform: translate(-50%, 0);
  opacity: 1;
  pointer-events: auto;
}

.tt-toast.is-pulse {
  animation: ttToastPulse 0.32s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes ttToastPulse {
  0% { transform: translate(-50%, 0) scale(1); }
  50% { transform: translate(-50%, 0) scale(1.05); }
  100% { transform: translate(-50%, 0) scale(1); }
}

.tt-toast-content {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 16px 11px 13px;
  background: rgba(22, 22, 26, 0.95);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 18px;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.38), inset 0 1px 0 rgba(255, 255, 255, 0.22);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  color: #fff;
  cursor: pointer;
  user-select: none;
  box-sizing: border-box;
}

.tt-toast-icon {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: rgba(245, 158, 11, 0.2);
  border: 1px solid rgba(245, 158, 11, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: #f59e0b;
}

.tt-toast-icon svg {
  width: 17px;
  height: 17px;
}

.tt-toast-body {
  display: flex;
  flex-direction: column;
  gap: 1px;
  text-align: left;
}

.tt-toast-title {
  font-size: 12.5px;
  font-weight: 700;
  color: #fbbf24;
  letter-spacing: -0.01em;
  line-height: 1.2;
}

.tt-toast-msg {
  font-size: 12.5px;
  color: rgba(255, 255, 255, 0.92);
  font-weight: 500;
  line-height: 1.35;
}

.tt-toast-close {
  background: rgba(255, 255, 255, 0.12);
  border: none;
  color: rgba(255, 255, 255, 0.7);
  width: 22px;
  height: 22px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  line-height: 1;
  padding: 0;
  margin-left: 4px;
  transition: background 0.2s, color 0.2s;
  flex-shrink: 0;
}

.tt-toast-close:hover {
  background: rgba(255, 255, 255, 0.25);
  color: #fff;
}
