/* Portfolio — Play button aligned to main .container right (not viewport corner) */
.portfolio-game-anchor {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 10000;
  pointer-events: none;
  padding-bottom: max(1rem, env(safe-area-inset-bottom, 0px));
  padding-left: env(safe-area-inset-left, 0px);
  padding-right: env(safe-area-inset-right, 0px);
}

.portfolio-game-anchor__inner {
  position: relative;
  pointer-events: none;
}

.portfolio-game-widget {
  position: absolute;
  right: 0;
  bottom: 0;
  left: auto;
  pointer-events: auto;
  font-family: var(--font-body);
}

html.portfolio-game-open {
  overflow: hidden;
  height: 100%;
  overscroll-behavior: none;
}

body.portfolio-game-open {
  overflow: hidden;
  overscroll-behavior: none;
}

.portfolio-game-window {
  position: absolute;
  bottom: calc(100% + 0.75rem);
  right: 0;
  left: auto;
  width: 380px;
  max-width: calc(
    100vw - 2rem - env(safe-area-inset-left, 0px) -
      env(safe-area-inset-right, 0px)
  );
  height: min(
    480px,
    calc(
      100vh - 7.5rem - env(safe-area-inset-top, 0px) -
        env(safe-area-inset-bottom, 0px)
    )
  );
  max-height: calc(
    100vh - 7.5rem - env(safe-area-inset-top, 0px) -
      env(safe-area-inset-bottom, 0px)
  );
  height: min(
    480px,
    calc(
      100dvh - 7.5rem - env(safe-area-inset-top, 0px) -
        env(safe-area-inset-bottom, 0px)
    )
  );
  max-height: calc(
    100dvh - 7.5rem - env(safe-area-inset-top, 0px) -
      env(safe-area-inset-bottom, 0px)
  );
  background: rgba(10, 10, 12, 0.98);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  box-shadow:
    0 8px 32px rgba(0, 0, 0, 0.45),
    0 0 0 1px rgba(212, 168, 59, 0.08);
  display: flex;
  flex-direction: column;
  opacity: 0;
  visibility: hidden;
  transform: translateY(12px) scale(0.97);
  transition:
    opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1),
    visibility 0.3s,
    transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  backdrop-filter: blur(12px);
}

.portfolio-game-window.active {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
}

.portfolio-game-window.active ~ .portfolio-game-toggle {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.portfolio-game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.65rem 0.85rem;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(
    180deg,
    rgba(212, 168, 59, 0.08) 0%,
    transparent 100%
  );
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  flex-shrink: 0;
}

.portfolio-game-header-info {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
}

.portfolio-game-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--gradient-accent);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--bg);
  flex-shrink: 0;
}

.portfolio-game-header-text h4 {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
  font-family: var(--font-display);
  color: var(--text);
}

.portfolio-game-status {
  margin: 0.2rem 0 0;
  font-size: 0.75rem;
  color: var(--text-subtle);
}

.portfolio-game-close {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.5rem;
  min-width: 44px;
  min-height: 44px;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  transition:
    color var(--transition),
    background var(--transition),
    transform 0.18s ease,
    filter 0.18s ease;
  flex-shrink: 0;
  touch-action: manipulation;
}

.portfolio-game-close:hover {
  background: var(--border);
  color: var(--text);
  transform: scale(1.08);
  filter: brightness(1.15);
}

.portfolio-game-close:active {
  transform: scale(0.94);
}

.portfolio-game-body {
  flex: 1 1 0;
  min-height: 0;
  overflow: hidden;
  padding: 0.65rem 0.75rem 0.7rem;
  display: flex;
  flex-direction: column;
  background: linear-gradient(
    180deg,
    rgba(255, 255, 255, 0.02) 0%,
    transparent 35%
  );
}

