#game-shell {--game-text:#f4e9dc;background:#141827;border-color:#414052}
#game-shell .play-area {width:100%;min-height:0;position:relative}
#game-shell #game-surface {aspect-ratio:2/1;border:1px solid #555462;background:#202c44;border-radius:4px}
#game-shell .game-menu {align-content:center;justify-items:start;text-align:left;padding:clamp(14px,4vw,54px);background:linear-gradient(90deg,#181827ed 10%,#242234cf 49%,#29253920)}
#game-shell .game-menu h2 {font:normal clamp(22px,4.2vw,54px)/1.02 Georgia,"SimSun",serif;letter-spacing:-.035em;color:#fff0d8;text-shadow:0 2px 15px #0008}
#game-shell .game-menu p {max-width:34ch;font-size:clamp(12px,1.6vw,17px);color:#fff0df}
#game-shell .game-menu button {justify-self:start}
#game-shell .primary-button {background:#f1c99b;color:#302338}
#game-shell .player-status {justify-content:center;text-align:center;font:500 clamp(12px,1.6vw,16px)/1.4 "Segoe UI",sans-serif}
#game-shell .player-hud {gap:clamp(8px,1.2vw,20px)}
#game-shell .stat {min-width:0}
#game-shell.is-restored-result .stat:has(#round-time) {display:none}
#game-shell .stat span {font-size:10px}
#game-shell .stat strong {font-size:clamp(13px,2vw,19px);white-space:nowrap}

