* {
  box-sizing: border-box;
}

:root {
  --accent: #8b6cff;
  --accent-2: #ff7bd5;
  --page-1: #241a4d;
  --page-2: #0c0919;
  --text: #f6f3ff;
  --muted: rgba(246, 243, 255, 0.72);
  --line: rgba(255, 255, 255, 0.16);
  --surface: rgba(255, 255, 255, 0.08);
}

body[data-theme='sea'] {
  --accent: #3ddad7;
  --accent-2: #4f8cff;
  --page-1: #0d3346;
  --page-2: #061219;
  --text: #eefcff;
  --muted: rgba(238, 252, 255, 0.72);
}

body[data-theme='sun'] {
  --accent: #ffb03a;
  --accent-2: #ff6b6b;
  --page-1: #432512;
  --page-2: #150c06;
  --text: #fff5e9;
  --muted: rgba(255, 245, 233, 0.74);
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: system-ui, -apple-system, 'PingFang SC', 'Microsoft YaHei', sans-serif;
  color: var(--text);
  background-color: var(--page-2);
  background-image:
    radial-gradient(circle at 15% 12%, color-mix(in srgb, var(--accent) 45%, transparent), transparent 58%),
    radial-gradient(circle at 85% 88%, color-mix(in srgb, var(--accent-2) 38%, transparent), transparent 60%),
    linear-gradient(160deg, var(--page-1), var(--page-2));
  background-attachment: fixed;
  transition: background-image 0.4s ease;
}

.pig-layer {
  position: fixed;
  inset: 0;
  z-index: 5;
  pointer-events: none;
  overflow: hidden;
}

.pig-walker {
  position: fixed;
  left: 0;
  top: 0;
  pointer-events: auto;
  cursor: pointer;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
  will-change: transform;
}

.pig-walker:focus-visible {
  outline: 2px solid var(--text);
  outline-offset: 4px;
  border-radius: 50%;
}

.pig-inner {
  width: 110px;
  height: 78px;
  margin-left: -55px;
  margin-top: -39px;
}

.pig-body {
  width: 100%;
  height: 100%;
  transform: scale(1, 1);
  transition: transform 0.12s ease-out;
}

.pig-svg {
  width: 100%;
  height: 100%;
  display: block;
  filter: drop-shadow(0 4px 6px rgba(90, 10, 45, 0.28));
  animation: pig-bob 0.32s infinite alternate ease-in-out;
  animation-play-state: paused;
}

.pig-walker.is-dragging .pig-svg {
  animation-play-state: paused;
}

.pig-ear {
  transform-box: fill-box;
  transform-origin: 82% 95%;
}

.pig-walker.is-airborne .pig-body {
  transform: scale(0.95, 1.07);
}

.pig-walker.is-airborne .pig-svg {
  animation: none;
}

.pig-walker.is-airborne .pig-ear {
  animation: ear-flap 0.3s infinite alternate ease-in-out;
}

.pig-walker.is-airborne .pig-tail {
  animation: tail-flap 0.3s infinite alternate ease-in-out;
}

.pig-walker.is-airborne .leg {
  animation-duration: 0.22s;
}

.pig-walker.is-landing .pig-body {
  animation: pig-land 0.45s cubic-bezier(0.34, 1.4, 0.5, 1);
}

@keyframes pig-land {
  0% {
    transform: scale(1.18, 0.7);
  }
  38% {
    transform: scale(0.93, 1.11);
  }
  68% {
    transform: scale(1.05, 0.96);
  }
  100% {
    transform: scale(1, 1);
  }
}

@keyframes ear-flap {
  from {
    transform: rotate(-15deg);
  }
  to {
    transform: rotate(17deg);
  }
}

@keyframes tail-flap {
  from {
    transform: rotate(-18deg);
  }
  to {
    transform: rotate(20deg);
  }
}

.pig-walker.is-walking .pig-svg {
  animation-play-state: running;
}

.leg {
  transform-box: fill-box;
  transform-origin: 50% 6%;
  animation-duration: 0.3s;
  animation-iteration-count: infinite;
  animation-direction: alternate;
  animation-timing-function: ease-in-out;
  animation-play-state: paused;
}

.pig-walker.is-walking .leg {
  animation-play-state: running;
}

.leg-near-a,
.leg-far-b {
  animation-name: leg-swing-forward;
}

.leg-near-b,
.leg-far-a {
  animation-name: leg-swing-back;
}

.pig-tail {
  transform-box: fill-box;
  transform-origin: 100% 80%;
  animation: tail-wiggle 0.5s infinite alternate ease-in-out;
  animation-play-state: paused;
}

.pig-walker.is-walking .pig-tail {
  animation-play-state: running;
}

