:root {
  --ink: #141414;
  --muted: #5f6661;
  --paper: #f3f6f2;
  --panel: #ffffff;
  --line: #d7ddd5;
  --red: #b23b32;
  --teal: #16746b;
  --gold: #c58a20;
  --charcoal: #242424;
  --green: #506d43;
  --night: #151819;
  --sky: #dfe9ee;
  --shadow: 0 18px 44px rgba(20, 20, 20, 0.14);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 14% 9%, rgba(197, 138, 32, 0.16), transparent 25%),
    linear-gradient(180deg, #fbfcfa 0%, var(--paper) 46%, #e9eee8 100%);
  font-family: "Microsoft JhengHei", "PingFang TC", "Noto Sans TC", Arial, sans-serif;
  line-height: 1.7;
  letter-spacing: 0;
}

button {
  font: inherit;
}

.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(21, 24, 25, 0.94);
  backdrop-filter: blur(16px);
}

.nav {
  width: min(1180px, calc(100% - 32px));
  min-height: 72px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: #fff;
  font-weight: 800;
  text-decoration: none;
  white-space: nowrap;
}

.brand-mark {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  color: #fff;
  background: var(--red);
  box-shadow: 0 8px 20px rgba(178, 59, 50, 0.32);
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.nav-links a {
  color: rgba(255, 255, 255, 0.82);
  padding: 8px 10px;
  border-radius: 8px;
  text-decoration: none;
  font-size: 14px;
}

.nav-links a:hover,
.nav-links a:focus-visible {
  color: #fff;
  background: rgba(255, 255, 255, 0.10);
  outline: none;
}

.game-hero {
  position: relative;
  color: #fff;
  background:
    linear-gradient(135deg, rgba(21, 24, 25, 0.95), rgba(36, 36, 36, 0.84)),
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.06) 0 1px, transparent 1px 80px);
  overflow: hidden;
}

.game-hero::after {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(90deg, rgba(21, 24, 25, 0.92) 0%, rgba(21, 24, 25, 0.74) 42%, rgba(21, 24, 25, 0.10) 100%),
    linear-gradient(180deg, rgba(21, 24, 25, 0.08) 0%, rgba(21, 24, 25, 0.56) 100%);
}

.hero-bg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center right;
  filter: saturate(0.94) contrast(1.03);
}

.game-hero-inner {
  position: relative;
  z-index: 1;
  width: min(1180px, calc(100% - 32px));
  min-height: clamp(330px, 52vh, 540px);
  margin: 0 auto;
  display: flex;
  align-items: center;
  padding: 56px 0 72px;
}

.eyebrow,
.panel-label {
  margin: 0 0 8px;
  color: var(--gold);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
}

.hero-copy h1 {
  margin: 0;
  font-size: clamp(42px, 8vw, 92px);
  line-height: 0.98;
}

.hero-copy p:last-child {
  max-width: 660px;
  margin: 22px 0 0;
  color: rgba(255, 255, 255, 0.82);
  font-size: clamp(17px, 2.2vw, 23px);
}

.arrow {
  position: absolute;
  left: 50%;
  top: 50%;
  width: min(48%, 30px);
  height: min(48%, 30px);
  transform: translate(-50%, -50%);
}

.arrow::before {
  content: "";
  position: absolute;
  left: 43%;
  top: 28%;
  width: 14%;
  height: 58%;
  border-radius: 8px;
  background: #fff;
}

.arrow::after {
  content: "";
  position: absolute;
  left: 20%;
  top: 4%;
  width: 60%;
  height: 44%;
  background: #fff;
  clip-path: polygon(50% 0, 100% 100%, 0 100%);
}

.game-shell {
  width: min(1180px, calc(100% - 32px));
  margin: -44px auto 42px;
  display: grid;
  grid-template-columns: 316px 1fr;
  gap: 18px;
  align-items: stretch;
}

.control-panel,
.board-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
}

.control-panel {
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding: 22px;
}

