/*
 * V10 final UI pass — append AFTER director10.css.
 * Presentation only: no story state, image filters, picture coordinates,
 * interaction transforms, reveal timings or video claims are changed here.
 * Existing hidden/disabled/paused/scene-changing/ending states retain priority.
 */

#game {
  --uf-ink: #f0eadf;
  --uf-body: #c6c0b3;
  --uf-muted: #a4a094;
  --uf-accent: #c7b58f;
  --uf-line: #c2b49132;
  --uf-surface: #111310;
  --uf-sans: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

/* 1. A quiet header with real 44px targets, separated from the picture. */
#game:not(.ending) #hud {
  border-bottom: 1px solid #b8b3a21a;
  background: linear-gradient(180deg, #0b0d0b, #0a0b0a);
}
#game:not(.ending) #hud .brand {
  color: #ddd7ca;
  font-family: var(--uf-sans);
  font-weight: 500;
  letter-spacing: .08em;
}
#game:not(.ending) #hud .brand span {
  color: #a8a397;
  font-weight: 400;
  letter-spacing: .015em;
  line-height: 1.45;
}
#game:not(.ending) #hud nav { gap: 5px; }
#game:not(.ending) #hud nav button {
  min-width: 44px;
  min-height: 44px;
  border: 1px solid #b8ac8d36;
  border-radius: 7px;
  background: #151710;
  color: #e0d6c0;
  box-shadow: inset 0 1px 0 #f3e3b708;
  font-family: var(--uf-sans);
}
#game:not(.ending) #hud #journal-btn {
  min-width: 58px;
  padding: 0 10px;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}
#game:not(.ending) #hud #sound-btn,
#game:not(.ending) #hud #pause-btn { font-size: 19px; }

/* 2. Dialogue has three reading levels; the frame still uses measured height. */
#game:not(.on-title):not(.ending) #dialogue {
  padding-top: 10px;
  border-top: 1px solid #b6a27b50;
  border-radius: 0;
  background: linear-gradient(180deg, #11130f 0, #0b0d0a 100%);
}
#game:not(.on-title):not(.ending) #dialogue #speaker {
  display: block;
  margin: 0 0 5px;
  color: var(--uf-accent);
  font-family: var(--uf-sans);
  font-size: 11.5px;
  font-weight: 500;
  letter-spacing: .06em;
  line-height: 1.4;
}
#game:not(.on-title):not(.ending) #dialogue #speaker::before {
  content: "";
  display: inline-block;
  width: 12px;
  height: 1px;
  margin: 0 7px 3px 0;
  background: #bca77d;
}
#game:not(.on-title):not(.ending) #dialogue #speaker:empty { display: none; }
#game:not(.on-title):not(.ending) #dialogue #dialogue-text {
  margin: 1px 0 8px;
  color: var(--uf-ink);
  font-size: 19px;
  font-weight: 400;
  line-height: 1.5;
  letter-spacing: .015em;
  text-wrap: pretty;
}
#game:not(.on-title):not(.ending) #dialogue #scene-direction {
  margin: 0 0 9px;
  color: var(--uf-body);
  font-family: var(--uf-sans);
  font-size: 13px;
  line-height: 1.62;
  letter-spacing: 0;
}
#game:not(.on-title):not(.ending) #dialogue #interaction {
  gap: 7px;
  margin-bottom: 2px;
}
#game:not(.on-title):not(.ending) #dialogue #interaction > button {
  min-height: 46px;
  padding: 9px 11px;
  border-radius: 5px;
  font-family: var(--uf-sans);
  font-size: 13px;
  font-weight: 500;
  line-height: 1.45;
  letter-spacing: .015em;
}
#game:not(.on-title):not(.ending) #dialogue #interaction > .primary {
  border: 1px solid #c8b17c9c;
  background: linear-gradient(120deg, #4b4230, #333327);
  color: #f4edde;
  box-shadow: inset 0 1px 0 #ebd7a712;
}
#game:not(.on-title):not(.ending) #dialogue #interaction > .secondary {
  border: 1px solid #aaa08850;
  background: #161812;
  color: #d0c7b5;
}
#game:not(.on-title):not(.ending) #dialogue #interaction > button:disabled {
  opacity: 1;
  border-color: #a99d8030;
  background: #181a15;
  color: #96968b;
  box-shadow: none;
  cursor: default;
}

