:root {
  color-scheme: light;
  font-family: "Microsoft YaHei", "PingFang SC", Arial, sans-serif;
  background: #eef6ea;
  color: #182720;
  --game-max-width: 680px;
  --leaf: #4e9b61;
  --leaf-dark: #276642;
  --sun: #f5a623;
  --berry: #d64b6b;
  --sky: #4b9bc8;
  --panel: rgba(255, 255, 255, 0.92);
}

html {
  height: 100%;
  overflow: hidden;
}

* {
  box-sizing: border-box;
}

body {
  width: 100vw;
  height: 100dvh;
  min-height: 0;
  margin: 0;
  display: grid;
  align-items: start;
  justify-items: center;
  overflow: hidden;
  padding: clamp(6px, 1.4vmin, 14px);
  background-color: #b7e7ff;
  background-image: url("../../assets/seaside-girl-dog-right-bg.png");
  background-position: center bottom;
  background-size: cover;
  background-attachment: fixed;
}

.site-logo-link {
  position: fixed;
  top: clamp(10px, 2vmin, 22px);
  left: clamp(10px, 2vmin, 22px);
  z-index: 3;
  width: clamp(38px, 5vw, 64px);
  aspect-ratio: 1;
  background-color: rgba(255, 255, 255, 0.36);
  background-image: url("../../assets/shiguangdao-logo-transparent.png");
  background-position: center;
  background-size: 82% 82%;
  background-repeat: no-repeat;
  border-radius: 999px;
  box-shadow: 0 8px 18px rgba(22, 88, 119, 0.12);
  cursor: pointer;
  transition: transform 180ms ease, background-color 180ms ease, box-shadow 180ms ease;
}

.site-logo-link:hover,
.site-logo-link:focus-visible {
  transform: translateY(-2px) scale(1.06);
  background-color: rgba(255, 255, 255, 0.56);
  box-shadow: 0 14px 28px rgba(22, 88, 119, 0.2);
  outline: none;
}

button,
a,
select {
  font: inherit;
}

.app-shell {
  position: relative;
  z-index: 1;
  width: min(100%, var(--game-max-width));
  height: 100%;
  min-height: 0;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  gap: clamp(6px, 1.2vmin, 10px);
  padding: 0;
}

.title-bar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: clamp(6px, 1.2vmin, 12px);
  padding: 2px 2px 0;
}

.back-link {
  min-height: 38px;
  padding: 9px 12px;
  border: 1px solid rgba(67, 119, 73, 0.36);
  border-radius: 8px;
  color: #17342f;
  background: linear-gradient(180deg, #ffffff, #f3fbea);
  box-shadow: 0 4px 10px rgba(48, 91, 56, 0.1);
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: transform 140ms ease, box-shadow 140ms ease, border-color 140ms ease;
}

.back-link:hover,
.back-link:focus-visible {
  transform: translateY(-1px);
  border-color: rgba(66, 199, 155, 0.68);
  outline: none;
}

.title-bar h1 {
  margin: 0;
  font-size: clamp(22px, 5vmin, 38px);
  line-height: 1.04;
  color: var(--leaf-dark);
  text-shadow: 0 2px 0 rgba(255, 255, 255, 0.72);
}

.title-bar p {
  margin: 0;
  color: #31594b;
  font-size: clamp(11px, 1.8vmin, 14px);
  text-align: right;
  max-width: 24em;
  padding: clamp(5px, 1vmin, 7px) clamp(7px, 1.3vmin, 10px);
  border: 1px solid rgba(78, 155, 97, 0.28);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.72);
  box-shadow: 0 8px 20px rgba(39, 102, 66, 0.08);
}

.game-header {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: clamp(5px, 1vmin, 10px);
}

.game-header div,
.toolbar,
.win-dialog {
  border: 1px solid rgba(96, 144, 92, 0.28);
  background: var(--panel);
  box-shadow: 0 14px 34px rgba(57, 91, 65, 0.13), inset 0 1px 0 rgba(255, 255, 255, 0.86);
}

.game-header div {
  min-width: 0;
  padding: clamp(6px, 1.1vmin, 10px) clamp(8px, 1.4vmin, 12px);
  border-radius: 8px;
  display: grid;
  gap: 4px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.98), rgba(246, 252, 240, 0.92)),
    var(--panel);
}

.game-header span {
  font-size: clamp(10px, 1.6vmin, 12px);
  color: #637566;
  letter-spacing: 0;
}

.game-header strong {
  font-size: clamp(16px, 2.8vmin, 22px);
  line-height: 1;
  white-space: nowrap;
  color: #1d3a2d;
}

.board-wrap {
  position: relative;
  align-self: center;
  justify-self: center;
  width: var(--board-width, min(100%, var(--game-max-width)));
  height: var(--board-height, auto);
  max-width: 100%;
  max-height: 100%;
  aspect-ratio: var(--board-ratio, 1 / 1);
}

.board {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: repeat(var(--cols), minmax(0, 1fr));
  grid-template-rows: repeat(var(--rows), minmax(0, 1fr));
  gap: clamp(3px, 0.9vmin, 8px);
  padding: clamp(5px, 1.2vmin, 12px);
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.22), transparent 42%),
    #dce9cb;
  border: 2px solid #9fbe8e;
  outline: 4px solid rgba(255, 255, 255, 0.62);
  box-shadow:
    0 18px 38px rgba(47, 82, 51, 0.18),
    inset 0 1px 0 rgba(255, 255, 255, 0.8);
  transition: border-color 180ms ease, box-shadow 180ms ease, background 180ms ease;
}

