:root {
  color-scheme: light;
  --bg: #f7fbff;
  --primary: #5cbf72;
  --target: #4d96ff;
  --accent: #ffd93d;
  --danger: #ff6b6b;
  --ink: #203040;
  --muted: #65758a;
  --card: #ffffff;
  --line: rgba(32, 48, 64, 0.12);
  --shadow: 0 6px 18px rgba(30, 60, 90, 0.12);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  overflow-x: hidden;
  background: linear-gradient(180deg, #f7fbff 0%, #eef8f2 62%, #fff9df 100%);
  color: var(--ink);
  font-family: "Microsoft YaHei", "PingFang SC", "Segoe UI", Arial, sans-serif;
}

button {
  font: inherit;
}

.app-shell {
  min-height: 100vh;
}

.home-view,
.result-view {
  min-height: 100vh;
  padding: 32px 20px 24px;
  display: grid;
  align-content: center;
  gap: 22px;
}

.home-hero,
.result-panel {
  width: min(960px, 100%);
  margin: 0 auto;
  text-align: center;
}

.brand-kicker {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 30px;
  padding: 4px 12px;
  border-radius: 999px;
  background: rgba(255, 217, 61, 0.48);
  color: #614d10;
  font-weight: 800;
}

.brand-lockup h1,
.result-panel h1 {
  margin: 12px 0 12px;
  font-size: 3.25rem;
  line-height: 1;
}

.brand-lockup p {
  margin: 0 auto;
  max-width: 540px;
  color: var(--muted);
  font-size: 1.2rem;
  line-height: 1.65;
}

.snake-preview {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 10px;
  margin: 32px auto 28px;
}

.preview-head {
  width: 54px;
  height: 54px;
  border: 4px solid #2c8c46;
  border-radius: 50%;
  background:
    radial-gradient(circle at 34px 18px, #203040 0 4px, transparent 5px),
    radial-gradient(circle at 34px 35px, #203040 0 4px, transparent 5px),
    var(--primary);
  box-shadow: var(--shadow);
}

.preview-segment,
.final-snake span {
  min-width: 88px;
  height: 44px;
  padding: 0 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 2px solid #2e8c4b;
  border-radius: 18px;
  background: var(--primary);
  color: var(--ink);
  font-weight: 900;
  box-shadow: var(--shadow);
}

.preview-ghost {
  border-color: var(--target);
  border-style: dashed;
  background: rgba(207, 228, 255, 0.62);
  opacity: 0.9;
}

.primary-action,
.secondary-action,
.icon-button {
  border: 0;
  cursor: pointer;
}

.primary-action {
  min-height: 58px;
  padding: 0 28px;
  border-radius: 999px;
  background: var(--ink);
  color: #fff;
  font-size: 1.08rem;
  font-weight: 900;
  box-shadow: 0 10px 24px rgba(32, 48, 64, 0.2);
}

.primary-action.compact {
  min-height: 48px;
  padding: 0 22px;
}

.secondary-action {
  min-height: 48px;
  padding: 0 18px;
  border: 2px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--ink);
  font-weight: 800;
}

.secondary-action.compact {
  min-height: 42px;
  padding: 0 16px;
}

.primary-action:hover,
.secondary-action:hover,
.icon-button:hover,
.boost-button:hover {
  transform: translateY(-1px);
}

.primary-action:focus-visible,
.secondary-action:focus-visible,
.icon-button:focus-visible,
.boost-button:focus-visible {
  outline: 4px solid rgba(77, 150, 255, 0.35);
  outline-offset: 3px;
}

.word-pack-note {
  color: var(--muted);
  font-weight: 700;
}

.steps-strip {
  width: min(960px, 100%);
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.steps-strip article {
  min-height: 104px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.78);
  box-shadow: var(--shadow);
}

.steps-strip strong,
.steps-strip span {
  display: block;
}

.steps-strip strong {
  margin-bottom: 8px;
  font-size: 1.08rem;
}

.steps-strip span {
  color: var(--muted);
  line-height: 1.45;
}

.game-view {
  min-height: 100vh;
  padding: 0;
  display: grid;
  place-items: stretch;
  background: #eef2fb;
}

.game-hud {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.icon-button {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--ink);
  color: #fff;
  font-size: 1.05rem;
  font-weight: 900;
}

.canvas-wrap {
  position: relative;
  width: 100vw;
  height: 100vh;
  aspect-ratio: 16 / 9;
  border: 0;
  border-radius: 0;
  background: #fff;
  box-shadow: none;
  overflow: hidden;
}

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

.corner-actions {
  position: absolute;
  top: max(18px, env(safe-area-inset-top));
  right: 22px;
  z-index: 3;
  display: flex;
  gap: 10px;
  padding: 8px;
  border-radius: 999px;
  background: rgba(32, 48, 64, 0.28);
  backdrop-filter: blur(6px);
}

.joystick-zone {
  --joy-x: 0px;
  --joy-y: 0px;
  position: absolute;
  left: max(34px, env(safe-area-inset-left));
  bottom: max(34px, env(safe-area-inset-bottom));
  z-index: 3;
  width: 150px;
  height: 150px;
  border-radius: 50%;
  background: rgba(32, 48, 64, 0.36);
  box-shadow: inset 0 0 0 2px rgba(255,255,255,0.18), 0 12px 32px rgba(32,48,64,0.18);
  touch-action: none;
}

.joystick-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 62px;
  height: 62px;
  border-radius: 50%;
  transform: translate(calc(-50% + var(--joy-x)), calc(-50% + var(--joy-y)));
  background: rgba(255,255,255,0.46);
  box-shadow: inset 0 0 0 2px rgba(255,255,255,0.36);
  pointer-events: none;
}

.boost-button {
  position: absolute;
  right: max(72px, env(safe-area-inset-right));
  bottom: max(42px, env(safe-area-inset-bottom));
  z-index: 3;
  width: 148px;
  height: 148px;
  border: 0;
  border-radius: 50%;
  background: rgba(32, 48, 64, 0.18);
  color: rgba(32, 48, 64, 0.56);
  font-size: 4.2rem;
  display: grid;
  place-items: center;
  box-shadow: inset 0 0 0 2px rgba(255,255,255,0.2), 0 12px 32px rgba(32,48,64,0.14);
  touch-action: none;
}

.boost-button.is-boosting {
  background: rgba(255, 217, 61, 0.42);
  color: #7c5c00;
  transform: scale(0.96);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.tutorial-layer {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(32, 48, 64, 0.28);
  backdrop-filter: blur(4px);
}

.tutorial-dialog {
  width: min(520px, 100%);
  padding: 26px;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 18px 46px rgba(30, 60, 90, 0.24);
}

.tutorial-dialog h2 {
  margin: 0 0 16px;
  font-size: 1.65rem;
}

.tutorial-dialog ol {
  margin: 0 0 22px;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 10px;
}

.tutorial-dialog li {
  padding: 14px;
  border-radius: 8px;
  background: #f7fbff;
}

.tutorial-dialog strong,
.tutorial-dialog span {
  display: block;
}

.tutorial-dialog span {
  margin-top: 4px;
  color: var(--muted);
}

.result-panel {
  padding: 30px 20px 24px;
}

.final-snake {
  margin: 24px auto;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
}

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

.metrics-grid article {
  min-height: 96px;
  padding: 14px;
  display: grid;
  align-content: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
}

.metrics-grid span {
  color: var(--muted);
  font-weight: 800;
}

.metrics-grid strong {
  margin-top: 6px;
  font-size: 1.7rem;
}

.weak-section {
  width: min(620px, 100%);
  margin: 22px auto 0;
  text-align: left;
}

.weak-section h2 {
  margin: 0 0 10px;
  text-align: center;
}

.weak-section ul {
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
  list-style: none;
}

.weak-section li {
  min-height: 48px;
  padding: 10px 14px;
  display: flex;
  justify-content: space-between;
  gap: 14px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.82);
  border: 1px solid var(--line);
}

.copy-card {
  width: min(720px, 100%);
  margin: 22px auto 0;
  padding: 16px;
  display: grid;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.86);
  box-shadow: var(--shadow);
  text-align: left;
}

