:root {
  color-scheme: light;
  --paper: #f6f1e5;
  --ink: #23362e;
  --muted: #65796b;
  --stroke: #d5d7c4;
  --mint: #dbe8d5;
  --coral: #e18c72;
  --stage: #e7ead9;
  font-family: Georgia, "Noto Serif TC", "PingFang TC", "Microsoft JhengHei", serif;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--paper); }
body { margin: 0; min-height: 100svh; color: var(--ink); background: var(--paper); }
button, input { font: inherit; }
button { cursor: pointer; -webkit-tap-highlight-color: transparent; }
button:focus-visible, canvas:focus-visible, input:focus-visible + .switch-track { outline: 3px solid #ad614d; outline-offset: 4px; }

.app-shell {
  width: min(1180px, 100%);
  min-height: 100svh;
  margin: 0 auto;
  padding: calc(28px + env(safe-area-inset-top)) clamp(18px, 4vw, 54px) calc(28px + env(safe-area-inset-bottom));
  position: relative;
}
.topbar { display: flex; align-items: center; gap: 15px; margin-bottom: clamp(24px, 4vh, 42px); }
.brand-mark { position: relative; width: 39px; height: 39px; border: 2px solid var(--ink); border-radius: 9px; background: var(--mint); transform: rotate(-7deg); flex: none; }
.brand-mark span { position: absolute; bottom: 18px; width: 7px; height: 19px; background: var(--ink); border-radius: 5px 5px 2px 2px; }
.brand-mark span:first-child { left: 10px; transform: rotate(-15deg); }
.brand-mark span:last-child { right: 9px; transform: rotate(15deg); }
.brand-copy { line-height: 1; }
.eyebrow, .section-index { margin: 0 0 6px; color: #8e6657; font-family: ui-monospace, "Cascadia Code", monospace; font-size: 11px; font-weight: 700; letter-spacing: .18em; }
h1 { margin: 0; font-size: clamp(25px, 3vw, 35px); font-weight: 800; letter-spacing: .05em; }
.title-dot { color: var(--coral); }
.help-button { margin-left: auto; padding: 10px 15px; border: 1.5px solid var(--ink); border-radius: 100px; color: var(--ink); background: transparent; font-size: 13px; font-weight: 700; }
.help-button:hover { background: var(--mint); }

.main-layout { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(330px, .85fr); gap: clamp(24px, 4vw, 58px); align-items: stretch; }
.pet-panel { min-width: 0; display: flex; flex-direction: column; }
.pet-stage {
  min-height: min(67vh, 630px);
  position: relative;
  overflow: hidden;
  isolation: isolate;
  border: 2px solid #879b86;
  border-radius: 34px 34px 24px 24px;
  background-color: var(--stage);
  background-image: radial-gradient(#b9c5ab 1.4px, transparent 1.4px);
  background-size: 26px 26px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  box-shadow: 12px 12px 0 #d1d9c7;
}
.pet-stage::before { content: ""; position: absolute; inset: 14px; border: 1px dashed #b1bea8; border-radius: 23px 23px 15px 15px; pointer-events: none; }
.stage-topline { position: absolute; top: 29px; left: 34px; right: 34px; display: flex; align-items: center; gap: 9px; z-index: 1; color: #667865; font-size: 12px; letter-spacing: .1em; }
.stage-sparkle { color: var(--coral); font-size: 21px; line-height: 1; }
.pet-halo { position: absolute; top: 19%; width: min(70%, 370px); aspect-ratio: 1; border-radius: 50%; background: #f7f5e6b8; box-shadow: 0 0 0 22px #f7f5e63a; }
#pet-canvas { position: relative; z-index: 2; display: block; width: clamp(222px, 31vw, 385px); height: auto; aspect-ratio: 192 / 208; image-rendering: pixelated; touch-action: none; user-select: none; -webkit-user-select: none; cursor: pointer; }
.stage-floor { position: absolute; bottom: 17%; width: 64%; height: 12px; display: flex; gap: 6px; align-items: center; justify-content: center; opacity: .55; }
.stage-floor span { display: block; height: 5px; background: #aebea4; border-radius: 9px; }
.stage-floor span:nth-child(1), .stage-floor span:nth-child(3) { width: 20%; }
.stage-floor span:nth-child(2) { width: 45%; }
.stage-hint { position: absolute; bottom: 31px; left: 16px; right: 16px; margin: 0; text-align: center; color: #526b58; font-size: 12px; font-weight: 700; letter-spacing: .03em; }
.stage-hint span { margin: 0 6px; color: var(--coral); }
.pet-status { display: flex; align-items: center; justify-content: center; gap: 9px; padding: 22px 0 0; font-size: 13px; font-weight: 700; color: #506d5a; }
.status-pip { width: 8px; height: 8px; background: #7aa66f; border: 1px solid #567c4d; border-radius: 50%; }

.controls-panel { display: flex; flex-direction: column; min-width: 0; padding-top: 10px; }
.controls-intro { margin-bottom: clamp(20px, 3vh, 33px); }
.controls-intro h2, .help-card h2 { margin: 0 0 12px; font-size: clamp(26px, 3vw, 38px); line-height: 1.25; letter-spacing: .025em; }
.controls-intro p { margin: 0; color: var(--muted); font-size: 14px; line-height: 1.7; }
.action-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.action-button { min-height: 76px; display: flex; align-items: center; gap: 14px; padding: 12px 17px; border: 1.5px solid var(--stroke); border-radius: 18px; background: #fffcf4; color: var(--ink); box-shadow: 3px 4px 0 #e0dfcf; text-align: left; font-size: 15px; font-weight: 800; transition: transform .15s ease, box-shadow .15s ease, background .15s ease; }
.action-button:hover { background: #f8eadf; transform: translateY(-2px); box-shadow: 4px 6px 0 #d9d9c9; }
.action-button:active, .action-button.is-playing { background: #f1d5c5; transform: translateY(2px); box-shadow: 1px 2px 0 #d9d9c9; }
.action-symbol { width: 32px; height: 32px; flex: none; display: grid; place-items: center; border: 1.5px solid #b5bfae; border-radius: 10px; background: #e9eee1; font-family: ui-monospace, monospace; font-size: 21px; font-weight: 400; }
.settings-card { display: flex; justify-content: space-between; align-items: center; gap: 18px; margin-top: clamp(25px, 4vh, 42px); padding: 20px 3px; border-top: 1px solid var(--stroke); border-bottom: 1px solid var(--stroke); }
.settings-card strong { font-size: 15px; }
.settings-card p { margin: 4px 0 0; color: var(--muted); font-size: 12px; line-height: 1.5; }
.switch { position: relative; flex: none; display: block; width: 54px; height: 32px; }
.switch input { position: absolute; inset: 0; opacity: 0; cursor: pointer; z-index: 2; }
.switch-track { position: absolute; inset: 0; border: 1.5px solid #869a87; border-radius: 99px; background: #d9e3d4; transition: background .2s; }
.switch-track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fffdf6; box-shadow: 1px 1px 0 #9da99a; transition: transform .2s; }
.switch input:checked + .switch-track { background: var(--coral); border-color: #b9735d; }
.switch input:checked + .switch-track::after { transform: translateX(22px); }
.connection-note { margin-top: 18px; color: #718172; font-size: 12px; line-height: 1.6; }

.help-panel { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: 20px; background: #23362ec7; }
.help-panel[hidden] { display: none; }
.help-card { position: relative; width: min(440px, 100%); padding: 36px; border: 2px solid var(--ink); border-radius: 24px; background: #fffcf4; box-shadow: 9px 10px 0 #a6b49d; }
.close-button { position: absolute; top: 14px; right: 16px; border: 0; background: none; color: var(--ink); font-size: 28px; line-height: 1; }
.help-card ol { padding-left: 1.4em; margin: 20px 0; line-height: 2; font-size: 15px; }
.help-footnote { margin: 0; padding-top: 14px; border-top: 1px solid var(--stroke); color: var(--muted); font-size: 12px; line-height: 1.6; }

@media (max-width: 850px) {
  .main-layout { grid-template-columns: 1fr; }
  .pet-stage { min-height: max(440px, min(59vh, 560px)); }
  #pet-canvas { width: clamp(220px, 45vw, 330px); }
  .controls-panel { padding-top: 0; }
}
@media (max-width: 540px) {
  .app-shell { padding-left: 16px; padding-right: 16px; }
  .topbar { margin-bottom: 22px; }
  .pet-stage { min-height: 470px; }
  #pet-canvas { width: min(72vw, 290px); }
  .stage-hint { font-size: 11px; }
  .action-button { min-height: 66px; padding: 10px; gap: 8px; font-size: 13px; }
  .action-symbol { width: 28px; height: 28px; font-size: 17px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; }
}