/* 3. Auto-scene control shares the action row, reclaiming a whole row of image.
   No control is removed: the separate pause-on-this-scene action remains 44px. */
#game:not(.on-title):not(.ending) #dialogue #interaction:has(> .flow-control) {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(108px, 1fr);
  align-items: stretch;
}
#game:not(.on-title):not(.ending) #dialogue #interaction > .flow-control {
  width: auto;
  min-width: 0;
  min-height: 44px;
  margin: 0;
  padding: 7px 8px;
  border: 1px solid #b6a27b30;
  border-radius: 5px;
  background: #141710;
  color: #c8b995;
  font-family: var(--uf-sans);
  font-size: 11.5px;
  font-weight: 400;
  line-height: 1.55;
  letter-spacing: 0;
  text-wrap: pretty;
}
#game #flow-status::before {
  width: 4px;
  height: 4px;
  margin-right: 5px;
  vertical-align: 2px;
  background: #c3b284;
}
#game:not(.on-title):not(.ending) #dialogue :is(#voice-replay, #skip-voice, #hint-btn) {
  min-height: 44px;
  border-radius: 5px;
  color: #aaa79a;
  font-family: var(--uf-sans);
  font-size: 12px;
  line-height: 1.35;
}
#game:not(.on-title):not(.ending) #dialogue #voice-replay { text-align: left; padding-left: 0; }
#game:not(.on-title):not(.ending) #dialogue #hint-btn { text-align: right; padding-right: 0; }

/* 4. On-image hints look related, while physical pieces keep their own skins.
   Do not change any target's position, transform, paper shape or image mapping. */
#game:not(.ending) #scene-touch :is(.si-hint, .ci-hint, .di-hint) {
  max-width: calc(100% - 24px);
  padding: 5px 9px;
  border: 1px solid #b5a98732;
  border-radius: 5px;
  background: #0c0f0beF;
  color: #ded7c8;
  box-shadow: 0 2px 8px #0003;
  font-family: var(--uf-sans);
  font-size: 12px;
  line-height: 1.45;
  letter-spacing: 0;
  text-shadow: none;
}
#game:not(.ending) #scene-touch :is(.ci-dock, .di-trace-assist, .di-focus-panel) {
  border: 1px solid #b5a98743;
  border-radius: 6px;
  background: #10140ff2;
  box-shadow: 0 4px 16px #0004;
}
#game:not(.ending) #scene-touch :is(.ci-button, .di-button) {
  min-width: 44px;
  min-height: 44px;
  border-color: #b5a1786b;
  border-radius: 5px;
  background: #262a20;
  color: #eee6d4;
  font-family: var(--uf-sans);
  font-size: 12px;
  line-height: 1.4;
}
#game:not(.ending) #scene-touch :is(.di-focus-heading, .di-focus-status) {
  letter-spacing: 0;
  line-height: 1.5;
}
#game:not(.ending) #scene-touch .di-focus-heading { color: #e5d8b9; }
#game:not(.ending) #scene-touch .di-focus-status { color: #c0bdaf; }
#game:not(.ending) #scene-touch .di-trace-progress {
  border-color: #b5a98743;
  border-radius: 5px;
  background: #0c100bea;
  color: #e5d4af;
  font-variant-numeric: tabular-nums;
}
#game:not(.on-title):not(.ending) #sound-caption {
  max-width: min(86%, 460px);
  padding: 5px 9px;
  border: 1px solid #b4ad9730;
  border-radius: 5px;
  background: #0b0d0be8;
  color: #d6d2c5;
  font-family: var(--uf-sans);
  font-size: 11.5px;
  line-height: 1.45;
  letter-spacing: 0;
}
#game #toast {
  max-width: min(90vw, 480px);
  padding: 10px 14px;
  border-radius: 6px;
  border-color: #c7b58f60;
  background: #22271eee;
  color: #f0e7d5;
  font-family: var(--uf-sans);
  font-size: 13px;
  line-height: 1.55;
}

