html,
body {
  width: 100%;
  height: 100%;
  min-height: 100%;
}

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

body {
  margin: 0;
  overflow: hidden;
  position: relative;
  background-color: #000;
  background-image:
    url("../assets/bg.png"),
    radial-gradient(circle at 20% 15%, rgba(80, 150, 255, 0.32), transparent 34%),
    radial-gradient(circle at 80% 85%, rgba(180, 80, 255, 0.22), transparent 30%),
    linear-gradient(135deg, #101827, #03060d);
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
  color: #eee;
  font-family: Arial, sans-serif;
}

body.math-page {
  overflow: auto;
  background-image:
    url("../assets/bg.png"),
    radial-gradient(circle at 14% 12%, rgba(91, 141, 255, 0.36), transparent 30%),
    radial-gradient(circle at 86% 18%, rgba(255, 96, 172, 0.22), transparent 28%),
    radial-gradient(circle at 52% 90%, rgba(66, 211, 146, 0.18), transparent 32%),
    linear-gradient(135deg, #080b12, #111622 52%, #090b10);
  background-attachment: fixed;
}

body::before {
  position: fixed;
  inset: 0;
  z-index: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(6px);
  content: "";
  pointer-events: none;
}

button,
input {
  font: inherit;
}

.container {
  position: relative;
  z-index: 1;
  display: flex;
  width: 100%;
  min-height: 100%;
  height: 100%;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: fadeIn 0.4s ease;
  transform: translateY(-6%);
}

.logo {
  margin-bottom: 25px;
  color: white;
  font-size: clamp(42px, 7vw, 64px);
  opacity: 0.95;
  text-shadow: 0 4px 20px rgba(0, 0, 0, 0.7);
  animation: fadeUp 0.5s ease;
}

.search-box {
  position: relative;
  display: flex;
  width: 580px;
  max-width: 90vw;
  height: 48px;
  align-items: center;
  border-radius: 999px;
  padding: 0 20px 0 52px;
  background: rgba(255, 255, 255, 0.18);
  backdrop-filter: blur(12px);
  box-shadow: 0 6px 25px rgba(0, 0, 0, 0.6);
  transform-origin: center;
  transition: 0.2s;
  animation: fadeUp 0.6s ease;
}

.search-box::before {
  position: absolute;
  left: 20px;
  width: 19px;
  height: 19px;
  background: rgba(255, 255, 255, 0.68);
  content: "";
  pointer-events: none;
  -webkit-mask: url("../assets/search.svg") center / contain no-repeat;
  mask: url("../assets/search.svg") center / contain no-repeat;
}

.search-box:hover,
.search-box:focus-within {
  background: rgba(255, 255, 255, 0.25);
  transform: scale(1.02);
}

.search-box input {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  color: white;
  font-size: 16px;
}

.search-box input::placeholder {
  color: rgba(255, 255, 255, 0.68);
}

.shortcuts {
  display: flex;
  width: 600px;
  max-width: 90vw;
  flex-wrap: wrap;
  justify-content: center;
  gap: 22px;
  margin-top: 30px;
  animation: fadeUp 0.7s ease;
}

@media (max-height: 620px) {
  .container {
    transform: translateY(-2%);
  }

  .logo {
    margin-bottom: 18px;
  }

  .shortcuts {
    gap: 14px;
    margin-top: 20px;
  }

  .shortcut {
    height: 96px;
  }
}

.shortcut {
  position: relative;
  display: flex;
  width: 100px;
  height: 110px;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border-radius: 14px;
  cursor: pointer;
  transition: all 0.18s ease;
}

.shortcut:hover {
  transform: translateY(-4px);
}

.icon {
  display: flex;
  width: 52px;
  height: 52px;
  align-items: center;
  justify-content: center;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.15);
  backdrop-filter: blur(10px);
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.4);
  transition: all 0.18s ease;
}

.shortcut:hover .icon {
  background: rgba(255, 255, 255, 0.25);
  box-shadow: 0 6px 20px rgba(255, 255, 255, 0.15);
}

.icon img {
  width: 65%;
  height: 65%;
  object-fit: contain;
}

.shortcut span {
  margin-top: 10px;
  color: rgba(255, 255, 255, 0.9);
  font-size: 13px;
  text-align: center;
}

.add-tile {
  color: white;
  font-size: 26px;
}