.moonbeam-meter {
  --moonbeam-fill:100%;
  --moonbeam-ink:#b9ede6;
  position:absolute;
  top:8.3%;
  right:1.77%;
  width:clamp(78px,11%,126px);
  box-sizing:border-box;
  padding:3px 6px 5px;
  color:var(--moonbeam-ink);
  background:#142033ed;
  pointer-events:none;
  font:600 clamp(10px,1vw,13px)/1.15 "Segoe UI","Microsoft YaHei",sans-serif;
}
.moonbeam-meter[hidden] {display:none}
.moonbeam-meter__title {display:flex;align-items:center;gap:5px}
.moonbeam-meter__title::before {
  content:"";display:block;width:.65em;height:.65em;margin-left:2px;
  border-radius:50%;box-shadow:-2px 1px 0 0 currentColor;transform:rotate(-25deg)
}
.moonbeam-meter__track {
  position:relative;display:block;height:5px;margin-top:3px;overflow:hidden;
  background:#455365;
}
.moonbeam-meter__track::before {
  content:"";position:absolute;inset:0 auto 0 0;width:var(--moonbeam-fill);
  background:linear-gradient(0deg,#87c9c5,#d6faf0);
}
.moonbeam-meter__track::after {
  content:"";position:absolute;inset:0;
  background:repeating-linear-gradient(90deg,transparent 0 calc(25% - 2px),#162234 calc(25% - 2px) 25%);
}
.moonbeam-meter[data-state=recharging] {--moonbeam-ink:#f4cf9c}
.moonbeam-meter[data-state=recharging] .moonbeam-meter__track::before {
  background:repeating-linear-gradient(120deg,#e5b97f 0 3px,#997857 3px 5px);
}
.moonbeam-meter[data-cue="restored"] {
  color:#ddfff8;
  box-shadow:inset 0 0 0 1px #a4e6d5;
}
#game-shell .player-controls button {font-size:12px}
#game-shell .player-controls {gap:5px}
.moon-actions {display:flex;gap:12px}
.moon-actions button {touch-action:none;user-select:none;min-width:65px}
.is-playing #game-shell[data-adapter=canvas] {grid-template-rows:auto minmax(0,1fr) auto;gap:8px}
.is-playing #game-shell .play-area {width:min(100%,calc((100dvh - 124px)*2))}
.is-playing.touch-device #game-shell[data-adapter=canvas] {grid-template-rows:auto minmax(0,1fr) auto auto}
@media(max-width:620px){#game-shell .player-controls{width:100%;margin-left:0}#game-shell .player-controls button{padding:5px 7px;min-height:32px;font-size:11px}#game-shell .game-menu{gap:5px}#game-shell .stat strong{font-size:13px}#game-shell .game-menu p{font-size:12px}}

/* Settings and history share the playfield's place in the page. */
.play-area:has(dialog[open]) #game-surface {display:none}
.play-area dialog[open] {position:static;width:100%;margin:0;box-sizing:border-box;max-height:min(60dvh,28rem);overflow:auto;overscroll-behavior:contain}
.settings-heading-bar {display:flex;align-items:center;justify-content:space-between;gap:12px}
.settings-heading-bar h2 {margin:0}
.is-playing.touch-device #game-settings[open] {padding:12px 16px 16px;scroll-padding-top:66px}
.is-playing.touch-device #game-settings .settings-heading-bar {
  position:sticky;top:-12px;z-index:1;margin:-12px -16px 0;padding:8px 16px;
  background:var(--panel);border-bottom:1px solid var(--line);
}
#game-shell .player-status #game-status {font-size:clamp(14px,1.7vw,19px);color:#ffefc9;line-height:1.3}
#install-dialog[open] {position:static;margin:12px auto}
#game-shell .player-status p:empty {display:none}

#game-shell .player-status:has(#game-status:empty):has(#view-notice:empty):has(#update-waiting[hidden]) {display:none}

/* Mobile focus keeps the scenery full-width and the touch targets at opposite edges. */
.is-playing.touch-device #game-shell[data-adapter=canvas] {
  --touch-left:max(10px,env(safe-area-inset-left));
  --stick-left:max(18px,env(safe-area-inset-left));
  --touch-right:max(10px,env(safe-area-inset-right));
  --touch-bottom:max(8px,env(safe-area-inset-bottom));
  padding-inline:env(safe-area-inset-left) env(safe-area-inset-right);
  row-gap:6px;
}
.is-playing.touch-device #game-shell .player-hud,
.is-playing.touch-device #game-shell .player-status {
  padding-inline:var(--touch-left) var(--touch-right);
}
.is-playing.touch-device #game-shell .play-area { width:100%; }
.is-playing.touch-device #game-shell.is-portrait-stage .play-area {
  width:min(100%,calc((100dvh - max(12px,env(safe-area-inset-top)) - max(12px,env(safe-area-inset-bottom)) - 180px)*var(--stage-aspect)));
}
.is-playing.touch-device #game-shell.is-portrait-stage #game-surface { aspect-ratio:var(--stage-aspect); }
.is-playing.touch-device #game-shell #game-surface { border-radius:0; }
.is-playing.touch-device #game-shell .touch-controls {
  justify-content:space-between;
  min-height:60px;
  padding:0 var(--touch-right) 0 var(--stick-left);
  gap:6px;
}
.is-playing.touch-device #game-shell .touch-stick {
  width:92px;
  height:92px;
  transform:scale(.64);
  margin:-16px;
}
.is-playing.touch-device #game-shell .touch-stick-knob { left:28px; top:28px; }
.is-playing.touch-device #game-shell .touch-stick::before { top:45px; }
.is-playing.touch-device #game-shell .touch-stick::after { left:45px; }
.is-playing.touch-device #game-shell .moon-actions { gap:5px; }
.is-playing.touch-device #game-shell .moon-actions button {
  position:relative;
  isolation:isolate;
  min-width:44px;
  min-height:44px;
  padding:4px 8px;
  border:0;
  border-radius:8px;
  background:none;
  font-size:11px;
}
.is-playing.touch-device #game-shell .moon-actions button::before {
  content:"";
  position:absolute;
  inset:6px 0;
  z-index:-1;
  border:1px solid #e7d3b355;
  border-radius:8px;
  background:#141827dd;
  pointer-events:none;
}
.is-playing.touch-device #game-shell .moon-actions button:active::before { background:#574135ed; }
.is-playing.touch-device #game-shell #act-fire[aria-disabled=true] { opacity:.55; cursor:default; }
.is-playing.touch-device #game-shell #act-fire[data-moonbeam=ready]::before {
  border-color:#9ccfc38c;
  box-shadow:inset 0 -2px #8cbfb1;
}
.is-playing.touch-device #game-shell #act-fire[data-moonbeam=recharging]::before {
  border-color:#edc18b;
  background:repeating-linear-gradient(120deg,#48362c 0 4px,#352c2a 4px 8px);
}
.is-playing.touch-device #game-shell:has(.game-menu:not([hidden]),dialog[open]) .touch-controls,
.is-playing.touch-device #game-shell.is-answering .touch-controls,
.is-playing.touch-device #game-shell.is-life-loss .touch-controls { visibility:hidden; }

