:root {
  --font: "Plus Jakarta Sans", Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --ink: #111827;
  --muted: #516174;
  --panel: rgba(255, 255, 255, .92);
  --line: rgba(17, 24, 39, .13);
  --teal: #0f766e;
  --blue: #2563eb;
  --gold: #fbbf24;
  --coral: #f97316;
  --danger: #dc2626;
  --gap: clamp(5px, 1vw, 9px);
}

* {
  box-sizing: border-box;
  letter-spacing: 0;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #0f172a;
  color: var(--ink);
  font-family: var(--font);
}

button {
  font: inherit;
  touch-action: manipulation;
}

.pattern-app {
  position: relative;
  width: 100%;
  height: 100svh;
  min-height: 360px;
  overflow: hidden;
  background:
    radial-gradient(circle at 10% 12%, rgba(251, 191, 36, .46), transparent 18%),
    radial-gradient(circle at 88% 8%, rgba(45, 212, 191, .36), transparent 22%),
    linear-gradient(135deg, #eef8ff 0%, #f8fafc 46%, #e8f7ef 100%);
  isolation: isolate;
  user-select: none;
}

.pattern-app::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  background:
    linear-gradient(rgba(15, 118, 110, .08) 1px, transparent 1px),
    linear-gradient(90deg, rgba(37, 99, 235, .08) 1px, transparent 1px);
  background-size: 42px 42px;
  mask-image: linear-gradient(180deg, rgba(0, 0, 0, .8), rgba(0, 0, 0, .18));
}

.asset-loader,
.game-overlay,
.rotate-overlay {
  position: absolute;
  inset: 0;
  z-index: 60;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background:
    linear-gradient(180deg, rgba(15, 23, 42, .42), rgba(15, 23, 42, .62)),
    radial-gradient(circle at 50% 20%, rgba(255, 255, 255, .35), transparent 34%);
  backdrop-filter: blur(12px);
}

.pattern-app.is-loading .asset-loader,
.game-overlay.is-visible {
  display: flex;
}

.asset-loader {
  z-index: 90;
  background:
    radial-gradient(circle at 26% 16%, rgba(255, 255, 255, .95), transparent 18%),
    radial-gradient(circle at 75% 18%, rgba(251, 191, 36, .42), transparent 24%),
    linear-gradient(135deg, #0f172a 0%, #0f766e 52%, #4338ca 100%);
}

.loader-card,
.overlay-card,
.rotate-card {
  width: min(520px, 100%);
  border: 1px solid rgba(255, 255, 255, .64);
  border-radius: 8px;
  background: rgba(255, 255, 255, .95);
  box-shadow: 0 26px 80px rgba(15, 23, 42, .26);
  padding: clamp(18px, 4vw, 34px);
  text-align: center;
}

.brand-loader {
  position: relative;
  overflow: hidden;
  background: linear-gradient(180deg, rgba(255, 255, 255, .98), rgba(239, 253, 247, .92));
}

.brand-loader::before {
  content: "";
  position: absolute;
  inset: -45% -18% auto;
  height: 140px;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, .78), transparent);
  transform: rotate(-8deg) translateX(-55%);
  animation: loaderSweep 2.2s ease-in-out infinite;
  pointer-events: none;
}

.loader-eyebrow,
.overlay-kicker,
.small-label {
  margin: 0;
  color: #0f766e;
  font-size: 10px;
  font-weight: 950;
  line-height: 1.2;
  text-transform: uppercase;
}

.loader-eyebrow,
.overlay-kicker {
  letter-spacing: .12em;
}

.loader-brand,
.overlay-card h2,
.rotate-card strong {
  margin: 0;
  color: #0f172a;
  line-height: 1.06;
  font-size: clamp(26px, 5vw, 40px);
  font-weight: 950;
}

.loader-brand {
  display: flex;
  justify-content: center;
  white-space: nowrap;
  font-size: clamp(28px, 9vw, 58px);
}

