@font-face {
  font-family: 'Pokemon';
  src: url('../assets/pokemon-font.ttf') format('truetype');
  font-weight: normal;
  font-style: normal;
}
:root {
  /* Max z-index 500 */
  /* sits on top of the modal backdrop */
  --modal-z-index: 15;
  --modal-backdrop-z-index: 300;
  --toast-z-index: 400;
  --prioritized-buttons-z-index: 250;
  --button-z-index: 50;
  --start-screen-z-index: 100;
}
html {
  font-size: 20px;
  -webkit-user-scalable: no;
  user-scalable: no;
  -webkit-user-select: none;
  user-select: none;
  touch-action: none;
}
p {
  margin: 0;
}
body {
  font-size: 1rem;
  visibility: visible;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  margin: 0 0;
  padding: 0;
  box-sizing: border-box;
  overflow: hidden;
  overscroll-behavior: none;
}
@keyframes pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0;
  }
}
.pkfnt {
  font-family: 'Pokemon', sans-serif;
}

.start-screen {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  /* solid white on load — covers everything before the iris is ready */
  background-color: white;
  z-index: var(--start-screen-z-index);
  overflow: hidden;
}
.start-screen-iris {
  position: absolute;
  /* Large enough to cover the full viewport diagonal */
  width: 300vmax;
  height: 300vmax;
  border-radius: 50%;
  background-color: white;
  top: 50%;
  left: 50%;
  /* No transition here — prevents Safari from animating the initial
     positioning of this element from transform:none on first paint. */
  transform: translate(-50%, -50%) scale(1);
  transform-origin: center center;
  will-change: transform;
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
  /* Centre the content inside the circle */
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}
.start-screen-closing {
  /* transparent so the game shows through the shrinking iris gap */
  background-color: transparent;
  pointer-events: none;
}
.start-screen-closing .start-screen-iris {
  transform: translate(-50%, -50%) scale(0);
  /* transition only added at closing time, never on initial paint */
  transition: transform 0.6s cubic-bezier(0.4, 0, 0.6, 1);
}
.start-screen-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
}
.loading-text-container {
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
}
.loading-bar-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  padding: 0;
}
.loading-bar {
  padding: 0;
}
.loading-bar-track {
  width: 14rem;
  height: 1.2rem;
  padding: 0;
  overflow: hidden;
  position: relative;
}
.loading-bar-fill {
  position: absolute;
  inset: 0;
  width: 0%;
  background-color: var(--border-color);
  transition: width 0.25s ease;
}
.start-button {
  margin-top: 1rem;
}
.start-button-text {
  animation: pulse 2s ease-in-out infinite;
}
.tileset-preview::after {
  content: 'Tileset Preview';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  color: red;
  background-color: rgba(0, 0, 0, 0.5);
  font-size: 1.5rem;
}
.main-canvas-container {
  margin-top: 1rem;
  display: flex;
  justify-content: center;
  align-items: center;
}

.sm {
  font-size: 0.5rem;
}
.md {
  font-size: 0.8rem;
}
.game-instructions {
  text-align: center;
}
.game-instructions-container {
  padding-top: 1rem;
  display: flex;
  width: 100%;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.camera-orbit-button {
  position: relative;
  width: 50px;
  height: 50px;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: transparent;
  border: none;
  padding: 0;
  cursor: pointer;
}
#rectFill {
  transform-origin: center;
  transform-box: fill-box; /* Crucial for SVG centering */
  transition: transform 0.4s cubic-bezier(0.22, 1, 0.36, 1);
  pointer-events: none; /* Don't block clicks */
  transform: scale(1);
}

/* State when the button is active */
.is-active #rectFill {
  transform: scale(0); /* Start hidden */
}

.camera-orbit-svg {
  overflow: visible;
}

.camera-orbit-arrow {
  transform-box: view-box;
  transform-origin: 125px 125px;
  transform: rotate(0deg);
}

.camera-orbit-image {
  position: absolute;
  /* Use 50% and negative margins or translate for perfect centering */
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  transition: filter 0.3s ease; /* Smooth color transition */
  pointer-events: none;
  filter: invert(1);
}
.is-active .camera-orbit-image {
  filter: invert(0);
}
/* Desktop: hide d-pad */
.info {
  position: absolute;
  display: flex;
  flex-direction: column;
  top: 0.5rem;
  left: 0.5rem;
  align-items: flex-start;
}