.portfolio-game-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 48px;
  padding: 0.65rem 1.15rem 0.65rem 0.85rem;
  border-radius: 999px;
  border: none;
  cursor: pointer;
  font-family: var(--font-body);
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--bg);
  background: var(--gradient-accent);
  box-shadow: 0 4px 22px var(--accent-glow);
  transition:
    transform 0.22s cubic-bezier(0.34, 1.45, 0.64, 1),
    box-shadow 0.22s ease,
    filter 0.2s ease;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.portfolio-game-toggle:hover {
  transform: translateY(-3px) scale(1.02);
  box-shadow: 0 10px 32px var(--accent-glow-strong);
  filter: brightness(1.07);
}

.portfolio-game-toggle:active {
  transform: translateY(-1px) scale(0.97);
  box-shadow: 0 3px 14px var(--accent-glow);
  filter: brightness(1.02);
}

.portfolio-game-toggle svg {
  flex-shrink: 0;
}

.portfolio-game-toggle-text {
  letter-spacing: 0.02em;
}

/* Phones: near-full-width panel, dynamic viewport, comfortable touch */
@media (max-width: 480px) {
  .portfolio-game-anchor {
    padding-bottom: max(0.75rem, env(safe-area-inset-bottom, 0px));
  }

  .portfolio-game-window {
    width: calc(
      100vw - 1.25rem - env(safe-area-inset-left, 0px) -
        env(safe-area-inset-right, 0px)
    );
    max-width: none;
    height: min(
      560px,
      calc(
        100vh - 5.5rem - env(safe-area-inset-top, 0px) -
          env(safe-area-inset-bottom, 0px)
      )
    );
    max-height: calc(
      100vh - 5rem - env(safe-area-inset-top, 0px) -
        env(safe-area-inset-bottom, 0px)
    );
    height: min(
      560px,
      calc(
        100dvh - 5.5rem - env(safe-area-inset-top, 0px) -
          env(safe-area-inset-bottom, 0px)
      )
    );
    max-height: calc(
      100dvh - 5rem - env(safe-area-inset-top, 0px) -
        env(safe-area-inset-bottom, 0px)
    );
    border-radius: var(--radius-xl);
  }

  .portfolio-game-header {
    padding: 0.7rem 0.75rem;
    padding-right: max(0.5rem, env(safe-area-inset-right, 0px));
  }

  .portfolio-game-body {
    padding: 0.55rem 0.65rem max(0.65rem, env(safe-area-inset-bottom, 0px));
  }

  .portfolio-game-toggle {
    min-height: 48px;
    padding: 0.6rem 1rem 0.6rem 0.8rem;
    font-size: 0.8125rem;
  }

  /* One row: mode pair + compact New game (avoid full-width flex-grow eating space) */
  .portfolio-game-body .portfolio-ttt-actions {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto;
    grid-template-rows: auto;
    align-items: stretch;
    gap: 0.4rem;
    flex-wrap: unset;
  }

  .portfolio-game-body .portfolio-ttt-mode-group {
    grid-column: 1 / 3;
    grid-row: 1;
    flex: unset;
    width: 100%;
    min-height: 44px;
  }

  .portfolio-game-body .portfolio-ttt-btn--mode {
    min-height: 44px;
    font-size: 0.72rem;
    padding: 0.45rem 0.35rem;
  }

  .portfolio-game-body .portfolio-ttt-btn--new {
    grid-column: 3;
    grid-row: 1;
    flex: none;
    width: auto;
    min-width: 0;
    max-width: none;
    min-height: 44px;
    max-height: 48px;
    align-self: stretch;
    font-size: 0.68rem;
    font-weight: 700;
    padding: 0.45rem 0.65rem;
    white-space: nowrap;
  }

  .portfolio-game-body .portfolio-ttt-status-panel {
    padding: 0.6rem 0.55rem;
  }

  .portfolio-game-body .portfolio-ttt-status {
    font-size: 0.95rem;
  }

  .portfolio-game-body .portfolio-ttt-board-wrap {
    min-height: 8rem;
  }

  .portfolio-game-body .portfolio-ttt-board-frame {
    padding: 0.5rem;
    border-radius: var(--radius-xl);
  }

  .portfolio-game-body .portfolio-ttt-board {
    gap: 0.42rem;
  }

  .portfolio-game-body .portfolio-ttt-hint {
    font-size: 0.7rem;
    padding: 0.45rem 0.5rem;
  }

  .portfolio-game-body .portfolio-ttt-result-overlay__card {
    padding: 0.75rem 0.85rem 0.9rem;
    max-width: 14rem;
  }

  .portfolio-game-body .portfolio-ttt-result-overlay__title {
    font-size: 0.88rem;
  }

  .portfolio-game-body .portfolio-ttt-result-preview {
    width: 5rem;
    gap: 0.16rem;
    margin-bottom: 0.5rem;
  }

  .portfolio-game-body .portfolio-ttt-result-preview__cell {
    font-size: 0.64rem;
  }

  .portfolio-game-body .portfolio-ttt-result-overlay__sub {
    font-size: 0.68rem;
    margin-bottom: 0.65rem;
  }

  .portfolio-game-body .portfolio-ttt-btn--try-again {
    min-height: 44px;
    font-size: 0.72rem;
  }
}