.board.mode-down {
  border-color: var(--sky);
}

.board.mode-left {
  border-color: var(--leaf);
}

.board.mode-right {
  border-color: var(--sun);
}

.board.mode-up {
  border-color: #8a6bd6;
}

.board.mode-split-vertical {
  border-color: var(--berry);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.34) 0 48%, rgba(214, 75, 107, 0.12) 48% 52%, rgba(255, 255, 255, 0.12) 52%),
    #dce9cb;
}

.tile {
  min-width: 0;
  min-height: 0;
  border: 1px solid rgba(96, 125, 85, 0.34);
  border-radius: 8px;
  background:
    linear-gradient(180deg, #ffffff 0%, #fffaf0 100%);
  font-size: clamp(18px, 4.8vmin, 40px);
  line-height: 1;
  display: grid;
  place-items: center;
  cursor: pointer;
  box-shadow:
    0 4px 9px rgba(78, 103, 80, 0.12),
    inset 0 1px 0 rgba(255, 255, 255, 0.9);
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.75);
  transition: transform 130ms ease, border-color 130ms ease, box-shadow 130ms ease, opacity 170ms ease, background 130ms ease;
}

.tile:hover {
  transform: translateY(-1px);
  border-color: var(--leaf);
  background: linear-gradient(180deg, #ffffff 0%, #f4ffe9 100%);
}

.tile.selected,
.tile.hint {
  border-color: var(--sun);
  box-shadow: 0 0 0 3px rgba(245, 166, 35, 0.25), 0 7px 16px rgba(78, 103, 80, 0.18);
}

.tile.empty {
  opacity: 0;
  pointer-events: none;
}

.tile.removing {
  transform: scale(0.82);
  opacity: 0;
}

.tile.wrong {
  animation: shake 180ms ease-in-out;
}

.path-layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  overflow: visible;
}

.path-layer polyline {
  fill: none;
  stroke: #f29d38;
  stroke-width: 6;
  stroke-linecap: round;
  stroke-linejoin: round;
  filter: drop-shadow(0 2px 3px rgba(107, 67, 18, 0.25));
}

.toolbar {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: clamp(5px, 1vmin, 10px);
  padding: clamp(6px, 1.1vmin, 10px);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.98), rgba(247, 252, 242, 0.93)),
    var(--panel);
}

.toolbar button,
.toolbar select,
.win-dialog button {
  min-height: clamp(34px, 5.2vmin, 42px);
  border: 1px solid rgba(67, 119, 73, 0.36);
  border-radius: 8px;
  background: linear-gradient(180deg, #ffffff, #f3fbea);
  color: #22382a;
  cursor: pointer;
  box-shadow: 0 4px 10px rgba(48, 91, 56, 0.1);
  transition: transform 130ms ease, border-color 130ms ease, box-shadow 130ms ease, background 130ms ease;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.game-header strong.danger {
  color: #c43f37;
}

.toolbar button:hover,
.toolbar select:hover,
.win-dialog button:hover {
  border-color: var(--leaf);
  transform: translateY(-1px);
  box-shadow: 0 7px 16px rgba(48, 91, 56, 0.15);
}

.toolbar button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.win-dialog {
  width: min(90vw, 330px);
  border-radius: 8px;
  padding: 26px 24px 24px;
  text-align: center;
  border: 2px solid rgba(78, 155, 97, 0.45);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.98), rgba(248, 255, 241, 0.96));
  animation: result-pop 280ms cubic-bezier(0.2, 1.2, 0.3, 1);
}

.win-dialog.result-success {
  border-color: rgba(78, 155, 97, 0.58);
  box-shadow: 0 20px 44px rgba(57, 91, 65, 0.24), inset 0 1px 0 rgba(255, 255, 255, 0.9);
}

.win-dialog.result-fail {
  border-color: rgba(214, 75, 107, 0.5);
  box-shadow: 0 20px 44px rgba(112, 43, 61, 0.22), inset 0 1px 0 rgba(255, 255, 255, 0.9);
}

.win-dialog h2 {
  margin: 0 0 8px;
  font-size: 28px;
  color: var(--leaf-dark);
}

.win-dialog p {
  margin: 0 0 18px;
  color: #456257;
  line-height: 1.6;
}

.win-dialog::backdrop {
  background: rgba(31, 42, 36, 0.44);
  backdrop-filter: blur(3px);
}

@keyframes shake {
  0%,
  100% {
    transform: translateX(0);
  }
  35% {
    transform: translateX(-5px);
  }
  70% {
    transform: translateX(5px);
  }
}

@keyframes result-pop {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@media (max-width: 560px) {
  body {
    padding: 6px;
  }

  .title-bar {
    align-items: start;
    flex-direction: column;
  }

  .title-bar p {
    text-align: left;
  }

  .game-header {
    gap: 6px;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .game-header div {
    padding: 8px;
  }

  .game-header strong {
    font-size: 17px;
  }

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

  .toolbar button,
  .toolbar select {
    min-width: 0;
    padding-inline: 4px;
    font-size: 12px;
  }

  .tile {
    border-radius: 6px;
  }
}
