:root {
  color-scheme: dark;
  font-family: "Microsoft YaHei", "PingFang SC", "Noto Sans CJK SC", system-ui, sans-serif;
  color: #f1e7cb; background: #111a1b;
  --ink: #192321; --gold: #d7ae66; --paper: #f4ddaa; --muted: #ccc1a5;
  --left: max(16px, env(safe-area-inset-left));
  --right: max(16px, env(safe-area-inset-right));
  --top: max(16px, env(safe-area-inset-top));
  --bottom: max(16px, env(safe-area-inset-bottom));
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; overscroll-behavior: none; }
button { font: inherit; }
button {
  color: #f4e6c6; border: 1px solid #9e8958; border-radius: 5px;
  background: linear-gradient(#34403a, #202923); min-height: 42px; padding: 8px 14px;
  cursor: pointer; touch-action: manipulation;
}
button:hover:not(:disabled) { border-color: #ffe4a2; filter: brightness(1.18); }
button:active:not(:disabled) { filter: brightness(.87); }
button:disabled { opacity: .53; cursor: default; }
button:focus-visible { outline: 2px solid #fbda8e; outline-offset: 3px; }
.primary { background: linear-gradient(#f2d18b, #be8845); color: #231d15; border-color: #edc37c; font-weight: 700; }
#game-shell { position: relative; height: 100vh; height: 100dvh; overflow: hidden; isolation: isolate; background: #171f20; }
#field { position: absolute; inset: 0; overflow: hidden; }
#stage { display: block; outline: none; touch-action: none; user-select: none; -webkit-user-select: none; }
#field { background: #192524; }
#field.title-backdrop { background: linear-gradient(90deg,#101d1d 3%,#132223c9 37%,#101e1d16 72%),
  url("./assets/title.webp") 62% center / cover no-repeat #202a2a; }
#boot-fallback {
  position: absolute; left: var(--left); bottom: var(--bottom); padding: 10px 15px;
  display: grid; gap: 8px; justify-items: start; color: #f0d29b; background: #172520;
}
#boot-retry { min-height: 44px; }
h2,p { margin: 0; }
.chapter { font-size: 13px; letter-spacing: .23em; color: #e0b673; }
kbd { font: inherit; font-size: 10px; color: #d9c49e; border: 1px solid #a5916066; padding: 0 3px; border-radius: 3px; margin-left: 3px; }
@media (max-width: 620px) and (orientation: portrait) {
  #field.title-backdrop { background: linear-gradient(0deg,#101d1d 7%,#142124d0 43%,#11202216 80%),
    url("./assets/title.webp") 68% top / cover no-repeat #162425; }
}
@media (pointer: coarse) { kbd { display: none; } }
.overlay { position: absolute; inset: 0; display: grid; place-items: center; padding: max(12px, env(safe-area-inset-top)) 12px max(12px, env(safe-area-inset-bottom)); background: #0c1515a8; }
.card { width: min(480px, 100%); max-height: 100%; overflow: auto; overscroll-behavior: contain; padding: clamp(17px, 4vw, 28px); border: 1px solid #b89f64; border-radius: 7px; background: linear-gradient(145deg,#29392f, #192221); box-shadow: 0 13px 42px #070f0dc4; }
.card.compact { width: min(355px, 100%); text-align: center; }
.card h2 { color: #f4da9d; font-size: 25px; letter-spacing: .06em; }
.card p { color: #dfd3b7; font-size: 14px; line-height: 1.5; margin: 8px 0 15px; }
.card header { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.menu { display: grid; gap: 9px; }
.mix-control { display: grid; grid-template-columns: auto 1fr; align-items: center; gap: 12px; min-height: 30px; color: #e4d4ae; font-size: 13px; }
.mix-control input { width: 100%; accent-color: #dfb574; }
/* Modal portraits and the journal share the bronze fittings of the field HUD. */
.dialogue-overlay {
  position: absolute; inset: 0; overflow: hidden;
  background: radial-gradient(ellipse at 71% 42%, #403b2d8f, #111b1deb 70%);
}
.dialogue-light {
  position: absolute; inset: 0; pointer-events: none;
  background: linear-gradient(108deg,#1f2f2d77 0 28%,#af7b3b1c 43%,transparent 62%),
    linear-gradient(0deg,#0e1414c9,transparent 68%);
}
.dialogue-overlay figure {
  position: absolute; margin: 0; width: min(38vw, 504px); aspect-ratio: 1;
  display: grid; align-items: end; pointer-events: none; overflow: hidden;
  filter: drop-shadow(0 10px 21px #10161399); transition: opacity .18s, filter .18s;
  -webkit-mask-image: linear-gradient(#000 0 72%,transparent 100%);
  mask-image: linear-gradient(#000 0 72%,transparent 100%);
}
.dialogue-overlay figure img { width: 100%; height: 100%; object-fit: contain; object-position: center bottom; }
.dialogue-npc img.face-inward { transform: scaleX(-1); }
.dialogue-hero { left: max(5%, var(--left)); bottom: 11%; }
.dialogue-npc { right: max(5%, var(--right)); top: max(4%, var(--top)); }
#dialogue-panel[data-speaker="npc"] .dialogue-hero,
#dialogue-panel[data-speaker="hero"] .dialogue-npc { opacity: .58; filter: saturate(.64) brightness(.8); }
#dialogue-close { position: absolute; top: var(--top); right: var(--right); }
.dialogue-caption {
  position: absolute; left: 50%; bottom: max(4vh,var(--bottom)); transform: translateX(-50%);
  width: min(740px,calc(100% - var(--left) - var(--right)));
  padding: 19px clamp(14px,3vw,32px) 14px; border: 1px solid #b69251; border-radius: 6px;
  background: linear-gradient(117deg,#232922fa,#1b2322f8 62%,#322c20f9);
  box-shadow: 0 16px 44px #070d0cc9,inset 0 0 0 4px #242922,inset 0 0 0 5px #8667396b;
}
.dialogue-caption h2 { color: #f4d79a; font-size: clamp(20px,2.5vw,28px); letter-spacing: .12em; margin-bottom: 8px; }
.dialogue-caption p { max-height: 6.4em; overflow: auto; color: #f3e5c8; font-size: clamp(14px,2vw,18px); line-height: 1.56; }
#dialogue-options { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 14px; }
#dialogue-next { margin-top: 13px; min-width: 104px; }
#journal-entries { display: grid; gap: 8px; margin-top: 12px; }
#journal-entries article { background: #182822; padding: 10px 12px; border: 1px solid #8f814c72; border-radius: 4px; }
#journal-entries h3 { margin: 0; color: #ecce91; font-size: 16px; }
#journal-entries p { margin: 4px 0 0; }
#native-rpg { position: absolute; inset: 0; z-index: 9; visibility: hidden; pointer-events: none; }
#native-rpg.open { visibility: visible; pointer-events: auto; background: #101c1ba8; }
#native-rpg canvas:focus { outline: none; }
@media (max-width: 620px) and (orientation: portrait) {
  .dialogue-overlay figure { width: min(66vw,350px); }
  .dialogue-hero { left: -4%; bottom: 21%; }
  .dialogue-npc { right: -1%; top: max(5%,var(--top)); }
  .dialogue-caption { bottom: var(--bottom); padding: 15px 13px 12px; }
  #dialogue-options button { min-height: 44px; padding: 6px 9px; }
}
@media (max-height: 495px) and (orientation: landscape) {
  .dialogue-overlay figure { width: min(33vw,61dvh); }
  .dialogue-caption { bottom: var(--bottom); padding-top: 13px; }
  .dialogue-caption p { max-height: 4.7em; }
  .dialogue-hero { bottom: 15%; }
  .dialogue-npc { top: var(--top); }
}
@media (prefers-reduced-motion: reduce) { .dialogue-overlay figure { transition: none; } }