.invert {
  filter: invert(1);
  -webkit-filter: invert(1); /* Legacy Safari support */
}

@media (max-width: 600px) {
  html {
    font-size: 14px;
  }

  .main-canvas-container {
    margin-top: 0.5rem;
    padding: 0 8px;
  }

  /* Hide keyboard instructions, show d-pad */
  .info {
    display: none;
  }

  .sm {
    font-size: 0.7rem;
  }
  .md {
    font-size: 1rem;
  }
}

.hidden {
  visibility: hidden;
}
.display-none {
  display: none;
}
.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;
}

/* === Focus styles === */
:focus-visible {
  outline: 3px solid #4a90d9;
  outline-offset: 3px;
}

/* === Button Bar === */
.button-bar {
  position: absolute;
  top: 14px;
  right: 0.5rem;
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 0.5rem;
}

.camera-switch-button.is-active,
.speaker-toggle-button.is-active {
  background-color: var(--border-color);
}
.camera-switch-button.is-active .camera-switch-icon,
.speaker-toggle-button.is-active .speaker-toggle-icon {
  filter: invert(1);
}
/* === Button Bar Buttons === */
.camera-switch-button,
.fullscreen-toggle-button,
.menu-toggle-button,
.speaker-toggle-button {
  height: 2rem;
  width: 2rem;
  font-size: 0.8em;
  padding: 0.15em 0.5em;
  cursor: pointer;
  opacity: 1;
  transition:
    opacity 0.3s ease,
    background-color 0.2s ease,
    color 0.2s ease;
}
.camera-switch-button {
  padding-left: 0.5rem;
  z-index: var(--button-z-index);
}
.speaker-toggle-button {
  z-index: 50;
  font-size: 1rem;
  padding-bottom: 0.25rem;
  z-index: var(--button-z-index);
}
.menu-toggle-button {
  padding-bottom: 0.5rem;
  z-index: var(--prioritized-buttons-z-index);
}
.fullscreen-toggle-button {
  font-size: 0.65rem;
  padding-bottom: 0.25rem;
  z-index: var(--prioritized-buttons-z-index);
}
.camera-switch-icon,
.speaker-toggle-icon {
  display: block;
  width: 1em;
  height: 1em;
  object-fit: contain;
}
.fullscreen-toggle-button.is-active,
.menu-toggle-button.is-active {
  background-color: var(--border-color);
  color: var(--border-background-color);
}

/* === Toast === */
.toast {
  position: fixed;
  left: 50%;
  transform: translateX(-50%) translateY(0);
  z-index: var(--toast-z-index);
  font-size: 0.95rem;
  line-height: 1.4;
  width: min(90vw, 34rem);
  max-width: 90vw;
  text-align: center;
  pointer-events: auto;
  touch-action: auto;
  box-sizing: border-box;
  margin: 0;
  padding: 0.7rem 2.2rem 0.7rem 0.9rem;
  transition:
    opacity 0.3s ease,
    transform 0.3s ease;
}

.toast--bottom {
  top: auto;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 0.75rem);
}

.toast--top {
  bottom: auto;
  top: calc(env(safe-area-inset-top, 0px) + 0.75rem);
}

.toast--hidden {
  opacity: 0;
  pointer-events: none;
}

.toast--bottom.toast--hidden {
  transform: translateX(-50%) translateY(0.5rem);
}

.toast--top.toast--hidden {
  transform: translateX(-50%) translateY(-0.5rem);
}

.toast__text {
  margin: 0;
}