.mouth-open {
  opacity: 0;
}

.pig-bubble {
  position: absolute;
  left: 0;
  top: -34px;
  transform: translate(-50%, -100%) scale(0.7);
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 13px;
  white-space: nowrap;
  color: #4a2436;
  background: #fff;
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.25);
  opacity: 0;
  pointer-events: none;
}

.pig-walker.is-grunting .pig-svg {
  animation: pig-bounce 0.5s cubic-bezier(0.3, 1.2, 0.5, 1) 2;
}

.pig-walker.is-grunting .mouth-open {
  animation: mouth-open-once 1s ease-in-out;
}

.pig-walker.is-grunting .mouth-closed {
  animation: mouth-closed-once 1s ease-in-out;
}

.pig-walker.is-grunting .pig-bubble {
  animation: bubble-pop 1s ease-out;
}

@keyframes pig-bounce {
  0% {
    transform: translateY(0) scale(1);
  }
  35% {
    transform: translateY(-12px) scale(1.05, 0.94);
  }
  65% {
    transform: translateY(-2px) scale(0.98, 1.05);
  }
  100% {
    transform: translateY(0) scale(1);
  }
}

@keyframes mouth-open-once {
  0% {
    opacity: 0;
  }
  8%, 30% {
    opacity: 1;
  }
  40%, 52% {
    opacity: 0;
  }
  60%, 82% {
    opacity: 1;
  }
  92%, 100% {
    opacity: 0;
  }
}

@keyframes mouth-closed-once {
  0%, 8% {
    opacity: 1;
  }
  20%, 88% {
    opacity: 0;
  }
  100% {
    opacity: 1;
  }
}

@keyframes bubble-pop {
  0% {
    opacity: 0;
    transform: translate(-50%, -80%) scale(0.7);
  }
  20%, 70% {
    opacity: 1;
    transform: translate(-50%, -110%) scale(1);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -140%) scale(0.9);
  }
}

@keyframes pig-bob {
  0% {
    transform: translateY(0) scale(1, 1);
  }
  45% {
    transform: translateY(-6px) scale(0.98, 1.04);
  }
  100% {
    transform: translateY(0) scale(1.02, 0.97);
  }
}

@keyframes leg-swing-forward {
  from {
    transform: rotate(15deg);
  }
  to {
    transform: rotate(-15deg);
  }
}

@keyframes leg-swing-back {
  from {
    transform: rotate(-15deg);
  }
  to {
    transform: rotate(15deg);
  }
}

@keyframes tail-wiggle {
  from {
    transform: rotate(-8deg);
  }
  to {
    transform: rotate(10deg);
  }
}

.page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding:
    calc(20px + var(--redding-safe-area-top, env(safe-area-inset-top, 0px)))
    calc(20px + var(--redding-safe-area-right, env(safe-area-inset-right, 0px)))
    calc(20px + var(--redding-safe-area-bottom, env(safe-area-inset-bottom, 0px)))
    calc(20px + var(--redding-safe-area-left, env(safe-area-inset-left, 0px)));
}

.page-head {
  text-align: center;
}

.page-head h1 {
  margin: 0 0 6px;
  font-size: 22px;
  letter-spacing: 1px;
}

.page-sub {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
}

.card-scene {
  width: min(430px, 100%);
  height: 238px;
  perspective: 1400px;
}

.card {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform 0.6s cubic-bezier(0.22, 0.9, 0.28, 1);
  cursor: pointer;
}

.card.is-flipped {
  transform: rotateY(180deg);
}

.card:focus-visible {
  outline: 2px solid var(--text);
  outline-offset: 6px;
  border-radius: 24px;
}

.card-face {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 18px 20px;
  border-radius: 22px;
  border: 1px solid var(--line);
  background: linear-gradient(150deg, var(--surface), rgba(255, 255, 255, 0.03));
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.35);
  backface-visibility: hidden;
  overflow: hidden;
}

.card-face::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 5px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
}

.card-back {
  transform: rotateY(180deg);
}

.front-top {
  display: flex;
  align-items: center;
  gap: 14px;
}

