main.main-content:has(.tg-page) {
  display: flex;
  flex-direction: column;
  padding-top: calc(0.35rem + env(safe-area-inset-top, 0px));
  padding-bottom: 0;
  min-height: calc(100svh - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
}

.tg-page {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  width: 100%;
  min-height: 0;
  --tg-silhouette: color-mix(in srgb, var(--accent-strong) 34%, #241b39);
  --tg-piece-stroke: rgba(20, 14, 33, 0.5);
}

[data-theme="dark"] .tg-page {
  --tg-silhouette: color-mix(in srgb, var(--accent) 28%, var(--surface-strong));
  --tg-piece-stroke: rgba(0, 0, 0, 0.45);
}

.tg-shell {
  display: flex;
  flex-direction: column;
  min-height: 0;
  width: 100%;
  max-width: 100%;
  margin: 0 auto;
  padding: 0.35rem 0.5rem 0.25rem;
  flex: 1 1 auto;
  --tg-shell-max-h: calc(
    100svh - 3.25rem - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px)
  );
  height: var(--tg-shell-max-h);
  max-height: var(--tg-shell-max-h);
}

.tg-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  flex-wrap: wrap;
  flex: 0 0 auto;
  margin-bottom: 0.35rem;
}

.tg-header-title {
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.tg-header-title h1 {
  margin: 0;
  font-size: clamp(1.05rem, 3.5vw, 1.45rem);
  line-height: 1.2;
}

.tg-level-label {
  margin: 0;
  font-weight: 700;
  color: var(--text-muted);
  font-size: 0.95rem;
}

.tg-header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.tg-toolbar {
  display: flex;
  justify-content: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  align-items: center;
  flex: 0 0 auto;
  margin-bottom: 0.35rem;
}

.tg-controls {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.tg-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 999px;
  padding: 0.4rem 0.7rem;
  font-weight: 800;
  font-size: 0.95rem;
  color: var(--text);
  white-space: nowrap;
}

.tg-chip--coins {
  border-color: color-mix(in srgb, #eab308 45%, var(--border));
}

.tg-chip--coins .tg-ico {
  fill: #eab308;
}

.tg-ico {
  width: 18px;
  height: 18px;
  fill: currentColor;
  flex-shrink: 0;
}

.tg-icon-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  min-width: 44px;
  height: 42px;
  padding: 0 0.85rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 800;
  cursor: pointer;
  transition: background 0.18s ease, border-color 0.18s ease, transform 0.12s ease,
    box-shadow 0.18s ease;
}

.tg-icon-btn:hover:not(:disabled) {
  border-color: color-mix(in srgb, var(--accent) 55%, var(--border));
  box-shadow: 0 4px 14px var(--accent-glow);
  transform: translateY(-1px);
}

.tg-icon-btn:active:not(:disabled) {
  transform: translateY(0);
}

.tg-icon-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.tg-btn-label {
  font-size: 0.9rem;
}

.tg-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 0.25rem;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 0.72rem;
  font-weight: 800;
}

[data-theme="dark"] .tg-badge {
  color: #1a1226;
}

.tg-board-outer {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  display: flex;
  align-items: stretch;
  justify-content: stretch;
  overflow: visible;
}

.tg-board-wrap {
  position: relative;
  flex: 1 1 auto;
  width: 100%;
  height: 100%;
  min-height: 0;
  min-width: 0;
  margin: 0;
  background: transparent;
  border: none;
  box-shadow: none;
  border-radius: 0;
  overflow: visible;
}

.tg-board-svg {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  overflow: visible;
}

/* Solid silhouette (no per-piece grid lines) */
.tg-silhouette {
  fill: var(--tg-silhouette);
  stroke: none;
}

.tg-slot {
  fill: transparent;
  stroke: none;
  pointer-events: none;
}