.control-panel h2,
.board-head h2 {
  margin: 0;
  line-height: 1.2;
}

.panel-note {
  margin: 8px 0 0;
  color: var(--muted);
}

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

.metrics div {
  min-height: 76px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8faf7;
}

.metrics span,
.progress-label {
  display: block;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.metrics strong {
  display: block;
  margin-top: 3px;
  color: var(--charcoal);
  font-size: 28px;
  line-height: 1.15;
}

.progress-label {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.progress-bar {
  height: 12px;
  border-radius: 999px;
  background: #e0e6df;
  overflow: hidden;
}

.progress-bar span {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--teal), var(--gold));
  transition: width 220ms ease;
}

.actions,
.level-actions {
  display: grid;
  gap: 10px;
}

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

.actions button:first-child {
  grid-column: 1 / -1;
}

.level-actions {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.actions button,
.level-actions button {
  min-height: 44px;
  border: 1px solid rgba(20, 20, 20, 0.10);
  border-radius: 8px;
  color: #fff;
  background: var(--charcoal);
  cursor: pointer;
}

.actions button:hover,
.actions button:focus-visible,
.level-actions button:hover,
.level-actions button:focus-visible {
  background: #000;
  outline: 3px solid rgba(178, 59, 50, 0.20);
}

#hintBtn {
  background: var(--teal);
}

#shuffleBtn,
#nextBtn {
  background: var(--red);
}

.toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--charcoal);
  font-weight: 700;
}

.toggle input {
  width: 20px;
  height: 20px;
  accent-color: var(--red);
}

.board-panel {
  position: relative;
  overflow: hidden;
  padding: 22px;
}

.board-panel::before {
  content: "";
  position: absolute;
  inset: auto -60px -90px auto;
  width: 270px;
  height: 270px;
  border: 28px solid rgba(22, 116, 107, 0.10);
  transform: rotate(18deg);
}

.board-head {
  position: relative;
  z-index: 1;
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: start;
  margin-bottom: 16px;
}

.available-badge {
  min-width: 96px;
  padding: 8px 12px;
  border-radius: 999px;
  color: #fff;
  background: var(--green);
  text-align: center;
  font-weight: 800;
  white-space: nowrap;
}

.board-stage {
  position: relative;
  min-height: clamp(438px, 68vh, 650px);
  display: grid;
  place-items: center;
  border: 1px solid #cfd8cf;
  border-radius: 8px;
  background:
    linear-gradient(0deg, rgba(243, 246, 242, 0.50), rgba(243, 246, 242, 0.50)),
    var(--level-bg, url("./assets/level-bg-01-taiwan-day.png")) center / cover no-repeat,
    linear-gradient(160deg, #edf4f0 0%, #fbfcfa 48%, #e5ebdf 100%);
  overflow: hidden;
}

.destination-card {
  position: absolute;
  z-index: 1;
  left: 18px;
  top: 18px;
  width: 116px;
  padding: 10px 12px;
  border: 1px dashed rgba(20, 20, 20, 0.26);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.76);
  transform: rotate(-3deg);
}

.destination-card span,
.destination-card strong {
  display: block;
}

.destination-card span {
  color: var(--red);
  font-size: 12px;
  font-weight: 900;
}

.destination-card strong {
  margin-top: 2px;
  font-size: 19px;
}

.board {
  --size: 6;
  position: relative;
  z-index: 1;
  display: grid;
  width: min(100%, 760px);
  grid-template-columns: repeat(var(--size), minmax(0, 1fr));
  grid-template-rows: repeat(var(--size), minmax(0, 1fr));
  gap: clamp(4px, 0.8vmin, 8px);
  padding: clamp(8px, 2vmin, 18px);
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}

.cell {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}

.cube {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 8px;
  color: #fff;
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.24), transparent 36%),
    var(--cube-color, var(--red));
  box-shadow:
    inset 0 -8px 0 rgba(0, 0, 0, 0.16),
    inset 0 0 0 2px rgba(255, 255, 255, 0.16),
    0 10px 0 var(--cube-side, #76251f),
    0 17px 20px rgba(20, 20, 20, 0.22);
  cursor: pointer;
  transition: transform 260ms ease, opacity 260ms ease, box-shadow 200ms ease, filter 200ms ease;
  touch-action: manipulation;
}

