.ae-page {
  display: flex;
  flex-direction: column;
}

.ae-shell {
  display: flex;
  flex-direction: column;
  min-height: 0;
  max-width: 860px;
  width: 100%;
  margin: 0 auto;
  padding: 0.65rem 0.75rem 0.5rem;
  border: none;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  overflow: visible;
  --ae-shell-max-h: calc(
    100svh - 13.5rem - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px)
  );
  height: var(--ae-shell-max-h);
  max-height: var(--ae-shell-max-h);
}

.ae-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  flex-wrap: wrap;
  flex: 0 0 auto;
  margin-bottom: 0.5rem;
}

.ae-header-title h1 {
  margin: 0;
  font-size: clamp(1.05rem, 3.5vw, 1.45rem);
  line-height: 1.2;
}

.ae-new-btn {
  border: 1px solid rgba(31, 51, 89, 0.28);
  border-radius: 10px;
  padding: 0.45rem 0.95rem;
  background: transparent;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  color: var(--text);
  transition: background 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease, transform 0.15s ease;
}

.ae-new-btn:hover {
  background: transparent;
  border-color: color-mix(in srgb, var(--accent) 55%, rgba(31, 51, 89, 0.55));
  box-shadow: 0 4px 14px rgba(91, 33, 182, 0.12);
  transform: translateY(-1px);
}

.ae-new-btn:active {
  transform: translateY(0);
}

.ae-toolbar {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  flex-wrap: wrap;
  align-items: center;
  flex: 0 0 auto;
  margin-bottom: 0.45rem;
}

.ae-stats {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  align-items: center;
}

.ae-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  border: 1px solid rgba(91, 33, 182, 0.14);
  background: transparent;
  border-radius: 999px;
  padding: 0.4rem 0.7rem;
  font-weight: 800;
  font-size: 0.95rem;
  color: var(--text);
  white-space: nowrap;
}

.ae-chip--strikes {
  border-color: rgba(214, 51, 108, 0.3);
}

.ae-chip--strikes .ae-ico {
  fill: #e64980;
}

.ae-chip--strikes.is-low .ae-ico {
  fill: #d6336c;
}

.ae-ico {
  width: 18px;
  height: 18px;
  fill: var(--text);
  flex-shrink: 0;
}

.ae-controls {
  display: flex;
  gap: 0.55rem;
  align-items: center;
  justify-content: flex-end;
}

.ae-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.3rem;
  border-radius: 10px;
  border: 1px solid rgba(31, 51, 89, 0.28);
  min-height: 40px;
  min-width: 44px;
  background: transparent;
  font: inherit;
  padding: 0 0.6rem;
  cursor: pointer;
  font-weight: 800;
  color: var(--text);
  transition: background 0.2s ease, border-color 0.2s ease, transform 0.15s ease;
}

.ae-icon-btn:hover:not(:disabled) {
  border-color: color-mix(in srgb, var(--accent) 55%, rgba(31, 51, 89, 0.55));
  transform: translateY(-1px);
}

.ae-icon-btn:disabled {
  opacity: 0.45;
  cursor: default;
}

.ae-icon-btn .ae-ico {
  fill: var(--accent);
}

.ae-zoom {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
}

.ae-zoom .ae-icon-btn {
  font-size: 1.2rem;
  min-width: 40px;
}

.ae-board-outer {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 0;
  padding: 0;
  background: transparent;
  overflow: hidden;
}

.ae-board-outer--loading .ae-board-wrap {
  visibility: hidden;
  pointer-events: none;
}

.ae-board-outer--loading .ae-win-panel {
  visibility: hidden;
}

.ae-board-outer.ae-board-outer--pan {
  cursor: grab;
  touch-action: none;
}

.ae-board-outer.ae-board-outer--pan.ae-board-outer--panning {
  cursor: grabbing;
}

.ae-board-outer.ae-board-outer--pan .ae-board-svg {
  touch-action: none;
}

#ae-zoom-out-btn[hidden] {
  display: none;
}

.ae-board-wrap {
  --ae-cols: 20;
  --ae-rows: 30;
  --ae-board-fit: 480px;
  --ae-board-fit-h: 720px;
  position: relative;
  margin: 0 auto;
  transform-origin: center center;
  overflow: visible;
  width: min(100%, var(--ae-board-fit));
  height: min(100%, var(--ae-board-fit-h));
  max-width: 100%;
  max-height: 100%;
  flex-shrink: 0;
}

.ae-board-svg {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: manipulation;
  user-select: none;
  overflow: visible;
}

