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

/* ===== BASE ===== */
html, body {
  height: 100%;
  background: #0c0d0f;
  color: #ededed;
  font-family: "Aptos", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  opacity: 0;
  transition: opacity 0.8s ease;
}

body.loaded {
  opacity: 1;
}

body.stage-open {
  overflow: hidden;
}

/* ===== TOP BAR ===== */
.topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 78px;
  background: rgba(12,13,15,0.95);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid rgba(255,255,255,0.06);
  z-index: 100;
}

.topbar-inner {
  max-width: 1600px;
  height: 100%;
  margin: 0 auto;
  padding: 0 5vw;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand {
  text-decoration: none;
  font-size: 1.05rem;
  letter-spacing: 0.22em;
  color: rgba(255,255,255,0.95);
}

/* ===== NAV ===== */
.menu-toggle {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
}

.menu-toggle span {
  display: block;
  width: 22px;
  height: 2px;
  margin: 5px 0;
  background: rgba(255,255,255,0.9);
}

.nav {
  display: flex;
  gap: 2.2rem;
}

.nav a {
  position: relative;
  text-decoration: none;
  font-size: 0.9rem;
  letter-spacing: 0.12em;
  color: rgba(255,255,255,0.6);
  padding-bottom: 6px;
}

.nav a:hover,
.nav a.active {
  color: #ffffff;
}

.nav a::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: 0;
  width: 0%;
  height: 1px;
  background: rgba(255,255,255,0.6);
  transition: width 0.28s ease, left 0.28s ease;
}

.nav a:hover::after,
.nav a.active::after {
  width: 100%;
  left: 0;
}

/* ===== PAGE ===== */
.page {
  padding-top: 120px;
}

.page-header {
  display: flex;
  justify-content: center;
  text-align: center;
  margin-bottom: 64px;
}

.page-header h1 {
  max-width: 900px;
  font-size: 2.4rem;
  font-weight: 500;
  letter-spacing: 0.18em;
  line-height: 1.25;
  color: rgba(255,255,255,0.9);
}

.meta {
  display: flex;
  justify-content: center;
  gap: 32px;
  margin-top: 18px;
  font-size: 0.75rem;
  letter-spacing: 0.16em;
  color: rgba(255,255,255,0.62);
  text-transform: uppercase;
}

/* ===== CONTENT SURFACE ===== */
.content-surface {
  background: #181818;
}

.content {
  max-width: 1100px;
  margin: 0 auto;
  padding: 96px 6vw 140px;
}

.content p.lede {
  font-size: 1.05rem;
  line-height: 1.75;
  margin: 0 auto 48px;
  text-align: center;
  color: rgba(255,255,255,0.78);
  max-width: 640px;
}

/* ===== IN-PAGE LAUNCH ===== */
.launch {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.launch-board {
  position: relative;
  width: 220px;
  height: 132px;
  border: 1px solid rgba(255,255,255,0.12);
  background:
    repeating-linear-gradient(90deg, rgba(255,255,255,0.05) 0 1px, transparent 1px 22px),
    repeating-linear-gradient(0deg, rgba(255,255,255,0.05) 0 1px, transparent 1px 22px),
    #0a0b0d;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.launch-board span {
  font-size: 1.4rem;
  letter-spacing: 0.4em;
  text-indent: 0.4em;
  color: rgba(255,255,255,0.9);
  font-weight: 500;
}

.launch-btn {
  -webkit-appearance: none;
  appearance: none;
  background: #ffffff;
  color: #0c0d0f;
  border: none;
  font-family: inherit;
  font-size: 0.82rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  padding: 16px 44px;
  cursor: pointer;
  transition: transform 0.15s ease, opacity 0.15s ease;
}

.launch-btn:hover {
  transform: translateY(-2px);
}

.launch-note {
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  color: rgba(255,255,255,0.42);
}

/* ===== HOW TO PLAY ===== */
.how {
  margin: 72px auto 0;
  max-width: 440px;
}

.how h2 {
  font-size: 0.7rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.6);
  margin-bottom: 18px;
  text-align: center;
}

