:root {
  color-scheme: dark;
  --bg: #10131b;
  --panel: rgba(14, 25, 35, 0.88);
  --panel-2: rgba(29, 45, 59, 0.94);
  --line: rgba(144, 196, 214, 0.28);
  --text: #edf2ff;
  --muted: #b0c4d6;
  --accent: #7de2c5;
  --danger: #ff6d8f;
}

body[data-theme="jata"] {
  --panel: rgba(12, 33, 24, 0.9);
  --panel-2: rgba(22, 66, 45, 0.94);
  --line: rgba(132, 214, 149, 0.32);
  --muted: #bdd7bf;
  --accent: #9ae66e;
}

body[data-theme="poop"] {
  --panel: rgba(45, 28, 15, 0.9);
  --panel-2: rgba(92, 57, 24, 0.94);
  --line: rgba(255, 195, 100, 0.34);
  --muted: #e2c59d;
  --accent: #ffc46f;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
}

body {
  display: grid;
  place-items: center;
  padding: 18px;
  background:
    linear-gradient(rgba(3, 12, 22, 0.72), rgba(3, 12, 22, 0.82)),
    var(--page-wallpaper, url("./assets/jata-drop-wallpaper.png")) center / cover fixed;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

body.lightweight-mode {
  background-attachment: scroll;
}

.app {
  width: min(100%, 860px);
  padding: 18px;
  border: 1px solid rgba(144, 196, 214, 0.18);
  border-radius: 8px;
  background: rgba(5, 13, 22, 0.56);
  box-shadow: 0 24px 72px rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(10px);
}

body[data-theme="jata"] .app {
  border-color: rgba(154, 230, 110, 0.22);
  background: rgba(4, 18, 12, 0.62);
}

body[data-theme="poop"] .app {
  border-color: rgba(255, 195, 100, 0.24);
  background: rgba(24, 14, 8, 0.62);
}

body[data-theme="jata"] .board-wrap {
  box-shadow: inset 0 0 0 1px rgba(154, 230, 110, 0.08);
}

body[data-theme="poop"] .board-wrap {
  box-shadow: inset 0 0 0 1px rgba(255, 195, 100, 0.08);
}

.top-bar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.brand-block {
  min-width: 0;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(28px, 7vw, 48px);
  line-height: 1;
  letter-spacing: 0;
}

.logo-mark {
  display: grid;
  gap: 4px;
  width: max-content;
  max-width: 100%;
  text-transform: uppercase;
}

.logo-main {
  display: inline-block;
  padding-right: 0.1em;
  color: #fff7e8;
  font-size: clamp(34px, 7vw, 52px);
  font-weight: 950;
  line-height: 0.88;
  text-shadow:
    0 2px 0 rgba(77, 42, 12, 0.98),
    0 0 16px rgba(255, 191, 100, 0.28);
}

.logo-main span {
  color: #ffc46f;
  text-shadow:
    0 2px 0 rgba(77, 42, 12, 0.98),
    0 0 12px rgba(255, 196, 111, 0.45);
}

.logo-sub {
  display: inline-flex;
  width: fit-content;
  padding: 3px 8px;
  border: 1px solid rgba(255, 196, 111, 0.38);
  border-radius: 7px;
  background: rgba(65, 36, 14, 0.72);
  color: #ffdca4;
  font-size: 12px;
  font-weight: 900;
  line-height: 1;
}

button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
  color: var(--text);
  font-weight: 800;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

button:active {
  transform: translateY(1px);
}

.top-actions,
.audio-actions,
.touch-controls {
  display: flex;
  gap: 8px;
}

.top-actions button,
.audio-actions button {
  padding: 0 14px;
}

.theme-picker {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

select {
  min-height: 42px;
  min-width: 180px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  background: var(--panel-2);
  color: var(--text);
  font: inherit;
  font-weight: 800;
}

button[aria-pressed="false"] {
  color: var(--muted);
  background: rgba(20, 28, 40, 0.84);
}

.game-layout {
  display: grid;
  grid-template-columns: 140px minmax(260px, 320px) 150px;
  align-items: start;
  justify-content: center;
  gap: 14px;
}

.panel {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.stat {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 42px;
  padding: 9px 10px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.04);
}

.stat span,
.label,
.help {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.stat strong {
  font-size: 18px;
}

.board-wrap {
  position: relative;
  width: min(100%, 320px);
  aspect-ratio: 1 / 2;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: rgba(6, 12, 20, 0.94);
}

canvas {
  display: block;
  width: 100%;
  height: auto;
}

#board {
  height: 100%;
}

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 8px;
  padding: 20px;
  background: rgba(8, 10, 16, 0.82);
  text-align: center;
}

.result-video {
  position: absolute;
  inset: 0;
  z-index: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.overlay.game-over-overlay {
  align-content: end;
  padding: 24px;
  background-color: rgba(8, 10, 16, 0.92);
  background-position: center;
  background-size: cover;
}

.overlay.celebration-overlay {
  align-content: end;
  overflow: hidden;
  padding: 24px;
  background-color: rgba(5, 18, 30, 0.72);
  background-position: center;
  background-size: cover;
}

.overlay.celebration-overlay::before,
.overlay.celebration-overlay::after {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  content: "";
}

.overlay.celebration-overlay::before {
  background-image:
    radial-gradient(circle at 14% 18%, rgba(255, 245, 176, 0.95) 0 2px, transparent 3px),
    radial-gradient(circle at 78% 22%, rgba(255, 142, 205, 0.9) 0 2px, transparent 3px),
    radial-gradient(circle at 48% 12%, rgba(125, 224, 255, 0.95) 0 2px, transparent 3px),
    radial-gradient(circle at 30% 72%, rgba(255, 255, 255, 0.82) 0 1px, transparent 2px),
    radial-gradient(circle at 84% 66%, rgba(255, 218, 103, 0.92) 0 2px, transparent 3px);
  animation: sparkle-drift 2.2s ease-in-out infinite alternate;
}

.overlay.celebration-overlay::after {
  background:
    radial-gradient(circle, rgba(255, 255, 255, 0.9) 0 1px, transparent 2px) 12% 82% / 58px 58px,
    radial-gradient(circle, rgba(255, 193, 94, 0.78) 0 2px, transparent 3px) 88% 16% / 72px 72px,
    radial-gradient(circle, rgba(129, 226, 255, 0.72) 0 2px, transparent 3px) 55% 28% / 66px 66px;
  animation: firework-pop 1.55s ease-in-out infinite;
}

.overlay strong,
.overlay span {
  position: relative;
  z-index: 2;
}

.overlay strong {
  font-size: 28px;
}

.overlay span {
  color: var(--muted);
  font-size: 14px;
}

.overlay.game-over-overlay strong,
.overlay.game-over-overlay span {
  justify-self: center;
  max-width: 240px;
  padding: 8px 12px;
  border: 1px solid rgba(235, 210, 166, 0.42);
  border-radius: 8px;
  background: rgba(5, 7, 11, 0.72);
  color: #fff7e8;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.7);
}

.overlay.game-over-overlay span {
  color: #f0d6b2;
}

.overlay.celebration-overlay strong,
.overlay.celebration-overlay span {
  justify-self: center;
  max-width: 250px;
  padding: 8px 12px;
  border: 1px solid rgba(255, 246, 185, 0.62);
  border-radius: 8px;
  background: rgba(10, 22, 34, 0.66);
  color: #fff9d7;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.62);
}

.overlay.celebration-overlay span {
  color: #ffe8ac;
}

@keyframes sparkle-drift {
  from {
    opacity: 0.72;
    transform: translateY(8px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(-8px) scale(1.04);
  }
}

@keyframes firework-pop {
  0%,
  100% {
    opacity: 0.45;
    transform: scale(0.94);
  }
  50% {
    opacity: 1;
    transform: scale(1.08);
  }
}

.hidden {
  display: none;
}

.next-panel {
  justify-items: center;
}

#next {
  width: 120px;
  height: 120px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.05);
}

.help {
  margin: 0;
  text-align: center;
  line-height: 1.4;
}

.touch-controls {
  display: none;
  margin-top: 12px;
}

html.touch-device .touch-controls,
body.touch-device .touch-controls {
  display: grid !important;
}

@media (pointer: coarse), (hover: none) {
  .touch-controls {
    display: grid;
    grid-template-columns: minmax(72px, 1fr) minmax(104px, 1.15fr) minmax(72px, 1fr) minmax(96px, 1.05fr);
    align-items: stretch;
    gap: 8px;
    touch-action: none;
  }

  .vertical-actions {
    display: grid;
    grid-template-rows: 1fr 1fr;
    gap: 8px;
  }

  .touch-controls button {
    min-height: 48px;
    border-width: 2px;
    font-size: 24px;
    line-height: 1;
    touch-action: none;
  }

  .rotate-action {
    border-color: rgba(255, 220, 140, 0.62);
    background: linear-gradient(180deg, rgba(118, 82, 34, 0.96), rgba(76, 49, 22, 0.96));
  }

  .down-action {
    border-color: rgba(140, 205, 255, 0.58);
    background: linear-gradient(180deg, rgba(39, 75, 106, 0.96), rgba(22, 48, 72, 0.96));
  }

  .hard-drop {
    min-height: 104px;
    border-color: rgba(255, 130, 130, 0.62);
    background: linear-gradient(180deg, rgba(148, 56, 36, 0.96), rgba(96, 38, 22, 0.96));
    font-size: 15px;
    letter-spacing: 0;
  }
}

@media (min-width: 741px) {
  html.touch-device .touch-controls,
  body.touch-device .touch-controls {
    grid-template-columns: minmax(78px, 1fr) minmax(108px, 1.1fr) minmax(78px, 1fr) minmax(102px, 1.05fr);
    align-items: stretch;
    gap: 8px;
    width: min(100%, 760px);
    margin: 14px auto 0;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: rgba(6, 13, 22, 0.72);
    box-shadow: none;
    backdrop-filter: blur(10px);
    touch-action: none;
  }

  html.touch-device .vertical-actions,
  body.touch-device .vertical-actions {
    display: grid;
    grid-template-rows: 1fr 1fr;
    gap: 8px;
  }

  html.touch-device .touch-controls button,
  body.touch-device .touch-controls button {
    min-height: 52px;
    border-width: 2px;
    font-size: 24px;
    line-height: 1;
    touch-action: none;
  }

  html.touch-device .hard-drop,
  body.touch-device .hard-drop {
    min-height: 112px;
    font-size: 15px;
    letter-spacing: 0;
  }
}

@media (max-width: 740px) {
  html,
  body {
    height: 100%;
    overflow: hidden;
  }

  body {
    padding: 0;
    place-items: stretch center;
    position: fixed;
    inset: 0;
  }

  .app {
    display: grid;
    grid-template-rows: auto auto minmax(0, 1fr) auto;
    gap: 5px;
    width: min(100%, 430px);
    height: var(--app-height, 100svh);
    max-height: var(--app-height, 100svh);
    min-height: 0;
    padding: max(6px, env(safe-area-inset-top)) 8px max(6px, env(safe-area-inset-bottom));
    border: 0;
    border-radius: 0;
    overflow: hidden;
    backdrop-filter: none;
  }

  .top-bar {
    display: grid;
    grid-template-columns: minmax(80px, auto) auto minmax(96px, 1fr) auto;
    align-items: center;
    gap: 5px;
    margin-bottom: 0;
    padding: 4px 5px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: rgba(9, 18, 29, 0.72);
    transition:
      transform 0.18s ease,
      background 0.18s ease;
  }

  .top-bar:focus-within,
  .top-bar:active {
    transform: translateY(1px) scale(1.01);
    background: rgba(20, 34, 47, 0.88);
  }

  body.focus-mode .top-bar {
    opacity: 0.5;
    transform: translateY(-2px) scale(0.98);
  }

  body.focus-mode .top-bar:focus-within,
  body.focus-mode .top-bar:active {
    opacity: 1;
    transform: translateY(0) scale(1.01);
  }

  .eyebrow {
    display: none;
  }

  h1 {
    max-width: 6.6em;
    overflow: hidden;
    font-size: clamp(15px, 4.7vw, 21px);
    line-height: 1;
    white-space: nowrap;
  }

  .logo-mark {
    gap: 2px;
    max-width: 86px;
  }

  .logo-main {
    font-size: clamp(14px, 4.4vw, 17px);
    line-height: 0.9;
  }

  .logo-sub {
    display: none;
  }

  .top-actions {
    justify-content: start;
    gap: 3px;
  }

  .top-actions button,
  .audio-actions button {
    min-height: 28px;
    padding: 0 6px;
    border-radius: 7px;
    font-size: 10px;
  }

  .theme-picker,
  .audio-actions {
    justify-content: space-between;
    gap: 4px;
  }

  .theme-picker span {
    display: none;
  }

  select {
    flex: 1;
    min-width: 0;
    min-height: 28px;
    padding: 0 6px;
    border-radius: 7px;
    font-size: 11px;
  }

  .audio-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .game-layout {
    grid-template-columns: 1fr;
    align-content: start;
    gap: 6px;
    min-height: 0;
  }

  .panel:first-child {
    grid-template-columns: repeat(4, 1fr);
    gap: 5px;
    padding: 6px;
    order: -1;
  }

  .stat {
    display: grid;
    justify-items: center;
    gap: 2px;
    min-height: 30px;
    padding: 4px;
  }

  .stat span {
    font-size: 10px;
  }

  .stat strong {
    font-size: 14px;
  }

  .board-wrap {
    width: min(100%, 304px, calc((var(--app-height, 100svh) - 282px) / 2));
    min-width: 188px;
    margin: 0 auto;
  }

  .next-panel {
    grid-column: 1 / -1;
    grid-template-columns: auto 48px 1fr;
    align-items: center;
    justify-items: start;
    padding: 4px 8px;
    min-height: 52px;
  }

  #next {
    width: 48px;
    height: 48px;
  }

  .help {
    font-size: 10px;
    text-align: left;
  }

  .touch-controls {
    display: grid;
    grid-template-columns: minmax(56px, 1fr) minmax(84px, 1.25fr) minmax(56px, 1fr) minmax(82px, 1.15fr);
    align-items: stretch;
    gap: 6px;
    margin-top: 0;
    padding-top: 2px;
    touch-action: none;
  }

  .vertical-actions {
    display: grid;
    grid-template-rows: 1fr 1fr;
    gap: 6px;
  }

  .touch-controls button {
    min-height: 42px;
    border-width: 2px;
    font-size: 22px;
    line-height: 1;
    touch-action: none;
  }

  .rotate-action {
    border-color: rgba(255, 220, 140, 0.62);
    background: linear-gradient(180deg, rgba(118, 82, 34, 0.96), rgba(76, 49, 22, 0.96));
  }

  .down-action {
    border-color: rgba(140, 205, 255, 0.58);
    background: linear-gradient(180deg, rgba(39, 75, 106, 0.96), rgba(22, 48, 72, 0.96));
  }

  .hard-drop {
    border-color: rgba(255, 130, 130, 0.62);
    background: linear-gradient(180deg, rgba(148, 56, 36, 0.96), rgba(96, 38, 22, 0.96));
    font-size: 15px;
    letter-spacing: 0;
    min-height: 90px;
  }
}

@media (max-width: 520px) {
  .app {
    padding-inline: 8px;
  }

  .next-panel {
    grid-template-columns: auto 52px 1fr;
  }

  #next {
    width: 52px;
    height: 52px;
  }

  .touch-controls {
    grid-template-columns: minmax(54px, 1fr) minmax(82px, 1.22fr) minmax(54px, 1fr) minmax(80px, 1.08fr);
  }

  .touch-controls button {
    min-height: 42px;
  }

  .hard-drop {
    min-height: 90px;
  }
}
