:root {
  --page-bg: #eef6f7;
  --shell-bg: #f8fbf8;
  --ink: #24313a;
  --muted: #667987;
  --panel: rgba(255, 255, 255, 0.9);
  --panel-strong: rgba(255, 255, 255, 0.96);
  --line: #86c6d1;
  --accent: #0f8da3;
  --accent-soft: #d9f3f6;
  --warm: #f4bc58;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  background:
    radial-gradient(circle at top left, rgba(255, 222, 150, 0.35), transparent 34%),
    linear-gradient(135deg, #f8fbf8 0%, #e8f6f8 50%, #f7f0df 100%);
  color: var(--ink);
  font-family: "Microsoft JhengHei", "PingFang TC", system-ui, sans-serif;
}

body {
  display: block;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
}

.game-shell {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background:
    radial-gradient(circle at 12% 0%, rgba(255, 222, 150, 0.32), transparent 36%),
    linear-gradient(135deg, #f8fbf8 0%, #e8f6f8 50%, #f7f0df 100%);
  border: 0;
  outline: 0;
  border-radius: 0;
  box-shadow: none;
}

.game-stage {
  position: absolute;
  left: 0;
  top: 0;
  width: 960px;
  height: 540px;
  overflow: hidden;
  background: var(--shell-bg);
  transform: scale(var(--stage-scale-x, 1), var(--stage-scale-y, 1));
  transform-origin: top left;
}

#gameCanvas {
  display: block;
  width: 960px;
  height: 540px;
  image-rendering: auto;
}

.start-screen {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: grid;
  align-items: end;
  padding: 0 58px 58px;
  background:
    linear-gradient(90deg, rgba(22, 34, 42, 0.76), rgba(22, 34, 42, 0.18) 54%, rgba(22, 34, 42, 0.42)),
    center / cover no-repeat url("assets/cgs/opening_blank_notebook_user_v1.png");
}

.start-copy {
  width: 520px;
  color: #ffffff;
  text-shadow: 0 2px 14px rgba(0, 0, 0, 0.36);
}

.start-copy span {
  display: block;
  margin-bottom: 10px;
  color: rgba(232, 249, 250, 0.86);
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0;
}

.start-copy h1 {
  margin: 0 0 12px;
  font-size: 42px;
  line-height: 1.08;
}

.start-copy p {
  margin: 0 0 24px;
  color: rgba(255, 255, 255, 0.86);
  font-size: 17px;
  line-height: 1.6;
}

.start-copy button {
  width: 142px;
  height: 46px;
  border: 1px solid rgba(255, 255, 255, 0.54);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.92);
  color: #0d7284;
  font: 800 17px "Microsoft JhengHei", system-ui, sans-serif;
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.26);
  cursor: pointer;
}

.start-copy button:hover {
  background: #ffffff;
}

.hud,
.control-hint,
.prompt,
.dialogue,
.memory-book,
.toast {
  position: absolute;
  z-index: 4;
  background: var(--panel);
  border: 1px solid rgba(15, 141, 163, 0.32);
  color: var(--ink);
  box-shadow: 0 12px 34px rgba(52, 83, 94, 0.16);
  backdrop-filter: blur(10px);
}

.hud {
  top: 14px;
  padding: 8px 13px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 700;
}

.top-left {
  left: 14px;
}

.top-right {
  right: 14px;
  max-width: 320px;
  text-align: right;
}

.audio-controls {
  position: absolute;
  z-index: 5;
  top: 56px;
  right: 14px;
  display: flex;
  gap: 8px;
}

.audio-controls button {
  min-width: 78px;
  min-height: 34px;
  padding: 7px 11px;
  border: 1px solid rgba(15, 141, 163, 0.32);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.88);
  color: #0d7284;
  font: 800 13px "Microsoft JhengHei", system-ui, sans-serif;
  box-shadow: 0 10px 24px rgba(52, 83, 94, 0.14);
  backdrop-filter: blur(10px);
  cursor: pointer;
}

.audio-controls button[aria-pressed="true"] {
  background: rgba(255, 238, 198, 0.94);
  color: #8a5b10;
  border-color: rgba(244, 188, 88, 0.72);
}

