:root {
  --sky: #b6d0ec;
  --sky-deep: #83b6df;
  --ink: #132742;
  --ink-soft: #516881;
  --paper: #ffffff;
  --line: #e8edf4;
  --primary: #1daee2;
  --primary-dark: #1286bc;
  --highlight: #f7c948;
  --danger: #f05a67;
  --shadow: 0 10px 22px rgba(43, 73, 110, 0.16);
  font-family: "Microsoft YaHei", "PingFang SC", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--sky);
  color: var(--ink);
  overscroll-behavior: none;
}

button {
  border: 0;
  font: inherit;
  color: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.game-shell {
  height: 100dvh;
  max-width: 520px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  background: var(--paper);
  box-shadow: 0 0 34px rgba(33, 56, 86, 0.14);
}

.home-screen {
  position: relative;
  height: 100dvh;
  max-width: 520px;
  margin: 0 auto;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(circle at 16% 17%, rgba(255, 255, 255, 0.42) 0 2px, transparent 3px) 0 0 / 26px 26px,
    linear-gradient(180deg, #b6d0ec 0%, #d9e8f7 43%, #f7fbff 100%);
  box-shadow: 0 0 34px rgba(33, 56, 86, 0.14);
}

.home-head {
  flex: 0 0 auto;
  display: flex;
  justify-content: flex-end;
  padding: max(18px, env(safe-area-inset-top)) 18px 0;
}

.home-settings {
  width: 48px;
  height: 48px;
}

.home-content {
  flex: 1;
  min-height: 0;
  padding: 20px 25px max(32px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  align-items: center;
}

.player-badge {
  position: absolute;
  top: max(24px, env(safe-area-inset-top));
  left: 22px;
  margin: 0;
  padding: 8px 13px;
  border-radius: 18px;
  color: var(--ink-soft);
  font-size: 13px;
  background: rgba(255, 255, 255, 0.72);
}

.player-badge strong {
  color: var(--primary-dark);
}

.brand-mark {
  margin: clamp(34px, 8vh, 72px) 0 30px;
  display: flex;
  flex-direction: column;
  text-align: center;
  font-weight: 800;
  line-height: 1;
  color: #fff;
  text-shadow: 0 3px 0 rgba(33, 74, 123, 0.19);
}

.brand-mark span {
  font-size: 34px;
  letter-spacing: 7px;
}

.brand-mark strong {
  margin-top: 8px;
  color: var(--primary-dark);
  font-size: 53px;
  letter-spacing: 4px;
  text-shadow: 0 3px 0 rgba(255, 255, 255, 0.6);
}

.progress-card {
  width: min(310px, 100%);
  padding: 20px 14px 18px;
  text-align: center;
  border-radius: 24px;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: var(--shadow);
}

.progress-card p {
  margin: 0 0 8px;
  color: var(--ink-soft);
  font-size: 14px;
}

.progress-number {
  font-size: 26px;
  font-weight: 700;
  color: var(--ink);
}

.progress-number strong {
  color: var(--primary-dark);
  font-size: 43px;
}

.progress-card small {
  display: block;
  margin-top: 6px;
  color: var(--ink-soft);
}

.inventory {
  width: min(310px, 100%);
  margin-top: 17px;
}

.inventory h2 {
  margin: 0 0 9px;
  color: var(--ink-soft);
  text-align: center;
  font-size: 13px;
  font-weight: 400;
}

.gift-balance {
  margin: 9px 0 0;
  color: var(--ink-soft);
  text-align: center;
  font-size: 12px;
}

.inventory-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 9px;
}

.inventory-item {
  min-height: 68px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.8);
  box-shadow: 0 3px 13px rgba(41, 74, 111, 0.08);
}

.inventory-item span {
  font-size: 13px;
  color: var(--ink-soft);
}

.inventory-item strong {
  color: var(--primary-dark);
  font-size: 24px;
}

.home-actions {
  width: min(310px, 100%);
  margin-top: auto;
  display: grid;
  gap: 12px;
}

.start-button,
.select-button {
  min-height: 56px;
  border-radius: 28px;
  font-size: 18px;
  font-weight: 700;
}

.start-button {
  color: #fff;
  background: linear-gradient(180deg, #31c5ee, #1599d5);
  box-shadow: 0 6px 0 rgba(13, 112, 174, 0.25), 0 12px 24px rgba(28, 146, 203, 0.22);
}

.start-button:active {
  transform: translateY(3px);
  box-shadow: 0 3px 0 rgba(13, 112, 174, 0.25);
}

.select-button {
  color: var(--primary-dark);
  background: rgba(255, 255, 255, 0.88);
}

.hud {
  flex: 0 0 auto;
  min-height: 112px;
  padding: max(18px, env(safe-area-inset-top)) 18px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: var(--sky);
}

.icon-button {
  width: 52px;
  height: 52px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: #fff;
  background: linear-gradient(145deg, #35c2eb, #1397d4);
  box-shadow: 0 5px 0 rgba(19, 104, 163, 0.25), var(--shadow);
}

.icon-button:active {
  transform: translateY(2px);
  box-shadow: 0 3px 0 rgba(19, 104, 163, 0.25);
}

.icon-button svg {
  width: 27px;
  height: 27px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.1;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon-button:last-child svg {
  fill: currentColor;
  stroke: none;
}

.level-status {
  text-align: center;
  min-width: 122px;
}

.level-title {
  color: #fff;
  font-size: 26px;
  font-weight: 700;
  text-shadow: 0 2px 1px rgba(37, 71, 110, 0.5);
}

.remaining-pill {
  display: inline-flex;
  gap: 5px;
  align-items: center;
  margin-top: 7px;
  padding: 5px 15px;
  border-radius: 16px;
  color: var(--ink);
  font-size: 13px;
  background: rgba(255, 255, 255, 0.8);
}

.board-frame {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: var(--paper);
  touch-action: none;
}

.zoom-tip {
  position: absolute;
  top: 12px;
  margin: 0;
  padding: 6px 12px;
  color: var(--ink-soft);
  font-size: 12px;
  border-radius: 18px;
  background: #f3f7fb;
  opacity: 1;
  transition: opacity 240ms ease;
  z-index: 2;
}

.zoom-tip.hidden {
  opacity: 0;
}

.board {
  max-width: 92vw;
  max-height: calc(100% - 52px);
  overflow: visible;
  transform: scale(var(--scale, 1));
  transform-origin: center;
  transition: transform 100ms ease-out;
}

.arrow {
  color: var(--ink);
  cursor: pointer;
}

.arrow .trail,
.arrow .head {
  fill: none;
  stroke: currentColor;
  stroke-width: var(--path-width, 5.1px);
  stroke-linecap: round;
  stroke-linejoin: round;
}

.arrow .hit-line {
  fill: none;
  stroke: transparent;
  stroke-width: var(--hit-width, 11px);
  stroke-linecap: round;
  stroke-linejoin: round;
  pointer-events: stroke;
}

.arrow.blocked .trail,
.arrow.blocked .head {
  color: var(--danger);
  animation: blocked 330ms ease;
}

.arrow.hinted .trail,
.arrow.hinted .head {
  color: var(--highlight);
  filter: drop-shadow(0 0 5px rgba(247, 201, 72, 0.75));
  animation: pulse 800ms ease-in-out infinite alternate;
}

.arrow.flowing {
  pointer-events: none;
}

.tools {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  padding: 12px 12px max(13px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: #f6f9fc;
}

.tool-button {
  position: relative;
  min-height: 72px;
  padding: 8px 4px 5px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  border-radius: 15px;
  background: #fff;
  box-shadow: 0 2px 10px rgba(38, 62, 88, 0.07);
}

.tool-button svg {
  width: 25px;
  height: 25px;
  fill: none;
  stroke: var(--primary-dark);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.tool-button span {
  font-size: 13px;
}

.tool-button small {
  min-width: 20px;
  padding: 1px 6px;
  border-radius: 8px;
  color: #fff;
  font-size: 11px;
  background: var(--primary);
}

.tool-button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.toast {
  position: fixed;
  bottom: 106px;
  left: 50%;
  transform: translate(-50%, 14px);
  padding: 10px 18px;
  border-radius: 20px;
  color: #fff;
  font-size: 14px;
  background: rgba(19, 39, 66, 0.88);
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease, transform 180ms ease;
  z-index: 20;
}

.toast.visible {
  transform: translate(-50%, 0);
  opacity: 1;
}

.modal,
.sheet {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 22px;
  background: rgba(16, 31, 51, 0.4);
  z-index: 10;
}

.sheet {
  align-items: flex-end;
  padding: 0;
}

.hidden {
  display: none !important;
}

.modal-card {
  width: min(330px, 100%);
  padding: 27px 21px 20px;
  text-align: center;
  border-radius: 23px;
  background: #fff;
  box-shadow: var(--shadow);
}

.modal-card h2,
.sheet-head h2 {
  margin: 0 0 10px;
  font-size: 23px;
}

.modal-card p {
  margin: 0 0 24px;
  color: var(--ink-soft);
}

.modal-actions,
.deadlock-actions {
  display: flex;
  gap: 10px;
}

.deadlock-actions {
  flex-wrap: wrap;
}

.deadlock-actions button:last-child {
  flex-basis: 100%;
}

.primary-button,
.secondary-button {
  min-height: 46px;
  flex: 1;
  border-radius: 14px;
  font-weight: 700;
}

.primary-button {
  color: #fff;
  background: var(--primary);
}

.secondary-button {
  color: var(--ink);
  background: #edf3f8;
}

.nickname-card p {
  color: var(--ink-soft);
  font-size: 14px;
  line-height: 1.6;
}

.nickname-input {
  width: 100%;
  height: 48px;
  margin: 8px 0 6px;
  padding: 0 14px;
  border: 1px solid #dbe5f0;
  border-radius: 12px;
  font: inherit;
  color: var(--ink);
  outline: none;
}

.nickname-input:focus {
  border-color: var(--primary);
}

.nickname-error {
  margin: 0 0 8px !important;
  color: var(--danger) !important;
  font-size: 12px !important;
}

.nickname-confirm {
  width: 100%;
  margin-top: 14px;
}

.sheet-card {
  width: min(520px, 100%);
  max-height: 72dvh;
  border-radius: 24px 24px 0 0;
  padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
  background: #fff;
}

.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 13px;
}

.sheet-head h2 {
  margin: 0;
}

.close-button {
  width: 44px;
  height: 44px;
  font-size: 31px;
  line-height: 1;
  color: var(--ink-soft);
  background: transparent;
}

.level-grid {
  max-height: calc(72dvh - 86px);
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
}

.level-chip {
  min-height: 48px;
  border-radius: 12px;
  font-weight: 700;
  background: #edf3f8;
}

.level-chip.current {
  color: #fff;
  background: var(--primary);
}

.level-chip:disabled {
  color: #acb7c4;
  background: #f5f6f8;
}

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

@keyframes pulse {
  from { opacity: 0.75; }
  to { opacity: 1; }
}

@media (max-height: 620px) {
  .brand-mark {
    margin: 8px 0 13px;
  }

  .brand-mark strong {
    font-size: 42px;
  }

  .home-content {
    padding-top: 8px;
    padding-bottom: 14px;
  }

  .hud {
    min-height: 88px;
    padding-top: 10px;
  }

  .icon-button {
    width: 45px;
    height: 45px;
  }

  .level-title {
    font-size: 22px;
  }

  .tools {
    padding-top: 8px;
  }

  .tool-button {
    min-height: 62px;
  }
}

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