/* Phone landscape: shorter chrome so the grid still fits */
@media (max-width: 896px) and (orientation: landscape) and (max-height: 500px) {
  .portfolio-game-window {
    height: min(
      420px,
      calc(
        100vh - 1.25rem - env(safe-area-inset-top, 0px) -
          env(safe-area-inset-bottom, 0px)
      )
    );
    max-height: calc(
      100vh - 1rem - env(safe-area-inset-top, 0px) -
        env(safe-area-inset-bottom, 0px)
    );
    height: min(
      420px,
      calc(
        100dvh - 1.25rem - env(safe-area-inset-top, 0px) -
          env(safe-area-inset-bottom, 0px)
      )
    );
    max-height: calc(
      100dvh - 1rem - env(safe-area-inset-top, 0px) -
        env(safe-area-inset-bottom, 0px)
    );
  }

  .portfolio-game-header {
    padding: 0.45rem 0.65rem;
  }

  .portfolio-game-avatar {
    width: 32px;
    height: 32px;
  }

  .portfolio-game-header-text h4 {
    font-size: 0.9rem;
  }

  .portfolio-game-body .portfolio-ttt-hud {
    gap: 0.35rem;
  }

  .portfolio-game-body .portfolio-ttt-status-panel {
    padding: 0.4rem 0.5rem;
  }

  .portfolio-game-body .portfolio-ttt-status {
    font-size: 0.85rem;
    min-height: 1.2em;
  }

  .portfolio-game-body .portfolio-ttt-btn--mode,
  .portfolio-game-body .portfolio-ttt-btn--new {
    min-height: 40px;
    padding-top: 0.35rem;
    padding-bottom: 0.35rem;
  }

  .portfolio-game-body .portfolio-ttt-footer {
    gap: 0.25rem;
  }

  .portfolio-game-body .portfolio-ttt-hint {
    font-size: 0.62rem;
    padding: 0.3rem 0.4rem;
  }
}