/* During exit only: let left/right slithers paint past the grid without shrinking it. */
.ae-board-outer.ae-board-outer--exit,
.ae-shell.ae-shell--exit {
  overflow: visible;
}

/* Status text is visually hidden (.sr-only); kept for screen-reader announcements. */

.ae-arrow-group {
  cursor: pointer;
}

.ae-arrow-body {
  fill: none;
  stroke: var(--text);
  stroke-width: 0.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.ae-arrow-hit {
  fill: none;
  stroke: transparent;
  stroke-width: 0.85;
  pointer-events: stroke;
}

.ae-arrow-head {
  fill: var(--text);
}

.ae-arrow-group.is-disabled {
  cursor: default;
  opacity: 0.35;
}

.ae-arrow-group.is-removed {
  opacity: 0;
  transition: opacity 0.18s ease;
}

.ae-arrow-group.is-exiting {
  pointer-events: none;
}

.ae-arrow-group.is-colliding {
  pointer-events: none;
}

.ae-arrow-group.is-colliding .ae-arrow-body {
  stroke: #d6336c;
}

.ae-arrow-group.is-colliding .ae-arrow-head {
  fill: #d6336c;
}

.ae-dot-grid {
  opacity: 0.9;
}

.ae-dot {
  fill: rgba(47, 38, 64, 0.28);
}

[data-theme="dark"] .ae-dot {
  fill: rgba(244, 233, 255, 0.22);
}

.ae-arrow-group.is-hint .ae-arrow-body {
  stroke: var(--accent);
  filter: drop-shadow(0 0 6px var(--accent-glow));
}

.ae-board-wrap.is-streak {
  animation: aeStreakGlow 0.8s ease-in-out 1;
}

@keyframes aeStreakGlow {
  0% {
    box-shadow: none;
  }
  50% {
    box-shadow: 0 0 0 2px rgba(124, 58, 237, 0.15), 0 0 24px rgba(124, 58, 237, 0.18);
    border-radius: 14px;
  }
  100% {
    box-shadow: none;
  }
}

.ae-shake {
  animation: aeShake 0.25s linear 1;
}

@keyframes aeShake {
  0% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-6px);
  }
  50% {
    transform: translateX(6px);
  }
  75% {
    transform: translateX(-4px);
  }
  100% {
    transform: translateX(0);
  }
}

.ae-overlay {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  border-radius: 12px;
  background: rgba(19, 8, 33, 0.35);
  color: #fff;
  font-weight: 900;
  text-align: center;
  z-index: 20;
}

.ae-overlay.is-visible {
  display: flex;
}

.ae-overlay__card {
  max-width: 360px;
  background: rgba(18, 12, 26, 0.65);
  border: 1px solid rgba(255, 255, 255, 0.14);
  box-shadow: var(--shadow-md);
  padding: 1rem;
  border-radius: 14px;
}

/* Win celebration card (matches Zip / Word Search) */
.ae-win-panel[hidden] {
  display: none !important;
}

.ae-win-panel {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.65rem;
  box-sizing: border-box;
  pointer-events: none;
}

.ae-win-panel__modal {
  position: relative;
  width: min(86%, 450px);
  padding: 0.9rem 1rem;
  border-radius: 14px;
  border: 1px solid rgba(115, 76, 226, 0.36);
  background:
    radial-gradient(circle at 12% 20%, rgba(255, 224, 143, 0.32) 0 24px, transparent 25px),
    radial-gradient(circle at 88% 18%, rgba(255, 170, 226, 0.24) 0 20px, transparent 21px),
    radial-gradient(circle at 84% 82%, rgba(132, 214, 255, 0.22) 0 22px, transparent 23px),
    rgba(255, 255, 255, 0.92);
  color: #22133f;
  font-size: 0.96rem;
  font-weight: 600;
  line-height: 1.45;
  text-align: center;
  box-shadow: 0 12px 34px rgba(36, 24, 85, 0.18);
  backdrop-filter: blur(1.5px);
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.55);
  overflow: hidden;
  pointer-events: auto;
}

.ae-win-panel:not([hidden]) .ae-win-panel__modal {
  animation: ae-win-pop 0.55s ease-out;
}

.ae-win-panel__modal::before,
.ae-win-panel__modal::after {
  content: "✦";
  position: absolute;
  color: rgba(116, 75, 232, 0.7);
  font-size: 1rem;
  pointer-events: none;
  animation: ae-win-sparkle-float 1.8s ease-in-out infinite;
}

.ae-win-panel__modal::before {
  left: 0.85rem;
  top: 0.5rem;
}

