/* Typography, spacing and control refinements requested for the game.
   Presentational only: original textures, images, story, ending logic and audio remain unchanged. */

/* 01. Japanese punctuation and small kana never become isolated lines. */
.dialogue-text,#soliloquy,.facility-pickup-dialogue p,
.facility-document-text,.facility-document-page h2,
.result-content h1,.result-content p,.record-card .cardname,
.ranking-explain,.ranking-summary p,.player-setup-card p {
  line-break:strict;word-break:normal;overflow-wrap:break-word;
  hanging-punctuation:allow-end;
}

/* 02. Intentional pauses in the found-paper monologue; smaller type on short screens. */
.facility-pickup-dialogue p{line-height:1.75; margin-bottom:20px;}
@media(max-height:660px){.facility-pickup-dialogue{padding-block:15px}.facility-pickup-dialogue p{font-size:16px;line-height:1.55}}

/* 03. Numbers with units, record times, and the billing figure stay intact. */
.amount-unit,.bill-row strong,.bill-due strong,.ranking-entry .rank-time,
#bestRecord,#deathRecord,#resultStats{white-space:nowrap;font-variant-numeric:tabular-nums;}
@media(max-width:350px){.bill-due strong{font-size:clamp(18px,5.2vw,23px)!important;}}

/* 04. Even spacing between the previous subject's notebook paragraphs. */
.facility-document-text p{margin-block:0 .94em;}
.facility-document-text p:last-child{margin-bottom:0;}

/* 05. Compact, stable instrument numerals and labels. */
.end-tag,.stage-info,#stageText,#inputText,.ranking-entry .rank-no,
#timeText,#heightText,.facility-document-index,#facilityMapStatus{
  font-variant-numeric:tabular-nums; font-feature-settings:'tnum' 1;
}
.stage-info,.end-tag{letter-spacing:.035em;}

/* 06. One spacing rhythm across the three record sections. */
#records .facility-archive,#records .ranking-summary,#records .records-end-title{
  max-width:650px;margin-inline:auto;
}
#records .facility-archive{margin-top:22px;margin-bottom:0;padding-top:17px;}
#records .ranking-summary{margin-top:24px;}
#records .records-end-title{margin-top:26px;margin-bottom:13px;}

/* 07. Narrow, subdued section rules: technical document, not decoration. */
#records .facility-archive-head,#records .ranking-summary-head{
  padding-bottom:9px;border-bottom:1px solid rgba(181,203,200,.22);
}
#records .records-end-title{padding-bottom:9px;border-bottom:1px solid rgba(181,203,200,.22);}

/* 08. Discovery count never shifts in width as records increase. */
.facility-archive-head span{min-width:4.4ch;white-space:nowrap;text-align:right;
  font-variant-numeric:tabular-nums;}