/* 5. Title and return visits: retain the single obvious start / resume action. */
#game.on-title #hud {
  border-color: #d6c69a14;
  background: linear-gradient(180deg, #090b09c9, #090b0938);
}
#game.on-title .title-kicker { color: #cbbfA7; letter-spacing: .14em; }
#game.on-title .title-quote { color: #d2cabe; line-height: 1.85; }
#game.on-title :is(#start-btn, #continue-btn) {
  min-height: 48px;
  border-radius: 5px;
  font-family: var(--uf-sans);
  font-weight: 500;
  letter-spacing: .08em;
}
#game.on-title #start-btn,
#game.on-title.ux9-has-save #continue-btn {
  border: 1px solid #d5c095;
  background: linear-gradient(115deg, #d8c49b, #bba476);
  color: #242318;
  box-shadow: 0 5px 22px #0003, inset 0 1px 0 #fff7df40;
}
#game.on-title.ux9-has-save #start-btn {
  border: 1px solid #bcb09366;
  background: #0c0f0cbb;
  color: #c8c0b0;
  box-shadow: none;
}
#game.on-title .ux9-resume-context {
  color: #bbb2a1;
  font-family: var(--uf-sans);
  font-size: 11.5px;
  line-height: 1.6;
}
#game.on-title .title-meta { color: #b3a998; font-size: 11.5px; }
#game.on-title .title-bottom { color: #b4aa99; font-size: 11px; }
#game.on-title :is(#about-btn, .ux9-create-entry a) { min-height: 44px; font-size: 12px; }
#game.on-title .ux9-create-entry { border-top-color: #baa47a3b; }
#game.on-title .ux9-create-entry a { color: #cdbc9d; }

/* 6. Modals and memory book: readable controls, paired portraits kept whole. */
#game #modal {
  border: 1px solid #ad9c765c;
  border-radius: 10px;
  background: #11150f;
  color: var(--uf-ink);
  box-shadow: 0 28px 100px #000b;
}
#game #modal::backdrop { background: #020403c9; backdrop-filter: blur(6px); }
#game #modal #modal-inner { padding: 0 20px 20px; }
#game #modal .modal-top {
  min-height: 64px;
  margin-bottom: 13px;
  background: #11150f;
  border-bottom: 1px solid #b4a47e3b;
}
#game #modal .modal-top h2 {
  margin: 0;
  font-size: 22px;
  line-height: 1.45;
  letter-spacing: .025em;
}
#game #modal .close-modal {
  width: 44px;
  min-width: 44px;
  min-height: 44px;
  border: 1px solid #b7a98230;
  border-radius: 6px;
  background: #1a1e15;
  color: #d7cbb1;
}
#game #modal :is(.modal-copy, .item-card p) {
  color: #c7c0b1;
  font-family: var(--uf-sans);
  font-size: 13.5px;
  line-height: 1.85;
  letter-spacing: 0;
}
#game #modal .settings-row {
  min-height: 44px;
  margin: 6px 0;
  gap: 10px;
  padding-bottom: 5px;
  border-bottom: 1px solid #a6987920;
  font-family: var(--uf-sans);
}
#game #modal .settings-row label { flex-basis: 91px; width: 91px; color: #d4cbb9; }
#game #modal .settings-row output { color: #cdbb91; font-variant-numeric: tabular-nums; }
#game #modal .settings-row input[type="range"] { min-height: 44px; accent-color: #d3bd87; }
#game #modal .toggle {
  min-height: 44px;
  margin: 5px 0;
  padding: 6px 9px;
  border: 1px solid transparent;
  border-radius: 6px;
  color: #c8c3b5;
  font-family: var(--uf-sans);
  font-size: 13px;
  line-height: 1.55;
}
#game #modal .toggle:has(input:checked) {
  border-color: #ad99712c;
  background: #202619;
  color: #e2d8bf;
}
#game #modal .toggle input { accent-color: #ccb480; }
#game #modal .modal-actions { gap: 9px; margin-top: 16px; }
#game #modal .modal-actions button {
  min-height: 46px;
  border-radius: 6px;
  font-family: var(--uf-sans);
  font-size: 13px;
}
#game #modal .modal-actions .primary { border: 1px solid #b7a07385; background: #4b412c; color: #f0e7d1; }
#game #modal .modal-actions .secondary { border: 1px solid #aa9d7d45; background: #1a1e16; color: #cfc6b2; }
#game #modal .small-button { min-height: 44px; color: #c6b38d; }
#game #modal .muted-label { color: #a8a18f; font-size: 12px; line-height: 1.75; }
#game #modal .muted-label a { min-height: 44px; color: #d4bf94; }
#game #modal .item-card {
  margin: 0 0 14px;
  padding: 14px;
  border: 1px solid #ac9a7333;
  border-radius: 7px;
  background: #181c14;
}
#game #modal .item-card h3 { margin: 0 0 11px; color: #e0cfaa; font-size: 16px; line-height: 1.5; }
#game #modal .item-card p { margin: 11px 0 0; }
#game #modal .memory-pair { gap: 8px; }
#game #modal .memory-pair figure { overflow: hidden; border: 1px solid #b7ab8b28; border-radius: 4px; background: #090b08; }
#game #modal .memory-pair img { object-fit: contain; }
#game #modal .memory-pair figcaption { padding: 7px 4px; color: #c9bea6; font-family: var(--uf-sans); font-size: 12px; line-height: 1.45; }