/* iPad / tablets: wider panel, taller play area, still touch-friendly */
@media (min-width: 481px) and (max-width: 1024px) {
  .portfolio-game-anchor {
    padding-bottom: max(1.25rem, env(safe-area-inset-bottom, 0px));
  }

  .portfolio-game-window {
    width: min(
      420px,
      calc(
        100vw - 2.5rem - env(safe-area-inset-left, 0px) -
          env(safe-area-inset-right, 0px)
      )
    );
    height: min(
      520px,
      calc(
        100vh - 8rem - env(safe-area-inset-top, 0px) -
          env(safe-area-inset-bottom, 0px)
      )
    );
    max-height: calc(
      100vh - 7.5rem - env(safe-area-inset-top, 0px) -
        env(safe-area-inset-bottom, 0px)
    );
    height: min(
      520px,
      calc(
        100dvh - 8rem - env(safe-area-inset-top, 0px) -
          env(safe-area-inset-bottom, 0px)
      )
    );
    max-height: calc(
      100dvh - 7.5rem - env(safe-area-inset-top, 0px) -
        env(safe-area-inset-bottom, 0px)
    );
    border-radius: var(--radius-xl);
  }

  .portfolio-game-header {
    padding: 0.75rem 1rem;
  }

  .portfolio-game-avatar {
    width: 40px;
    height: 40px;
  }

  .portfolio-game-body {
    padding: 0.75rem 0.85rem 0.85rem;
  }

  .portfolio-game-body .portfolio-ttt-btn--mode {
    min-height: 44px;
    font-size: 0.78rem;
    padding: 0.5rem 0.65rem;
  }

  .portfolio-game-body .portfolio-ttt-btn--new {
    min-height: 44px;
    font-size: 0.78rem;
    padding: 0.5rem 1rem;
  }

  .portfolio-game-body .portfolio-ttt-status {
    font-size: 1.02rem;
  }

  .portfolio-game-body .portfolio-ttt-board-wrap {
    min-height: 9rem;
  }

  .portfolio-game-body .portfolio-ttt-board-frame {
    padding: 0.55rem;
  }

  .portfolio-game-body .portfolio-ttt-board {
    gap: 0.4rem;
  }

  .portfolio-game-body .portfolio-ttt-hint {
    font-size: 0.72rem;
    padding: 0.45rem 0.55rem;
  }

  .portfolio-game-body .portfolio-ttt-result-overlay__title {
    font-size: 0.9rem;
  }

  .portfolio-game-body .portfolio-ttt-result-overlay__sub {
    font-size: 0.7rem;
  }
}

/* Large desktop only: slightly denser control strip (not on touch tablets) */
@media (min-width: 1025px) {
  .portfolio-game-body .portfolio-ttt-btn--mode {
    font-size: 0.72rem;
    padding: 0.48rem 0.55rem;
    min-height: 0;
  }

  .portfolio-game-body .portfolio-ttt-btn--new {
    font-size: 0.72rem;
    padding: 0.48rem 0.85rem;
    min-height: 0;
  }

  .portfolio-game-body .portfolio-ttt-status {
    font-size: 1rem;
  }
}

/* Mobile / tablet (≤1024px): under nav sidebar; Play right; modal centered on full container width */
@media (max-width: 1024px) {
  .portfolio-game-anchor {
    z-index: 99;
  }

  /*
   * Widget must span the .container — otherwise position:absolute .portfolio-game-window
   * uses the narrow toggle-only box as containing block and left:50% looks off-center.
   */
  .portfolio-game-widget {
    width: 100%;
    max-width: 100%;
    left: 0;
    right: auto;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
  }

  .portfolio-game-window {
    right: auto;
    left: 50%;
    transform: translateX(-50%) translateY(12px) scale(0.97);
  }

  .portfolio-game-window.active {
    transform: translateX(-50%) translateY(0) scale(1);
  }

  body:has(.nav-sidebar.open) .portfolio-game-toggle {
    display: none !important;
  }
}

@media (max-width: 1024px) and (prefers-reduced-motion: reduce) {
  .portfolio-game-window,
  .portfolio-game-window.active {
    transform: translateX(-50%);
  }
}

@media (prefers-reduced-motion: reduce) {
  .portfolio-game-window {
    transition: none;
  }

  .portfolio-game-toggle {
    transition: none;
  }

  .portfolio-game-toggle:hover {
    transform: none;
  }
}

/* ----- Tic tac toe main content (modal) ----- */
.portfolio-game-body .portfolio-ttt-shell {
  max-width: none;
  margin: 0;
  padding: 0;
  border-radius: 0;
  background: transparent;
  border: none;
  box-shadow: none;
  position: relative;
  flex: 1 1 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  gap: 0.5rem;
}

.portfolio-game-body .portfolio-ttt-hud {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  margin: 0;
}

.portfolio-game-body .portfolio-ttt-status-panel {
  text-align: center;
  padding: 0.55rem 0.65rem 0.6rem;
  border-radius: var(--radius-lg);
  background: linear-gradient(
    145deg,
    rgba(22, 22, 26, 0.95) 0%,
    rgba(15, 15, 18, 0.88) 100%
  );
  border: 1px solid var(--border-strong);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.04),
    0 4px 20px rgba(0, 0, 0, 0.2);
}