.control-hint {
  left: 50%;
  bottom: 12px;
  transform: translateX(-50%);
  padding: 8px 14px;
  border-radius: 999px;
  color: #395060;
  font-size: 13px;
}

.prompt {
  left: 50%;
  bottom: 58px;
  min-width: 190px;
  transform: translateX(-50%);
  padding: 9px 14px;
  border-radius: 999px;
  text-align: center;
  font-size: 15px;
  font-weight: 700;
  color: #0b6f80;
  opacity: 0;
  transition: opacity 120ms linear, transform 120ms ease;
}

.prompt.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(-2px);
}

.dialogue {
  inset: 0;
  z-index: 7;
  border: 0;
  background: transparent;
  box-shadow: none;
  backdrop-filter: none;
  pointer-events: none;
}

.dialogue.has-portrait,
.dialogue.has-backdrop {
  background: rgba(14, 21, 26, 0.18);
}

.dialogue-backdrop {
  position: absolute;
  inset: 0;
  filter: saturate(0.94) contrast(0.96) brightness(0.92);
}

.dialogue-backdrop::after {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(0deg, rgba(7, 11, 14, 0.44), rgba(7, 11, 14, 0.04) 54%, rgba(255, 255, 255, 0.04)),
    rgba(240, 249, 250, 0.08);
}

.dialogue-portrait {
  position: absolute;
  left: 46px;
  bottom: 116px;
  width: 390px;
  height: 390px;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  pointer-events: none;
}

.dialogue-portrait img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 20px 28px rgba(0, 0, 0, 0.28));
}

.dialogue-panel {
  position: absolute;
  left: 42px;
  right: 42px;
  bottom: 28px;
  min-height: 128px;
  padding: 17px 20px 16px;
  border: 1px solid rgba(15, 141, 163, 0.32);
  border-radius: 16px;
  background: var(--panel-strong);
  box-shadow: 0 12px 34px rgba(52, 83, 94, 0.16);
  backdrop-filter: blur(10px);
  pointer-events: auto;
}

.dialogue.has-portrait .dialogue-panel {
  left: 330px;
  min-height: 138px;
}

.dialogue.has-backdrop:not(.has-portrait) .dialogue-panel {
  background: rgba(255, 255, 255, 0.93);
}

.dialogue-name {
  margin-bottom: 8px;
  color: #0f7f93;
  font-weight: 800;
  font-size: 16px;
}

.dialogue-text {
  min-height: 44px;
  color: #263641;
  font-size: 18px;
  line-height: 1.55;
}

.dialogue-next {
  position: absolute;
  right: 18px;
  bottom: 12px;
  color: var(--muted);
  font-size: 13px;
}

.choice-options {
  display: grid;
  gap: 8px;
  margin-top: 12px;
  max-width: 520px;
}

.choice-options button {
  min-height: 34px;
  padding: 7px 12px;
  border: 1px solid rgba(15, 141, 163, 0.28);
  border-radius: 999px;
  background: rgba(247, 251, 251, 0.9);
  color: #395060;
  font: 800 14px "Microsoft JhengHei", system-ui, sans-serif;
  text-align: left;
  cursor: pointer;
}

.choice-options button.selected,
.choice-options button:hover {
  border-color: rgba(15, 141, 163, 0.72);
  background: #d9f3f6;
  color: #0d6574;
}

.memory-book {
  top: 34px;
  left: 68px;
  width: 824px;
  height: 458px;
  padding: 22px 26px 18px;
  border-radius: 16px;
  background:
    linear-gradient(90deg, rgba(235, 213, 177, 0.72) 0 49.4%, rgba(160, 126, 86, 0.28) 49.5% 50.5%, rgba(247, 232, 199, 0.82) 50.6% 100%),
    rgba(255, 252, 240, 0.96);
  border-color: rgba(143, 115, 83, 0.32);
}

.memory-book h2 {
  margin: 0 0 10px;
  color: #70502f;
  font-size: 24px;
}

.memory-book ul {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px 24px;
  margin: 0;
  padding: 0;
  list-style: none;
  color: #2f414d;
  font-size: 15px;
}

.album-memory-page {
  display: grid;
  grid-template-columns: 132px 1fr;
  gap: 12px;
  align-items: stretch;
  min-height: 128px;
  padding: 10px;
  border: 1px solid rgba(143, 115, 83, 0.24);
  border-radius: 8px;
  background: rgba(255, 250, 235, 0.72);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.42);
}