.loader-brand span {
  display: inline-block;
  background: linear-gradient(135deg, #0f172a 0%, #0f766e 52%, #f97316 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  opacity: 0;
  transform: translateX(-28px) translateY(8px) rotate(-5deg);
  animation: brandLetterIn .68s cubic-bezier(.18, .86, .25, 1.18) forwards;
  animation-delay: calc(var(--i) * .075s);
}

.loader-card p,
.overlay-card p,
.rotate-card p {
  margin: 12px 0 0;
  color: var(--muted);
  line-height: 1.55;
}

.loader-bar {
  height: 10px;
  margin-top: 18px;
  border-radius: 999px;
  overflow: hidden;
  background: #dceee7;
}

.loader-bar span {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #0f766e, #2563eb, #f97316);
  transition: width .25s ease;
}

@keyframes brandLetterIn {
  0% { opacity: 0; transform: translateX(-28px) translateY(8px) rotate(-5deg); }
  68% { opacity: 1; transform: translateX(3px) translateY(0) rotate(1deg); }
  100% { opacity: 1; transform: translateX(0) translateY(0) rotate(0); }
}

@keyframes loaderSweep {
  0%, 18% { transform: rotate(-8deg) translateX(-62%); }
  62%, 100% { transform: rotate(-8deg) translateX(62%); }
}

.rotate-overlay {
  z-index: 75;
}

.rotate-card {
  max-width: 380px;
}

.rotate-phone {
  position: relative;
  width: 108px;
  height: 108px;
  margin: 0 auto 18px;
}

.rotate-phone::before,
.rotate-phone::after,
.rotate-phone span {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
}

.rotate-phone::before {
  width: 46px;
  height: 74px;
  border: 5px solid #0f172a;
  border-radius: 14px;
  background: linear-gradient(180deg, #f8fafc, #dcfce7);
  box-shadow: 0 18px 36px rgba(15, 23, 42, .16);
  transform: translate(-50%, -50%) rotate(0deg);
  animation: phoneTurn 1.8s ease-in-out infinite;
}

.rotate-phone::after {
  width: 82px;
  height: 82px;
  border: 4px solid rgba(15, 118, 110, .32);
  border-left-color: #0f766e;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  animation: rotateRing 1.8s linear infinite;
}

.rotate-phone span {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #f97316;
  transform: translate(-50%, 20px);
}

@keyframes phoneTurn {
  0%, 22% { transform: translate(-50%, -50%) rotate(0deg); }
  58%, 100% { transform: translate(-50%, -50%) rotate(90deg); }
}

@keyframes rotateRing {
  to { transform: translate(-50%, -50%) rotate(360deg); }
}

.game-topbar {
  position: absolute;
  top: max(10px, env(safe-area-inset-top));
  left: max(10px, env(safe-area-inset-left));
  right: max(10px, env(safe-area-inset-right));
  z-index: 20;
  min-height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 10px;
  border: 1px solid rgba(255, 255, 255, .7);
  border-radius: 8px;
  background: rgba(255, 255, 255, .86);
  box-shadow: 0 14px 40px rgba(15, 23, 42, .12);
  backdrop-filter: blur(14px);
}

.game-title {
  position: relative;
  min-width: 0;
  display: grid;
  gap: 3px;
  padding-left: 42px;
}

.game-title::before {
  content: "";
  position: absolute;
  left: 0;
  top: 50%;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background:
    radial-gradient(circle at 30% 30%, #fbbf24 0 5px, transparent 6px),
    radial-gradient(circle at 70% 68%, #38bdf8 0 5px, transparent 6px),
    linear-gradient(135deg, #4338ca, #0f766e);
  box-shadow: 0 8px 20px rgba(67, 56, 202, .2);
  transform: translateY(-50%);
}

.game-kicker {
  color: #0f766e;
  font-size: 10px;
  font-weight: 950;
  line-height: 1.2;
  text-transform: uppercase;
}

.game-title strong {
  overflow: hidden;
  color: #0f172a;
  font-size: clamp(15px, 2.5vw, 22px);
  line-height: 1.08;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.hud {
  display: flex;
  align-items: center;
  gap: 8px;
}

.hud-item {
  min-width: 70px;
  padding: 7px 8px;
  border: 1px solid rgba(15, 23, 42, .1);
  border-radius: 8px;
  background: rgba(255, 255, 255, .82);
}

.hud-item span {
  display: block;
  color: #0f766e;
  font-size: 9px;
  font-weight: 950;
  text-transform: uppercase;
}

.hud-item strong {
  display: block;
  margin-top: 2px;
  color: #0f172a;
  font-size: 17px;
  line-height: 1;
}

.game-body {
  position: absolute;
  inset: 84px max(10px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
  z-index: 5;
  display: grid;
  grid-template-columns: minmax(430px, 1fr) minmax(280px, 370px);
  gap: 12px;
  min-height: 0;
}

.board-panel,
.mission-panel {
  min-height: 0;
}

.board-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 10px;
  padding: 12px;
  border: 1px solid rgba(255, 255, 255, .72);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, .9), rgba(255, 255, 255, .76)),
    radial-gradient(circle at 18% 14%, rgba(251, 191, 36, .22), transparent 24%);
  box-shadow: 0 20px 56px rgba(15, 23, 42, .14);
  backdrop-filter: blur(12px);
}

.board-toolbar {
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.board-toolbar strong {
  display: block;
  margin-top: 2px;
  color: #0f172a;
  font-size: clamp(17px, 2.4vw, 25px);
  line-height: 1.1;
}

.step-pill {
  flex: 0 0 auto;
  min-width: 78px;
  padding: 9px 12px;
  border-radius: 999px;
  background: #0f172a;
  color: #ffffff;
  font-size: 13px;
  font-weight: 900;
  text-align: center;
}

.board-wrap {
  position: relative;
  min-height: 0;
  display: grid;
  place-items: center;
}

.board {
  position: relative;
  width: min(100%, calc((100svh - 138px) * 1.32));
  max-width: 780px;
  aspect-ratio: 7 / 5;
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  grid-template-rows: repeat(5, minmax(0, 1fr));
  gap: var(--gap);
  padding: var(--gap);
  border: 1px solid rgba(15, 23, 42, .14);
  border-radius: 8px;
  background:
    radial-gradient(circle at 20% 22%, rgba(255, 255, 255, .9), transparent 18%),
    linear-gradient(135deg, #e0f2fe 0%, #dff7ec 52%, #fff7ed 100%);
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, .56), 0 18px 40px rgba(15, 23, 42, .14);
}

.cell {
  position: relative;
  min-width: 0;
  min-height: 0;
  display: grid;
  place-items: center;
  border: 1px solid rgba(15, 23, 42, .09);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, .72), rgba(255, 255, 255, .4)),
    radial-gradient(circle at 50% 100%, rgba(15, 118, 110, .12), transparent 48%);
  overflow: hidden;
}

.cell.is-start {
  background:
    radial-gradient(circle at 50% 50%, rgba(15, 118, 110, .2), transparent 42%),
    linear-gradient(180deg, rgba(255, 255, 255, .78), rgba(220, 252, 231, .62));
}

.cell.is-path {
  box-shadow: inset 0 0 0 3px rgba(37, 99, 235, .18);
}

.cell.is-current {
  box-shadow: inset 0 0 0 3px rgba(249, 115, 22, .42);
}

.start-flag {
  position: absolute;
  left: 7px;
  top: 7px;
  width: 18px;
  height: 24px;
  border-left: 4px solid #0f172a;
}

.start-flag::before {
  content: "";
  position: absolute;
  left: 3px;
  top: 1px;
  width: 18px;
  height: 12px;
  border-radius: 2px 6px 6px 2px;
  background: linear-gradient(135deg, #f97316, #fbbf24);
}

.path-marker-stack {
  position: absolute;
  right: 5px;
  top: 5px;
  z-index: 1;
  width: min(42px, calc(100% - 10px));
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 2px;
  pointer-events: none;
}

.path-marker {
  width: 13px;
  height: 13px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: #1d4ed8;
  color: #ffffff;
  box-shadow: 0 4px 10px rgba(29, 78, 216, .2);
}

.path-marker-stack.is-dense .path-marker {
  width: 11px;
  height: 11px;
}

.path-marker::before {
  content: "";
  display: block;
  width: 0;
  height: 0;
}

.path-marker.up::before {
  border-left: 3px solid transparent;
  border-right: 3px solid transparent;
  border-bottom: 6px solid currentColor;
}

.path-marker.down::before {
  border-left: 3px solid transparent;
  border-right: 3px solid transparent;
  border-top: 6px solid currentColor;
}

.path-marker.left::before {
  border-top: 3px solid transparent;
  border-bottom: 3px solid transparent;
  border-right: 6px solid currentColor;
}

.path-marker.right::before {
  border-top: 3px solid transparent;
  border-bottom: 3px solid transparent;
  border-left: 6px solid currentColor;
}

.shape-token {
  position: relative;
  z-index: 2;
  width: min(56%, 48px);
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  color: #ffffff;
  font-size: clamp(13px, 2.2vw, 20px);
  font-weight: 950;
  text-shadow: 0 1px 0 rgba(0, 0, 0, .22);
  filter: drop-shadow(0 10px 12px rgba(15, 23, 42, .18));
  transition: transform .2s ease, opacity .2s ease;
}

.shape-token.is-collected {
  transform: scale(.2) rotate(40deg);
  opacity: 0;
}

.cell.is-collecting {
  box-shadow: inset 0 0 0 3px rgba(250, 204, 21, .7), 0 14px 26px rgba(250, 204, 21, .22);
}

.cell.is-collecting::after {
  content: "";
  position: absolute;
  inset: 4px;
  z-index: 5;
  border: 2px solid rgba(250, 204, 21, .95);
  border-radius: inherit;
  pointer-events: none;
  animation: collect-ring .28s ease-out forwards;
}

.cell.is-collecting .shape-token {
  z-index: 6;
}

.shape-token.circle {
  border-radius: 50%;
}

.shape-token.square {
  border-radius: 8px;
}

.shape-token.triangle {
  width: min(60%, 54px);
  aspect-ratio: 1.08;
  clip-path: polygon(50% 5%, 95% 92%, 5% 92%);
}

.shape-token.diamond {
  border-radius: 7px;
  transform: rotate(45deg);
}

.shape-token.diamond span {
  transform: rotate(-45deg);
}

.shape-token.star {
  width: min(62%, 56px);
  clip-path: polygon(50% 2%, 61% 35%, 96% 35%, 67% 55%, 79% 90%, 50% 69%, 21% 90%, 33% 55%, 4% 35%, 39% 35%);
}

.shape-token.hex {
  clip-path: polygon(24% 7%, 76% 7%, 100% 50%, 76% 93%, 24% 93%, 0 50%);
}

.shape-token.red { background: linear-gradient(135deg, #ef4444, #be123c); }
.shape-token.blue { background: linear-gradient(135deg, #38bdf8, #2563eb); }
.shape-token.yellow { background: linear-gradient(135deg, #fde047, #f97316); }
.shape-token.green { background: linear-gradient(135deg, #34d399, #0f766e); }
.shape-token.purple { background: linear-gradient(135deg, #a78bfa, #6d28d9); }
.shape-token.orange { background: linear-gradient(135deg, #fb923c, #ea580c); }

.shape-token.diamond.is-collected {
  transform: scale(.2) rotate(85deg);
}

@keyframes collect-ring {
  0% {
    opacity: .9;
    transform: scale(.72);
  }

  100% {
    opacity: 0;
    transform: scale(1.28);
  }
}

.character {
  position: absolute;
  z-index: 8;
  left: 0;
  top: 0;
  width: clamp(46px, 8vw, 82px);
  aspect-ratio: 120 / 140;
  transform: translate(-50%, -70%);
  transition:
    left .36s cubic-bezier(.2, .88, .28, 1.12),
    top .36s cubic-bezier(.2, .88, .28, 1.12);
  pointer-events: none;
  filter: drop-shadow(0 14px 14px rgba(15, 23, 42, .18));
}

.character-svg {
  width: 100%;
  height: 100%;
  overflow: visible;
}

.hero-flip {
  transform-origin: 60px 76px;
  transform: scaleX(var(--face, 1));
}

.hero-bob {
  transform-origin: 60px 120px;
  animation: heroIdle 1.6s ease-in-out infinite;
}

.hero-shadow {
  transform-origin: center;
  animation: heroShadow 1.6s ease-in-out infinite;
}

.character.is-walking .hero-bob {
  animation: heroWalkBob .38s ease-in-out infinite;
}

.character.is-walking .hero-arm-left {
  transform-origin: 42px 62px;
  animation: armSwing .38s ease-in-out infinite;
}

.character.is-walking .hero-arm-right {
  transform-origin: 78px 62px;
  animation: armSwingReverse .38s ease-in-out infinite;
}

.character.is-walking .hero-leg-left {
  transform-origin: 52px 91px;
  animation: legStride .38s ease-in-out infinite;
}

.character.is-walking .hero-leg-right {
  transform-origin: 69px 91px;
  animation: legStrideReverse .38s ease-in-out infinite;
}

.character.is-bump {
  animation: characterBump .32s ease;
}

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

@keyframes heroShadow {
  0%, 100% { transform: scaleX(1); opacity: .18; }
  50% { transform: scaleX(.88); opacity: .12; }
}

@keyframes heroWalkBob {
  0%, 100% { transform: translateY(0) rotate(-1deg); }
  50% { transform: translateY(-7px) rotate(1deg); }
}

@keyframes armSwing {
  0%, 100% { transform: rotate(13deg); }
  50% { transform: rotate(-15deg); }
}

@keyframes armSwingReverse {
  0%, 100% { transform: rotate(-13deg); }
  50% { transform: rotate(15deg); }
}

@keyframes legStride {
  0%, 100% { transform: rotate(-10deg); }
  50% { transform: rotate(14deg); }
}

@keyframes legStrideReverse {
  0%, 100% { transform: rotate(12deg); }
  50% { transform: rotate(-13deg); }
}

@keyframes characterBump {
  0%, 100% { transform: translate(-50%, -70%) rotate(0deg); }
  35% { transform: translate(-50%, -75%) rotate(-8deg); }
  70% { transform: translate(-50%, -68%) rotate(6deg); }
}

.mission-panel {
  display: grid;
  grid-template-rows: auto minmax(74px, auto) minmax(0, 1fr);
  gap: 10px;
}

.mission-card,
.queue-card,
.controls-card {
  border: 1px solid rgba(255, 255, 255, .72);
  border-radius: 8px;
  background: rgba(255, 255, 255, .88);
  box-shadow: 0 16px 42px rgba(15, 23, 42, .1);
  backdrop-filter: blur(12px);
}

.mission-card {
  padding: 13px;
}

.mission-card p {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.pattern-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
}

.pattern-chip {
  position: relative;
  width: 44px;
  height: 50px;
  display: grid;
  justify-items: center;
  gap: 3px;
  color: #0f172a;
  font-size: 10px;
  font-weight: 900;
}

.pattern-chip::after {
  content: attr(data-step);
  position: absolute;
  right: -2px;
  bottom: 4px;
  width: 16px;
  height: 16px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: #0f172a;
  color: #ffffff;
  font-size: 9px;
}

.pattern-chip.is-done {
  opacity: .45;
}

.pattern-chip .shape-token {
  width: 32px;
  height: 32px;
}

.queue-card {
  min-height: 76px;
  padding: 10px;
}

.queue-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.mini-btn {
  min-height: 32px;
  border: 1px solid rgba(15, 23, 42, .12);
  border-radius: 8px;
  background: #ffffff;
  color: #0f172a;
  padding: 0 11px;
  font-size: 12px;
  font-weight: 900;
  cursor: pointer;
}

.route-strip {
  min-height: 34px;
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 8px;
}

.route-step {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #eef2ff;
  color: #1d4ed8;
}

.route-step::before {
  content: "";
  display: block;
  width: 0;
  height: 0;
}

.route-step.up::before {
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  border-bottom: 10px solid currentColor;
}

.route-step.down::before {
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  border-top: 10px solid currentColor;
}

.route-step.left::before {
  border-top: 6px solid transparent;
  border-bottom: 6px solid transparent;
  border-right: 10px solid currentColor;
}

.route-step.right::before {
  border-top: 6px solid transparent;
  border-bottom: 6px solid transparent;
  border-left: 10px solid currentColor;
}

.route-empty {
  color: var(--muted);
  font-size: 13px;
  font-weight: 750;
}

.controls-card {
  min-height: 0;
  display: grid;
  grid-template-rows: auto auto;
  align-content: end;
  gap: 10px;
  padding: 12px;
}

.arrow-pad {
  align-self: center;
  justify-self: center;
  width: 100%;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  grid-template-rows: 38px;
  gap: 6px;
}

.arrow-btn {
  position: relative;
  min-height: 38px;
  border: 0;
  border-radius: 8px;
  background: linear-gradient(180deg, #ffffff, #e7f0ff);
  color: #0f172a;
  box-shadow: inset 0 0 0 1px rgba(15, 23, 42, .12), 0 7px 0 #b7c7e8;
  cursor: pointer;
}

.arrow-btn:disabled,
.primary-action:disabled,
.secondary-action:disabled,
.mini-btn:disabled {
  cursor: not-allowed;
  opacity: .55;
}

.arrow-btn:active:not(:disabled) {
  transform: translateY(4px);
  box-shadow: inset 0 0 0 1px rgba(15, 23, 42, .12), 0 3px 0 #b7c7e8;
}

.arrow-btn span {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 0;
  height: 0;
  transform: translate(-50%, -50%);
}

.arrow-btn.up { grid-column: 1; grid-row: 1; }
.arrow-btn.left { grid-column: 2; grid-row: 1; }
.arrow-btn.right { grid-column: 3; grid-row: 1; }
.arrow-btn.down { grid-column: 4; grid-row: 1; }

.arrow-btn.up span {
  border-left: 10px solid transparent;
  border-right: 10px solid transparent;
  border-bottom: 15px solid currentColor;
}

.arrow-btn.down span {
  border-left: 10px solid transparent;
  border-right: 10px solid transparent;
  border-top: 15px solid currentColor;
}

.arrow-btn.left span {
  border-top: 10px solid transparent;
  border-bottom: 10px solid transparent;
  border-right: 15px solid currentColor;
}

.arrow-btn.right span {
  border-top: 10px solid transparent;
  border-bottom: 10px solid transparent;
  border-left: 15px solid currentColor;
}

.action-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.primary-action,
.secondary-action {
  min-height: 52px;
  border-radius: 8px;
  padding: 0 16px;
  font-weight: 950;
  cursor: pointer;
}

.primary-action {
  border: 0;
  background: linear-gradient(135deg, #0f766e, #2563eb);
  color: #ffffff;
  box-shadow: 0 13px 28px rgba(37, 99, 235, .22);
}

.secondary-action {
  border: 1px solid rgba(15, 23, 42, .13);
  background: #ffffff;
  color: #0f172a;
}

.primary-action.wide {
  width: min(260px, 100%);
  margin-top: 22px;
}

.feedback {
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 40;
  min-width: 170px;
  max-width: min(430px, calc(100% - 28px));
  padding: 12px 18px;
  border-radius: 8px;
  background: rgba(15, 23, 42, .9);
  color: #ffffff;
  box-shadow: 0 18px 46px rgba(15, 23, 42, .2);
  font-size: clamp(18px, 3.2vw, 24px);
  font-weight: 950;
  text-align: center;
  transform: translate(-50%, -20px);
  opacity: 0;
  pointer-events: none;
}

.feedback.show {
  animation: feedbackPop 1.05s ease;
}

.feedback.good {
  background: rgba(15, 118, 110, .94);
}

.feedback.bad {
  background: rgba(190, 18, 60, .94);
}

@keyframes feedbackPop {
  0% { transform: translate(-50%, 12px) scale(.92); opacity: 0; }
  18%, 76% { transform: translate(-50%, 0) scale(1); opacity: 1; }
  100% { transform: translate(-50%, -20px) scale(.96); opacity: 0; }
}

.overlay-card {
  position: relative;
  overflow: hidden;
}

.overlay-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  margin-top: 22px;
}

.menu-art {
  position: relative;
  width: min(320px, 100%);
  height: 100px;
  margin: 0 auto 18px;
}

.menu-path {
  position: absolute;
  left: 20px;
  right: 20px;
  top: 52px;
  height: 8px;
  border-radius: 999px;
  background:
    linear-gradient(90deg, #2563eb 0 33%, transparent 33% 39%, #0f766e 39% 70%, transparent 70% 76%, #f97316 76% 100%);
}

.menu-shape {
  position: absolute;
  top: 30px;
  width: 44px;
  height: 44px;
  filter: drop-shadow(0 12px 16px rgba(15, 23, 42, .16));
}

.menu-shape.one {
  left: 22px;
  border-radius: 50%;
  background: linear-gradient(135deg, #ef4444, #be123c);
}

.menu-shape.two {
  left: calc(50% - 22px);
  clip-path: polygon(50% 4%, 96% 92%, 4% 92%);
  background: linear-gradient(135deg, #38bdf8, #2563eb);
}

.menu-shape.three {
  right: 22px;
  border-radius: 8px;
  background: linear-gradient(135deg, #fde047, #f97316);
}

.win-spark {
  position: absolute;
  inset: -70px;
  background:
    radial-gradient(circle at 20% 26%, rgba(251, 191, 36, .62) 0 5px, transparent 6px),
    radial-gradient(circle at 78% 32%, rgba(45, 212, 191, .5) 0 5px, transparent 6px),
    radial-gradient(circle at 42% 82%, rgba(37, 99, 235, .42) 0 4px, transparent 5px),
    radial-gradient(circle at 70% 78%, rgba(249, 115, 22, .55) 0 6px, transparent 7px);
  animation: burstSpin 3s linear infinite;
  pointer-events: none;
}

.win-card > *:not(.win-spark) {
  position: relative;
}

@keyframes burstSpin {
  to { transform: rotate(360deg); }
}

@media (max-width: 900px) {
  .game-body {
    grid-template-columns: minmax(350px, 1fr) minmax(238px, .72fr);
    gap: 8px;
  }

  .board-panel,
  .mission-card,
  .queue-card,
  .controls-card {
    padding: 9px;
  }

  .hud-item {
    min-width: 58px;
  }
}

@media (max-height: 520px) and (orientation: landscape) {
  .game-topbar {
    min-height: 52px;
    padding: 6px 8px;
  }

  .game-body {
    inset: 66px max(8px, env(safe-area-inset-right)) max(6px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
    grid-template-columns: minmax(322px, 1fr) minmax(220px, .64fr);
    gap: 7px;
  }

  .game-title {
    padding-left: 36px;
  }

  .game-title::before {
    width: 28px;
    height: 28px;
  }

  .game-title strong {
    max-width: 210px;
    font-size: 16px;
  }

  .game-kicker,
  .small-label,
  .loader-eyebrow,
  .overlay-kicker {
    font-size: 8px;
  }

  .hud {
    gap: 5px;
  }

  .hud-item {
    min-width: 51px;
    padding: 5px 6px;
  }

  .hud-item span {
    font-size: 8px;
  }

  .hud-item strong {
    font-size: 14px;
  }

  .board-toolbar {
    min-height: 34px;
  }

  .board-toolbar strong {
    font-size: 16px;
  }

  .step-pill {
    min-width: 64px;
    padding: 7px 8px;
    font-size: 11px;
  }

  .mission-panel {
    grid-template-rows: auto auto minmax(0, 1fr);
    gap: 7px;
  }

  .mission-card p {
    margin-top: 6px;
    font-size: 11px;
    line-height: 1.28;
  }

  .pattern-row {
    gap: 5px;
    margin-top: 7px;
  }

  .pattern-chip {
    width: 34px;
    height: 40px;
    font-size: 8px;
  }

  .pattern-chip .shape-token {
    width: 26px;
    height: 26px;
    font-size: 10px;
  }

  .queue-card {
    min-height: 60px;
  }

  .route-strip {
    min-height: 25px;
    margin-top: 5px;
  }

  .route-step {
    width: 23px;
    height: 23px;
    border-radius: 6px;
    font-size: 10px;
  }

  .controls-card {
    gap: 7px;
  }

  .arrow-pad {
    grid-template-rows: 32px;
    gap: 5px;
  }

  .arrow-btn {
    min-height: 32px;
  }

  .arrow-btn.up span,
  .arrow-btn.down span {
    border-left-width: 10px;
    border-right-width: 10px;
  }

  .arrow-btn.up span { border-bottom-width: 15px; }
  .arrow-btn.down span { border-top-width: 15px; }

  .arrow-btn.left span,
  .arrow-btn.right span {
    border-top-width: 10px;
    border-bottom-width: 10px;
  }

  .arrow-btn.left span { border-right-width: 15px; }
  .arrow-btn.right span { border-left-width: 15px; }

  .primary-action,
  .secondary-action {
    min-height: 38px;
    padding: 0 10px;
    font-size: 12px;
  }

  .mini-btn {
    min-height: 26px;
    padding: 0 8px;
    font-size: 10px;
  }

  .loader-card,
  .overlay-card {
    padding: 12px;
  }

  .overlay-card h2 {
    font-size: clamp(24px, 8vh, 38px);
  }
}

@media (max-width: 760px) and (orientation: portrait) {
  .pattern-app:not(.is-loading) .rotate-overlay {
    display: flex;
  }
}

@media (max-width: 430px) {
  .loader-card,
  .overlay-card,
  .rotate-card {
    padding-inline: 12px;
  }

  .loader-brand {
    font-size: clamp(24px, 9vw, 34px);
  }
}

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