.portfolio-game-body .portfolio-ttt-status-eyebrow {
  display: block;
  font-size: 0.6rem;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--text-subtle);
  margin-bottom: 0.35rem;
}

.portfolio-game-body .portfolio-ttt-status {
  font-family: var(--font-display);
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--text);
  min-height: 1.35em;
  line-height: 1.3;
}

.portfolio-ttt-hud {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.portfolio-ttt-status {
  font-family: var(--font-display);
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text);
  text-align: center;
  min-height: 1.4em;
}

.portfolio-ttt-status span {
  color: var(--accent-light);
}

.portfolio-game-body .portfolio-ttt-actions {
  display: flex;
  flex-direction: row;
  align-items: stretch;
  gap: 0.45rem;
  flex-wrap: nowrap;
}

.portfolio-game-body .portfolio-ttt-mode-group {
  display: flex;
  flex: 1 1 auto;
  min-width: 0;
  border-radius: var(--radius);
  border: 1px solid var(--border-strong);
  overflow: hidden;
  background: var(--bg-elevated);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.03);
}

.portfolio-game-body .portfolio-ttt-btn--mode {
  flex: 1 1 0;
  min-width: 0;
  margin: 0;
  border-radius: 0;
  border: none;
  border-right: 1px solid var(--border);
  font-size: 0.68rem;
  font-weight: 600;
  padding: 0.45rem 0.4rem;
  background: transparent;
  color: var(--text-muted);
  transition:
    background 0.2s ease,
    color 0.2s ease,
    transform 0.18s cubic-bezier(0.34, 1.45, 0.64, 1),
    filter 0.18s ease;
}

.portfolio-game-body .portfolio-ttt-btn--mode:last-child {
  border-right: none;
}

.portfolio-game-body .portfolio-ttt-btn--mode:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  filter: brightness(1.12);
}

.portfolio-game-body .portfolio-ttt-btn--mode:active:not(:disabled) {
  transform: scale(0.96);
  filter: brightness(0.95);
}

.portfolio-game-body .portfolio-ttt-btn--mode.is-active {
  background: linear-gradient(
    180deg,
    rgba(232, 192, 74, 0.22) 0%,
    rgba(212, 168, 59, 0.14) 100%
  );
  color: #f0d078;
  text-shadow: 0 0 14px rgba(232, 192, 74, 0.35);
  border-color: transparent;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.06),
    0 0 0 1px rgba(212, 168, 59, 0.22);
}

.portfolio-game-body .portfolio-ttt-btn--mode.is-active:hover:not(:disabled) {
  background: linear-gradient(
    180deg,
    rgba(232, 192, 74, 0.3) 0%,
    rgba(212, 168, 59, 0.2) 100%
  );
  color: #f5dc98;
  text-shadow: 0 0 18px rgba(240, 208, 120, 0.45);
  filter: brightness(1.04);
}

.portfolio-game-body .portfolio-ttt-btn--mode.is-active:active:not(:disabled) {
  filter: brightness(0.98);
}

.portfolio-game-body .portfolio-ttt-btn--new {
  flex: 0 0 auto;
  padding: 0.45rem 0.75rem;
  font-size: 0.68rem;
  font-weight: 700;
  white-space: nowrap;
  box-shadow: 0 2px 12px var(--accent-glow);
  transition:
    transform 0.2s cubic-bezier(0.34, 1.45, 0.64, 1),
    box-shadow 0.2s ease,
    filter 0.2s ease,
    background 0.2s ease,
    color 0.2s ease;
}

.portfolio-ttt-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: center;
}

.portfolio-ttt-btn {
  font-family: var(--font-body);
  font-size: 0.8125rem;
  font-weight: 600;
  padding: 0.5rem 0.95rem;
  border-radius: var(--radius);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text-muted);
  cursor: pointer;
  transition:
    color var(--transition),
    border-color var(--transition),
    background var(--transition),
    transform 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}

