* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { width: 100%; height: 100%; background: #DCD7D0; color: #4A4036; font-family: Georgia, 'Songti SC', serif; }
body { height: 100dvh; display: flex; flex-direction: column; }
button, input, summary, a { -webkit-tap-highlight-color: transparent; }
button, summary, a { touch-action: manipulation; }
button { cursor: pointer; color: #4A4036; font: inherit; background: #E8E4DF; border: 1px solid #B8B2A8; border-radius: 10px; padding: 10px 16px; min-height: 44px; }
button:hover { background: #F2EDE6; }
button:disabled { opacity: .55; cursor: default; }
a { color: #4A4036; }
:focus-visible { outline: 3px solid #465F70; outline-offset: 3px; }
[hidden] { display: none !important; }
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 4px 16px; border-bottom: 1px solid #B8B2A8; font-size: 12px; letter-spacing: 1.5px; min-height: 53px; }
.topbar a { text-decoration: none; font-weight: bold; padding: 12px 0; }
.topbar button { font-size: 13px; }
#stage { flex: 1; min-height: 160px; position: relative; overflow: hidden; }
canvas { display: block; width: 100%; height: 100%; touch-action: none; }
#ui-layer { position: absolute; inset: 0; padding: clamp(20px, 4vh, 60px) 20px; background: linear-gradient(#E8E4DF, #DCD7D0 60%, #CEC9C1); overflow: auto; display: flex; flex-direction: column; align-items: center; gap: 14px; text-align: center; }
#ui-layer h1 { font-size: clamp(30px, 5vw, 52px); font-weight: normal; margin-bottom: 4px; }
#ui-layer p { max-width: 720px; line-height: 1.6; }
#ui-layer > button { width: min(100%, 680px); }
#ui-layer strong { font-weight: normal; font-size: 18px; display: block; }
#ui-layer small { display: block; font-size: 13px; line-height: 1.6; margin-top: 5px; color: #5C5147; }
.mode-list { width: min(100%, 400px); display: grid; gap: 12px; margin-top: 12px; }
.partner-list { width: min(100%, 1000px); display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-top: 12px; }
.partner-list button { min-height: 160px; padding: 22px 16px; }
#inventory { position: absolute; left: 12px; right: 12px; bottom: 12px; display: flex; gap: 8px; flex-wrap: wrap; pointer-events: none; }
#inventory button { pointer-events: auto; font-size: 12px; }
.controls { padding: 8px 16px max(8px, env(safe-area-inset-bottom)); border-top: 1px solid #B8B2A8; font-family: system-ui, sans-serif; font-size: 12px; }
#game-status { line-height: 1.6; min-height: 20px; }
.tools { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.tools label { display: flex; align-items: center; min-height: 44px; gap: 8px; }
input { width: 18px; height: 18px; accent-color: #6D8A73; }
summary { cursor: pointer; padding: 12px 0; }
#instructions { position: absolute; z-index: 20; background: #F2EDE6; padding: 20px; border: 1px solid #B8B2A8; border-radius: 12px; right: 12px; bottom: 88px; max-width: 460px; max-height: 65dvh; overflow: auto; margin-left: 12px; line-height: 1.7; }
#instructions p { margin-bottom: 12px; }
#privacy-banner { position: fixed; z-index: 10001; bottom: 12px; left: 12px; max-width: min(440px, calc(100vw - 24px)); background: #F2EDE6; border: 1px solid #B8B2A8; padding: 16px; border-radius: 12px; font: 13px/1.6 system-ui, sans-serif; box-shadow: 0 4px 24px #4A403622; }
#privacy-banner p { margin-bottom: 10px; }
#privacy-banner button { margin-right: 8px; margin-top: 4px; font-size: 13px; }
#game-error { position: fixed; z-index: 10002; top: 70px; left: 12px; right: 12px; padding: 18px; background: #F2EDE6; border: 2px solid #8B4545; }
.noscript { position: fixed; inset: 0; z-index: 20000; background: #E8E4DF; padding: 30px; overflow: auto; line-height: 1.8; }
.noscript p { max-width: 760px; margin: 20px 0; }
@media (max-width: 700px) { .partner-list { grid-template-columns: repeat(2, 1fr); gap: 10px; } .partner-list button { min-height: 135px; padding: 14px 10px; } .topbar > span { font-size: 10px; letter-spacing: .5px; } #ui-layer { padding: 20px 16px; gap: 10px; } #ui-layer small { font-size: 12px; } }
@media (max-height: 520px) { .mode-list { grid-template-columns: 1fr 1fr; width: min(100%, 680px); } #ui-layer { padding: 12px; gap: 8px; } #ui-layer h1 { font-size: 28px; } .partner-list button { min-height: 115px; padding: 10px; } .controls { padding-top: 2px; padding-bottom: 2px; } .topbar { min-height: 48px; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { scroll-behavior: auto !important; animation: none !important; transition: none !important; } }

/* ---- Objective + settlement ------------------------------------------- */
.objective { width: min(100%, 720px); background: #EFEAE3; border: 1px solid #C9C2B7; border-radius: 12px; padding: 12px 16px; text-align: left; }
.objective strong { font-size: 15px; }
.objective span { display: block; margin-top: 4px; font-size: 13px; color: #5C5147; }
.hint { color: #6B6056; font-size: 13px; }
#ui-layer[data-phase="roundEnd"], #ui-layer[data-phase="gameOver"] { justify-content: flex-start; padding-top: clamp(14px, 3vh, 40px); gap: 10px; }
#ui-layer[data-phase="roundEnd"] h1, #ui-layer[data-phase="gameOver"] h1 { font-size: clamp(26px, 3.6vw, 42px); }
.result-banner { font-size: 13px; letter-spacing: 1px; text-transform: none; color: var(--tier, #5C5147); }
#ui-layer[data-tier="S"] { --tier: #8E6F2E; --tier-soft: #F1E7CE; --tier-line: #C7AE74; }
#ui-layer[data-tier="A"] { --tier: #4F6B52; --tier-soft: #E3EADF; --tier-line: #A8BCA4; }
#ui-layer[data-tier="B"] { --tier: #465F70; --tier-soft: #E1E7EB; --tier-line: #A9BCC7; }
#ui-layer[data-tier="C"] { --tier: #7A6448; --tier-soft: #EAE1D4; --tier-line: #C9B79E; }
#ui-layer[data-tier="D"] { --tier: #6B6056; --tier-soft: #E8E2D9; --tier-line: #C1B7A9; }
#ui-layer[data-tier="F"] { --tier: #8B4545; --tier-soft: #EFDDDA; --tier-line: #C9998F; }
#ui-layer[data-tier="clean"] { --tier: #4F6B52; --tier-soft: #E3EADF; --tier-line: #A8BCA4; }
#ui-layer[data-tier="good"] { --tier: #465F70; --tier-soft: #E1E7EB; --tier-line: #A9BCC7; }
#ui-layer[data-tier="tight"] { --tier: #8A6A2F; --tier-soft: #F0E7D3; --tier-line: #CBB588; }
#ui-layer[data-tier="edge"] { --tier: #8B5A3C; --tier-soft: #F0E2D8; --tier-line: #CBA998; }
.result-card { width: min(100%, 620px); background: var(--tier-soft, #EFEAE3); border: 1px solid var(--tier-line, #C9C2B7); border-radius: 16px; padding: 18px 20px; display: grid; gap: 12px; }
.result-head { width: min(100%, 620px); display: grid; justify-items: center; gap: 8px; background: var(--tier-soft, #EFEAE3); border: 1px solid var(--tier-line, #C9C2B7); border-radius: 16px; padding: 14px 20px 16px; }
.seal { width: 70px; height: 70px; border-radius: 50%; border: 3px solid var(--tier, #4A4036); color: var(--tier, #4A4036); background: #FBF8F3; display: grid; place-items: center; font: 34px/1 Georgia, serif; }
.result-score { display: flex; align-items: baseline; gap: 8px; justify-content: center; }
#ui-layer .result-score strong { font-size: 40px; font-weight: normal; line-height: 1.05; font-family: Georgia, serif; color: var(--tier, #4A4036); }
.result-score span { font-size: 15px; color: #6B6056; }
.comment { font-size: 15px; line-height: 1.7; max-width: 46em; }
.allowance { display: flex; align-items: center; gap: 10px; width: 100%; }
.allowance-track { flex: 1; height: 12px; border-radius: 6px; background: #00000014; overflow: hidden; border: 1px solid #00000010; }
.allowance-track i { display: block; height: 100%; background: linear-gradient(90deg, #A9BF9C, #C4A87A 55%, #C09090); }
.allowance.is-failed .allowance-track { border-color: #8B4545; }
.allowance.is-failed .allowance-track i { background: #B47F75; }
.allowance-num { font: 12px/1.4 ui-monospace, monospace; color: #5C5147; white-space: nowrap; }
.result-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 0; text-align: left; }
.result-stats.wide { grid-template-columns: repeat(4, 1fr); width: min(100%, 620px); }
.result-stats div { background: #FFFFFF88; border-radius: 10px; padding: 8px 10px; }
.result-stats dt { font-size: 11px; color: #6B6056; letter-spacing: .5px; }
.result-stats dd { margin: 2px 0 0; font-size: 16px; }
.round-list { width: min(100%, 620px); list-style: none; display: grid; gap: 6px; text-align: left; }
.round-list li { display: grid; grid-template-columns: 22px 56px 1fr 72px 62px; align-items: center; gap: 8px; background: #FFFFFF77; border: 1px solid #00000010; border-radius: 10px; padding: 5px 10px; font-size: 13px; }
.round-list li.is-fail { background: #F3E2DF; border-color: #C9998F; }
.round-list li.is-pending { opacity: .5; }
.round-list .r-index { color: #8A7F74; font: 12px/1 ui-monospace, monospace; }
.round-list .r-name { font-size: 13px; }
.round-list .r-verdict { color: var(--tier, #6B6056); font-size: 12px; text-align: right; }
.round-list .r-score { text-align: right; font-family: Georgia, serif; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; width: min(100%, 620px); }
.actions button { flex: 1 1 150px; min-height: 52px; }
.shop-next { width: min(100%, 900px); display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 10px; }
@media (max-width: 700px) {
  .result-stats, .result-stats.wide { grid-template-columns: repeat(2, 1fr); }
  .round-list li { grid-template-columns: 18px 44px 1fr 52px; }
  .round-list .r-verdict { display: none; }
  #ui-layer .result-score strong { font-size: 36px; }
  .result-head { padding: 14px; }
  .seal { width: 66px; height: 66px; font-size: 30px; }
}

/* Short viewports: keep the summary (score, rounds, stats and actions) above the fold. */
@media (max-height: 880px) {
  #ui-layer[data-phase="gameOver"], #ui-layer[data-phase="roundEnd"] { padding: 12px; gap: 8px; }
  #ui-layer[data-phase="gameOver"] h1, #ui-layer[data-phase="roundEnd"] h1 { font-size: clamp(24px, 3vw, 34px); }
  #ui-layer[data-phase="gameOver"] > p, #ui-layer[data-phase="roundEnd"] > p { line-height: 1.4; }
  .result-head { padding: 10px 16px 12px; gap: 6px; }
  .seal { width: 54px; height: 54px; font-size: 26px; border-width: 2px; }
  #ui-layer .result-score strong { font-size: 32px; }
  .comment { font-size: 13px; }
  .round-list li { padding: 3px 8px; font-size: 12px; }
  .result-stats div { padding: 5px 8px; }
  .result-stats dt { font-size: 10px; }
  .result-stats dd { font-size: 14px; }
  .actions button { min-height: 46px; }
  .actions button small { font-size: 11px; }
}