/* 7. Finale typography: keep the director's opacity / timing / framing intact. */
#game #salute { color: #ece4d3; }
#game #salute .salute-kicker { color: #b8a889; font-size: 11px; letter-spacing: .22em; }
#game #salute-dedication { color: #f0e5cd; text-wrap: balance; }
#game #salute .salute-body { color: #ccc4b5; line-height: 1.95; }
#game #salute-names { color: #c5b697; font-size: 12px; line-height: 2; }
#game #salute .salute-note { color: #a69b87; font-size: 11.5px; line-height: 1.85; }
#game #salute .ux9-end-actions { width: min(100%, 360px); }
#game #salute .ux9-end-actions :is(button, a) { min-height: 44px; border-radius: 6px; font-family: var(--uf-sans); font-size: 12px; }
#game #salute .ux9-end-row button:first-child { border-color: #c4ab766b; background: #342e20; color: #e8d6af; }
#game #salute.ux9-with-actions #salute-replay { min-height: 44px; font-size: 11.5px; color: #b7ad99; }
#game .fd-photograph figcaption { color: #5d5140; }
#game .fd-photograph figcaption small { color: #71624f; line-height: 1.55; }

/* 8. Responsive hierarchy; never use cover or enlarge the dialogue over a face. */
@media (min-width: 900px) and (min-height: 600px) {
  #game:not(.ending) {
    --ui-reading-width: clamp(326px, 29vw, 410px);
    --ui-stage-right: calc(var(--ui-shell-inset) + var(--ui-reading-width) + 30px);
  }
  #game:not(.on-title):not(.ending) #scene-frame { border-color: #b9a77e25; box-shadow: 0 12px 48px #0006; }
  #game:not(.on-title):not(.ending) #dialogue {
    padding: 22px 18px 8px;
    border-top: 0;
    border-left: 1px solid #b4a27a3d;
    border-radius: 0 6px 6px 0;
    background: linear-gradient(90deg, #13170fbb, #0d100a66);
  }
  #game:not(.on-title):not(.ending) #dialogue #speaker { margin-bottom: 11px; font-size: 12px; }
  #game:not(.on-title):not(.ending) #dialogue #dialogue-text { margin-bottom: 16px; font-size: 23px; line-height: 1.65; }
  #game:not(.on-title):not(.ending) #dialogue #scene-direction { margin-bottom: 20px; font-size: 14px; line-height: 1.8; }
  #game:not(.on-title):not(.ending) #dialogue #interaction > button { min-height: 48px; }
  #game:not(.on-title):not(.ending) #sound-caption { max-width: min(38vw, 460px); }
  #game:not(.ending) #hud nav { gap: 8px; }
}
@media (min-width: 820px) {
  #game #modal:has(.memory-pair) { width: min(880px, calc(100vw - 48px)); }
  #game #modal:has(.memory-pair) #modal-inner { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: 16px; align-items: start; }
  #game #modal:has(.memory-pair) :is(.modal-top, #modal-inner > .modal-copy) { grid-column: 1 / -1; }
  #game #modal:has(.memory-pair) .item-card { align-self: start; }
}
@media (max-width: 760px) {
  #game:not(.on-title):not(.ending) #dialogue { width: calc(100% - 16px); padding-right: 12px; padding-left: 12px; }
  #game:not(.ending) #hud .brand span { font-size: 10.5px; }
  #game.on-title h1 { letter-spacing: .045em; }
  #game.on-title .title-bottom { gap: 8px; }
  #game #modal #modal-inner { padding-right: 16px; padding-left: 16px; }
  #game #modal .item-card { padding: 11px; }
  #game #salute .salute-body { font-size: 13.5px; }
  #game .fd-photograph figcaption { font-size: 11px; }
}
@media (max-width: 370px) {
  #game:not(.on-title):not(.ending) #dialogue { padding-left: 10px; padding-right: 10px; }
  #game:not(.on-title):not(.ending) #dialogue #dialogue-text { font-size: 18px; line-height: 1.5; }
  #game:not(.on-title):not(.ending) #dialogue #scene-direction { font-size: 12.5px; line-height: 1.6; }
  #game:not(.on-title):not(.ending) #dialogue #interaction > button { padding-right: 8px; padding-left: 8px; font-size: 12.5px; }
  #game:not(.on-title):not(.ending) #dialogue #interaction > .flow-control { font-size: 11px; }
  #game:not(.ending) #hud { padding-left: 10px; padding-right: 10px; }
  #game:not(.ending) #hud nav { gap: 4px; }
  #game #modal .settings-row label { flex-basis: 84px; width: 84px; font-size: 12px; }
}
@media (min-width: 700px) and (max-height: 599px) {
  #game:not(.on-title):not(.ending) #dialogue { padding: 8px 8px 0; }
  #game:not(.on-title):not(.ending) #dialogue #dialogue-text { font-size: 17px; line-height: 1.45; }
  #game:not(.on-title):not(.ending) #dialogue #scene-direction { font-size: 12px; line-height: 1.5; margin-bottom: 8px; }
  #game:not(.on-title):not(.ending) #dialogue #interaction:has(> .flow-control) { grid-template-columns: minmax(0, 1.4fr) minmax(104px, 1fr); }
  #game:not(.on-title):not(.ending) #dialogue #interaction > button { font-size: 12px; padding: 7px; }
  #game:not(.on-title):not(.ending) #dialogue #interaction > .flow-control { font-size: 10.5px; }
}
@media (max-height: 640px) {
  #game #salute.ux9-with-actions { justify-content: flex-start; padding-top: max(28px, env(safe-area-inset-top)); }
  #game #salute h2 { font-size: 50px; }
  #game #salute-names { margin: 13px 0; }
}