.cube::before {
  content: "";
  position: absolute;
  left: 27%;
  right: 27%;
  top: -10%;
  height: 24%;
  border: clamp(2px, 0.5vmin, 4px) solid rgba(255, 255, 255, 0.70);
  border-bottom: 0;
  border-radius: 9px 9px 0 0;
}

.cube::after {
  content: "";
  position: absolute;
  right: 12%;
  bottom: 12%;
  width: 20%;
  height: 28%;
  border-radius: 5px 5px 8px 8px;
  background: rgba(255, 255, 255, 0.24);
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.20);
}

.cube:hover,
.cube:focus-visible {
  transform: translateY(-3px);
  outline: none;
  filter: brightness(1.05);
}

.cube.removable {
  box-shadow:
    inset 0 -8px 0 rgba(0, 0, 0, 0.16),
    inset 0 0 0 2px rgba(255, 255, 255, 0.20),
    0 10px 0 var(--cube-side, #76251f),
    0 17px 22px rgba(20, 20, 20, 0.22),
    0 0 0 4px rgba(197, 138, 32, 0.20);
}

.cube.blocked {
  animation: bump 260ms ease;
}

.cube.blocker {
  animation: blockerPulse 580ms ease;
}

.cube.hint {
  animation: hintPulse 900ms ease infinite;
}

.cube.leaving {
  pointer-events: none;
  opacity: 0;
}

.cube.leaving[data-dir="up"] {
  transform: translateY(-170px) scale(0.78);
}

.cube.leaving[data-dir="down"] {
  transform: translateY(170px) scale(0.78);
}

.cube.leaving[data-dir="left"] {
  transform: translateX(-170px) scale(0.78);
}

.cube.leaving[data-dir="right"] {
  transform: translateX(170px) scale(0.78);
}

.arrow.dir-up {
  transform: translate(-50%, -50%) rotate(0deg);
}

.arrow.dir-right {
  transform: translate(-50%, -50%) rotate(90deg);
}

.arrow.dir-down {
  transform: translate(-50%, -50%) rotate(180deg);
}

.arrow.dir-left {
  transform: translate(-50%, -50%) rotate(270deg);
}

.status-text {
  min-height: 34px;
  margin: 14px 0 0;
  color: var(--muted);
  font-weight: 700;
}

@keyframes bump {
  0%,
  100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-5px);
  }
  50% {
    transform: translateX(5px);
  }
  75% {
    transform: translateX(-3px);
  }
}

@keyframes blockerPulse {
  0%,
  100% {
    filter: brightness(1);
  }
  50% {
    filter: brightness(1.22);
  }
}

@keyframes hintPulse {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-6px);
  }
}

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

  .game-shell {
    margin-top: -28px;
  }

  .control-panel {
    order: 2;
  }

  .board-panel {
    order: 1;
  }
}

@media (max-width: 620px) {
  .nav {
    min-height: 64px;
    align-items: flex-start;
    flex-direction: column;
    justify-content: center;
    padding: 12px 0;
  }

  .brand {
    white-space: normal;
  }

  .nav-links {
    justify-content: flex-start;
  }

  .game-hero-inner {
    padding: 36px 0 58px;
  }

  .hero-copy h1 {
    font-size: clamp(38px, 15vw, 58px);
  }

  .board-panel,
  .control-panel {
    padding: 16px;
  }

  .board-head {
    align-items: stretch;
    flex-direction: column;
  }

  .available-badge {
    width: fit-content;
  }

  .board-stage {
    min-height: 420px;
  }

  .destination-card {
    left: 10px;
    top: 10px;
    width: 96px;
  }

  .board {
    gap: 4px;
    padding: 8px;
  }

  .metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

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