/* 09. Only NEW receives stronger contrast; other status text stays subdued. */
.facility-archive-card.unread .facility-new-label{color:#f5cf95;font-weight:900;letter-spacing:.045em;}

/* 10. Locked entries remain visually locked but not illegible. */
.facility-archive-card:disabled{opacity:1;background:#111c22e5;border-color:#526168;color:#c7cfd0;}
.facility-archive-card:disabled .facility-card-info strong{color:#c7cfd0;}
.facility-archive-card:disabled .facility-card-info small{color:#aab8bb;}
.facility-archive-card:disabled .facility-card-mark{color:#718086;}

/* 11. Fixed aligned columns, even with long subject names. */
.ranking-list-title{display:grid;grid-template-columns:64px minmax(0,1fr) 94px;
  align-items:center;gap:8px;min-width:0;}
.ranking-list-title span:last-child{text-align:right;}
.ranking-entry{display:grid;grid-template-columns:minmax(0,1fr) 94px;
  align-items:center;column-gap:8px;min-width:0;}
.ranking-entry .rank-left{display:grid;grid-template-columns:64px minmax(0,1fr);
  gap:8px;min-width:0;align-items:center;}
.ranking-entry .rank-name{display:block;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;}
.ranking-entry .rank-time{width:94px;text-align:right;}

/* 12. Monospaced digits prevent subtle rank changes during refreshing. */
.ranking-entry .rank-no,.ranking-entry .rank-time{font-variant-numeric:tabular-nums;
  font-feature-settings:'tnum' 1;}

/* 13. Own entry is highlighted in restrained steel grey, not green. */
.ranking-entry.is-self{background:rgba(139,165,177,.12);border-left:3px solid #8baab5;}

/* 14. All ranking rows share one comfortable tap/read height. */
.ranking-entry{min-height:52px;padding-block:12px;}

/* 15. A gap keeps update separate from the last recorded subject. */
.ranking-refresh{margin-top:25px;}

/* 16. END headings break cleanly on small phones without orphan punctuation. */
.result-content > h1{max-width:100%;line-break:strict;word-break:normal;
  overflow-wrap:break-word;text-wrap:balance;}

/* 17. Stable spacing of END number, title and the summary. */
.result-content > .end-tag{line-height:1.25;}
.result-content > h1{line-height:1.3!important;}
.result-content > #resultCopy{line-height:1.48!important;}

/* 18. The existing END image is never changed, just given a little air. */
.result-content > .end-illustration{margin-block:5px!important;}

/* 19. Retry is always the primary action, other records remain secondary. */
.result-content > #replayBtn{font-weight:900!important;min-height:47px!important;}
.result-content > #resultRankingBtn,.result-content > #facilityResultBtn{
  background:rgba(9,22,29,.85)!important;border-color:#748d93!important;
  color:#d9e7e5!important;font-size:12px!important;min-height:43px!important;
}

/* 20. Consistent share and export button sizes. */
.result-content > #xShareBtn,.result-content > #saveCardBtn{
  min-height:44px!important;box-sizing:border-box;padding-inline:12px;
  display:flex;align-items:center;justify-content:center;
}

/* 21. Less extreme line height in long stories; no text is removed. */
.facility-document-text{line-height:1.9;}

/* 22. Comfortable prose width and side gutters without changing map asset. */
.facility-document-page{max-width:540px;padding-inline:clamp(17px,4.8vw,27px);}
.facility-document-scroll{padding-inline:clamp(10px,3vw,18px);}

/* 23. A few intentional single-line emotional beats. */
.facility-document-text p.facility-emphasis{margin-block:1.3em 1.6em;
  font-weight:750;letter-spacing:.008em;}

/* 24. End of episode 3: pause, then the descending ceiling. */
.facility-document-text p.facility-final-line{margin-top:2.2em;
  font-weight:900;letter-spacing:.008em;}

/* 25. Archive attachment heading and chapter fraction share the baseline. */
.facility-document-map-head{align-items:baseline;flex-wrap:wrap;row-gap:4px;}
.facility-document-map-head strong{min-width:0;}
.facility-document-map-head span{margin-left:auto;min-width:4.2ch;text-align:right;
  font-variant-numeric:tabular-nums;}

/* 26. Align the top sensor plates and numbers. */
.hud-number{display:flex;flex-direction:column;justify-content:center;min-height:66px;}
.hud-number strong{font-variant-numeric:tabular-nums;line-height:1.15!important;}
.hud-number em{letter-spacing:0;}

/* 27. Clear separation between stage and progress count, no change to LEDs. */
.stage-info{gap:7px!important;padding-top:7px!important;padding-bottom:7px!important;}
.stage-info #stageText{line-height:1.2;}
.stage-info #inputText{line-height:1.25;}
@media(max-height:520px) and (orientation:landscape){.stage-info{gap:3px!important;}}

/* 28. Instruction card has reliable lateral breathing space. */
#gamePrompt{padding-inline:clamp(7px,2vw,14px)!important;
  line-break:strict;word-break:normal;overflow-wrap:break-word;}
@media(max-width:340px){#gamePrompt{padding-inline:7px!important;}}

/* 29. Consistent minimum closing/back tap areas across archive, record and leaderboard. */
#records .close-panel,#rankingPanel .close-panel,#facilityDocumentClose,#viewerClose{
  min-height:44px;min-width:80px;display:inline-flex;align-items:center;justify-content:center;
  line-height:1.25;white-space:nowrap;
}

/* 30. Unified tactile response for non-gameplay buttons, with keyboard focus. */
#records button:not(:disabled),#rankingPanel button:not(:disabled),
#facilityDocument button:not(:disabled),.facility-pickup button:not(:disabled),
.player-setup-card button:not(:disabled),.result-content button:not(:disabled),
#viewerClose{transition:filter .12s ease-out,transform .1s ease-out;}
#records button:not(:disabled):active,#rankingPanel button:not(:disabled):active,
#facilityDocument button:not(:disabled):active,.facility-pickup button:not(:disabled):active,
.player-setup-card button:not(:disabled):active,.result-content button:not(:disabled):active,
#viewerClose:active{filter:brightness(1.12);transform:translateY(1px);}
#records button:focus-visible,#rankingPanel button:focus-visible,
#facilityDocument button:focus-visible,.facility-pickup button:focus-visible,
.player-setup-card button:focus-visible,.result-content button:focus-visible,
#viewerClose:focus-visible{outline:2px solid #e6d7ad;outline-offset:3px;}
@media(prefers-reduced-motion:reduce){
 #records button,#rankingPanel button,#facilityDocument button,
 .facility-pickup button,.player-setup-card button,.result-content button,#viewerClose{
  transition:none!important;
 }
}

/* Very short landscape screens keep the existing responsive END arrangement. */
@media(max-height:500px) and (min-width:520px){
 .result-content > .end-illustration{margin:0 auto!important;}
 .result-content > #replayBtn,.result-content > #xShareBtn,
 .result-content > #saveCardBtn{min-height:39px!important;}
}


/* Tablet/desktop viewport fit: keep the original phone layout and game behavior. */
@media (min-width:700px) and (min-height:600px){
  #keypad{width:clamp(148px,11vw,172px)!important;}
  #keys{grid-template-columns:repeat(2,minmax(0,1fr));grid-template-rows:repeat(5,54px);}
  #keys .key{width:100%;height:54px;min-width:0;}
  .stage-info{
    width:clamp(148px,11vw,172px)!important;
    max-width:clamp(148px,11vw,172px)!important;
    bottom:calc(env(safe-area-inset-bottom,0px) + 338px)!important;
  }
  #joystick{width:clamp(102px,7vw,118px);height:clamp(102px,7vw,118px);}
  #gamePrompt{
    left:max(190px,calc(50% - 300px))!important;
    right:max(15px,calc(50% - 300px))!important;
    bottom:calc(env(safe-area-inset-bottom,0px) + 163px)!important;
    font-size:clamp(14px,1.3vw,19px)!important;
  }
}
/* Dialogue text can be read in full; the advance indicator stays visible. */
#dialogueText,#outroText{
  min-height:0;
  overflow-x:hidden!important;
  overflow-y:auto!important;
  overscroll-behavior:contain;
  -webkit-overflow-scrolling:touch;
  scrollbar-width:thin;
}
.dialogue-panel .dialogue-footer{flex-shrink:0;margin-top:8px;}
@media (min-width:700px) and (min-height:600px){
  #dialogue .dialogue-panel,#outroDialogue .dialogue-panel{
    left:clamp(12px,1.3vw,24px)!important;
    right:clamp(12px,1.3vw,24px)!important;
    height:clamp(230px,25dvh,295px)!important;
    max-height:calc(100dvh - 80px)!important;
  }
}
/* The records button must not cover the countdown timer during play. */
#hud:not(.hidden) ~ #quickNav{top:calc(env(safe-area-inset-top,0px) + 94px)!important;}