.menu {
  position: absolute;
  top: 6px;
  right: 6px;
  z-index: 5;
  padding: 6px;
  color: rgba(255, 255, 255, 0.8);
  cursor: pointer;
  font-size: 16px;
  opacity: 0;
  transition: 0.15s;
}

.shortcut:hover .menu {
  opacity: 1;
}

.menu:hover {
  color: white;
}

.modal {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 999;
  display: flex;
  width: 100%;
  height: 100%;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.8);
  animation: fadeIn 0.2s ease;
}

.hidden {
  display: none;
}

.modal-content {
  width: 320px;
  border-radius: 16px;
  padding: 22px;
  background: rgba(30, 30, 30, 0.95);
  backdrop-filter: blur(10px);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.7);
  animation: popIn 0.2s ease;
}

.modal-content h3 {
  margin: 0 0 14px;
  color: white;
  font-size: 18px;
  font-weight: 500;
}

.modal-content input {
  width: 100%;
  margin-bottom: 12px;
  border: none;
  border-radius: 8px;
  outline: none;
  padding: 11px 12px;
  background: rgba(255, 255, 255, 0.1);
  color: white;
  font-size: 14px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 8px;
}

.modal-actions button {
  border: none;
  border-radius: 8px;
  padding: 8px 14px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
}

#save-btn {
  background: #3b82f6;
  color: white;
}

#cancel-btn {
  background: transparent;
  color: rgba(255, 255, 255, 0.7);
}

.danger {
  background: transparent;
  color: #ff5f56;
}

.math-shell {
  position: relative;
  z-index: 1;
  width: min(1320px, 100%);
  min-height: 100%;
  margin: 0 auto;
  padding: 30px 24px 42px;
}

.math-hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 430px);
  align-items: end;
  gap: 18px;
  margin-bottom: 20px;
}

.math-eyebrow {
  margin: 0 0 7px;
  color: rgba(255, 255, 255, 0.58);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.math-hero h1 {
  margin: 0;
  color: #fff;
  font-size: clamp(42px, 7vw, 76px);
  line-height: 0.95;
  text-shadow: 0 16px 44px rgba(0, 0, 0, 0.42);
}

.math-search {
  position: relative;
  width: 100%;
}

.math-search::before {
  position: absolute;
  top: 50%;
  left: 16px;
  z-index: 1;
  width: 16px;
  height: 16px;
  background: rgba(255, 255, 255, 0.62);
  content: "";
  pointer-events: none;
  transform: translateY(-50%);
  -webkit-mask: url("../assets/search.svg") center / contain no-repeat;
  mask: url("../assets/search.svg") center / contain no-repeat;
}

.math-search input {
  width: 100%;
  height: 46px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 999px;
  outline: none;
  padding: 0 18px 0 42px;
  background: rgba(10, 13, 20, 0.68);
  color: #fff;
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.06) inset,
    0 16px 36px rgba(0, 0, 0, 0.22);
  backdrop-filter: blur(16px);
  font-size: 15px;
}

.math-search input::placeholder {
  color: rgba(255, 255, 255, 0.54);
}

.math-search input:focus {
  border-color: rgba(125, 211, 252, 0.72);
  box-shadow:
    0 0 0 4px rgba(125, 211, 252, 0.13),
    0 16px 36px rgba(0, 0, 0, 0.24);
}

.math-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}

.math-categories {
  display: flex;
  min-width: 0;
  flex: 1;
  gap: 8px;
  overflow-x: auto;
  padding: 2px 1px 8px;
  scroll-behavior: smooth;
}

.category-chip,
.math-action,
.page-chip {
  border: 1px solid rgba(255, 255, 255, 0.13);
  border-radius: 999px;
  padding: 9px 14px;
  background: rgba(255, 255, 255, 0.08);
  color: rgba(255, 255, 255, 0.76);
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
  transition:
    background-color 0.16s ease,
    border-color 0.16s ease,
    color 0.16s ease,
    opacity 0.16s ease,
    transform 0.16s ease;
}

.category-chip:hover,
.math-action:hover,
.page-chip:hover:not(:disabled) {
  border-color: rgba(255, 255, 255, 0.24);
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  transform: translateY(-1px);
}

.category-chip.active,
.page-chip.active {
  border-color: rgba(125, 211, 252, 0.62);
  background: rgba(125, 211, 252, 0.18);
  color: #e9f8ff;
}

