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

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

body {
  background: #000;
  font-family: Arial, Helvetica, sans-serif;
  color: #fff;
  overflow-x: hidden;
  overflow-y: auto;
}

.app {
  width: 100%;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  height: 74px;
  display: flex;
  align-items: center;
  padding: 0 18px;
  gap: 18px;
  flex-shrink: 0;
}

.back {
  font-size: 42px;
  line-height: 1;
  font-weight: 300;
  margin-top: -2px;
}

.title {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: 0.2px;
}

.title span {
  font-weight: 500;
}

.game-area {
  flex: 1;
  min-height: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 12px;
  overflow: hidden;
}

.grid {
  width: min(62vw, 560px);
  max-width: 100%;
  max-height: calc(100vh - 74px - 96px - 24px);
  aspect-ratio: 1 / 1;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  position: relative;
}

.cell {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  border-right: 1px solid rgba(255, 255, 255, 0.9);
  border-bottom: 1px solid rgba(255, 255, 255, 0.9);
  min-width: 0;
  min-height: 0;
}

.cell:nth-child(3n) {
  border-right: none;
}

.cell:nth-child(n + 7) {
  border-bottom: none;
}

.square,
.cell img {
  width: 74%;
  height: 74%;
  max-width: 100%;
  max-height: 100%;
  object-fit: cover;
  border-radius: 12px;
  display: block;
}

.bottom-text {
  min-height: 96px;
  height: auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 24px;
  font-size: 16px;
  font-weight: 500;
  color: #f0f0f0;
  flex-shrink: 0;
}

.popup-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background-color: rgba(0, 0, 0, 0.5);
  z-index: 9999;
}

.popup-message {
  display: none;
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 10000;
  max-width: 420px;
  width: 90%;
}

.popup-content {
  background: rgba(20, 20, 25, 0.95);
  backdrop-filter: blur(20px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  padding: 40px 30px;
  border-radius: 20px;
  box-shadow: 0 25px 50px rgba(0, 0, 0, 0.5);
  text-align: center;
  position: relative;
  animation: fadeInUp 0.3s ease-out;
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translate(-50%, -60%);
  }
  to {
    opacity: 1;
    transform: translate(-50%, -50%);
  }
}

#popup-text {
  color: #e0e0e0;
  font-size: 1.3rem;
  margin: 0 0 25px 0;
  line-height: 1.4;
  font-weight: 400;
}

.play-btn {
  background: #1e285a;
  color: #fff;
  border: none;
  padding: 14px 32px;
  font-size: 1.1rem;
  font-weight: 600;
  border-radius: 50px;
  cursor: pointer;
  transition: 0.25s ease;
}

.play-btn:hover {
  background: #0930f7;
  transform: translateY(-2px);
}

.next-btn {
  background: #1238f5;
  margin-left: 10px;
}

.close-popup {
  position: absolute;
  top: 15px;
  right: 20px;
  font-size: 24px;
  color: #888;
  cursor: pointer;
  transition: color 0.2s;
}

.close-popup:hover {
  color: #fff;
}

.desktop-instructions {
  display: none;
}

.mobile-controls {
  display: flex;
  width: 100%;
  flex-direction: row;
  flex-wrap: nowrap;
  align-items: center;
  gap: 8px;
  overflow-x: auto;
  overflow-y: hidden;
  white-space: nowrap;
  padding: 0;
  -webkit-overflow-scrolling: touch;
}

.control-btn {
  flex: 1 1 0;
  min-width: 84px;
  height: 44px;
  padding: 0 10px;
  border: none;
  border-radius: 6px;
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  line-height: 1.1;
  white-space: normal;
  text-align: center;
  cursor: pointer;
}

.position-btn,
.shape-btn,
.color-btn,
.audio-btn {
  background: #fff !important;
  color: #000 !important;
}

.cell-number {
  font-weight: 900;
  font-size: 80px;
  line-height: 1;
}

@media (max-width: 991px) {
  .app {
    min-height: 100dvh;
  }

  .topbar {
    height: 64px;
    padding: 0 16px;
  }

  .game-area {
    padding: 8px 12px 6px;
    overflow: visible;
  }

  .grid {
    width: min(92vw, 420px);
    max-height: none;
    margin-top: -6px;
  }

  .bottom-text {
    width: 100%;
    min-width: 0;
    min-height: 72px;
    padding: 6px 10px calc(8px + env(safe-area-inset-bottom));
    align-items: flex-start;
    overflow: hidden;
  }

  .desktop-instructions {
    display: none;
  }

  .mobile-controls {
    display: flex;
  }

  .control-btn {
    min-width: 88px;
    height: 42px;
    font-size: 11px;
  }

  .cell-number {
    font-size: 80px;
  }
}

