:root {
  --ink: #30282b;
  --muted: #74696c;
  --panel: rgba(255, 253, 248, 0.94);
  --rose: #db6f83;
  --rose-deep: #b84d63;
  --green: #5f9e69;
  --line: rgba(48, 40, 43, 0.13);
  --shadow: 0 18px 36px rgba(112, 70, 74, 0.15);
  font-family: "Microsoft YaHei", "PingFang SC", system-ui, sans-serif;
}

html {
  min-height: 100%;
  overscroll-behavior: none;
  touch-action: manipulation;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

body {
  margin: 0;
  min-height: 100svh;
  overflow-x: hidden;
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  background:
    radial-gradient(circle at 16% 7%, rgba(255, 255, 255, 0.72), transparent 25%),
    linear-gradient(180deg, #f9e0e3 0%, #fff5e3 44%, #e4f2dc 100%);
  color: var(--ink);
}

body.standalone .topbar {
  padding-top: 4px;
}

input,
textarea {
  user-select: text;
  -webkit-user-select: text;
}

button {
  border: 0;
  color: inherit;
  font: inherit;
  cursor: pointer;
  touch-action: manipulation;
}

.game-shell {
  width: min(100%, 1180px);
  min-height: 100vh;
  margin: 0 auto;
  padding: max(12px, env(safe-area-inset-top)) 12px max(16px, env(safe-area-inset-bottom));
}

.topbar,
.top-actions,
.scene-head,
.card-title-row,
.pafu-actions {
  display: flex;
  align-items: center;
}

.topbar {
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.top-actions {
  gap: 8px;
}

.eyebrow,
h1,
h2,
p {
  margin: 0;
}

.eyebrow {
  color: var(--rose-deep);
  font-size: 12px;
  font-weight: 900;
}

h1 {
  margin-top: 2px;
  font-size: 26px;
  line-height: 1.05;
  letter-spacing: 0;
}

h2 {
  font-size: 17px;
  line-height: 1.1;
}

.wallet {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 96px;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  font-size: 18px;
}

.wallet span {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #fff8b8, #f2be50 60%, #b87b22);
}

.app-button,
.music-button,
.soft-button {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  color: var(--rose-deep);
  font-size: 13px;
  font-weight: 900;
}

.app-button,
.music-button {
  min-width: 58px;
  height: 44px;
}

.app-button {
  padding: 0 12px;
}

.music-button.playing {
  background: #30282b;
  color: #fff8f1;
}

.scene-card,
.pafu-card,
.controls,
.dashboard article {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.scene-card {
  overflow: hidden;
}

.scene-head {
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

#goalText {
  text-align: right;
}

canvas {
  display: block;
  width: 100%;
  height: min(72vh, 720px);
  min-height: 470px;
  background: #cfecc2;
  touch-action: none;
}

.pafu-card {
  display: grid;
  grid-template-columns: 82px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  padding: 12px;
  margin-top: 10px;
}

.pafu-face {
  position: relative;
  width: 76px;
  height: 76px;
  border-radius: 8px;
  background: linear-gradient(180deg, #d8edf5, #dff0d6);
}

.pafu-face::before {
  position: absolute;
  left: 14px;
  bottom: 10px;
  width: 49px;
  height: 45px;
  content: "";
  border-radius: 49% 51% 46% 46%;
  background: #fffdf7;
  box-shadow: inset -7px -7px 0 #eee4da;
}

.ear,
.eye,
.nose,
.cheek {
  position: absolute;
  z-index: 1;
  display: block;
}

.ear {
  top: 11px;
  width: 20px;
  height: 26px;
  border-radius: 70% 30% 70% 30%;
  background: #f4c84f;
  box-shadow: inset -4px -4px 0 rgba(149, 91, 32, 0.12);
}

.ear.left {
  left: 18px;
  transform: rotate(-25deg);
}

.ear.right {
  right: 16px;
  transform: rotate(105deg);
}

.eye {
  top: 38px;
  width: 6px;
  height: 8px;
  border-radius: 50%;
  background: #31282b;
}

.eye.left {
  left: 31px;
}

.eye.right {
  right: 28px;
}

.nose {
  left: 35px;
  top: 49px;
  width: 8px;
  height: 6px;
  border-radius: 50%;
  background: #3a3033;
}

.cheek {
  top: 48px;
  width: 9px;
  height: 6px;
  border-radius: 50%;
  background: rgba(238, 139, 150, 0.45);
}

.cheek.left {
  left: 23px;
}

.cheek.right {
  right: 20px;
}

.card-title-row {
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 5px;
}

.card-title-row strong {
  padding: 5px 8px;
  border-radius: 999px;
  background: #fff0f2;
  color: var(--rose-deep);
  font-size: 12px;
}

#tipText {
  min-height: 36px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.pafu-actions {
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 8px;
}

.soft-button {
  min-height: 34px;
  padding: 0 10px;
  background: linear-gradient(180deg, #fffdf8, #fff2ea);
  box-shadow: none;
}

.soft-button:active,
.action-button:active,
.pig-chip:active {
  transform: translateY(1px);
}

meter {
  width: 100%;
  height: 15px;
  margin-top: 8px;
}

meter::-webkit-meter-bar {
  border: 0;
  border-radius: 999px;
  background: #eadfd9;
}

meter::-webkit-meter-optimum-value {
  border-radius: 999px;
  background: linear-gradient(90deg, var(--green), #e0bd5f);
}

.controls {
  position: sticky;
  z-index: 5;
  bottom: max(0px, env(safe-area-inset-bottom));
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 7px;
  margin-top: 10px;
  padding: 8px;
  background: rgba(255, 253, 248, 0.95);
  backdrop-filter: blur(14px);
}

.action-button {
  display: grid;
  gap: 3px;
  min-height: 60px;
  align-content: center;
  padding: 7px 4px;
  border-radius: 8px;
  border: 1px solid rgba(48, 40, 43, 0.08);
  background: linear-gradient(180deg, #fffaf3, #f7eee7);
  text-align: center;
}

.action-button.active {
  background: var(--ink);
  color: white;
}

.danger-button {
  color: #8c3f4c;
}

.danger-button strong {
  color: #9b3548;
}

.action-button:disabled,
.soft-button:disabled {
  cursor: default;
  opacity: 0.48;
}

.action-button strong {
  font-size: 13px;
  font-weight: 900;
}

.action-button small {
  color: var(--muted);
  font-size: 11px;
}

.action-button.active small {
  color: rgba(255, 255, 255, 0.75);
}

.dashboard {
  display: grid;
  gap: 10px;
  margin-top: 10px;
}

.dashboard article {
  padding: 12px;
}

.pig-list {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-top: 10px;
}

.pig-chip {
  display: grid;
  gap: 4px;
  min-height: 82px;
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(180deg, #fffdf8, #fff7ef);
  text-align: left;
}

.pig-chip.listed {
  outline: 2px solid rgba(219, 111, 131, 0.3);
}

.pig-chip.selected {
  outline: 3px solid rgba(101, 167, 109, 0.42);
  background: linear-gradient(180deg, #f4fff0, #fff8ef);
}

.pig-chip strong {
  font-size: 14px;
}

.pig-chip small,
.log {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.log {
  display: grid;
  gap: 5px;
  max-height: 160px;
  margin-top: 10px;
  overflow: auto;
}

.hidden {
  display: none !important;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  align-items: end;
  padding: max(12px, env(safe-area-inset-top)) 12px max(12px, env(safe-area-inset-bottom));
  background: rgba(48, 40, 43, 0.36);
  backdrop-filter: blur(8px);
}

.breed-panel {
  width: min(100%, 720px);
  max-height: min(78vh, 720px);
  margin: 0 auto;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 24px 56px rgba(48, 40, 43, 0.24);
  padding: 14px;
}

.modal-head,
.modal-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.icon-button {
  display: grid;
  width: 36px;
  height: 36px;
  place-items: center;
  border-radius: 8px;
  background: #fff3f0;
  color: var(--rose-deep);
  font-size: 22px;
  font-weight: 900;
}

.modal-note {
  margin-top: 8px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.breed-grid {
  display: grid;
  gap: 8px;
  margin: 12px 0;
}

.breed-option {
  display: grid;
  grid-template-columns: 82px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  min-height: 78px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(180deg, #fffdf8, #fff7ef);
  text-align: left;
}

.breed-option.selected {
  outline: 3px solid rgba(101, 167, 109, 0.42);
  background: linear-gradient(180deg, #f4fff0, #fff8ef);
}

.breed-option strong {
  font-size: 14px;
}

.breed-option small {
  display: block;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.pig-photo {
  display: block;
  width: 82px;
  aspect-ratio: 1.28;
  overflow: hidden;
  border: 1px solid rgba(48, 40, 43, 0.1);
  border-radius: 8px;
  background: #fff8ec;
}

.pig-photo img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.pig-option-copy {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.pig-panel {
  width: min(100%, 620px);
}

.pig-profile {
  display: grid;
  grid-template-columns: 112px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  margin-top: 12px;
}

.pig-profile .pig-photo {
  width: 112px;
}

.pig-profile-main {
  display: grid;
  gap: 7px;
  min-width: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.pig-profile-main strong {
  color: var(--ink);
  font-size: 15px;
}

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

.stat-cell {
  display: grid;
  gap: 4px;
  padding: 7px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffaf3;
  font-size: 11px;
}

.stat-cell b,
.stat-cell em {
  font-style: normal;
}

.stat-cell i {
  display: block;
  height: 6px;
  overflow: hidden;
  border-radius: 999px;
  background: #eadfd9;
}

.stat-cell i::before {
  display: block;
  width: var(--value);
  height: 100%;
  content: "";
  border-radius: inherit;
}

.stat-cell.good i::before {
  background: #6faf72;
}

.stat-cell.warn i::before {
  background: #d9a94c;
}

.stat-cell.bad i::before {
  background: #d66d73;
}

.name-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  margin-top: 12px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.name-row input {
  min-width: 0;
  height: 38px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffdf8;
  color: var(--ink);
  font: inherit;
}

.death-actions {
  margin-top: 12px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: max(18px, env(safe-area-inset-bottom));
  z-index: 40;
  max-width: min(90vw, 420px);
  transform: translateX(-50%);
  padding: 12px 16px;
  border: 1px solid rgba(48, 40, 43, 0.12);
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.96);
  box-shadow: 0 18px 42px rgba(48, 40, 43, 0.2);
  color: var(--ink);
  font-size: 15px;
  font-weight: 900;
  text-align: center;
}

.confirm-button {
  width: min(180px, 48%);
}

.confirm-button:disabled {
  background: linear-gradient(180deg, #fffaf3, #f7eee7);
  color: var(--muted);
}

@media (min-width: 720px) {
  .game-shell {
    padding-inline: 22px;
  }

  h1 {
    font-size: 32px;
  }

  .pafu-card {
    grid-template-columns: 100px minmax(0, 1fr);
  }

  .pafu-face {
    width: 90px;
    height: 90px;
  }

  .dashboard {
    grid-template-columns: 1.15fr 0.85fr;
  }

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

  .pig-list {
    grid-template-columns: repeat(3, 1fr);
  }

  .action-button strong {
    font-size: 15px;
  }

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

@media (min-width: 720px) and (orientation: portrait) {
  canvas {
    height: min(58svh, 600px);
    min-height: 500px;
  }

  .pafu-card {
    grid-template-columns: 82px minmax(0, 1fr);
    padding: 10px;
  }

  .pafu-face {
    width: 76px;
    height: 76px;
  }

  .controls {
    gap: 8px;
  }

  .action-button {
    min-height: 66px;
  }

  .pig-list {
    grid-template-columns: 1fr;
    max-height: 270px;
    overflow: auto;
  }

  .log {
    max-height: 270px;
  }
}

@media (min-width: 900px) and (orientation: landscape) {
  body {
    overflow: hidden;
  }

  .game-shell {
    display: grid;
    width: min(100vw, 1280px);
    height: 100dvh;
    min-height: 0;
    grid-template-columns: minmax(0, 1fr) 342px;
    grid-template-rows: auto 118px auto minmax(0, 1fr);
    gap: 10px;
    padding: max(8px, env(safe-area-inset-top)) 10px max(8px, env(safe-area-inset-bottom));
  }

  .topbar {
    grid-column: 1 / -1;
    margin-bottom: 0;
  }

  h1 {
    font-size: 27px;
  }

  .wallet,
  .app-button,
  .music-button {
    height: 40px;
  }

  .app-button,
  .music-button {
    min-width: 54px;
    padding-inline: 10px;
  }

  .scene-card {
    display: flex;
    min-height: 0;
    grid-column: 1;
    grid-row: 2 / 5;
    flex-direction: column;
  }

  .scene-head {
    flex: 0 0 auto;
    padding: 8px 10px;
    font-size: 12px;
  }

  canvas {
    flex: 1 1 auto;
    height: auto;
    min-height: 0;
  }

  .pafu-card {
    grid-column: 2;
    grid-row: 2;
    grid-template-columns: 72px minmax(0, 1fr);
    gap: 9px;
    align-self: stretch;
    margin-top: 0;
    padding: 10px;
    overflow: hidden;
  }

  .pafu-face {
    width: 68px;
    height: 68px;
  }

  .pafu-face::before {
    left: 12px;
    width: 44px;
    height: 40px;
  }

  .card-title-row {
    margin-bottom: 3px;
  }

  #tipText {
    min-height: 0;
    max-height: 38px;
    overflow: hidden;
    font-size: 12px;
  }

  .pafu-actions {
    gap: 6px;
    margin-top: 6px;
  }

  .soft-button {
    min-height: 32px;
  }

  meter {
    height: 12px;
    margin-top: 6px;
  }

  .controls {
    position: static;
    grid-column: 2;
    grid-row: 3;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-self: start;
    gap: 7px;
    margin-top: 0;
    padding: 8px;
    backdrop-filter: none;
  }

  .action-button {
    min-height: 50px;
  }

  .action-button strong {
    font-size: 14px;
  }

  .dashboard {
    display: grid;
    min-height: 0;
    grid-column: 2;
    grid-row: 4;
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 1.2fr) minmax(92px, 0.8fr);
    gap: 10px;
    margin-top: 0;
    overflow: hidden;
  }

  .dashboard article {
    display: flex;
    min-height: 0;
    flex-direction: column;
    padding: 10px;
    overflow: hidden;
  }

  .pig-list {
    grid-template-columns: 1fr;
    gap: 7px;
    min-height: 0;
    margin-top: 8px;
    overflow: auto;
    overscroll-behavior: contain;
  }

  .pig-chip {
    min-height: 74px;
    padding: 8px;
  }

  .pig-chip strong {
    font-size: 13px;
  }

  .pig-chip small,
  .log {
    font-size: 11px;
  }

  .log {
    min-height: 0;
    max-height: none;
    overflow: auto;
    overscroll-behavior: contain;
  }

  .modal-backdrop {
    align-items: center;
  }

  .breed-panel {
    max-height: min(88vh, 720px);
  }
}

@media (min-width: 1100px) and (orientation: landscape) {
  .game-shell {
    grid-template-columns: minmax(0, 1fr) 372px;
  }

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

@media (max-width: 420px) {
  .breed-option {
    grid-template-columns: 72px minmax(0, 1fr);
    padding: 8px;
  }

  .pig-photo {
    width: 72px;
  }

  .pig-profile {
    grid-template-columns: 1fr;
  }

  .pig-profile .pig-photo {
    width: 100%;
    max-width: 180px;
  }

  .name-row {
    grid-template-columns: 1fr;
  }
}