.portfolio-ttt-btn:hover:not(:disabled):not(.portfolio-ttt-btn--primary) {
  color: var(--text);
  border-color: var(--border-focus);
  background: var(--bg-elevated);
}

.portfolio-ttt-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.portfolio-ttt-btn.is-active {
  border-color: var(--accent);
  color: var(--accent-light);
  background: var(--accent-dim);
}

.portfolio-ttt-btn--primary {
  background: var(--gradient-accent);
  color: var(--bg);
  border-color: transparent;
  box-shadow: 0 4px 18px var(--accent-glow);
  transition:
    color var(--transition),
    background var(--transition),
    border-color var(--transition),
    transform 0.22s cubic-bezier(0.34, 1.45, 0.64, 1),
    box-shadow 0.22s ease,
    filter 0.2s ease;
}

.portfolio-ttt-btn--primary:hover:not(:disabled),
.portfolio-ttt-btn--primary:focus-visible:not(:disabled) {
  color: var(--bg);
  background: var(--gradient-accent);
  border-color: transparent;
  transform: translateY(-2px);
  box-shadow: 0 8px 26px var(--accent-glow-strong);
  filter: brightness(1.08);
}

.portfolio-ttt-btn--primary:active:not(:disabled) {
  color: var(--bg);
  background: var(--gradient-accent);
  border-color: transparent;
  transform: translateY(0) scale(0.96);
  box-shadow: 0 2px 12px var(--accent-glow);
  filter: brightness(1.03);
}

.portfolio-ttt-btn--primary.is-active {
  color: var(--bg);
  background: var(--gradient-accent);
  border-color: transparent;
}

/* Board: fill remaining column height (avoid align-items:center collapse + broken cqh) */
.portfolio-game-body .portfolio-ttt-board-wrap {
  flex: 1 1 0;
  min-height: 7.5rem;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: stretch;
}

.portfolio-game-body .portfolio-ttt-board-frame {
  position: relative;
  overflow: hidden;
  flex: 1 1 0;
  min-height: 0;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.45rem;
  border-radius: var(--radius-lg);
  background: linear-gradient(
    160deg,
    rgba(212, 168, 59, 0.06) 0%,
    rgba(10, 10, 12, 0.5) 45%,
    rgba(15, 15, 18, 0.85) 100%
  );
  border: 1px solid rgba(212, 168, 59, 0.18);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.05),
    0 8px 28px rgba(0, 0, 0, 0.25);
}

/* End-game overlay: centered on board */
.portfolio-game-body .portfolio-ttt-result-overlay {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 0.65rem;
  background: rgba(6, 6, 8, 0.78);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  border-radius: inherit;
}

.portfolio-game-body .portfolio-ttt-result-overlay.is-visible {
  display: flex;
}

