:root {
  --bg: #171717;
  --panel: #202020;
  --grid: #111111;
  --text: #f7f7f7;
  --muted: #b8b8b8;
  --accent: #ffb700;
  --accent-soft: rgba(255, 183, 0, 0.12);
  --button: #ffb700;
  --button-text: #171717;
  --brick-red: #ff5d5d;
  --brick-cyan: #6ee7ff;
  --brick-green: #7dff9a;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  width: 100%;
  height: 100dvh;
  min-height: 100dvh;
  overflow: hidden;
  font-family: "Trebuchet MS", "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}

.app {
  height: 100dvh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  overflow: hidden;
}

.panel {
  width: 100%;
  height: 100%;
  background: var(--panel);
  border: 1px solid rgba(255, 183, 0, 0.2);
  padding: 24px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.panel__header,
.header-actions,
.title-row,
.touch-actions {
  display: flex;
  align-items: center;
}

.panel__header {
  justify-content: space-between;
  gap: 16px;
}

.panel__header > div {
  min-width: 0;
}

.header-actions {
  flex: 0 0 auto;
  gap: 8px;
}

.eyebrow,
.help,
.stat__label,
.slider-label {
  color: var(--muted);
}

.eyebrow {
  margin: 0 0 6px;
  font-size: 0.8rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.title-row h1 {
  margin: 0;
  font-size: 20px;
}

.stat {
  display: inline-flex;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
  padding: 5px 10px;
  border: 1px solid rgba(255, 183, 0, 0.18);
  border-radius: 999px;
  background: var(--accent-soft);
}

.stat strong {
  color: var(--accent);
}

.stat__label {
  font-size: 0.8rem;
}

button {
  border: 0;
  border-radius: 999px;
  background: var(--button);
  color: var(--button-text);
  padding: 10px 16px;
  font: inherit;
  cursor: pointer;
}

button:disabled {
  cursor: default;
  opacity: 0.55;
}

button:focus-visible,
input:focus-visible {
  outline: 3px solid rgba(255, 183, 0, 0.35);
  outline-offset: 2px;
}

.secondary-button {
  border: 1px solid rgba(255, 183, 0, 0.22);
  background: rgba(255, 183, 0, 0.08);
  color: var(--text);
}

.icon-button {
  width: 38px;
  height: 38px;
  padding: 0;
  display: inline-grid;
  place-items: center;
  font-size: 1.45rem;
  line-height: 1;
}

.board {
  position: relative;
  aspect-ratio: 4 / 5;
  width: min(100%, calc((100dvh - 190px) * 0.8));
  max-height: 100%;
  align-self: center;
  margin-top: 16px;
  overflow: hidden;
  border-radius: 16px;
  background:
    linear-gradient(rgba(255, 255, 255, 0.035) 1px, transparent 1px) 0 0 / 42px 42px,
    linear-gradient(90deg, rgba(255, 255, 255, 0.035) 1px, transparent 1px) 0 0 / 42px 42px,
    radial-gradient(circle at 50% 105%, rgba(255, 183, 0, 0.14), transparent 45%),
    var(--grid);
  box-shadow: inset 0 0 0 3px #0d0d0d, inset 0 0 0 4px rgba(255, 183, 0, 0.22);
  touch-action: none;
}

#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.launch-hint {
  position: absolute;
  left: 50%;
  bottom: 20%;
  transform: translateX(-50%);
  max-width: calc(100% - 40px);
  padding: 8px 12px;
  border: 1px solid rgba(255, 183, 0, 0.24);
  border-radius: 999px;
  background: rgba(23, 23, 23, 0.78);
  color: var(--text);
  text-align: center;
  pointer-events: none;
}

.launch-hint.hidden {
  display: none;
}

.help {
  margin: 16px 0 0;
  line-height: 1.5;
}

.slide-controls {
  margin-top: 14px;
  display: none;
  gap: 8px;
  width: min(100%, 420px);
  align-self: center;
}

.slider-label {
  font-size: 0.8rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

.overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(23, 23, 23, 0.74);
  z-index: 10;
}

.overlay.hidden,
.hidden {
  display: none;
}

.modal {
  width: min(100%, 720px);
  max-height: calc(100dvh - 32px);
  overflow: auto;
  padding: 20px;
  border: 1px solid rgba(255, 183, 0, 0.24);
  border-radius: 16px;
  background: var(--panel);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.5);
}

.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.modal h2 {
  margin: 2px 0 0;
}

.final-score {
  margin: 0 0 16px;
  color: var(--muted);
}

.final-score strong {
  color: var(--text);
}

.overlay-options {
  display: flex;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 8px;
}

.language-menu {
  position: relative;
}

.flag-icon {
  width: 24px;
  height: 16px;
  display: block;
}

.language-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: 174px;
  max-height: min(360px, calc(100dvh - 120px));
  overflow: auto;
  padding: 6px;
  border: 1px solid rgba(255, 183, 0, 0.18);
  border-radius: 12px;
  background: #202020;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.42);
  z-index: 20;
}

.language-option {
  width: 100%;
  min-height: 36px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  text-align: left;
}

.language-option:hover,
.language-option.active {
  background: rgba(255, 183, 0, 0.1);
}

.sound-toggle {
  border: 1px solid rgba(255, 183, 0, 0.22);
  background: rgba(255, 183, 0, 0.08);
  color: var(--text);
  box-shadow: none;
}

.sound-toggle[aria-pressed="true"] {
  background: var(--button);
  color: var(--button-text);
}