.math-action {
  flex: 0 0 auto;
  background: linear-gradient(135deg, #38bdf8, #8b5cf6);
  color: #fff;
  box-shadow: 0 12px 28px rgba(56, 189, 248, 0.18);
}

.math-action:disabled,
.page-chip:disabled {
  cursor: default;
  opacity: 0.42;
  transform: none;
}

.math-status-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 28px;
  margin-bottom: 12px;
  color: rgba(255, 255, 255, 0.58);
  font-size: 13px;
  font-weight: 700;
}

.math-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(172px, 1fr));
  gap: 14px;
}

.game-card {
  position: relative;
  display: flex;
  min-width: 0;
  aspect-ratio: 0.78;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.06), transparent),
    rgba(14, 18, 28, 0.72);
  color: #fff;
  cursor: pointer;
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.06) inset,
    0 20px 42px rgba(0, 0, 0, 0.28);
  text-align: left;
  transform: translateY(0);
  transition:
    border-color 0.16s ease,
    box-shadow 0.16s ease,
    transform 0.16s ease;
}

.game-card:hover,
.game-card:focus-visible {
  border-color: rgba(125, 211, 252, 0.48);
  box-shadow:
    0 0 0 3px rgba(125, 211, 252, 0.12),
    0 24px 52px rgba(0, 0, 0, 0.34);
  transform: translateY(-4px);
}

.game-card.launching {
  opacity: 0.76;
}

.game-art {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  background:
    radial-gradient(circle at 30% 10%, rgba(125, 211, 252, 0.28), transparent 34%),
    linear-gradient(135deg, #151b28, #0d1018);
}

.game-art img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scale(1);
  transition: transform 0.22s ease;
}

.game-card:hover .game-art img {
  transform: scale(1.05);
}

.game-fallback {
  display: grid;
  width: 100%;
  height: 100%;
  place-items: center;
  background:
    radial-gradient(circle at 50% 28%, rgba(255, 255, 255, 0.18), transparent 34%),
    linear-gradient(135deg, #2563eb, #9333ea);
  color: #fff;
  font-size: 44px;
  font-weight: 800;
}

.game-meta {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  display: grid;
  min-height: 54px;
  align-content: end;
  padding: 28px 12px 12px;
  background: linear-gradient(to top, rgba(5, 7, 12, 0.9), rgba(5, 7, 12, 0));
}

.game-meta strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.game-meta strong {
  color: #fff;
  font-size: 13.5px;
  line-height: 1.2;
}

.game-card-loading {
  pointer-events: none;
}

.game-card-loading div,
.game-card-loading span {
  margin: 12px;
  border-radius: 8px;
  background: linear-gradient(
    90deg,
    rgba(255, 255, 255, 0.06),
    rgba(255, 255, 255, 0.16),
    rgba(255, 255, 255, 0.06)
  );
  background-size: 220% 100%;
  animation: loadingSweep 1.1s linear infinite;
}

.game-card-loading div {
  flex: 1;
  margin-bottom: 0;
}

.game-card-loading span {
  display: block;
  height: 38px;
}

.math-message {
  grid-column: 1 / -1;
  width: min(520px, 100%);
  margin: 40px auto;
  border: 1px solid rgba(255, 255, 255, 0.13);
  border-radius: 8px;
  padding: 24px;
  background: rgba(13, 17, 25, 0.76);
  backdrop-filter: blur(14px);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.32);
  text-align: center;
}

.math-message h2 {
  margin: 0 0 8px;
  color: #fff;
  font-size: 22px;
}

.math-message p {
  margin: 0;
  color: rgba(255, 255, 255, 0.66);
  font-size: 14px;
  line-height: 1.5;
}

.math-message button {
  margin-top: 18px;
  border: 1px solid rgba(125, 211, 252, 0.54);
  border-radius: 999px;
  padding: 10px 16px;
  background: rgba(125, 211, 252, 0.15);
  color: #e9f8ff;
  cursor: pointer;
  font-size: 14px;
  font-weight: 700;
}

.math-pagination {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-top: 22px;
}