@media (max-width: 600px) {
  .topbar {
    height: 58px;
  }

  .title {
    font-size: 22px;
  }

  .game-area {
    padding: 4px 10px 4px;
  }

  .grid {
    width: min(90vw, 340px);
    margin-top: -4px;
  }

  .bottom-text {
    min-height: 68px;
    padding: 4px 8px calc(6px + env(safe-area-inset-bottom));
  }

  .control-btn {
    min-width: 84px;
    height: 40px;
    font-size: 11px;
  }
}

@media (min-width: 992px) {
  .game-area {
    padding: 12px;
  }

  .grid {
    width: min(62vw, 560px);
    max-width: 100%;
    max-height: calc(100vh - 74px - 96px - 24px);
  }

  .bottom-text {
    min-height: 96px;
    padding: 12px 24px;
    font-size: 18px;
  }

  .desktop-instructions {
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    gap: 24px;
    width: 100%;
    text-align: center;
  }

  .desktop-instructions > div {
    flex: 1;
    white-space: nowrap;
  }

  .mobile-controls {
    display: none;
  }

  .cell-number {
    font-size: 130px;
  }
}

/* tutorial popup */
:root {
  --info-modal-accent: #2390d5;
  --info-modal-bg: #ffffff;
  --info-modal-muted: #5b6675;
  --info-modal-overlay: rgba(15, 23, 42, 0.45);
  --info-modal-shadow: 0 20px 50px rgba(35, 144, 213, 0.22);
  --info-modal-radius: 18px;
}

.info-modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--info-modal-overlay);
}

.info-modal-card {
  position: relative;
  width: 100%;
  max-width: 520px;
  background: var(--info-modal-bg);
  border-radius: var(--info-modal-radius);
  padding: 32px 28px;
  box-shadow: var(--info-modal-shadow);
  border-top: 6px solid var(--info-modal-accent);
}

.info-modal-title {
  margin: 0 0 16px;
  font-size: 28px;
  line-height: 1.2;
  color: var(--info-modal-accent);
}

.info-modal-text {
  margin: 0;
  font-size: 16px;
  line-height: 1.7;
  color: var(--info-modal-muted);
}

.info-modal-close {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 50%;
  background: #eef7fd;
  color: var(--info-modal-accent);
  font-size: 22px;
  cursor: pointer;
}


.info-modal-title,
.info-modal-text,
.info-modal-close {
  opacity: 1;
}

.info-modal-card.is-animated {
  animation: infoModalPop 0.55s cubic-bezier(0.22, 1, 0.36, 1);
}

.info-modal-card.is-animated .info-modal-title {
  opacity: 0;
  transform: translateY(12px);
  animation: infoFadeUp 0.45s ease 0.2s forwards;
}

.info-modal-card.is-animated .info-modal-text {
  opacity: 0;
  transform: translateY(16px);
  clip-path: inset(0 0 100% 0);
  animation: infoTextReveal 0.9s ease 0.35s forwards;
}

.info-modal-card.is-animated .info-modal-close {
  opacity: 0;
  animation: infoFadeIn 0.35s ease 0.3s forwards;
}


/* effects */
@keyframes infoBackdropFade {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes infoModalPop {
  from {
    opacity: 0;
    transform: translateY(24px) scale(0.94);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes infoFadeUp {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

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

@keyframes infoTextReveal {
  from {
    opacity: 0;
    transform: translateY(16px);
    clip-path: inset(0 0 100% 0);
  }
  to {
    opacity: 1;
    transform: translateY(0);
    clip-path: inset(0 0 0 0);
  }
}

.cell {
    display: flex;
    justify-content: center;
    align-items: center;
}

.cell-number {
    white-space: nowrap; /* Prevent wrapping */
}

/* modern end score popup */
/* ============================
   MODERN N-BACK SCORE POPUP
   ============================ */

#nbscore_overlay{
    position:fixed;
    inset:0;
    display:none;
    justify-content:center;
    align-items:center;
    padding:16px;
    background:rgba(0,0,0,.45);
    z-index:999999;
    font-family:Arial,Helvetica,sans-serif;
}

#nbscore_modal{
    width:min(700px,95vw);
    background:#fff;
    border-radius:18px;
    overflow:hidden;
    box-shadow:0 20px 60px rgba(0,0,0,.35);
}

/* ---------- Header ---------- */

#nbscore_header{
    background:#1d95e8;
    color:#fff;
    display:flex;
    justify-content:space-between;
    align-items:center;
    padding:18px 24px;
}

#nbscore_title{
    font-size:22px;
    font-weight:700;
}

#nbscore_close{
    border:none;
    background:none;
    color:#fff;
    font-size:30px;
    cursor:pointer;
}

/* ---------- Body ---------- */

#nbscore_body{
    padding:24px;
}

#nbscore_level{
    margin:0;
    text-align:center;
    color:#1565d8;
    font-size:clamp(30px,5vw,52px);
}

#nbscore_score_label{
    margin-top:10px;
    text-align:center;
    color:#777;
    font-size:clamp(18px,3vw,24px);
}