.toast__text--action {
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.toast__close {
  position: absolute;
  top: 0.35em;
  right: 0.35em;
  background: none;
  border: none;
  color: #000;
  font-family: inherit;
  font-size: 0.85em;
  cursor: pointer;
  padding: 0.2em;
  line-height: 1;
  pointer-events: auto;
  touch-action: auto;
}

@media (max-width: 600px) {
  .toast {
    width: min(90vw, 30rem);
    max-width: 90vw;
    font-size: 1rem;
    padding: 0.8rem 2.4rem 0.8rem 1rem;
  }
}

/* === Portfolio Modal === */
/* ── Portfolio modal outer wrapper (tabs float above the pkbd box) ── */
.portfolio-modal-outer {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  max-width: 50vw;
  width: fit-content;
}

/* ── Tab strip — sits above the modal, overlaps its top border ── */
.portfolio-modal-tab-strip {
  display: flex;
  flex-direction: row;
  align-items: flex-end;
  margin-left: 0.4em;
  position: relative;
  z-index: 20;
  margin-bottom: -20px;
}
.portfolio-modal-tab {
  font-size: 0.6em;
  user-select: none;
  -webkit-user-select: none;
  background-color: #b3b2b2;
}
.portfolio-modal-tab.is-active {
  background-color: #fff;
  position: relative;
  z-index: 21;
  cursor: default;
}
.portfolio-modal-tab.is-active:hover {
  transform: none;
  box-shadow: none;
}

/* ── Tab panels — CSS grid stacking keeps height fixed to tallest panel ── */
.portfolio-modal-panels {
  display: grid;
  grid-template-columns: 1fr;
}
.portfolio-tab-panel {
  grid-area: 1 / 1;
  display: flex;
  flex-direction: column;
  gap: 1em;
}
.portfolio-tab-panel.is-hidden {
  visibility: hidden;
  pointer-events: none;
}

/* ── Controls panel ── */
.pm-controls-list {
  display: flex;
  flex-direction: column;
  gap: 0.8em;
}
.pm-controls-row {
  display: flex;
  align-items: center;
  gap: 0.6em;
  font-size: 0.65em;
}
.pm-controls-action {
  min-width: 4.5em;
  font-weight: bold;
}
.pm-controls-keys {
  display: flex;
  align-items: center;
  gap: 0.3em;
  flex-wrap: wrap;
}
.pm-controls-kbd {
  font-family: 'Pokemon', sans-serif;
  background-color: #ebebeb;
  border: 1px solid var(--border-color);
  border-bottom-width: 2px;
  padding: 0.1em 0.45em;
  font-size: inherit;
  font-style: normal;
  border-radius: 2px;
}
.pm-controls-or {
  opacity: 0.5;
  font-size: 0.9em;
}

.portfolio-modal-backdrop {
  position: fixed;
  inset: 0;
  background-color: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: var(--modal-backdrop-z-index);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition:
    opacity 0.2s ease,
    visibility 0s linear 0.2s;
  touch-action: auto;
}
.portfolio-modal-backdrop.is-open {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}
.portfolio-modal {
  contain: none;
  box-sizing: border-box;
  padding: 1.2em 1.4em;
  display: flex;
  flex-direction: column;
  gap: 1em;
  max-height: 90vh;
  touch-action: auto;
  width: 100%;
}
.portfolio-modal > * {
  position: relative;
  z-index: var(--modal-z-index);
}
.portfolio-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5em;
}
.portfolio-modal-title {
  font-size: 0.85em;
  font-weight: normal;
  margin: 0;
  line-height: 1.3;
}
.portfolio-modal-close {
  flex-shrink: 0;
  font-size: 0.85em;
  line-height: 1;
  padding: 0.1em 0.35em;
  cursor: pointer;
  padding-bottom: 0.5rem;
}
.portfolio-modal-bio {
  display: flex;
  flex-direction: column;
  gap: 0.7em;
  font-size: 0.65em;
  line-height: 1.6;
}
.portfolio-modal-links {
  display: flex;
  gap: 1rem;
  justify-content: center;
  align-items: center;
  width: 100%;
  flex-wrap: wrap;
}
.portfolio-link {
  display: flex;
  align-items: center;
  gap: 0.4em;
  font-size: 0.65em;
  text-decoration: none;
  color: inherit;
}
.portfolio-link-icon {
  width: 18px;
  height: 18px;
  object-fit: contain;
}
.portfolio-modal-footer {
  text-align: center;
  font-size: 0.45em;
  opacity: 0.6;
  margin: 0;
}

@media (max-width: 600px) {
  .portfolio-modal-bio {
    font-size: 0.75em;
  }
  .portfolio-link {
    font-size: 0.75em;
    gap: 0.5rem;
  }
  .portfolio-modal-footer {
    font-size: 0.55em;
    gap: 0.5rem;
  }
}
@media (max-width: 720px) {
  .portfolio-modal-outer {
    max-width: 90vw;
  }
  .portfolio-modal {
    padding: 1em 1.2em;
  }
  /* .portfolio-modal-links {
    flex-direction: column;
  } */
}