.credits-page {
  overflow: auto;
  background-image:
    url("../assets/bg.png"),
    radial-gradient(circle at 18% 16%, rgba(125, 211, 252, 0.32), transparent 32%),
    radial-gradient(circle at 78% 80%, rgba(167, 139, 250, 0.24), transparent 32%),
    linear-gradient(135deg, #080b12, #111622 58%, #090b10);
  background-attachment: fixed;
}

.credits-shell {
  position: relative;
  z-index: 1;
  display: grid;
  width: 100%;
  min-height: 100%;
  place-items: center;
  padding: 30px 20px;
}

.credits-panel {
  width: min(620px, 100%);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  padding: 34px;
  background: rgba(12, 16, 24, 0.76);
  backdrop-filter: blur(16px);
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.06) inset,
    0 24px 70px rgba(0, 0, 0, 0.38);
  animation: popIn 0.22s ease;
}

.credits-icon {
  width: 52px;
  height: 52px;
  margin-bottom: 18px;
}

.credits-eyebrow {
  margin: 0 0 8px;
  color: rgba(125, 211, 252, 0.86);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.credits-panel h1 {
  margin: 0 0 16px;
  color: #fff;
  font-size: clamp(34px, 7vw, 58px);
  line-height: 1;
}

.credits-panel p {
  margin: 0 0 12px;
  color: rgba(255, 255, 255, 0.72);
  font-size: 16px;
  line-height: 1.62;
}

.credits-panel a {
  color: #9bddff;
  font-weight: 800;
  text-decoration: none;
}

.credits-panel a:hover {
  text-decoration: underline;
}

.credits-panel button {
  margin-top: 18px;
  border: 1px solid rgba(125, 211, 252, 0.54);
  border-radius: 999px;
  padding: 11px 17px;
  background: rgba(125, 211, 252, 0.15);
  color: #e9f8ff;
  cursor: pointer;
  font-size: 14px;
  font-weight: 800;
  transition:
    background-color 0.16s ease,
    transform 0.16s ease;
}

.credits-panel button:hover {
  background: rgba(125, 211, 252, 0.22);
  transform: translateY(-1px);
}

.error-shell {
  position: relative;
  z-index: 1;
  display: grid;
  width: 100%;
  height: 100%;
  min-height: 100%;
  place-items: center;
  padding: 24px;
}

.error-panel {
  width: min(520px, 100%);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 18px;
  padding: 30px;
  background: rgba(20, 23, 30, 0.72);
  backdrop-filter: blur(16px);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.42);
  animation: popIn 0.22s ease;
}

.error-code {
  width: max-content;
  margin-bottom: 16px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 999px;
  padding: 6px 11px;
  background: rgba(255, 255, 255, 0.1);
  color: rgba(255, 255, 255, 0.76);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
}

.error-panel h1 {
  margin: 0 0 12px;
  color: #fff;
  font-size: clamp(30px, 6vw, 46px);
  line-height: 1.04;
}

.error-panel p {
  margin: 0;
  color: rgba(255, 255, 255, 0.74);
  font-size: 15px;
  line-height: 1.55;
}

.error-panel strong,
.error-file span {
  color: #fff;
  font-weight: 700;
}

.error-file {
  margin-top: 10px !important;
  color: rgba(255, 255, 255, 0.58) !important;
}

.error-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 24px;
}

.error-actions button {
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 999px;
  padding: 10px 16px;
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  cursor: pointer;
  font-size: 14px;
  font-weight: 700;
  transition:
    background-color 0.16s ease,
    border-color 0.16s ease,
    transform 0.16s ease;
}

.error-actions button:first-child {
  border-color: rgba(98, 177, 255, 0.58);
  background: #3b82f6;
}

.error-actions button:hover {
  background: rgba(255, 255, 255, 0.16);
  transform: translateY(-1px);
}

.error-actions button:first-child:hover {
  background: #4f8df7;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

@keyframes fadeUp {
  from {
    opacity: 0;
    transform: translateY(10px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes popIn {
  from {
    opacity: 0;
    transform: scale(0.9);
  }

  to {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes loadingSweep {
  from {
    background-position: 120% 0;
  }

  to {
    background-position: -120% 0;
  }
}

@media (max-width: 760px) {
  .math-shell {
    padding: 22px 16px 34px;
  }

  .math-hero {
    grid-template-columns: 1fr;
    align-items: start;
  }

  .math-toolbar,
  .math-status-row {
    align-items: stretch;
    flex-direction: column;
  }

  .math-action {
    width: 100%;
  }

  .math-grid {
    grid-template-columns: repeat(auto-fill, minmax(146px, 1fr));
    gap: 11px;
  }
}