.ae-win-panel__modal::after {
  right: 0.85rem;
  bottom: 0.5rem;
  animation-delay: 0.45s;
}

@keyframes ae-win-pop {
  0% {
    opacity: 0;
    transform: scale(0.94);
    filter: saturate(0.7) brightness(0.95);
  }
  100% {
    opacity: 1;
    transform: scale(1);
    filter: saturate(1.08) brightness(1);
  }
}

@keyframes ae-win-sparkle-float {
  0%,
  100% {
    transform: translateY(0) rotate(0deg);
    opacity: 0.65;
  }
  50% {
    transform: translateY(-4px) rotate(10deg);
    opacity: 1;
  }
}

.ae-win-panel__title,
.ae-win-panel__detail {
  margin: 0;
  font: inherit;
  font-weight: inherit;
  line-height: inherit;
  color: inherit;
}

.ae-win-panel__detail + .ae-win-panel__detail {
  margin-top: 0.25rem;
}

.ae-win-panel__btn {
  margin-top: 0.65rem;
  width: 100%;
  border: 1px solid rgba(115, 76, 226, 0.36);
  background: var(--surface-strong, rgba(255, 255, 255, 0.95));
  border-radius: 10px;
  min-height: 40px;
  padding: 0.35rem 0.75rem;
  cursor: pointer;
  font: inherit;
  font-weight: 700;
  color: #22133f;
  transition: background 0.2s ease, border-color 0.2s ease, transform 0.15s ease;
}

.ae-win-panel__btn:hover {
  border-color: color-mix(in srgb, var(--accent) 55%, rgba(115, 76, 226, 0.55));
  transform: translateY(-1px);
}

[data-theme="dark"] .ae-win-panel__modal {
  border-color: rgba(185, 160, 255, 0.62);
  color: #f2f5ff;
  background:
    radial-gradient(circle at 12% 20%, rgba(255, 224, 143, 0.24) 0 24px, transparent 25px),
    radial-gradient(circle at 88% 18%, rgba(255, 170, 226, 0.18) 0 20px, transparent 21px),
    radial-gradient(circle at 84% 82%, rgba(132, 214, 255, 0.18) 0 22px, transparent 23px),
    rgba(20, 24, 48, 0.9);
  box-shadow: 0 14px 36px rgba(4, 6, 18, 0.5);
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.4);
}

[data-theme="dark"] .ae-win-panel__title,
[data-theme="dark"] .ae-win-panel__detail {
  color: #f2f5ff;
}

[data-theme="dark"] .ae-win-panel__btn {
  color: #f2f5ff;
  border-color: rgba(185, 160, 255, 0.45);
  background: rgba(31, 38, 72, 0.85);
}

/* Desktop: game shell fills the laptop viewport; SEO copy scrolls in below (like Zip / Queens). */
@media (min-width: 1025px) {
  .ae-page {
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: none;
    min-height: calc(
      100dvh - 3.5rem - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px)
    );
    padding: clamp(0.35rem, 1.2vw, 0.85rem) clamp(0.5rem, 2vw, 1.25rem) 0;
  }

  .ae-shell {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    min-height: calc(
      100dvh - 4.5rem - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px)
    );
    height: auto;
    max-height: none;
    width: 100%;
    max-width: min(920px, 100%);
    margin-inline: auto;
    overflow: hidden;
  }

  .ae-shell.ae-shell--exit {
    overflow: visible;
  }

  .ae-header {
    margin-bottom: 0.4rem;
  }

  .ae-toolbar {
    margin-bottom: 0.35rem;
  }

  .ae-board-outer {
    flex: 1 1 auto;
    min-height: 0;
  }

  .ae-page__seo {
    flex: 0 0 auto;
    margin-top: clamp(1.25rem, 2.5vh, 2rem);
    padding-bottom: 1.5rem;
    max-width: min(920px, 100%);
    margin-inline: auto;
    width: 100%;
  }
}

@media (max-width: 1024px) {
  .ae-header {
    display: grid;
    grid-template-columns: minmax(0, 1fr) var(--ws-toolbar-control-height, 2.35rem);
    align-items: center;
    gap: 0.35rem 0.5rem;
  }

  .ae-header .word-search-game-shell__expand-btn {
    grid-column: 2;
    grid-row: 1;
    justify-self: end;
    align-self: start;
  }

  .ae-header-title {
    grid-column: 1;
    grid-row: 1;
    min-width: 0;
  }

  .ae-header-actions {
    grid-column: 1 / -1;
    grid-row: 2;
  }
}

