* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  overflow-x: hidden;
  background:
    linear-gradient(180deg, #26323a 0%, #1c2826 48%, #17211d 100%);
  color: #fffaf0;
  font-family: "Trebuchet MS", Verdana, sans-serif;
  text-align: center;
}

.game-shell {
  width: min(900px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: 18px 20px 26px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
}

.game-header {
  width: min(800px, 100%);
  margin-bottom: 12px;
}

.eyebrow {
  margin: 0 0 4px;
  color: #ffd98a;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(32px, 6vw, 56px);
  line-height: 0.95;
  color: #ffffff;
  text-shadow: 0 4px 0 rgba(35, 18, 38, 0.45);
}

.instructions {
  margin: 8px 0 0;
  color: #f8edcf;
  font-size: clamp(15px, 2.4vw, 18px);
  font-weight: 700;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.28);
}

canvas {
  background: #0b3d0b;
  display: block;
  width: 100%;
  max-width: 800px;
  height: auto;
  max-height: calc(100vh - 190px);
  aspect-ratio: 8 / 5;
  border: 4px solid #f3d58b;
  border-radius: 8px;
  box-shadow:
    0 18px 38px rgba(0, 0, 0, 0.38),
    0 0 0 2px rgba(255, 255, 255, 0.16) inset;
}

.play-area {
  width: min(100%, 800px);
  display: flex;
  flex-direction: column;
  align-items: center;
}

.progress-ribbon {
  width: min(100%, 800px);
  min-height: 44px;
  margin-bottom: 8px;
  padding: 6px 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  border: 2px solid rgba(255, 232, 150, 0.85);
  border-radius: 8px;
  background: rgba(54, 38, 75, 0.78);
  box-shadow:
    0 8px 20px rgba(0, 0, 0, 0.25),
    0 0 0 2px rgba(255, 255, 255, 0.1) inset;
}

.progress-step {
  width: 42px;
  height: 32px;
  display: inline-grid;
  place-items: center;
  border: 2px solid rgba(255, 255, 255, 0.28);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  color: #fff8dc;
  font-size: 20px;
  line-height: 1;
  transform: translateY(0);
  transition: transform 160ms ease, background 160ms ease, border-color 160ms ease;
}

.progress-step.is-complete {
  background: rgba(255, 217, 138, 0.28);
  border-color: rgba(255, 217, 138, 0.72);
}

.progress-step.is-active {
  background: #ffe36f;
  border-color: #fff8dc;
  color: #34224a;
  transform: translateY(-2px) scale(1.12);
  box-shadow: 0 5px 0 rgba(34, 18, 49, 0.55);
}

.control-rail {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.controls {
  min-height: 52px;
  margin-top: 10px;
  display: flex;
  gap: 10px;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
}

.touch-pad {
  margin-top: 12px;
  width: 208px;
  display: grid;
  grid-template-columns: repeat(3, 64px);
  grid-template-rows: repeat(3, 58px);
  gap: 8px;
  justify-content: center;
  touch-action: none;
  user-select: none;
}

button {
  min-width: 104px;
  min-height: 38px;
  padding: 9px 16px;
  border: 2px solid rgba(255, 255, 255, 0.7);
  border-radius: 8px;
  background: #5d3f86;
  color: #fff8dc;
  cursor: pointer;
  font: 700 14px/1 "Trebuchet MS", Verdana, sans-serif;
  box-shadow: 0 5px 0 rgba(34, 18, 49, 0.7);
  transition: transform 120ms ease, background 120ms ease, box-shadow 120ms ease;
}

.touch-btn {
  min-width: 64px;
  min-height: 58px;
  padding: 0;
  border-radius: 12px;
  font-size: 25px;
  line-height: 1;
}

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

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

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

.touch-down {
  grid-column: 2;
  grid-row: 3;
}

button:hover {
  background: #71519a;
  transform: translateY(-1px);
}

button:active {
  transform: translateY(3px);
  box-shadow: 0 2px 0 rgba(34, 18, 49, 0.7);
}

button:focus-visible {
  outline: 3px solid #ffd98a;
  outline-offset: 3px;
}

.primary-action {
  min-width: 124px;
  min-height: 44px;
  background: #f0b83b;
  color: #34224a;
  border-color: rgba(255, 255, 255, 0.86);
}

.primary-action:hover {
  background: #ffd45f;
}

#restartBtn {
  display: none;
}

@media (max-height: 680px) {
  .game-shell {
    justify-content: flex-start;
    padding-top: 10px;
  }

  .eyebrow {
    display: none;
  }

  h1 {
    font-size: clamp(28px, 5vw, 40px);
  }

  .instructions {
    margin-top: 4px;
  }
}

@media (pointer: coarse), (max-height: 820px) {
  .game-shell {
    padding: 10px 16px 18px;
  }

  .game-header {
    margin-bottom: 8px;
  }

  .eyebrow {
    font-size: 11px;
  }

  h1 {
    font-size: clamp(30px, 5vw, 46px);
    text-shadow: 0 3px 0 rgba(35, 18, 38, 0.45);
  }

  .instructions {
    margin-top: 5px;
    font-size: 15px;
  }

  canvas {
    width: min(100%, calc((100vh - 410px) * 1.6), 800px);
  }

  .controls {
    min-height: 44px;
    margin-top: 8px;
  }

  button {
    min-height: 36px;
  }

  .touch-pad {
    margin-top: 10px;
    width: 208px;
    grid-template-columns: repeat(3, 64px);
    grid-template-rows: repeat(3, 58px);
    gap: 8px;
  }

  .touch-btn {
    min-width: 64px;
    min-height: 58px;
    font-size: 25px;
  }
}

@media (min-width: 900px) and (max-height: 820px) {
  .game-shell {
    width: 100%;
    padding: 10px 18px 16px;
  }

  .game-header {
    margin-bottom: 8px;
  }

  .play-area {
    width: 100%;
    display: grid;
    grid-template-columns: minmax(0, 1fr) 208px;
    grid-template-areas:
      "progress controls"
      "board controls";
    justify-content: center;
    align-items: center;
    gap: 8px 14px;
  }

  .progress-ribbon {
    grid-area: progress;
    width: 100%;
    margin-bottom: 0;
  }

  canvas {
    grid-area: board;
  }

  canvas {
    width: 100%;
    max-height: calc(100vh - 190px);
  }

  .control-rail {
    grid-area: controls;
    width: 208px;
    flex-shrink: 0;
  }

  .controls {
    margin-top: 0;
  }

  .touch-pad {
    margin-top: 12px;
  }
}

@media (min-width: 820px) and (min-height: 860px) {
  .touch-pad {
    width: 220px;
    grid-template-columns: repeat(3, 66px);
    grid-template-rows: repeat(3, 56px);
    gap: 8px;
  }

  .touch-btn {
    min-width: 66px;
    min-height: 56px;
    font-size: 24px;
  }
}