.album-memory-page img {
  width: 132px;
  height: 104px;
  align-self: center;
  object-fit: cover;
  border: 5px solid rgba(255, 255, 255, 0.95);
  box-shadow: 0 8px 16px rgba(85, 62, 39, 0.18);
  background: #f6ead1;
}

.album-page-copy {
  min-width: 0;
}

.album-page-copy em,
.album-page-copy strong,
.album-page-copy span,
.album-page-copy small {
  display: block;
}

.album-page-copy em {
  margin-bottom: 4px;
  color: #0d7284;
  font-size: 12px;
  font-style: normal;
  font-weight: 800;
}

.album-page-copy strong {
  color: #5d4329;
  font-size: 14px;
  line-height: 1.25;
}

.album-page-copy span {
  margin-top: 6px;
  color: #493d32;
  font-size: 12px;
  line-height: 1.35;
}

.album-page-copy small {
  margin-top: 6px;
  color: #796651;
  font-size: 11px;
  line-height: 1.35;
}

.album-memory-page.missing {
  filter: grayscale(0.45);
  opacity: 0.82;
}

.album-memory-page.missing img {
  object-fit: contain;
}

.album-pocket {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 48px;
  padding: 8px 12px;
  border: 1px dashed rgba(143, 115, 83, 0.46);
  border-radius: 8px;
  background: rgba(255, 247, 224, 0.68);
}

.album-pocket strong {
  color: #70502f;
  white-space: nowrap;
}

.pocket-items {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  color: #796651;
  font-size: 13px;
}

.pocket-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  max-width: 240px;
  padding: 5px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.76);
  border: 1px solid rgba(211, 167, 86, 0.46);
  color: #6c481a;
  font-weight: 800;
}

.pocket-chip img {
  width: 26px;
  height: 26px;
  object-fit: contain;
}

.notebook-page {
  display: grid;
  grid-template-columns: 54px 1fr;
  gap: 12px;
  align-items: center;
  min-height: 66px;
  padding: 8px 10px;
  border: 1px solid rgba(143, 115, 83, 0.22);
  border-radius: 12px;
  background: rgba(255, 250, 233, 0.72);
}

.notebook-page img {
  width: 48px;
  height: 48px;
  object-fit: contain;
}

.notebook-page strong,
.notebook-page span {
  display: block;
}

.notebook-page strong {
  color: #5d4329;
  font-size: 14px;
}

.notebook-page span {
  margin-top: 3px;
  color: #6c5c4a;
  font-size: 12px;
  line-height: 1.35;
}

.notebook-page.missing {
  filter: grayscale(0.75);
  opacity: 0.7;
}

.memory-book p {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.cg-overlay {
  position: absolute;
  inset: 0;
  z-index: 8;
  display: block;
  background: #071014;
  overflow: hidden;
}

.cg-card {
  position: absolute;
  left: 42px;
  right: 42px;
  bottom: 30px;
  min-height: 144px;
  padding: 18px 22px 17px;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.62);
  border-radius: 16px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.28);
  text-align: left;
  backdrop-filter: blur(10px);
}

.cg-card h2 {
  margin: 0 0 8px;
  color: #0d7284;
  font-size: 22px;
}

.cg-art {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 0;
  background: #d8eef2;
  color: #ffffff;
  font-size: 20px;
  font-weight: 800;
  filter: saturate(0.96) contrast(0.96) brightness(0.94);
}

.cg-art::after {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(0deg, rgba(7, 11, 14, 0.5), rgba(7, 11, 14, 0.03) 58%, rgba(255, 255, 255, 0.04)),
    rgba(230, 248, 250, 0.05);
}

.cg-card p {
  margin: 6px 0;
  color: #2d3f4a;
  font-size: 17px;
  line-height: 1.55;
}

.cg-card span,
.cg-en {
  color: var(--muted);
  font-size: 14px;
}

.ending-actions {
  position: absolute;
  z-index: 2;
  inset: 24px 32px 188px;
  display: grid;
  grid-template-columns: 1fr 360px;
  gap: 18px;
  align-items: start;
  pointer-events: none;
}