@media (hover: hover) {
  #game:not(.ending) #hud nav button:hover:not(:disabled) { border-color: #c7b58f73; background: #26291f; }
  #game:not(.on-title):not(.ending) #dialogue #interaction > .primary:hover:not(:disabled) { border-color: #e1c48d; background: #5d5036; }
  #game:not(.on-title):not(.ending) #dialogue #interaction > .flow-control:hover:not(:disabled) { border-color: #b7a4776e; background: #22291b; }
  #game #modal .close-modal:hover { background: #2a3020; }
}
#game :is(button, input, a):focus-visible { outline: 2px solid #e6cd91; outline-offset: 3px; }
#game:not(.on-title):not(.ending) #dialogue #interaction > button:not(:disabled):active { filter: brightness(1.12); }

/* State safety: presentation must never make unavailable controls active. */
#game [hidden], #game #modal [hidden] { display: none !important; }
#game.scene-changing :is(#scene-touch, #dialogue) { opacity: 0 !important; pointer-events: none !important; }
#game.memory-transition #dialogue { opacity: 0 !important; pointer-events: none !important; }
#game.memory-transition :is(#scene-touch, #sound-caption) { visibility: hidden !important; }
#game.saluting :is(#dialogue, #chapter-marker),
#game.saluting #hud :is(.brand, #journal-btn) { display: none !important; }
/* Keep the finale controllable on touch screens without a full-width bar. */
#game.saluting #hud {
  display: flex !important;
  top: max(10px, calc(env(safe-area-inset-top) + 6px));
  right: max(10px, env(safe-area-inset-right));
  left: auto;
  width: auto;
  height: auto;
  padding: 0;
  border: 0;
  background: transparent;
  z-index: 21;
  pointer-events: none;
}
#game.saluting #hud nav { gap: 6px; pointer-events: auto; }
#game.saluting #hud nav button {
  width: 44px;
  min-width: 44px;
  height: 44px;
  min-height: 44px;
  padding: 0;
  border: 1px solid #d9cda64d;
  border-radius: 50%;
  color: #eee5cf;
  background: #0d100cbf;
  font-size: 18px;
  opacity: 1;
}
#game.saluting #salute {
  padding-top: max(76px, calc(env(safe-area-inset-top) + 66px));
}
#game #scene-touch :is(.ci-root, .di-root).is-done :is(.ci-dock, .di-focus-panel, .di-trace-assist) { display: none !important; }
#game.paused #scene-touch *, #game #scene-touch .is-paused * { animation-play-state: paused !important; }
@media (prefers-reduced-motion: reduce) {
  #game :is(#dialogue button, #hud button, #modal button) { transition: none !important; }
}
#game.reduced-motion :is(#dialogue button, #hud button, #modal button) { transition: none !important; }