.portfolio-game-body .portfolio-ttt-result-overlay__card {
  width: 100%;
  max-width: 15.5rem;
  margin: 0 auto;
  padding: 0.85rem 1rem 1rem;
  text-align: center;
  border-radius: var(--radius-lg);
  background: linear-gradient(
    165deg,
    rgba(22, 22, 28, 0.98) 0%,
    rgba(12, 12, 16, 0.99) 100%
  );
  border: 1px solid rgba(212, 168, 59, 0.28);
  box-shadow:
    0 12px 36px rgba(0, 0, 0, 0.45),
    inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

.portfolio-game-body .portfolio-ttt-result-overlay__title {
  display: block;
  font-family: var(--font-display);
  font-size: 0.95rem;
  font-weight: 700;
  line-height: 1.25;
  color: var(--text);
  margin: 0 0 0.4rem;
}

/* Mini board: final positions + winning line (decorative; aria-hidden) */
.portfolio-game-body .portfolio-ttt-result-preview {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-template-rows: repeat(3, minmax(0, 1fr));
  gap: 0.18rem;
  width: 5.25rem;
  max-width: 100%;
  aspect-ratio: 1;
  margin: 0 auto 0.55rem;
  user-select: none;
}

.portfolio-game-body .portfolio-ttt-result-preview__cell {
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  min-width: 0;
  min-height: 0;
  font-family: var(--font-display);
  font-size: 0.68rem;
  font-weight: 700;
  line-height: 1;
  border-radius: 4px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: linear-gradient(
    165deg,
    rgba(22, 22, 26, 0.95) 0%,
    rgba(10, 10, 14, 0.98) 100%
  );
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
  color: var(--text-muted);
}

.portfolio-game-body .portfolio-ttt-result-preview__cell.is-x {
  color: var(--accent-light);
}

.portfolio-game-body .portfolio-ttt-result-preview__cell.is-o {
  color: var(--accent-secondary);
}

.portfolio-game-body .portfolio-ttt-result-preview__cell.is-winning {
  border-color: rgba(14, 165, 233, 0.45);
  background: var(--accent-secondary-dim);
  box-shadow: inset 0 0 0 1px rgba(14, 165, 233, 0.2);
}

.portfolio-game-body .portfolio-ttt-result-overlay__sub {
  margin: 0 0 0.75rem;
  font-size: 0.72rem;
  line-height: 1.4;
  color: var(--text-muted);
}

.portfolio-game-body .portfolio-ttt-btn--try-again {
  width: 100%;
  max-width: 100%;
  margin: 0;
  padding: 0.5rem 0.85rem;
  font-size: 0.75rem;
  font-weight: 700;
}

/* Square board; equal cells (minmax prevents content from shrinking tracks) */
.portfolio-game-body .portfolio-ttt-board {
  box-sizing: border-box;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-template-rows: repeat(3, minmax(0, 1fr));
  aspect-ratio: 1;
  width: 100%;
  max-width: 100%;
  max-height: 100%;
  min-width: 0;
  min-height: 0;
  height: auto;
  margin: 0;
  gap: 0.3rem;
  align-self: center;
}

/* Fixed box model: same border width in every state — no layout shift on tap / hover / win */
.portfolio-game-body .portfolio-ttt-cell {
  box-sizing: border-box;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  margin: 0;
  padding: 0;
  font-family: var(--font-display);
  font-size: clamp(1rem, 6vw, 1.75rem);
  touch-action: manipulation;
  border-radius: var(--radius);
  border-width: 1px;
  border-style: solid;
  border-color: rgba(255, 255, 255, 0.07);
  background: linear-gradient(
    165deg,
    rgba(22, 22, 26, 0.9) 0%,
    rgba(12, 12, 15, 0.95) 100%
  );
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  transition:
    border-color var(--transition),
    background var(--transition),
    box-shadow var(--transition),
    transform 0.2s cubic-bezier(0.34, 1.45, 0.64, 1),
    filter 0.2s ease;
}

.portfolio-game-body .portfolio-ttt-cell:hover:not(:disabled):not(.is-taken) {
  border-color: rgba(212, 168, 59, 0.45);
  background: linear-gradient(
    165deg,
    rgba(212, 168, 59, 0.08) 0%,
    rgba(22, 22, 26, 0.9) 100%
  );
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.06),
    inset 0 0 0 1px rgba(212, 168, 59, 0.18);
  transform: scale(1.03);
  filter: brightness(1.08);
}

.portfolio-game-body .portfolio-ttt-cell:active:not(:disabled):not(.is-taken) {
  transform: scale(0.94);
  filter: brightness(0.92);
}

.portfolio-game-body .portfolio-ttt-cell.is-x {
  text-shadow: 0 0 20px var(--accent-glow);
}

.portfolio-game-body .portfolio-ttt-cell.is-o {
  text-shadow: 0 0 18px rgba(14, 165, 233, 0.35);
}

.portfolio-game-body .portfolio-ttt-cell.is-winning {
  border-color: rgba(212, 168, 59, 0.55);
  background: linear-gradient(
    145deg,
    rgba(212, 168, 59, 0.2) 0%,
    rgba(14, 165, 233, 0.12) 100%
  );
  box-shadow:
    inset 0 0 0 1px rgba(212, 168, 59, 0.35),
    inset 0 1px 0 rgba(255, 255, 255, 0.05),
    0 4px 16px rgba(14, 165, 233, 0.12);
}

