@font-face {
  font-family: "Island Playful";
  src: url("assets/welcome-playful.woff2") format("woff2");
  font-style: normal;
  font-weight: 400 900;
  font-display: swap;
}

:root {
  color-scheme: light;
  --ink: #463027;
  --ink-soft: #71594c;
  --paper: #fff6df;
  --paper-strong: #fffaf0;
  --teal: #286f70;
  --teal-dark: #1a5256;
  --wood: #a9744a;
  --edge: #c8ad85;
  --shadow: 0 8px 24px #3d342530;
  --display: "Island Playful", "Songti SC", "STSong", serif;
  --body: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; }
body { color: var(--ink); background: #5ab5b6; font-family: var(--body); font-size: 15px; line-height: 1.6; -webkit-tap-highlight-color: transparent; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; touch-action: manipulation; }
button, a, input, select { outline-offset: 4px; }
:focus-visible { outline: 3px solid #194f59; }
button:disabled, input:disabled, select:disabled { cursor: default; opacity: .55; }
::selection { color: #fffaf0; background: #286f70; }
input, textarea { caret-color: var(--teal-dark); }
* { scrollbar-width: thin; scrollbar-color: #b49672 #fff6df; }
::-webkit-scrollbar { width: 7px; height: 7px; }
::-webkit-scrollbar-track { background: #fff6df; }
::-webkit-scrollbar-thumb { background: #b49672; border: 2px solid #fff6df; border-radius: 6px; }

.island-world { position: fixed; inset: 0; isolation: isolate; overflow: hidden; }
#game { display: block; width: 100%; height: 100%; touch-action: none; outline-offset: -5px; }
.topbar { position: absolute; z-index: 20; top: calc(12px + var(--safe-top)); left: 16px; right: 16px; display: flex; align-items: center; gap: 14px; pointer-events: none; }
.island-name { color: #3e2b22; background: var(--paper); padding: 3px 13px 5px; border-radius: 10px; box-shadow: var(--shadow); font: 30px/1.25 var(--display); white-space: nowrap; }
.player-identity { display: flex; flex-direction: column; justify-content: center; min-width: 96px; padding: 7px 12px; background: #fff8e9ed; border-radius: 10px; line-height: 1.3; }
.player-identity strong { font-size: 13px; font-weight: 650; }
#connectionStatus { display: inline-flex; align-items: center; gap: 5px; margin-top: 3px; color: var(--ink-soft); font-size: 11px; }
#connectionStatus::before { content: ""; width: 5px; height: 5px; flex-shrink: 0; border-radius: 50%; background: #9c724b; }
#connectionStatus[data-state="online"]::before { background: #34745b; }
#connectionStatus[data-state="offline"] { color: #8a3f2e; }
#connectionStatus[data-state="offline"]::before { background: #a54b35; }
.map-tools { display: flex; gap: 6px; margin-left: auto; pointer-events: auto; }
.map-tools button, .quiet-button { min-height: 44px; padding: 9px 14px; color: var(--ink); background: var(--paper-strong); border: 1px solid var(--edge); border-radius: 9px; font-size: 13px; font-weight: 600; white-space: nowrap; }
.map-tools button[aria-pressed="true"], .map-tools button[aria-expanded="true"] { color: #fffaf0; background: var(--teal-dark); border-color: var(--teal-dark); }

.story-panel { position: absolute; z-index: 10; top: calc(78px + var(--safe-top)); left: 16px; width: min(410px, calc(100% - 32px)); padding: 10px 14px; background: #fff8e9ee; border-radius: 12px; box-shadow: 0 5px 17px #35433a1c; cursor: pointer; transition: padding .25s; }
.story-panel.is-quiet #storyTitle, .story-panel.is-quiet #dialogue { display: none; }
.story-panel.is-quiet { padding-block: 6px; width: auto; max-width: min(410px, calc(100% - 32px)); }
.story-panel.is-quiet #objective { margin: 0; }
#storyTitle { margin: 0 0 4px; font: 22px/1.3 var(--display); text-wrap: balance; }
#dialogue { margin: 0; font-size: 14px; line-height: 1.55; overflow-wrap: anywhere; }
#objective { margin: 5px 0 0; color: #506044; font-size: 12px; line-height: 1.5; }
#dialogue:empty, #objective:empty, #storyTitle:empty { display: none; }
#storageFeedback { color: #883c27; font-size: 12px; margin: 5px 0 0; }

.action-panel { position: absolute; z-index: 30; left: 50%; bottom: calc(14px + var(--safe-bottom)); width: min(680px, calc(100% - 32px)); max-height: min(300px, 44vh); overflow: auto; padding: 10px 12px; color: var(--ink); background: #fff8eaf7; border-radius: 14px; box-shadow: var(--shadow); transform: translateX(-50%); touch-action: pan-y; }
.actions { display: flex; flex-direction: column; gap: 8px; }
.action-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 8px; }
.action-row--chips { flex-wrap: nowrap; justify-content: flex-start; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.action-row--chips::-webkit-scrollbar { display: none; }
.chip-label { flex-shrink: 0; color: var(--ink-soft); font-size: 12px; font-weight: 600; min-width: 2.4em; }
.chip-label:empty { display: none; }
.actions .chip { display: inline-flex; align-items: center; gap: 4px; flex: 0 0 auto; min-width: 0; min-height: 40px; padding: 6px 13px; color: var(--ink); background: #fffaf0; border: 1px solid #d8c19c; border-radius: 999px; font-size: 13px; font-weight: 600; white-space: nowrap; }
.actions .chip[aria-pressed="true"] { color: #fffaf0; background: var(--teal); border-color: var(--teal); }
.chip-icon { display: inline-block; width: 24px; height: 24px; margin-left: -5px; background-image: var(--items-sheet, none); background-size: 400% 200%; }
.action-note { margin: 0; color: var(--ink-soft); font-size: 13px; text-align: center; }
.actions input[type="text"] { flex: 1; }
.actions > p, .actions > h2, .actions > h3, .actions > .action-heading, .actions > .action-description { flex-basis: 100%; margin: 0; }
.actions > h2, .actions > h3, .action-heading { font: 20px/1.4 var(--display); }
.actions > p, .action-description { color: var(--ink-soft); font-size: 13px; line-height: 1.5; }
.actions button, .action-button { min-width: 80px; min-height: 44px; padding: 9px 16px; color: var(--ink); background: #f3e4c6; border: 1px solid #ba9568; border-radius: 10px; font-size: 14px; font-weight: 600; }
.actions button.primary, .actions button[data-tone="primary"], .actions button[data-primary="true"] { color: #fffaf0; background: var(--teal-dark); border-color: var(--teal-dark); }
.actions button.secondary, .actions button[data-tone="quiet"] { background: transparent; border-color: #ccb897; }
.actions button[aria-pressed="true"] { color: #fffaf0; background: var(--teal); border-color: var(--teal); }
.actions button:active:not(:disabled), .map-tools button:active:not(:disabled), .quiet-button:active:not(:disabled) { transform: translateY(1px); }
.action-row, .field-row, .range-row, .power-row { display: flex; flex-basis: 100%; align-items: center; gap: 10px; }
.actions label { display: flex; align-items: center; gap: 10px; min-height: 44px; color: var(--ink); font-size: 13px; }
.actions label > span, .actions label > output { flex-shrink: 0; white-space: nowrap; }
.actions label:has(input[type="range"]) { flex: 1 1 240px; }
.actions input[type="range"] { width: 100%; min-width: 100px; height: 44px; margin: 0; accent-color: var(--teal); touch-action: pan-x; cursor: pointer; }
.actions select { min-height: 44px; padding: 8px 30px 8px 10px; color: var(--ink); background: #fffaf0; border: 1px solid #ba9568; border-radius: 8px; }
.actions output { min-width: 3em; font-variant-numeric: tabular-nums; }
.actions input[type="text"], .actions textarea { width: 100%; min-height: 44px; padding: 10px 12px; color: var(--ink); background: #fffaf0; border: 1px solid #ba9568; border-radius: 8px; font-size: 16px; }

.toast { position: absolute; z-index: 75; left: 50%; bottom: calc(26px + var(--safe-bottom)); max-width: min(480px, calc(100% - 40px)); padding: 10px 16px; color: #fffaf0; background: #254e4bf5; border-radius: 10px; box-shadow: 0 5px 16px #152d2a30; font-size: 14px; line-height: 1.5; text-align: center; pointer-events: none; transform: translateX(-50%); }
body:has(#actionPanel:not([hidden])) .toast { bottom: calc(var(--action-panel-height, 188px) + 26px + var(--safe-bottom)); }
.joystick { position: fixed; z-index: 25; width: 112px; height: 112px; border: 2px solid #fff8e9a6; border-radius: 50%; background: #2b665d26; pointer-events: none; touch-action: none; }
.joystick-knob { position: absolute; left: 50%; top: 50%; width: 44px; height: 44px; margin: -22px 0 0 -22px; border: 1px solid #e4d6b5; border-radius: 50%; background: #fff6dfe8; box-shadow: 0 3px 10px #173c3933; }

.side-panel { position: absolute; z-index: 55; top: calc(74px + var(--safe-top)); right: 16px; width: min(380px, calc(100% - 32px)); max-height: calc(100% - 94px - var(--safe-top) - var(--safe-bottom)); padding: 18px; overflow: auto; background: var(--paper-strong); border-radius: 14px; box-shadow: var(--shadow); touch-action: pan-y; }
.panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 16px; }
.panel-heading h2 { margin: 0; font: 25px/1.3 var(--display); }
.quiet-button { flex-shrink: 0; padding-inline: 12px; background: transparent; }
.help-steps { margin: 0; }
.help-steps > div + div { margin-top: 18px; }
.help-steps dt { margin-bottom: 4px; font-size: 14px; font-weight: 700; }
.help-steps dd { margin: 0; color: var(--ink-soft); font-size: 14px; line-height: 1.65; }
.memory-panel { width: min(520px, calc(100% - 32px)); }
.memory-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px 12px; }
.memory-list > p, .memory-list > .empty-note { grid-column: 1 / -1; margin: 0; color: var(--ink-soft); font-size: 14px; }
.memory-list article, .memory-item { min-width: 0; }
.memory-list img { display: block; width: 100%; height: auto; border-radius: 6px; }
.memory-list h3 { margin: 8px 0 3px; font-size: 14px; line-height: 1.45; }
.memory-list time, .memory-list small, .memory-list figcaption { color: var(--ink-soft); font-size: 12px; line-height: 1.5; }
.memory-list figure { margin: 0; }
.memory-list a { color: var(--teal-dark); text-underline-offset: 3px; }
.memory-list button { min-height: 44px; padding: 6px 10px; color: var(--teal-dark); background: #edf1e5; border: 1px solid #b8c6ac; border-radius: 8px; }

.arrival-overlay { position: absolute; inset: 0; z-index: 80; display: grid; place-items: center; padding: max(20px, var(--safe-top)) 20px max(20px, var(--safe-bottom)); overflow: auto; background: #163c3d64; touch-action: pan-y; }
.arrival-panel { width: min(510px, 100%); padding: 29px 26px 23px; background: var(--paper-strong); border-radius: 16px; box-shadow: 0 12px 45px #16342e45; text-align: center; }
.arrival-panel h2 { margin: 0; font: clamp(27px, 4.6vw, 36px)/1.3 var(--display); text-wrap: balance; }
.arrival-intro { margin: 9px 0 22px; color: var(--ink-soft); font-size: 14px; }
.character-choices { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.character-choice { display: flex; flex-direction: column; align-items: center; justify-content: center; min-width: 0; min-height: 142px; padding: 17px 10px; border: 1px solid; border-radius: 12px; }
.character-choice--big { color: #493957; background: #eee5f0; border-color: #bda8ca; }
.character-choice--small { color: #654333; background: #f7e8d6; border-color: #d8b39b; }
.character-choice strong { font: 25px/1.4 var(--display); }
.character-choice span { margin-top: 4px; font-size: 11px; line-height: 1.5; white-space: nowrap; }
.character-preview { display: block; width: 100%; height: 144px; margin-bottom: 7px; object-fit: contain; }
.character-choice:active { transform: translateY(2px); }
.arrival-note { margin: 17px 0 0; color: var(--ink-soft); font-size: 12px; }
.loading-screen { position: absolute; inset: 0; z-index: 90; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 24px; background: #f9f0dd; text-align: center; }
.loading-title { font: 58px/1.2 var(--display); color: #4d3729; }
.loading-screen p { margin: 16px 0 0; color: var(--ink-soft); font-size: 14px; }
.loading-screen button { min-height: 46px; margin-top: 16px; padding: 10px 20px; border: 1px solid var(--teal-dark); border-radius: 10px; color: #fffaf0; background: var(--teal-dark); }

@media (hover: hover) {
  .map-tools button:hover, .quiet-button:hover { background: #f1e5cd; }
  .map-tools button[aria-pressed="true"]:hover, .map-tools button[aria-expanded="true"]:hover { background: var(--teal); }
  .actions button:hover:not(:disabled) { filter: brightness(.96); }
  .character-choice:hover { border-color: #69513d; }
}

@media (min-width: 900px) {
  .topbar { left: 24px; right: 24px; top: calc(18px + var(--safe-top)); }
  .story-panel { left: 24px; top: calc(86px + var(--safe-top)); }
  .action-panel { bottom: calc(22px + var(--safe-bottom)); }
  .side-panel { top: calc(84px + var(--safe-top)); right: 24px; }
}

@media (max-width: 540px) {
  .topbar { top: calc(8px + var(--safe-top)); left: 10px; right: 10px; gap: 7px; }
  .island-name { padding: 5px 9px; font-size: 25px; }
  .player-identity { min-width: 65px; padding: 7px 8px; }
  .player-identity strong { font-size: 12px; }
  #connectionStatus { font-size: 11px; gap: 4px; }
  .map-tools { gap: 4px; }
  .map-tools button { min-width: 44px; padding: 8px 9px; font-size: 12px; border-radius: 8px; }
  .story-panel { top: calc(66px + var(--safe-top)); left: 10px; width: calc(100% - 20px); padding: 10px 13px; }
  #storyTitle { font-size: 20px; }
  #dialogue { font-size: 13px; }
  #objective { font-size: 11px; margin-top: 4px; }
  .action-panel { width: calc(100% - 20px); padding: 12px; bottom: calc(10px + var(--safe-bottom)); max-height: 37vh; }
  .actions { gap: 8px; }
  .actions button { min-width: 76px; flex: 1 1 auto; padding: 9px 12px; font-size: 13px; }
  .side-panel { top: calc(64px + var(--safe-top)); right: 10px; width: calc(100% - 20px); max-height: calc(100% - 82px - var(--safe-top) - var(--safe-bottom)); padding: 15px; }
  .arrival-overlay { padding-inline: 16px; }
  .arrival-panel { padding: 24px 18px 20px; }
  .character-preview { height: 126px; }
  .character-choice { min-height: 132px; padding-inline: 7px; }
}

@media (max-width: 360px) {
  .topbar { left: 8px; right: 8px; gap: 5px; }
  .island-name { padding-inline: 7px; font-size: 22px; }
  .player-identity { min-width: 60px; padding-inline: 6px; }
  .map-tools { gap: 3px; }
  .map-tools button { padding-inline: 6px; font-size: 11px; }
  .character-choices { gap: 8px; }
  .character-choice strong { font-size: 23px; }
  .character-choice span { font-size: 11px; }
}

@media (max-height: 650px) {
  .story-panel { padding-block: 8px; }
  #storyTitle { font-size: 18px; margin-bottom: 2px; }
  #dialogue { font-size: 12px; }
  #objective { font-size: 11px; margin-top: 3px; }
  .action-panel { max-height: 34vh; padding-block: 10px; }
  .arrival-panel { padding-block: 19px; }
  .arrival-intro { margin-bottom: 14px; }
  .character-preview { height: 102px; }
  .character-choice { min-height: 110px; padding-block: 12px; }
  .arrival-note { margin-top: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
  button:active { transform: none !important; }
}

.sound-toggle { display: inline-grid; place-items: center; width: 44px; padding: 0 !important; }
.sound-toggle svg { width: 20px; height: 20px; }
.sound-toggle[data-on="true"] .mute, .sound-toggle[data-on="false"] .wave { display: none; }
.map-tools .sound-toggle[aria-pressed="true"] { color: var(--ink); background: var(--paper-strong); border-color: var(--edge); }
.map-tools .sound-toggle[aria-pressed="false"] { color: #9a6a52; }

body:has(#actionPanel:not([hidden])) .toast { bottom: calc(var(--action-panel-height, 188px) + 26px + var(--safe-bottom)); }

.card-overlay { position: absolute; inset: 0; z-index: 85; display: grid; place-items: center; padding: 24px; background: #2b1a1ab0; }
.rose-card { position: relative; width: min(380px, 100%); padding: 18px 18px 20px; background: #fff7ea; border-radius: 18px; box-shadow: 0 18px 50px #2a101860; text-align: center; }
.card-overlay.is-fresh .rose-card { animation: card-in .7s cubic-bezier(.2,.9,.3,1.2) both; }
@keyframes card-in { from { transform: translateY(40px) scale(.85) rotate(-4deg); opacity: 0; } to { transform: none; opacity: 1; } }
.rose-card__art { display: block; width: 78%; max-height: 42vh; margin: -70px auto 4px; object-fit: contain; filter: drop-shadow(0 10px 14px #6a2a3040); }
.rose-card__paper { padding: 16px 14px 10px; border: 1px dashed #e2c7b5; border-radius: 10px; background: #fffdf7; }
.rose-card__text { margin: 0; color: #7a2f3d; font: 26px/1.5 var(--display); text-wrap: balance; }
.rose-card__meta { margin: 10px 0 0; color: var(--ink-soft); font-size: 12px; }
.rose-card__close { min-width: 120px; min-height: 46px; margin-top: 16px; padding: 10px 22px; color: #fffaf0; background: #b54a63; border: 0; border-radius: 999px; font-size: 15px; font-weight: 650; }
.memory-section { grid-column: 1 / -1; margin: 6px 0 -4px; font: 18px/1.3 var(--display); }
.keepsake { grid-column: 1 / -1; display: flex; align-items: center; gap: 10px; min-height: 52px; padding: 8px 14px !important; color: #7a2f3d !important; background: #fdf0f0 !important; border: 1px solid #ecc4c9 !important; border-radius: 12px !important; text-align: left; }
.chip-icon--rose { width: 34px; height: 34px; margin: 0; }

@media (max-width: 540px) {
  .map-tools button.sound-toggle { width: 40px; min-width: 40px; }
  .actions .chip { min-height: 38px; padding: 5px 11px; font-size: 12.5px; }
  .story-panel.is-quiet { max-width: calc(100% - 20px); }
}
@media (max-width: 400px) {
  .player-identity #connectionStatus { display: none; }
  .map-tools button { padding-inline: 7px; }
}

/* 纪念卡飞进相册时，相册按钮弹一下 */
.map-tools button.is-bump { animation: album-bump .9s ease-out; }
@keyframes album-bump { 0% { transform: scale(1); } 25% { transform: scale(1.22) rotate(-4deg); background: #ffe7a8; } 55% { transform: scale(.95); } 100% { transform: scale(1); } }
@media (prefers-reduced-motion: reduce) { .map-tools button.is-bump { animation: none; } }

.arrival-login { display: inline-block; margin-top: 18px; padding: 12px 28px; border-radius: 999px; color: #fffaf0; background: #2f6f6c; font-weight: 700; text-decoration: none; box-shadow: 0 6px 16px #1d3d3b40; }

.encounter-list, .recipe-list { list-style: none; margin: 4px 0 14px; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.encounter-list li, .recipe-list li { padding: 6px 10px; border-radius: 999px; background: #fff3dc; color: #5a4030; font-size: 13px; line-height: 1.3; }
.encounter-list li small { margin-left: 6px; color: #9a7d62; font-size: 11px; }
.recipe-list li[data-known="false"] { background: #efe6d6; color: #b3a28c; letter-spacing: .1em; }

/* 鸭子送来的信：字多，左对齐、小一点 */
.card-overlay.is-note .rose-card__text { font-size: 18px; line-height: 1.75; text-align: left; }
.card-overlay.is-note .rose-card__paper { margin-top: 8px; }