#nbscore_score{
    text-align:center;
    color:#1565d8;
    font-size:clamp(44px,8vw,68px);
    font-weight:700;
    margin-top:4px;
}

.nbscore_separator{
    border:none;
    border-top:1px solid #e5e5e5;
    margin:24px 0;
}

/* ---------- Top Stats ---------- */

#nbscore_stats{
    display:grid;
    grid-template-columns:repeat(3,1fr);
    gap:18px;
}

.nbscore_stat_card{
    text-align:center;
}

.nbscore_icon{
    font-size:30px;
    margin-bottom:8px;
}

.nbscore_stat_name{
    color:#666;
    font-size:16px;
    margin-bottom:8px;
}

.nbscore_green{color:#14913a;}
.nbscore_red{color:#db3a18;}
.nbscore_orange{color:#eb9100;}

.nbscore_green_text,
.nbscore_red_text,
.nbscore_orange_text{
    font-size:32px;
    font-weight:700;
}

.nbscore_green_text{color:#14913a;}
.nbscore_red_text{color:#db3a18;}
.nbscore_orange_text{color:#eb9100;}

/* ---------- Bottom Stats ---------- */

#nbscore_bottom_stats{
    display:grid;
    grid-template-columns:repeat(3,1fr);
    gap:18px;
}

.nbscore_bottom_card{
    text-align:center;
}

.nbscore_bottom_name{
    color:#666;
    font-size:16px;
}

#nbscore_precision,
#nbscore_recall,
#nbscore_f1{
    margin-top:6px;
    color:#1565d8;
    font-size:30px;
    font-weight:700;
}

.nbscore_vertical_line{
    display:none;
}

/* ---------- Footer ---------- */

#nbscore_footer{
    display:flex;
    gap:14px;
    padding:20px 24px;
    border-top:1px solid #e5e5e5;
}

#nbscore_cancel_btn,
#nbscore_playagain_btn{
    flex:1;
    height:52px;
    border-radius:10px;
    font-size:18px;
    font-weight:700;
    cursor:pointer;
    transition:.2s;
}

#nbscore_cancel_btn{
    background:#fff;
    color:#1565d8;
    border:2px solid #1565d8;
}

#nbscore_cancel_btn:hover{
    background:#f4f8ff;
}

#nbscore_playagain_btn{
    background:#1565d8;
    color:#fff;
    border:none;
}

#nbscore_playagain_btn:hover{
    background:#0d59c4;
}

/* ---------- Mobile ---------- */

@media (max-width:600px){

    #nbscore_overlay{
        padding:10px;
    }

    #nbscore_body{
        padding:12px;
    }

    .nbscore_separator{
        margin:10px 0;
    }

    /* ---------- Top stats ---------- */

    #nbscore_stats{
        gap:2px;
    }

    .nbscore_icon{
        font-size:14px;
        margin-bottom:2px;
    }

    .nbscore_stat_name{
        font-size:9px;
        margin-bottom:2px;
    }

    .nbscore_green_text,
    .nbscore_red_text,
    .nbscore_orange_text{
        font-size:13px;
        font-weight:700;
    }

    /* ---------- Bottom stats ---------- */

    #nbscore_bottom_stats{
        gap:2px;
    }

    .nbscore_bottom_name{
        font-size:9px;
    }

    #nbscore_precision,
    #nbscore_recall,
    #nbscore_f1{
        font-size:15px;
        margin-top:2px;
    }

    /* ---------- Buttons ---------- */

    #nbscore_footer{
        display:flex;
        flex-direction:row;
        gap:10px;
        padding:16px;
    }

    #nbscore_cancel_btn,
    #nbscore_playagain_btn{
        flex:1;
        width:auto;
        height:54px;

        border-radius:14px;
        font-size:18px;
        font-weight:700;

        transition:.15s ease;
    }

    #nbscore_cancel_btn{
        background:#fff;
        color:#1565d8;
        border:2px solid #1565d8;
    }

    #nbscore_playagain_btn{
        background:linear-gradient(to bottom,#2e86ff,#1565d8);
        color:#fff;
        border:none;
        box-shadow:0 4px 14px rgba(21,101,216,.35);
    }

    #nbscore_cancel_btn:active,
    #nbscore_playagain_btn:active{
        transform:scale(.97);
    }
}

@media (max-width:380px){

    .nbscore_icon{
        font-size:12px;
    }

    .nbscore_stat_name,
    .nbscore_bottom_name{
        font-size:8px;
    }

    .nbscore_green_text,
    .nbscore_red_text,
    .nbscore_orange_text{
        font-size:12px;
    }

    #nbscore_precision,
    #nbscore_recall,
    #nbscore_f1{
        font-size:13px;
    }

    #nbscore_cancel_btn,
    #nbscore_playagain_btn{
        height:50px;
        font-size:16px;
    }
}

/* modern end score popup end */

.hidden {
  display: none;
}