.avatar {
  flex: 0 0 auto;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  overflow: visible;
  background: radial-gradient(circle at 34% 28%, #ffeaf2, #ffd3e2);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.3);
}

.pig {
  width: 100%;
  height: 100%;
  display: block;
  filter: drop-shadow(0 2px 3px rgba(120, 20, 60, 0.25));
}

.who {
  min-width: 0;
}

.name {
  margin: 0;
  font-size: 26px;
  letter-spacing: 2px;
}

.role {
  margin: 4px 0 0;
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 13px;
  color: #fff;
  background: linear-gradient(100deg, var(--accent), var(--accent-2));
}

.edu {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding-top: 10px;
  border-top: 1px dashed var(--line);
}

.edu-label {
  font-size: 12px;
  letter-spacing: 1px;
  color: var(--muted);
}

.edu-value {
  font-size: 15px;
  line-height: 1.45;
}

.site {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.site-link {
  align-self: flex-start;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.4px;
  color: var(--text);
  text-decoration: none;
  border-bottom: 2px solid transparent;
  background-image: linear-gradient(90deg, var(--accent), var(--accent-2));
  background-repeat: no-repeat;
  background-size: 100% 2px;
  background-position: 0 100%;
  padding-bottom: 2px;
}

.site-link:hover {
  filter: brightness(1.15);
}

.site-link:focus-visible {
  outline: 2px solid var(--text);
  outline-offset: 3px;
  border-radius: 4px;
}

.chips {
  margin-top: auto;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  padding: 4px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.06);
  font-size: 13px;
}

.back-title {
  margin: 4px 0 0;
  font-size: 17px;
  letter-spacing: 1px;
}

.hobby-list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.hobby {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 14px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.07);
  font-size: 16px;
}

.hobby-icon {
  font-size: 20px;
}

.back-note {
  margin: 0;
  font-size: 13px;
  line-height: 1.5;
  color: var(--muted);
}

.back-foot {
  margin: auto 0 0;
  font-size: 12px;
  letter-spacing: 1px;
  color: var(--muted);
}

.controls {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  justify-content: center;
}

.btn-flip {
  padding: 10px 22px;
  border: none;
  border-radius: 999px;
  font-size: 15px;
  font-family: inherit;
  color: #fff;
  background: linear-gradient(100deg, var(--accent), var(--accent-2));
  box-shadow: 0 10px 22px rgba(0, 0, 0, 0.28);
  cursor: pointer;
}

.btn-flip:hover {
  filter: brightness(1.08);
}

.btn-flip:focus-visible,
.swatch:focus-visible {
  outline: 2px solid var(--text);
  outline-offset: 3px;
}

.themes {
  display: flex;
  gap: 10px;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.06);
}

.swatch {
  width: 22px;
  height: 22px;
  padding: 0;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
}

.swatch-night {
  background: linear-gradient(140deg, #8b6cff, #ff7bd5);
}

.swatch-sea {
  background: linear-gradient(140deg, #3ddad7, #4f8cff);
}

.swatch-sun {
  background: linear-gradient(140deg, #ffb03a, #ff6b6b);
}

.swatch.is-active {
  border-color: var(--text);
}

@media (max-width: 420px) {
  .card-scene {
    height: 250px;
  }

  .name {
    font-size: 23px;
  }
}

@media (orientation: landscape) and (max-height: 520px) {
  .page {
    gap: 10px;
    padding-top: calc(10px + var(--redding-safe-area-top, env(safe-area-inset-top, 0px)));
    padding-bottom: calc(10px + var(--redding-safe-area-bottom, env(safe-area-inset-bottom, 0px)));
  }

  .page-head h1 {
    font-size: 17px;
  }

  .page-sub {
    font-size: 12px;
  }

  .card-scene {
    width: min(470px, 100%);
    height: 186px;
  }

  .card-face {
    padding: 10px 16px;
    gap: 6px;
    border-radius: 16px;
  }

  .avatar {
    width: 40px;
    height: 40px;
    font-size: 19px;
  }

  .name {
    font-size: 19px;
  }

  .role {
    font-size: 11px;
    padding: 2px 8px;
  }

  .edu {
    padding-top: 6px;
  }

  .edu-label {
    font-size: 11px;
  }

  .edu-value {
    font-size: 13px;
  }

  .chip {
    font-size: 12px;
    padding: 2px 10px;
  }

  .back-title {
    font-size: 14px;
    margin-top: 0;
  }

  .hobby-list {
    flex-direction: row;
    gap: 8px;
  }

  .hobby {
    flex: 1;
    padding: 6px 10px;
    font-size: 13px;
  }

  .site {
    gap: 0;
  }

  .site-link {
    font-size: 13px;
    padding-bottom: 1px;
  }

  .site .edu-label {
    display: none;
  }
  .hobby-icon {
    font-size: 16px;
  }

  .back-note {
    font-size: 12px;
  }

  .back-foot {
    display: none;
  }

  .btn-flip {
    padding: 7px 18px;
    font-size: 13px;
  }

  .swatch {
    width: 18px;
    height: 18px;
  }

  .pig-inner {
    width: 84px;
    height: 60px;
    margin-left: -42px;
    margin-top: -30px;
  }
}