.tg-slot.is-hint {
  fill: color-mix(in srgb, var(--tg-silhouette) 55%, #ffd54a);
  animation: tg-hint-pulse 0.9s ease-in-out 2;
}

@keyframes tg-hint-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* Draggable pieces */
.tg-piece {
  cursor: grab;
  stroke: var(--tg-piece-stroke);
  stroke-width: 0.04;
  stroke-linejoin: round;
  transition: filter 0.12s ease;
}

.tg-piece.is-dragging {
  cursor: grabbing;
  filter: drop-shadow(0 6px 10px rgba(0, 0, 0, 0.35));
}

.tg-piece.is-selected {
  stroke: #ffffff;
  stroke-width: 0.09;
}

.tg-piece.is-locked {
  cursor: default;
}

.tg-piece--large_tri { fill: #f6c945; }
.tg-piece--medium_tri { fill: #2fb56b; }
.tg-piece--small_tri { fill: #f3854b; }
.tg-piece--square { fill: #4d8df6; }
.tg-piece--parallelogram { fill: #ef5d5d; }
.tg-piece[data-variant="1"].tg-piece--large_tri { fill: #ec5ba6; }
.tg-piece[data-variant="1"].tg-piece--small_tri { fill: #34d0d6; }

/* Win celebration card (matches Zip / Word Search / Arrow Escape) */
.tg-win-panel[hidden] {
  display: none !important;
}

.tg-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;
}

.tg-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;
}

.tg-win-panel:not([hidden]) .tg-win-panel__modal {
  animation: tg-win-pop 0.55s ease-out;
}

.tg-win-panel__modal::before,
.tg-win-panel__modal::after {
  content: "✦";
  position: absolute;
  color: rgba(116, 75, 232, 0.7);
  font-size: 1rem;
  pointer-events: none;
  animation: tg-win-sparkle-float 1.8s ease-in-out infinite;
}

.tg-win-panel__modal::before {
  left: 0.85rem;
  top: 0.5rem;
}

.tg-win-panel__modal::after {
  right: 0.85rem;
  bottom: 0.5rem;
  animation-delay: 0.45s;
}

@keyframes tg-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 tg-win-sparkle-float {
  0%,
  100% {
    transform: translateY(0) rotate(0deg);
    opacity: 0.65;
  }
  50% {
    transform: translateY(-4px) rotate(10deg);
    opacity: 1;
  }
}

.tg-win-panel__title,
.tg-win-panel__detail {
  margin: 0;
  font: inherit;
  font-weight: inherit;
  line-height: inherit;
  color: inherit;
}

.tg-win-panel__detail + .tg-win-panel__detail {
  margin-top: 0.25rem;
}

.tg-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;
}

.tg-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"] .tg-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"] .tg-win-panel__title,
[data-theme="dark"] .tg-win-panel__detail {
  color: #f2f5ff;
}

[data-theme="dark"] .tg-win-panel__btn {
  color: #f2f5ff;
  border-color: rgba(185, 160, 255, 0.45);
  background: rgba(31, 38, 72, 0.85);
}

.tg-status {
  margin: 0.4rem 0 0;
}

.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;
}

/* SEO copy */
.tg-page__seo {
  max-width: 860px;
  width: 100%;
  margin: 1.5rem auto 0;
}

.tg-copy h2 {
  font-size: clamp(1.1rem, 3vw, 1.4rem);
}

.tg-copy p {
  line-height: 1.65;
  color: var(--text-muted);
}

@media (min-width: 1025px) {
  .tg-page {
    min-height: calc(
      100dvh - 2.5rem - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px)
    );
    padding: 0.25rem 0.5rem 0;
  }

  .tg-shell {
    --tg-shell-max-h: calc(
      100dvh - 3rem - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px)
    );
    height: var(--tg-shell-max-h);
    max-height: var(--tg-shell-max-h);
    padding: 0.3rem 0.65rem 0.2rem;
  }

  .tg-page__seo {
    flex: 0 0 auto;
    margin-top: clamp(1.25rem, 2.5vh, 2rem);
    padding-bottom: 1.5rem;
  }
}

/* Mobile / tablet only — desktop layout unchanged above 1024px. */
@media (max-width: 1024px) {
  .tg-shell {
    --tg-shell-max-h: calc(
      100svh - 3rem - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px)
    );
    padding: 0.25rem 0.4rem 0.2rem;
  }

  .tg-page:not(.tg-page--play-focus) .tg-shell {
    display: flex;
    flex-direction: column;
    height: var(--tg-shell-max-h);
    max-height: var(--tg-shell-max-h);
    overflow: hidden;
  }

  .tg-header {
    display: grid;
    grid-template-columns: minmax(0, 1fr) var(--ws-toolbar-control-height, 2.35rem);
    align-items: center;
    gap: 0.35rem 0.5rem;
    margin-bottom: 0.3rem;
  }

  .tg-header .word-search-game-shell__expand-btn {
    grid-column: 2;
    grid-row: 1;
    justify-self: end;
    align-self: start;
  }

  .tg-header-title {
    grid-column: 1;
    grid-row: 1;
    min-width: 0;
  }

  .tg-header-title h1 {
    font-size: 1.05rem;
  }

  .tg-level-label {
    font-size: 0.88rem;
  }

  .tg-header-actions {
    grid-column: 1 / -1;
    grid-row: 2;
    justify-self: end;
    width: 100%;
    display: flex;
    justify-content: flex-end;
  }

  .tg-toolbar {
    justify-content: center;
    width: 100%;
    margin-bottom: 0.3rem;
  }

  .tg-controls {
    width: 100%;
    max-width: 100%;
    justify-content: center;
    flex-wrap: nowrap;
    gap: 0.4rem;
  }

  .tg-icon-btn {
    flex: 1 1 0;
    min-width: 0;
    max-width: 7.5rem;
    height: 40px;
    padding: 0 0.45rem;
  }

  /* Touch only: flip/hint keep focus/hover after tap, which makes borders flash on piece taps. */
  @media (hover: none) and (pointer: coarse) {
    #tg-flip-btn:focus,
    #tg-flip-btn:focus-visible,
    #tg-hint-btn:focus,
    #tg-hint-btn:focus-visible {
      outline: none;
    }

    #tg-flip-btn:hover:not(:disabled),
    #tg-hint-btn:hover:not(:disabled) {
      border-color: var(--border);
      box-shadow: none;
      transform: none;
    }
  }

  .tg-btn-label {
    display: none;
  }

  .tg-chip {
    font-size: 0.88rem;
    padding: 0.35rem 0.65rem;
  }

  .tg-board-outer {
    flex: 1 1 auto;
    min-height: 0;
    overflow: hidden;
  }

  .tg-board-wrap {
    height: 100%;
    width: 100%;
    min-height: 0;
    overflow: hidden;
  }

  .tg-board-svg {
    touch-action: none;
  }
}