.copy-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.copy-card h2 {
  margin: 0;
  font-size: 1.15rem;
}

.copy-card pre {
  max-height: 280px;
  margin: 0;
  padding: 14px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f7fbff;
  white-space: pre-wrap;
  line-height: 1.65;
  font-family: "Microsoft YaHei", "PingFang SC", "Segoe UI", Arial, sans-serif;
}

.result-actions {
  margin-top: 24px;
  display: flex;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
}

.rotate-overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: none;
  place-items: center;
  padding: 28px;
  background:
    radial-gradient(circle at 50% 26%, rgba(77, 150, 255, 0.22), transparent 34%),
    rgba(247, 251, 255, 0.96);
  text-align: center;
}

.rotate-card {
  width: min(340px, 100%);
  padding: 24px 22px;
  border: 1px solid rgba(77, 150, 255, 0.24);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 22px 54px rgba(30, 60, 90, 0.18);
}

.rotate-icon {
  display: grid;
  place-items: center;
  width: 62px;
  height: 62px;
  margin: 0 auto 14px;
  border-radius: 50%;
  color: #fff;
  background: var(--target);
  font-size: 2rem;
  font-weight: 900;
}

.rotate-card strong {
  display: block;
  font-size: 1.35rem;
}

.rotate-card p {
  margin: 10px 0 0;
  color: var(--muted);
  line-height: 1.6;
}

