:root {
  --bg: #fffaf5;
  --panel: #fff3dc;
  --panel-soft: #fff8ec;
  --pink: #f6a8bf;
  --pink-deep: #d9829b;
  --lavender: #d9cdf7;
  --peach: #ffd1b8;
  --brown: #795947;
  --brown-soft: #a98367;
  --green: #9fcd75;
  --border: #efc6cc;
  --shadow: 0 18px 40px rgba(143, 94, 75, 0.14);
  --small-shadow: 0 8px 20px rgba(143, 94, 75, 0.12);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  overflow-x: hidden;
}

body {
  color: var(--brown);
  background:
    radial-gradient(circle at 12% 16%, rgba(246, 168, 191, 0.18), transparent 24%),
    radial-gradient(circle at 82% 8%, rgba(217, 205, 247, 0.22), transparent 22%),
    linear-gradient(180deg, var(--bg) 0%, #fff6ea 100%);
  font-family: "Trebuchet MS", "Segoe UI", sans-serif;
}

button,
a {
  font: inherit;
}

.portfolio-shell {
  width: min(1120px, 100%);
  margin: 0 auto;
  padding: 56px 20px 34px;
}

.hero {
  position: relative;
  display: grid;
  justify-items: center;
  gap: 8px;
  margin: 0 auto 34px;
  text-align: center;
}

.hero-kicker {
  margin: 0;
  color: var(--pink-deep);
  font-size: clamp(1rem, 2vw, 1.25rem);
  font-weight: 700;
}

.hero h1 {
  margin: 0;
  color: var(--brown);
  font-size: clamp(3rem, 8vw, 6.2rem);
  line-height: 0.95;
  text-shadow: 0 4px 0 #ffe4eb, 0 9px 20px rgba(121, 89, 71, 0.14);
}

.hero-subtitle {
  margin: 0;
  padding: 8px 18px;
  color: var(--brown);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 999px;
  box-shadow: var(--small-shadow);
  font-weight: 700;
}

.title-decor {
  position: absolute;
  display: flex;
  align-items: center;
  gap: 12px;
  top: 38px;
  color: var(--pink-deep);
  pointer-events: none;
}

.title-decor-left {
  left: max(4%, calc(50% - 330px));
}

.title-decor-right {
  right: max(4%, calc(50% - 330px));
}

.pixel-heart {
  width: 18px;
  height: 18px;
  background: var(--pink);
  clip-path: polygon(
    50% 90%,
    10% 52%,
    10% 24%,
    32% 14%,
    50% 30%,
    68% 14%,
    90% 24%,
    90% 52%
  );
  box-shadow: 0 3px 0 rgba(121, 89, 71, 0.12);
}

.sparkle {
  color: #d6a7e8;
  font-size: 1.6rem;
}

.game-stage {
  position: relative;
  max-width: 100%;
  padding: 26px 18px 28px;
}

.log-track {
  /* Master rail value — the ONLY place vertical placement is tuned.
     Raise to lift the chameleon, lower to drop it. */
  --rail-y: 61.5%;
  position: relative;
  width: min(100%, 980px);
  margin: 0.4em auto 1.4em;
  aspect-ratio: 2345 / 670;
  overflow: visible;
}

.log-image {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  pointer-events: none;
  user-select: none;
}

/* Walking rail: single source of truth for chameleon Y and X bounds.
   Tune --rail-y only. Higher % = rail moves up, lower % = rail moves down. */
.log-rail {
  position: absolute;
  left: 8%;
  right: 8%;
  bottom: var(--rail-y);
  height: 0;
  z-index: 2;
  pointer-events: none;
}

/* temporary debug only */
.log-track.debug .log-rail {
  height: 2px;
  background: rgba(255, 0, 0, 0.35);
}

.log-zones {
  display: flex;
  justify-content: center;
  gap: clamp(12px, 3vw, 28px);
  width: min(100%, 980px);
  margin: 0 auto;
  padding-inline: 4%;
}

.tab-button {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 172px;
  min-width: 172px;
  min-height: 56px;
  padding: 12px 18px;
  color: var(--brown);
  background: rgba(255, 248, 236, 0.9);
  border: 1px solid #eed1c6;
  border-radius: 18px;
  box-shadow: 0 6px 0 #eec5aa, var(--small-shadow);
  cursor: pointer;
  font-weight: 800;
  transform: translateY(0) scale(1);
  transform-origin: center bottom;
  transition:
    transform 260ms ease,
    background 220ms ease,
    border-color 220ms ease,
    box-shadow 220ms ease;
}

.tab-button:hover,
.tab-button:focus-visible {
  transform: translateY(-3px) scale(1);
  outline: none;
  border-color: var(--pink);
}

.tab-button.is-active {
  min-width: 172px;
  min-height: 56px;
  background: linear-gradient(180deg, #ffe1ea 0%, #ffc8d7 100%);
  border-color: var(--pink-deep);
  box-shadow: 0 8px 0 #e8a2b1, 0 14px 26px rgba(216, 130, 155, 0.22);
  transform: translateY(-8px) scale(1.08);
}

.tab-icon {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  color: var(--pink-deep);
  background: #fff8ec;
  border: 1px solid #f0c9cf;
  border-radius: 8px;
}

.tab-label-short {
  display: none;
}

/* Chameleon guide */

.chameleon {
  --x: 0px;
  --scale: 0.42;
  --dir: 1;
  /* Sprite frames carry ~95px of transparent padding below the feet
     (at natural frame size). Scaled compensation pulls the feet onto the rail. */
  --feet-offset: calc(-95px * var(--scale));
  position: absolute;
  /* --x is track-relative; rail bounds from JS already include the rail's 8% inset */
  left: 0;
  bottom: calc(var(--rail-y) + var(--feet-offset));
  z-index: 4;
  background-image: url("assets/chameleon-spritesheet.png");
  background-repeat: no-repeat;
  background-size: auto;
  image-rendering: auto;
  translate: var(--x) 0;
  scale: calc(var(--scale) * var(--dir)) var(--scale);
  transform-origin: center bottom;
  transition: translate 120ms linear;
  filter: drop-shadow(0 8px 8px rgba(78, 85, 48, 0.18));
  cursor: default;
}

.chameleon.face-left {
  --dir: -1;
}

.chameleon.face-right {
  --dir: 1;
}

.chameleon.guide-focused {
  outline: none;
  border: none;
}

.chameleon.jump {
  animation: guideJump 0.42s ease-out;
}

@keyframes guideJump {
  0%,
  100% {
    translate: var(--x) 0;
  }

  45% {
    translate: var(--x) -28px;
  }
}

/* Mobile guide controls */

.guide-controls {
  position: fixed;
  left: 50%;
  bottom: max(14px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: none;
  align-items: center;
  gap: 10px;
  padding: 10px;
  background: rgba(255, 248, 236, 0.92);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: 999px;
  box-shadow: var(--shadow);
  z-index: 80;
}

.guide-control-btn {
  min-width: 44px;
  min-height: 44px;
  border: 1px solid #efd4c8;
  border-radius: 999px;
  background: var(--panel-soft);
  color: var(--brown);
  font-weight: 800;
  font-size: 18px;
  cursor: pointer;
  box-shadow: 0 4px 0 #eec5aa;
  transition: transform 180ms ease, box-shadow 180ms ease;
}

.guide-control-btn:active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 #eec5aa;
}

.guide-control-open {
  min-width: 72px;
  padding-inline: 16px;
  background: linear-gradient(180deg, #ffe1ea 0%, #ffc8d7 100%);
  border-color: var(--pink-deep);
  color: var(--brown);
  font-size: 14px;
  box-shadow: 0 4px 0 #e8a2b1;
}

.guide-control-open:active {
  box-shadow: 0 2px 0 #e8a2b1;
}

.guide-control-btn:focus-visible {
  outline: 3px solid rgba(246, 168, 191, 0.7);
  outline-offset: 3px;
}

/* Content panel */

.content-panel {
  position: relative;
  z-index: 1;
  width: min(900px, 100%);
  min-height: 276px;
  margin: -6px auto 0;
  padding: clamp(22px, 4vw, 34px);
  background: rgba(255, 243, 220, 0.94);
  border: 1px solid var(--border);
  border-radius: 28px;
  box-shadow: var(--shadow);
}

.tab-panel {
  animation: panelIn 360ms ease both;
}

.tab-panel h2 {
  margin: 0 0 14px;
  color: var(--brown);
  font-size: clamp(1.55rem, 3vw, 2.1rem);
}

.tab-panel p {
  margin: 0;
  color: #8a6a58;
  line-height: 1.7;
}

.tag-list,
.mini-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.tag-list {
  margin-top: 24px;
}

.tag-list span,
.mini-tags {
  padding: 8px 12px;
  color: #7a5f78;
  background: #f5edff;
  border: 1px solid #dfcff4;
  border-radius: 999px;
  font-size: 0.92rem;
  font-weight: 700;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
}

.badge-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.mini-card {
  min-width: 0;
  padding: 18px;
  background: var(--panel-soft);
  border: 1px solid #efd4c8;
  border-radius: 20px;
  box-shadow: 0 10px 20px rgba(143, 94, 75, 0.08);
}

.mini-card h3 {
  margin: 10px 0 8px;
  color: var(--brown);
  font-size: 1rem;
  overflow-wrap: anywhere;
}

.mini-card p {
  font-size: 0.93rem;
}

.card-icon,
.badge-mark {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  color: var(--pink-deep);
  background: #ffe6ed;
  border: 1px solid #f1c2cc;
  border-radius: 12px;
  font-weight: 900;
}

.badge-card {
  background: linear-gradient(180deg, #fff8ec 0%, #fff0d8 100%);
}

.contact-dock {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 28px;
}

.contact-dock a {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  padding: 10px 14px;
  color: var(--brown);
  text-decoration: none;
  background: #fff8ec;
  border: 1px solid #efd4c8;
  border-radius: 999px;
  box-shadow: var(--small-shadow);
  font-weight: 800;
}

.contact-dock a:hover,
.contact-dock a:focus-visible {
  outline: none;
  border-color: var(--pink);
  background: #ffeef3;
}

/* Cloud decoration kept, flower/garden/vine decoration removed */

.cloud {
  position: absolute;
  z-index: 0;
  width: 106px;
  height: 38px;
  border: 2px solid rgba(217, 205, 247, 0.72);
  border-radius: 999px;
  opacity: 0.55;
}

.cloud::before,
.cloud::after {
  content: "";
  position: absolute;
  bottom: 12px;
  border: 2px solid rgba(217, 205, 247, 0.72);
  border-bottom: 0;
  border-radius: 999px 999px 0 0;
  background: transparent;
}

.cloud::before {
  left: 18px;
  width: 34px;
  height: 24px;
}

.cloud::after {
  right: 20px;
  width: 42px;
  height: 30px;
}

.cloud-one {
  top: 8px;
  left: 6%;
}

.cloud-two {
  right: 6%;
  bottom: 240px;
  transform: scale(0.8);
}

/* Animations */

@keyframes panelIn {
  from {
    opacity: 0;
    transform: translateY(12px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Responsive */

@media (max-width: 820px) {
  .portfolio-shell {
    padding: 42px 14px 28px;
  }

  .game-stage {
    padding-inline: 0;
    overflow-x: clip;
  }

  /* The phone shows a cropped slice of the same scene:
     the track is wider than the screen and clipped by the stage.
     Vertical placement still comes only from --rail-y. */
  .log-track {
    width: 160%;
    margin-left: 50%;
    translate: -50% 0;
  }

  /* Keep the walkable rail inside the visible (cropped) slice of the scene.
     Horizontal bounds belong to the rail; --rail-y stays the single vertical value. */
  .log-rail {
    left: 22%;
    right: 22%;
  }

  .tab-button,
  .tab-button.is-active {
    flex: 1 1 0;
    width: auto;
    min-width: 0;
    max-width: 132px;
    min-height: 46px;
    padding: 10px 12px;
    border-radius: 15px;
    box-shadow: 0 5px 0 #eec5aa, var(--small-shadow);
  }

  .tab-button.is-active {
    transform: translateY(-5px) scale(1.06);
    box-shadow: 0 6px 0 #e8a2b1, 0 10px 20px rgba(216, 130, 155, 0.2);
  }

  .tab-icon {
    display: none;
  }

  .tab-label-full {
    display: none;
  }

  .tab-label-short {
    display: inline;
  }

  .chameleon {
    --scale: 0.34;
  }

  .content-panel {
    width: calc(100% - 8px);
    min-height: 250px;
    margin-top: 8px;
    padding: 22px;
    border-radius: 22px;
  }

  .card-grid,
  .badge-grid {
    grid-template-columns: 1fr;
  }

  .cloud-two {
    display: none;
  }
}

@media (max-width: 768px) {
  body {
    padding-bottom: 96px;
  }

  .guide-controls {
    display: flex;
    z-index: 100;
  }
}

@media (max-width: 440px) {
  .hero {
    margin-bottom: 22px;
  }

  .title-decor {
    top: 22px;
    gap: 6px;
  }

  .pixel-heart {
    width: 14px;
    height: 14px;
  }

  .sparkle {
    font-size: 1.2rem;
  }

  .tab-button,
  .tab-button.is-active {
    padding: 9px 8px;
    font-size: 0.82rem;
    min-height: 40px;
  }

  .chameleon {
    --scale: 0.28;
  }

  .contact-dock a {
    padding-inline: 12px;
  }

  .guide-controls {
    gap: 7px;
    padding: 8px;
  }

  .guide-control-btn {
    min-width: 40px;
    min-height: 40px;
    font-size: 16px;
  }

  .guide-control-open {
    min-width: 64px;
    font-size: 13px;
  }
}

/* Reduced motion */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
  }

  .chameleon,
  .chameleon.jump,
  .tab-panel {
    animation: none !important;
    transition: none !important;
  }
}

body.reduce-motion .chameleon,
body.reduce-motion .chameleon.jump,
body.reduce-motion .tab-panel {
  animation: none !important;
  transition: none !important;
}