.restart-button {
  justify-self: start;
  align-self: start;
  min-width: 138px;
  min-height: 44px;
  border: 1px solid rgba(255, 255, 255, 0.58);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.9);
  color: #0d7284;
  font: 900 17px "Microsoft JhengHei", system-ui, sans-serif;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.24);
  cursor: pointer;
  pointer-events: auto;
}

.guestbook {
  max-height: 316px;
  padding: 16px 16px 14px;
  border: 1px solid rgba(255, 255, 255, 0.58);
  border-radius: 16px;
  background: rgba(255, 252, 240, 0.9);
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.22);
  backdrop-filter: blur(10px);
  pointer-events: auto;
  overflow: hidden;
}

.guestbook h3 {
  margin: 0 0 10px;
  color: #70502f;
  font-size: 18px;
}

.guestbook form {
  display: grid;
  grid-template-columns: 96px 1fr 64px;
  gap: 8px;
  align-items: stretch;
}

.guestbook-hp {
  position: absolute;
  left: -10000px;
  width: 1px;
  height: 1px;
  opacity: 0;
  overflow: hidden;
}

.guestbook input,
.guestbook textarea {
  min-width: 0;
  border: 1px solid rgba(143, 115, 83, 0.28);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.82);
  color: #2f414d;
  font: 700 13px "Microsoft JhengHei", system-ui, sans-serif;
  outline: none;
}

.guestbook input {
  height: 42px;
  padding: 0 10px;
}

.guestbook textarea {
  height: 42px;
  padding: 9px 10px;
  resize: none;
}

.guestbook input:focus,
.guestbook textarea:focus {
  border-color: rgba(15, 141, 163, 0.72);
  box-shadow: 0 0 0 3px rgba(15, 141, 163, 0.12);
}

.guestbook button {
  height: 42px;
  border: 0;
  border-radius: 999px;
  background: #0f8da3;
  color: #ffffff;
  font: 900 13px "Microsoft JhengHei", system-ui, sans-serif;
  cursor: pointer;
}

.guestbook button:disabled {
  opacity: 0.58;
  cursor: wait;
}

.guestbook-status {
  min-height: 18px;
  margin: 9px 2px 6px;
  color: #796651;
  font-size: 12px;
}

.guestbook-list {
  display: grid;
  gap: 7px;
  max-height: 154px;
  margin: 0;
  padding: 0 4px 0 0;
  list-style: none;
  overflow: auto;
}

.guestbook-list li {
  padding: 8px 10px;
  border: 1px solid rgba(143, 115, 83, 0.2);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.62);
}

.guestbook-list strong {
  display: block;
  color: #0d7284;
  font-size: 12px;
}

.guestbook-list p {
  margin: 4px 0 0;
  color: #493d32;
  font-size: 13px;
  line-height: 1.45;
}

.guestbook-list time {
  display: block;
  margin-top: 4px;
  color: #8f7c65;
  font-size: 11px;
}

.toast {
  left: 50%;
  top: 82px;
  transform: translateX(-50%);
  padding: 11px 17px;
  border-radius: 999px;
  color: #785418;
  background: rgba(255, 245, 202, 0.96);
  border-color: rgba(244, 188, 88, 0.65);
  font-size: 15px;
  font-weight: 800;
}

.fade {
  position: absolute;
  inset: 0;
  z-index: 7;
  display: grid;
  place-items: center;
  background: rgba(255, 255, 255, 0);
  color: #123b45;
  font-size: 28px;
  font-weight: 800;
  pointer-events: none;
  opacity: 0;
  transition: opacity 260ms ease, background 260ms ease;
}

.fade.active {
  opacity: 1;
  background: rgba(244, 250, 251, 0.94);
}

.touch-controls {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: var(--touch-zone-height, 112px);
  z-index: 30;
  display: none;
  pointer-events: none;
  padding: 0 max(16px, env(safe-area-inset-left)) max(14px, env(safe-area-inset-bottom));
  background:
    linear-gradient(0deg, rgba(243, 250, 251, 0.92), rgba(243, 250, 251, 0.28) 78%, rgba(243, 250, 251, 0));
}

.touch-left,
.touch-right {
  position: absolute;
  bottom: max(18px, env(safe-area-inset-bottom));
  display: flex;
  gap: 14px;
}