@media(orientation:portrait) and (max-width:620px) {
  .is-playing.touch-device #game-shell.is-earthrise #game-status { min-height:2.6em; }
  .is-playing.touch-device #game-shell .play-area { display:flex; flex-direction:column; }
  .is-playing.touch-device #game-shell .moonbeam-meter:not([hidden]) {
    position:static;
    order:-1;
    align-self:flex-end;
    display:flex;
    align-items:center;
    gap:6px;
    width:auto;
    margin:0 var(--touch-right) 3px 0;
    padding:2px 4px;
  }
  .is-playing.touch-device #game-shell .moonbeam-meter__track { width:48px; margin:0; }
  .is-playing.touch-device #game-shell[data-adapter=canvas] {
    align-content:center;
    grid-template-rows:auto auto auto auto;
  }
}

@media(orientation:landscape) and (max-height:560px) {
  .is-playing.touch-device #game-shell[data-adapter=canvas] {
    grid-template-rows:auto minmax(0,1fr) auto;
    padding-top:max(4px,env(safe-area-inset-top));
    padding-bottom:max(4px,env(safe-area-inset-bottom));
    row-gap:4px;
  }
  .is-playing.touch-device #game-shell .play-area {
    grid-row:2;
    width:min(100%,calc((100dvh - max(4px,env(safe-area-inset-top)) - max(4px,env(safe-area-inset-bottom)) - 58px)*2));
  }
  .is-playing.touch-device #game-shell .touch-controls {
    position:absolute;
    inset:auto var(--touch-right) calc(var(--touch-bottom) + 23px) var(--stick-left);
    z-index:2;
    padding:0;
    align-items:flex-end;
    pointer-events:none;
  }
  .is-playing.touch-device #game-shell .touch-stick,
  .is-playing.touch-device #game-shell .moon-actions button { pointer-events:auto; }
  .is-playing.touch-device #game-shell .touch-stick { margin-bottom:0; transform-origin:center bottom; }
  .is-playing.touch-device #game-shell .moon-actions {
    flex-direction:column;
    align-items:stretch;
    gap:0;
  }
  .is-playing.touch-device #game-shell .moon-actions:has(#act-strike:not([hidden])) {
    display:grid;
    grid-template-columns:repeat(2,auto);
    column-gap:4px;
  }
  .is-playing.touch-device #game-shell .moon-actions button { padding-inline:6px; }
  .is-playing.touch-device #game-shell .player-status { grid-row:3; }
  #game-shell .player-status #game-status { font-size:clamp(11px,1.5vw,14px); }
}

@media(orientation:landscape) and (max-width:640px) and (max-height:560px) {
  .is-playing.touch-device #game-shell .player-hud { flex-wrap:nowrap; gap:6px; }
  .is-playing.touch-device #game-shell .player-controls { width:auto; margin-left:auto; gap:3px; }
  .is-playing.touch-device #game-shell .player-controls button { padding-inline:4px; font-size:10px; }
}

@media(orientation:landscape) and (max-width:520px) and (max-height:560px) {
  .is-playing.touch-device #game-shell .player-hud { flex-wrap:wrap; }
  .is-playing.touch-device #game-shell .play-area {
    width:min(100%,calc((100dvh - max(4px,env(safe-area-inset-top)) - max(4px,env(safe-area-inset-bottom)) - 108px)*2));
  }
}