@media (hover: none) and (pointer: coarse) and (orientation: portrait) {
  .rotate-overlay {
    display: grid;
  }
}

@media (orientation: landscape) and (max-height: 540px) {
  .home-view,
  .result-view {
    min-height: 100vh;
    padding: max(14px, env(safe-area-inset-top)) max(18px, env(safe-area-inset-right)) max(14px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left));
    align-content: center;
    gap: 12px;
  }

  .brand-lockup h1,
  .result-panel h1 {
    margin: 8px 0;
    font-size: clamp(2rem, 8vw, 3rem);
  }

  .brand-lockup p,
  .word-pack-note {
    font-size: 0.95rem;
  }

  .snake-preview {
    margin: 14px auto 12px;
  }

  .steps-strip {
    display: none;
  }

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

  .metrics-grid article {
    min-height: 76px;
    padding: 10px;
  }

  .metrics-grid strong {
    font-size: 1.22rem;
  }

  .final-snake {
    margin: 12px auto;
  }

  .copy-card {
    margin-top: 12px;
  }

  .copy-card pre {
    max-height: 126px;
    font-size: 0.86rem;
  }

  .joystick-zone {
    width: 108px;
    height: 108px;
    left: max(18px, env(safe-area-inset-left));
    bottom: max(18px, env(safe-area-inset-bottom));
  }

  .joystick-knob {
    width: 48px;
    height: 48px;
  }

  .boost-button {
    width: 108px;
    height: 108px;
    right: max(34px, env(safe-area-inset-right));
    bottom: max(18px, env(safe-area-inset-bottom));
    font-size: 3.2rem;
  }
}

@media (max-width: 820px) {
  .home-view,
  .result-view {
    align-content: start;
    padding-top: 22px;
  }

  .brand-lockup h1,
  .result-panel h1 {
    font-size: 2.35rem;
  }

  .steps-strip,
  .metrics-grid {
    grid-template-columns: 1fr;
  }

  .game-view {
    min-height: 100vh;
  }

  .canvas-wrap {
    height: 100vh;
  }
}

@media (max-width: 520px) {
  .joystick-zone {
    width: 118px;
    height: 118px;
    left: 20px;
    bottom: 24px;
  }

  .joystick-knob {
    width: 50px;
    height: 50px;
  }

  .boost-button {
    width: 112px;
    height: 112px;
    right: 24px;
    bottom: 28px;
    font-size: 3.3rem;
  }

  .snake-preview {
    gap: 8px;
  }

  .preview-segment,
  .final-snake span {
    min-width: 76px;
    height: 40px;
    font-size: 0.9rem;
  }
}

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

@media (hover: none) and (pointer: coarse) and (orientation: landscape) and (max-height: 540px) {
  .home-view,
  .result-view {
    min-height: 100vh;
    padding: max(14px, env(safe-area-inset-top)) max(18px, env(safe-area-inset-right)) max(14px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left));
    align-content: center;
    gap: 12px;
  }

  .steps-strip {
    display: none;
  }

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

  .copy-card pre {
    max-height: 126px;
  }

  .joystick-zone {
    width: 108px;
    height: 108px;
    left: max(18px, env(safe-area-inset-left));
    bottom: max(18px, env(safe-area-inset-bottom));
  }

  .boost-button {
    width: 108px;
    height: 108px;
    right: max(34px, env(safe-area-inset-right));
    bottom: max(18px, env(safe-area-inset-bottom));
  }
}