.how dl {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 11px 20px;
  font-size: 0.84rem;
}

.how dt {
  color: #ffffff;
  letter-spacing: 0.04em;
}

.how dd {
  color: rgba(255,255,255,0.6);
}

/* ===== BACK LINK ===== */
.back-link {
  margin-top: 72px;
  text-align: center;
}

.back-link a {
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  color: rgba(255,255,255,0.62);
  text-decoration: none;
}

.back-link a:hover {
  color: #ffffff;
}

/* ===== FOOTER ===== */
.footer {
  height: 64px;
  border-top: 1px solid rgba(255,255,255,0.06);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px 14px;
  flex-wrap: wrap;
  padding: 0 6vw;
}

.footer .copyright {
  font-size: 0.7rem;
  letter-spacing: 0.14em;
  color: rgba(255,255,255,0.6);
}

.footer-meta {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 4px 14px;
}

.footer-meta a {
  font-size: 0.66rem;
  letter-spacing: 0.1em;
  color: rgba(255,255,255,0.4);
  text-decoration: none;
  transition: color 0.25s ease;
}

.footer-meta a:hover {
  color: rgba(255,255,255,0.7);
}

/* ===== GRAIN ===== */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='160' height='160' filter='url(%23n)' opacity='0.008'/%3E%3C/svg%3E");
  pointer-events: none;
  z-index: 0;
}

/* ==================================================
   FULL-SCREEN PLAY STAGE
   ================================================== */
.stage {
  position: fixed;
  inset: 0;
  height: 100%;
  height: 100dvh;
  z-index: 2000;
  background:
    radial-gradient(120% 80% at 50% 0%, rgba(255,255,255,0.04), transparent 60%),
    #08090b;
  display: flex;
  flex-direction: column;
}

.stage[hidden] {
  display: none;
}

/* top bar: stats + next + controls */
.stage-bar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 16px max(20px, env(safe-area-inset-left)) 16px max(20px, env(safe-area-inset-left));
  padding-top: max(16px, env(safe-area-inset-top));
  border-bottom: 1px solid rgba(255,255,255,0.07);
}

.stat-group {
  display: flex;
  gap: 30px;
}

.stat {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.stat span {
  font-size: 0.56rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.4);
}

.stat b {
  font-size: 1.3rem;
  font-weight: 500;
  letter-spacing: 0.02em;
  color: #ffffff;
  font-variant-numeric: tabular-nums;
}

.bar-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

.next-mini {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
}

.next-mini span {
  font-size: 0.52rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.4);
}

.next-mini canvas {
  display: block;
}

.icon-btn {
  -webkit-appearance: none;
  appearance: none;
  background: none;
  border: 1px solid rgba(255,255,255,0.18);
  color: rgba(255,255,255,0.85);
  font-family: inherit;
  font-size: 0.62rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  padding: 9px 14px;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.icon-btn:hover {
  background: rgba(255,255,255,0.08);
  border-color: rgba(255,255,255,0.4);
  color: #fff;
}

/* play area: board fills available height */
.play-area {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  position: relative;
}

.board-wrap {
  position: relative;
  border: 1px solid rgba(255,255,255,0.14);
  background: #0a0b0d;
  line-height: 0;
  box-shadow: 0 40px 120px -40px rgba(0,0,0,0.9);
}

canvas.board {
  display: block;
  touch-action: none;
}

.board-wrap.flash::after {
  content: "";
  position: absolute;
  inset: 0;
  background: #ffffff;
  pointer-events: none;
  opacity: 0;
  animation: lineFlash 0.22s ease;
}

@keyframes lineFlash {
  0% { opacity: 0; }
  30% { opacity: 0.5; }
  100% { opacity: 0; }
}

/* overlay (start / pause / game over) */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: 24px;
  text-align: center;
  background: rgba(8,9,11,0.85);
  backdrop-filter: blur(3px);
  line-height: 1.4;
}

