:root {
  color-scheme: dark;
  font-family: ui-monospace, "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  background: #070a11;
  color: #f5f7fb;
}

* {
  box-sizing: border-box;
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  background:
    linear-gradient(rgba(99, 230, 183, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(99, 230, 183, 0.035) 1px, transparent 1px),
    radial-gradient(circle at 18% 12%, rgba(36, 190, 137, 0.15), transparent 32rem),
    radial-gradient(circle at 88% 80%, rgba(116, 87, 255, 0.14), transparent 30rem),
    #070a11;
  background-size: 32px 32px, 32px 32px, auto, auto, auto;
}

button,
input {
  font: inherit;
}

.game-shell {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: clamp(0.75rem, 3vw, 2.5rem);
}

.game-card {
  width: min(100%, 1030px);
  padding: clamp(1rem, 2.5vw, 1.75rem);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 22px;
  background: rgba(15, 20, 31, 0.94);
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.48), inset 0 1px rgba(255, 255, 255, 0.04);
  backdrop-filter: blur(18px);
}

.game-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1.5rem;
  margin-bottom: 1.25rem;
}

.eyebrow,
.panel-label {
  margin: 0 0 0.35rem;
  color: #67e7b8;
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.15em;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1,
h2 {
  margin-bottom: 0;
  line-height: 1;
  letter-spacing: -0.055em;
}

h1 {
  font-size: clamp(2rem, 6vw, 3.35rem);
  text-shadow: 3px 3px 0 #263d37, 0 0 24px rgba(99, 230, 183, 0.15);
}

h2 {
  font-size: clamp(2rem, 7vw, 3.5rem);
}

.stats {
  display: flex;
  gap: 0.65rem;
}

.stat-box {
  display: grid;
  min-width: 116px;
  padding: 0.65rem 0.85rem;
  border: 1px solid rgba(99, 230, 183, 0.24);
  border-radius: 10px;
  background: rgba(99, 230, 183, 0.08);
  box-shadow: inset 0 -3px rgba(0, 0, 0, 0.18);
}

.stat-box--best {
  border-color: rgba(255, 204, 77, 0.28);
  background: rgba(255, 204, 77, 0.08);
}

.stat-box span {
  color: #98a3b5;
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.stat-box strong {
  margin-top: 0.2rem;
  color: #75f1c4;
  font-size: 1.35rem;
}

.stat-box--best strong {
  color: #ffd45f;
}

.game-layout {
  display: grid;
  grid-template-columns: minmax(0, 650px) minmax(230px, 1fr);
  gap: 1.25rem;
  align-items: start;
}

.board-wrap {
  position: relative;
  overflow: hidden;
  width: 100%;
  border: 2px solid rgba(99, 230, 183, 0.33);
  border-radius: 14px;
  background: #0a1019;
  box-shadow: 0 0 0 5px rgba(99, 230, 183, 0.045), 0 20px 50px rgba(0, 0, 0, 0.34);
}

canvas {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 1;
  image-rendering: auto;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.dpad {
  display: grid;
  grid-template-columns: repeat(3, 64px);
  grid-template-rows: repeat(2, 64px);
  gap: 8px;
  width: max-content;
  margin: 1rem auto 0;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.dpad-button {
  display: grid;
  width: 64px;
  min-width: 64px;
  height: 64px;
  min-height: 64px;
  padding: 0;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.17);
  border-radius: 13px;
  background: linear-gradient(145deg, #263547, #14202d);
  color: #ecfff8;
  font-size: 1.65rem;
  line-height: 1;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.45);
  box-shadow: 0 5px 0 #091019, 0 10px 24px rgba(0, 0, 0, 0.3), inset 0 1px rgba(255, 255, 255, 0.09);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.dpad-button:hover {
  background: linear-gradient(145deg, #30465d, #192a39);
  box-shadow: 0 6px 0 #091019, 0 12px 26px rgba(0, 0, 0, 0.34), inset 0 1px rgba(255, 255, 255, 0.12);
}

.dpad-button:active,
.dpad-button.is-pressed {
  transform: translateY(4px);
  background: linear-gradient(145deg, #67e7b8, #2f9d78);
  color: #06120d;
  text-shadow: none;
  box-shadow: 0 1px 0 #091019, inset 0 2px 5px rgba(0, 0, 0, 0.18);
}

.dpad-up {
  grid-column: 2;
  grid-row: 1;
}

.dpad-left {
  grid-column: 1;
  grid-row: 2;
}

.dpad-down {
  grid-column: 2;
  grid-row: 2;
}

.dpad-right {
  grid-column: 3;
  grid-row: 2;
}

.side-panel {
  display: grid;
  gap: 0.85rem;
}

.panel-block {
  padding: 1rem;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.035);
  box-shadow: inset 0 -4px rgba(0, 0, 0, 0.14);
}

.last-item strong,
.last-item span {
  display: block;
}

.last-item strong {
  margin: 0.65rem 0 0.3rem;
  color: #ffffff;
  font-size: 1.1rem;
}

.last-item span,
.wrap-hint {
  color: #909bad;
  font-size: 0.76rem;
  line-height: 1.55;
}

.panel-heading {
  padding-bottom: 0.85rem;
  border-bottom: 1px dashed rgba(255, 255, 255, 0.12);
}

.panel-heading h2 {
  font-size: 1.8rem;
}

.leaderboard-list {
  display: grid;
  gap: 0.55rem;
  margin: 0.8rem 0 0;
  padding: 0;
  list-style: none;
}

.leaderboard-status {
  min-height: 1.15rem;
  margin: 0.7rem 0 0;
  color: #9ca8b9;
  font-size: 0.7rem;
  line-height: 1.45;
  text-align: center;
}

.leaderboard-status.is-unavailable {
  color: #ffc37a;
}

.leaderboard-retry,
.leaderboard-notice {
  margin-top: 0.65rem;
  text-align: center;
}

.leaderboard-retry p,
.leaderboard-notice {
  margin-bottom: 0.55rem;
  color: #ffc37a;
  font-size: 0.7rem;
  line-height: 1.45;
}

.leaderboard-retry button {
  min-height: 34px;
  padding: 0.5rem 0.7rem;
  font-size: 0.68rem;
}

.leaderboard-notice {
  color: #75f1c4;
}

.firebase-debug-status {
  margin: 0.65rem 0 0;
  color: #8fa0b5;
  font-size: 0.62rem;
  line-height: 1.45;
  overflow-wrap: anywhere;
  white-space: pre-line;
}

.leaderboard-row {
  display: grid;
  grid-template-columns: 1.7rem minmax(0, 1fr) auto;
  gap: 0.55rem;
  align-items: center;
  min-height: 2.25rem;
  padding: 0.45rem 0.55rem;
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.035);
  color: #dce2ec;
  font-size: 0.8rem;
}

.leaderboard-row:first-child {
  background: rgba(255, 204, 77, 0.09);
}

.leaderboard-rank {
  color: #ffd45f;
  font-weight: 900;
}

.leaderboard-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.leaderboard-score {
  color: #74e9bd;
  font-weight: 800;
}

.leaderboard-empty {
  color: #657083;
}

button {
  min-height: 44px;
  padding: 0.8rem 1.2rem;
  border: 0;
  border-radius: 9px;
  background: #63e6b7;
  color: #07120e;
  font-weight: 900;
  cursor: pointer;
  box-shadow: 0 5px 0 #277f60, 0 11px 26px rgba(99, 230, 183, 0.18);
  transition: transform 140ms ease, background-color 140ms ease, box-shadow 140ms ease;
}

button:hover {
  transform: translateY(-2px);
  background: #82f0ca;
  box-shadow: 0 7px 0 #277f60, 0 14px 30px rgba(99, 230, 183, 0.26);
}

button:active {
  transform: translateY(3px);
  box-shadow: 0 2px 0 #277f60;
}

button:focus-visible,
input:focus-visible {
  outline: 3px solid #ffffff;
  outline-offset: 3px;
}

.restart-button {
  width: 100%;
}

.wrap-hint {
  margin: 0;
  text-align: center;
}

.controls {
  margin: 1rem 0 0;
  color: #929cac;
  font-size: 0.8rem;
  line-height: 1.8;
  text-align: center;
}

kbd {
  display: inline-grid;
  min-width: 1.7rem;
  min-height: 1.7rem;
  margin: 0 0.06rem;
  padding: 0 0.3rem;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-bottom-width: 3px;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.06);
  color: #dce2ec;
  font-family: inherit;
  font-size: 0.7rem;
  font-weight: 800;
}

.game-over {
  position: absolute;
  inset: 0;
  display: flex;
  visibility: hidden;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  padding: 1rem;
  background: rgba(5, 8, 14, 0.82);
  opacity: 0;
  backdrop-filter: blur(6px);
  transition: opacity 180ms ease, visibility 180ms ease;
}

.game-over.is-visible {
  visibility: visible;
  opacity: 1;
}

.game-over > p:not(.eyebrow) {
  margin: 0.9rem 0 1.4rem;
  color: #b9c2d0;
}

.game-over strong {
  color: #ffffff;
}

.record-modal {
  position: fixed;
  z-index: 10;
  inset: 0;
  display: grid;
  visibility: hidden;
  place-items: center;
  padding: 1rem;
  background: rgba(3, 5, 9, 0.82);
  opacity: 0;
  backdrop-filter: blur(8px);
  transition: opacity 180ms ease, visibility 180ms ease;
}

.record-modal.is-visible {
  visibility: visible;
  opacity: 1;
}

.record-card {
  width: min(100%, 420px);
  padding: clamp(1.25rem, 5vw, 2rem);
  border: 2px solid rgba(255, 204, 77, 0.5);
  border-radius: 14px;
  background: #111725;
  box-shadow: 8px 8px 0 rgba(255, 204, 77, 0.12), 0 28px 70px rgba(0, 0, 0, 0.55);
}

.record-card h2 {
  font-size: clamp(1.8rem, 8vw, 2.6rem);
  line-height: 1.05;
}

.record-card > p:not(.eyebrow) {
  margin: 0.9rem 0 1.15rem;
  color: #a9b3c3;
  font-size: 0.84rem;
}

.record-card label {
  display: block;
  margin-bottom: 0.4rem;
  color: #d7ddea;
  font-size: 0.74rem;
  font-weight: 800;
  text-transform: uppercase;
}

.record-card input {
  width: 100%;
  min-height: 46px;
  margin-bottom: 0.9rem;
  padding: 0.75rem;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  background: #080d16;
  color: #ffffff;
}

.record-card button {
  width: 100%;
}

.record-error {
  margin: 0 0 0.8rem;
  color: #ffc37a;
  font-size: 0.76rem;
  line-height: 1.45;
}

.record-actions {
  display: grid;
  grid-template-columns: 1fr 0.72fr;
  gap: 0.65rem;
}

.record-cancel-button {
  background: #293544;
  color: #e6ecf5;
  box-shadow: 0 5px 0 #111923, 0 11px 26px rgba(0, 0, 0, 0.18);
}

@media (max-width: 820px) {
  .game-layout {
    grid-template-columns: 1fr;
  }

  .side-panel {
    grid-template-columns: 1fr 1.35fr;
  }

  .restart-button,
  .wrap-hint {
    grid-column: 1 / -1;
  }
}

@media (max-width: 590px) {
  .game-shell {
    align-items: start;
    padding: 0.55rem;
  }

  .game-card {
    padding: 0.8rem;
    border-radius: 15px;
  }

  .game-header {
    display: grid;
    gap: 0.8rem;
  }

  .stats,
  .stat-box {
    width: 100%;
  }

  .side-panel {
    grid-template-columns: 1fr;
  }

  .restart-button,
  .wrap-hint {
    grid-column: auto;
  }

  .board-wrap {
    border-radius: 9px;
  }

  .dpad {
    grid-template-columns: repeat(3, 64px);
    grid-template-rows: repeat(2, 64px);
    gap: 9px;
    margin-top: 0.85rem;
  }

  .controls {
    margin-top: 0.8rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}

/* ?embed=1 — played inside the saitora.nedelchevweb.com player: fits the frame, no credit badge, no double-tap zoom */
html.is-embed { touch-action: manipulation; -webkit-text-size-adjust: 100%; }
.is-embed .saitora-credit { display: none !important; }
.is-embed body { min-height: 0; }
.is-embed .game-shell { min-height: 100vh; min-height: 100dvh; padding: clamp(0.5rem, 1.6vw, 1rem); }
.is-embed .game-card { box-shadow: none; }
.is-embed .game-header { margin-bottom: 0.8rem; }
.is-embed .game-layout { grid-template-columns: auto minmax(230px, 1fr); }
.is-embed .play-column { width: min(650px, 100%, calc(100vh - 250px)); width: min(650px, 100%, calc(100dvh - 250px)); min-width: 260px; margin-inline: auto; }
@media (hover: hover) and (pointer: fine) {
  .is-embed .dpad { display: none; }
  .is-embed .play-column { width: min(650px, 100%, calc(100vh - 230px)); width: min(650px, 100%, calc(100dvh - 230px)); }
}
@media (max-width: 820px) {
  .is-embed .game-layout { grid-template-columns: 1fr; }
}
@media (max-width: 590px) {
  .is-embed .game-shell { padding: 0.4rem; }
  .is-embed .game-card { padding: 0.6rem; }
  .is-embed .game-header { display: flex; align-items: center; gap: 0.6rem; margin-bottom: 0.6rem; }
  .is-embed .game-header .eyebrow { display: none; }
  .is-embed h1 { font-size: 1.45rem; }
  .is-embed .stats, .is-embed .stat-box { width: auto; }
  .is-embed .stats { gap: 0.4rem; }
  .is-embed .stat-box { min-width: 0; padding: 0.35rem 0.6rem; }
  .is-embed .stat-box span { font-size: 0.56rem; }
  .is-embed .stat-box strong { font-size: 1.05rem; margin-top: 0.1rem; }
  .is-embed .play-column { width: min(100%, calc(100vh - 250px)); width: min(100%, calc(100dvh - 250px)); min-width: 0; }
  .is-embed .controls { display: none; }
  .is-embed .dpad { grid-template-columns: repeat(3, 60px); grid-template-rows: repeat(2, 60px); margin-top: 0.7rem; }
  .is-embed .dpad-button { width: 60px; min-width: 60px; height: 60px; min-height: 60px; }
}