.touch-left {
  left: max(18px, env(safe-area-inset-left));
}

.touch-right {
  right: max(18px, env(safe-area-inset-right));
}

.touch-controls button {
  width: 74px;
  height: 74px;
  border: 1px solid rgba(15, 141, 163, 0.34);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.9);
  color: #0d7284;
  font: 900 28px "Microsoft JhengHei", system-ui, sans-serif;
  box-shadow: 0 12px 28px rgba(52, 83, 94, 0.18);
  backdrop-filter: blur(8px);
  pointer-events: auto;
  touch-action: none;
}

.touch-controls button:active {
  transform: translateY(1px) scale(0.98);
  background: rgba(217, 243, 246, 0.92);
}

.game-shell.touch-mode .touch-controls {
  display: block;
}

.game-shell.touch-mode .control-hint {
  display: none;
}

.hidden {
  display: none;
}

@media (max-width: 980px), (max-height: 560px) {
  .game-stage {
    border-radius: 0;
    outline: 0;
    box-shadow: none;
  }

  .hud {
    top: 9px;
    padding: 7px 10px;
    font-size: 12px;
  }

  .top-left {
    left: 9px;
  }

  .top-right {
    right: 9px;
    max-width: 260px;
  }

  .audio-controls {
    top: 46px;
    right: 9px;
  }

  .audio-controls button {
    min-width: 64px;
    min-height: 30px;
    padding: 6px 9px;
    font-size: 12px;
  }

  .start-screen {
    padding: 0 34px 42px;
  }

  .start-copy {
    width: min(520px, 82vw);
  }

  .start-copy h1 {
    font-size: 34px;
  }

  .dialogue-portrait {
    left: 20px;
    bottom: 134px;
    width: 300px;
    height: 330px;
  }

  .dialogue-panel {
    left: 20px;
    right: 20px;
    bottom: 96px;
    min-height: 122px;
    padding: 14px 16px 15px;
  }

  .dialogue.has-portrait .dialogue-panel {
    left: 246px;
  }

  .dialogue-text {
    font-size: 16px;
    line-height: 1.48;
  }

  .choice-options {
    max-width: none;
  }

  .memory-book {
    top: 18px;
    left: 22px;
    width: 916px;
    height: 404px;
    padding: 18px 20px 16px;
  }

  .memory-book ul {
    gap: 10px 16px;
  }

  .album-memory-page {
    grid-template-columns: 108px 1fr;
    min-height: 112px;
  }

  .album-memory-page img {
    width: 108px;
    height: 86px;
  }

  .cg-card {
    left: 20px;
    right: 20px;
    bottom: 88px;
    min-height: 128px;
    padding: 15px 17px 16px;
  }

  .cg-card h2 {
    font-size: 20px;
  }

  .cg-card p {
    font-size: 15px;
    line-height: 1.45;
  }

  .ending-actions {
    inset: 14px 20px 242px;
    grid-template-columns: 1fr 330px;
  }

  .guestbook {
    max-height: 224px;
    padding: 13px;
  }

  .guestbook form {
    grid-template-columns: 78px 1fr 58px;
  }

  .guestbook-list {
    max-height: 76px;
  }
}

@media (max-width: 720px) {
  .dialogue-portrait {
    left: 14px;
    bottom: 172px;
    width: 220px;
    height: 248px;
    opacity: 0.94;
  }

  .dialogue.has-portrait .dialogue-panel {
    left: 18px;
  }

  .dialogue-panel {
    bottom: 112px;
  }

  .ending-actions {
    inset: 12px 16px 246px;
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .restart-button {
    min-width: 124px;
    min-height: 40px;
    font-size: 15px;
  }

  .guestbook {
    justify-self: end;
    width: min(390px, 88vw);
  }
}

@media (max-width: 420px) {
  .touch-left,
  .touch-right {
    gap: 8px;
    bottom: max(16px, env(safe-area-inset-bottom));
  }

  .touch-left {
    left: max(12px, env(safe-area-inset-left));
  }

  .touch-right {
    right: max(12px, env(safe-area-inset-right));
  }

  .touch-controls button {
    width: 64px;
    height: 64px;
    font-size: 24px;
  }

  .touch-controls {
    --touch-zone-height: 104px;
  }
}