.portfolio-game-body .portfolio-ttt-cell:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

/* vmin tracks the smaller modal dimension so marks scale with the board */
@supports (aspect-ratio: 1) {
  .portfolio-game-body .portfolio-ttt-cell {
    font-size: clamp(1.05rem, 10vmin, 1.85rem);
  }
}

.portfolio-ttt-board {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-template-rows: repeat(3, minmax(0, 1fr));
  gap: 0.55rem;
  aspect-ratio: 1;
  margin: 0 auto;
}

.portfolio-ttt-cell {
  box-sizing: border-box;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  border-radius: var(--radius-lg);
  border-width: 1px;
  border-style: solid;
  border-color: var(--border);
  background: var(--surface);
  cursor: pointer;
  padding: 0;
  margin: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-size: clamp(1.75rem, 10vw, 2.35rem);
  font-weight: 800;
  line-height: 1;
  color: var(--text);
  transition:
    border-color var(--transition),
    background var(--transition),
    box-shadow var(--transition);
  -webkit-tap-highlight-color: transparent;
}

.portfolio-ttt-cell:hover:not(:disabled):not(.is-taken) {
  border-color: var(--border-focus);
  background: var(--bg-elevated);
}

.portfolio-ttt-cell:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.portfolio-ttt-cell.is-taken {
  cursor: default;
}

.portfolio-ttt-cell.is-x {
  color: var(--accent-light);
}

.portfolio-ttt-cell.is-o {
  color: var(--accent-secondary);
}

.portfolio-ttt-cell.is-winning {
  border-color: rgba(14, 165, 233, 0.55);
  background: var(--accent-secondary-dim);
  box-shadow: inset 0 0 0 1px rgba(14, 165, 233, 0.25);
}

.portfolio-ttt-cell:disabled {
  opacity: 1;
}

.portfolio-game-body .portfolio-ttt-footer {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-top: 0.1rem;
}

.portfolio-game-body .portfolio-ttt-hint {
  margin: 0;
  padding: 0.4rem 0.45rem;
  font-size: 0.65rem;
  line-height: 1.4;
  text-align: center;
  color: var(--text-subtle);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--border);
}

.portfolio-game-body .portfolio-ttt-hint strong {
  color: var(--text-muted);
  font-weight: 600;
}

.portfolio-ttt-hint {
  margin: 1.1rem 0 0;
  text-align: center;
  font-size: 0.8125rem;
  color: var(--text-subtle);
  line-height: 1.5;
}

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

@media (prefers-reduced-motion: reduce) {
  .portfolio-ttt-cell,
  .portfolio-ttt-btn,
  .portfolio-ttt-btn--primary,
  .portfolio-game-toggle,
  .portfolio-game-close,
  .portfolio-game-body .portfolio-ttt-btn--mode,
  .portfolio-game-body .portfolio-ttt-btn--new {
    transition: none;
  }

  .portfolio-ttt-btn--primary:hover,
  .portfolio-ttt-btn--primary:focus-visible,
  .portfolio-ttt-btn--primary:active,
  .portfolio-game-toggle:hover,
  .portfolio-game-toggle:active,
  .portfolio-game-close:hover,
  .portfolio-game-close:active,
  .portfolio-game-body .portfolio-ttt-btn--mode:hover,
  .portfolio-game-body .portfolio-ttt-btn--mode:active,
  .portfolio-game-body .portfolio-ttt-cell:hover,
  .portfolio-game-body .portfolio-ttt-cell:active {
    transform: none;
    filter: none;
  }

  .portfolio-game-body .portfolio-ttt-btn--mode.is-active,
  .portfolio-game-body .portfolio-ttt-btn--mode.is-active:hover,
  .portfolio-game-body .portfolio-ttt-btn--mode.is-active:active {
    text-shadow: none;
    filter: none;
  }

  .portfolio-game-body .portfolio-ttt-result-overlay {
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }
}