/* Tribute footer: keep the dedication primary and make the original QR readable. */
#game #salute {
  justify-content: flex-start;
  justify-content: safe center;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}
#game #salute > * { flex-shrink: 0; }
#game #salute-replay { position: static; margin: 10px auto 0; }
#game #salute .salute-footer {
  display: none;
  width: min(100%, 360px);
  margin: 24px auto 0;
  padding-top: 18px;
  border-top: 1px solid #b8a88930;
  font-family: var(--uf-sans);
}
#game #salute.ux9-with-actions .salute-footer { display: block; }
#game #salute .salute-contact { display: flex; gap: 16px; align-items: center; justify-content: space-between; text-align: left; }
#game #salute .salute-contact-copy { min-width: 0; }
#game #salute .salute-account { margin: 0 0 8px; color: #c8bca5; font-size: 13px; line-height: 1.7; letter-spacing: 0; }
#game #salute .salute-contact-hint { margin: 0; color: #9e9686; font-size: 11px; line-height: 1.9; letter-spacing: 0; }
#game #salute #salute-contact { position: static; flex: 0 0 92px; width: 92px; min-width: 92px; margin: 0; padding: 4px; border: 0; border-radius: 6px; background: #fff; line-height: 0; cursor: zoom-in; }
#game #salute #salute-contact img { display: block; width: 100%; height: auto; border-radius: 3px; }
#game #salute .salute-fiction { margin: 16px 0 0; color: #9e9686; font-size: 10px; line-height: 1.8; letter-spacing: .02em; text-wrap: balance; }
#game #modal .contact-modal { text-align: center; }
#game #modal .contact-account { margin: 0 0 16px; color: #dfd0af; font-size: 15px; line-height: 1.7; }
#game #modal .contact-modal img { display: block; width: min(100%, 360px); height: auto; margin: 0 auto; border-radius: 6px; user-select: auto; -webkit-touch-callout: default; }
#game #modal .contact-modal .muted-label { margin: 16px 0 0; }
@media (max-height: 740px) {
  #game #salute { justify-content: flex-start; }
  #game #salute .salute-footer { margin-top: 18px; padding-top: 14px; }
}
@media (min-width: 761px) and (min-height: 641px) and (max-height: 900px) {
  #game #salute h2 { font-size: 80px; margin-bottom: 16px; }
  #game #salute .salute-kicker { margin-bottom: 12px; }
  #game #salute-dedication { margin-bottom: 14px; }
  #game #salute-names { margin: 18px 0 14px; }
}