.overlay[hidden] {
  display: none;
}

.overlay h2 {
  font-size: 1.6rem;
  font-weight: 500;
  letter-spacing: 0.28em;
  text-indent: 0.28em;
  color: #ffffff;
}

.overlay p {
  font-size: 0.8rem;
  letter-spacing: 0.06em;
  color: rgba(255,255,255,0.6);
  max-width: 220px;
}

.overlay .btn {
  -webkit-appearance: none;
  appearance: none;
  margin-top: 4px;
  padding: 13px 34px;
  background: #ffffff;
  border: none;
  color: #0c0d0f;
  font-family: inherit;
  font-size: 0.74rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  cursor: pointer;
  transition: transform 0.15s ease;
}

.overlay .btn:hover {
  transform: translateY(-2px);
}

/* difficulty selector (in the overlay) */
.diff {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}

.diff-btn {
  -webkit-appearance: none;
  appearance: none;
  background: none;
  border: 1px solid rgba(255,255,255,0.2);
  color: rgba(255,255,255,0.7);
  font-family: inherit;
  font-size: 0.66rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  padding: 9px 16px;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.diff-btn:hover {
  border-color: rgba(255,255,255,0.45);
  color: #fff;
}

.diff-btn.active {
  background: #ffffff;
  border-color: #ffffff;
  color: #0c0d0f;
}

/* touch control: flag-mode toggle */
.touch-controls {
  display: none;
  flex: 0 0 auto;
  width: 100%;
  max-width: 360px;
  margin: 0 auto;
  padding: 12px max(16px, env(safe-area-inset-left))
           max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}

.tbtn {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.15);
  color: rgba(255,255,255,0.9);
  font-family: inherit;
  font-size: 0.78rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  padding: 16px 0;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease;
}

.tbtn:active {
  background: rgba(255,255,255,0.18);
  border-color: rgba(255,255,255,0.45);
}

.tbtn.on {
  background: #ffffff;
  border-color: #ffffff;
  color: #0c0d0f;
}

/* show controls on touch devices */
body.touch .touch-controls {
  display: block;
}

/* ===== MOBILE ===== */
@media (max-width: 1024px) {
  .menu-toggle {
    display: block;
  }

  .nav {
    position: absolute;
    top: 78px;
    left: 0;
    right: 0;
    background: #0c0d0f;
    flex-direction: column;
    align-items: center;
    gap: 22px;
    padding: 28px 0 36px;
    border-bottom: 1px solid rgba(255,255,255,0.06);
    opacity: 0;
    pointer-events: none;
    transform: translateY(-6px);
    transition: opacity 0.25s ease, transform 0.25s ease;
  }

  .nav.open {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0);
  }
}

@media (max-width: 760px) {
  .topbar { height: 64px; }
  .nav { top: 64px; }
  .nav a { font-size: 0.78rem; }

  .page { padding-top: 92px; }
  .page-header { margin-bottom: 40px; }
  .page-header h1 { font-size: 1.5rem; letter-spacing: 0.1em; }
  .meta { gap: 16px; font-size: 0.65rem; }

  .content { padding: 56px 5vw 110px; }
  .content p.lede { font-size: 0.95rem; }

  .touch-controls { display: block; }

  .stage-bar {
    gap: 12px;
    padding: 12px 16px;
    padding-top: max(12px, env(safe-area-inset-top));
  }

  .stat-group { gap: 18px; }
  .stat b { font-size: 1.05rem; }
  .stat span { font-size: 0.5rem; }
  .bar-right { gap: 10px; }
  .icon-btn { padding: 8px 11px; font-size: 0.56rem; letter-spacing: 0.1em; }
  .play-area { padding: 10px; }
}

/* very short landscape: hide the next preview to save vertical room */
@media (max-height: 520px) {
  .next-mini { display: none; }
}

/* full-screen game: lock page scroll, rubber-banding, selection and callouts on all devices */
.stage {
  touch-action: none;
  overscroll-behavior: contain;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