.mode-heading {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 0.8rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.mode-options {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.mode-button {
  width: 100%;
  border-radius: 12px;
  padding: 8px;
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  background: #272727;
  border: 1px solid rgba(255, 183, 0, 0.16);
  color: var(--text);
  text-align: left;
  transition: border-color 120ms ease, background 120ms ease, transform 120ms ease;
}

.mode-button:hover,
.mode-button:active {
  background: #303030;
  border-color: rgba(255, 183, 0, 0.46);
  transform: translateY(-1px);
}

.mode-copy,
.mode-copy span,
.mode-button small {
  display: block;
}

.mode-copy span {
  font-weight: 700;
}

.mode-button small {
  margin-top: 3px;
  color: var(--muted);
  line-height: 1.35;
}

.mode-preview {
  position: relative;
  width: 72px;
  aspect-ratio: 1;
  border-radius: 8px;
  background:
    linear-gradient(#2a2a2a 0 0) 0 0 / calc(25% - 2px) calc(25% - 2px),
    #111111;
  background-repeat: round;
  overflow: hidden;
  box-shadow: inset 0 0 0 1px rgba(255, 183, 0, 0.14);
}

.mode-preview::before,
.mode-preview::after {
  content: "";
  position: absolute;
  border-radius: 3px;
}

.mode-preview::before {
  left: 10px;
  right: 10px;
  top: 12px;
  height: 9px;
  background:
    linear-gradient(90deg, var(--brick-red), var(--brick-cyan), var(--brick-green), var(--accent));
  box-shadow: 0 13px 0 rgba(255, 255, 255, 0.22), 0 26px 0 rgba(255, 183, 0, 0.3);
}

.mode-preview::after {
  left: 23px;
  bottom: 13px;
  width: 26px;
  height: 6px;
  background: var(--accent);
  box-shadow: 13px -13px 0 -9px #fff;
}

.mode-preview--cascade::before {
  top: 18px;
  box-shadow: 0 13px 0 rgba(255, 255, 255, 0.22), 0 26px 0 rgba(255, 183, 0, 0.3);
}

.mode-preview--rush::after {
  box-shadow: 13px -15px 0 -9px #fff, -14px -14px 0 -11px rgba(255, 255, 255, 0.45), -23px -18px 0 -12px rgba(255, 255, 255, 0.22);
}

.mode-preview--shield::before {
  background: linear-gradient(90deg, #8a8a8a, var(--brick-cyan), #8a8a8a, var(--accent));
}

.mode-preview--power::after {
  box-shadow: 13px -13px 0 -9px #fff, -20px -18px 0 -8px var(--brick-green), 24px -25px 0 -8px var(--brick-cyan);
}

.mode-preview--precision::after {
  left: 29px;
  width: 14px;
}

@media (min-width: 721px) and (orientation: landscape) {
  .panel {
    display: grid;
    grid-template-columns: minmax(0, calc((100dvh - 52px) * 0.8)) clamp(220px, 24vw, 320px);
    grid-template-rows: auto minmax(0, 1fr);
    grid-template-areas:
      "board header"
      "board help";
    align-items: start;
    justify-content: center;
    gap: 20px 24px;
  }

  .panel__header {
    grid-area: header;
    flex-direction: column;
    align-items: stretch;
    gap: 14px;
  }

  .header-actions {
    justify-content: flex-start;
    flex-wrap: wrap;
  }

  .board {
    grid-area: board;
    justify-self: center;
    width: 100%;
    max-width: calc((100dvh - 52px) * 0.8);
    margin-top: 0;
  }

  .help {
    grid-area: help;
    margin: 0;
    align-self: end;
  }
}

@media (max-width: 640px) {
  .panel {
    width: 100vw;
    height: 100dvh;
    min-height: 100dvh;
    max-height: 100dvh;
    border: 0;
    box-shadow: none;
    padding: max(8px, env(safe-area-inset-top)) 8px max(8px, env(safe-area-inset-bottom));
  }

  .panel__header {
    gap: 10px;
  }

  .header-actions {
    gap: 6px;
  }

  .stat {
    padding: 5px 8px;
  }

  .stat--lives {
    display: none;
  }

  .icon-button {
    width: 34px;
    height: 34px;
    font-size: 1.25rem;
  }

  .board {
    width: min(calc(100vw - 16px), calc((100dvh - 132px) * 0.8));
    margin-top: 10px;
    border-radius: 14px;
    flex: 0 1 auto;
  }

  .help {
    display: none;
  }

  .modal {
    padding: 16px;
  }

  .modal-header {
    flex-direction: column;
    gap: 12px;
    margin-bottom: 12px;
  }

  .overlay-options {
    justify-content: flex-start;
  }

  .language-dropdown {
    left: 0;
    right: auto;
  }

  .mode-options {
    grid-template-columns: 1fr;
  }

  .mode-button {
    grid-template-columns: 54px minmax(0, 1fr);
    padding: 8px;
    gap: 9px;
  }

  .mode-preview {
    width: 54px;
  }
}

@media (max-width: 640px) and (max-height: 700px) {
  .eyebrow {
    display: none;
  }

  .board {
    width: min(calc(100vw - 16px), calc((100dvh - 112px) * 0.8));
  }

  .launch-hint {
    bottom: 15%;
  }
}

@media (max-width: 640px) and (orientation: portrait) {
  .board {
    width: min(calc(100vw - 16px), calc((100dvh - 182px) * 0.8));
  }

  .slide-controls {
    display: grid;
  }
}

@media (max-width: 640px) and (max-height: 700px) and (orientation: portrait) {
  .board {
    width: min(calc(100vw - 16px), calc((100dvh - 148px) * 0.8));
  }
}
