/* The approved visual theme is shared with ui-preview.html. This stylesheet
   only fits the live game and adapts its existing overlay state containers. */
:root { color-scheme: dark; font-family: 'Yufen Print', 'PingFang SC', 'Microsoft YaHei', sans-serif; }
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; background: #171715; overscroll-behavior: none; }
body { touch-action: none; user-select: none; -webkit-user-select: none; }
body.rankings-open { touch-action: pan-y; }
body.characters-open { touch-action: pan-x; }
[hidden] { display: none !important; }

#safe-area {
  --stage-top: max(env(safe-area-inset-top), var(--toy-safe-top, 0px));
  --stage-right: max(env(safe-area-inset-right), var(--toy-safe-right, 0px));
  --stage-bottom: max(env(safe-area-inset-bottom), var(--toy-safe-bottom, 0px));
  --stage-left: max(env(safe-area-inset-left), var(--toy-safe-left, 0px));
  position: fixed;
  top: 0; left: 0;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
}
@supports (height: 100dvh) {
  #safe-area { width: 100dvw; height: 100dvh; }
}
#frame {
  --ui-safe-top: calc(var(--stage-top) / var(--game-scale, 1));
  --ui-safe-right: calc(var(--stage-right) / var(--game-scale, 1));
  --ui-safe-bottom: calc(var(--stage-bottom) / var(--game-scale, 1));
  --ui-safe-left: calc(var(--stage-left) / var(--game-scale, 1));
  --ui-content-top: var(--ui-safe-top);
  position: absolute;
  left: 50%; top: 50%;
  width: var(--game-width, 960px);
  height: var(--game-height, 540px);
  transform: translate(-50%, -50%) scale(var(--game-scale, 1));
  transform-origin: center;
}
#game { display: block; width: 100%; height: 100%; }
#hud { isolation: isolate; }
#hud { inset: var(--ui-content-top) var(--ui-safe-right) var(--ui-safe-bottom) var(--ui-safe-left); }
#controls { inset: var(--ui-safe-top) var(--ui-safe-right) var(--ui-safe-bottom) var(--ui-safe-left); }
#frame .paper-overlay { padding: var(--ui-content-top) var(--ui-safe-right) var(--ui-safe-bottom) var(--ui-safe-left); }
#frame .paper-quick-actions { top: calc(21px + var(--ui-safe-top)); right: calc(28px + var(--ui-safe-right)); }

/* Passive legends stay above the pause shade and never receive input or focus. */
.paper-keyboard-hints {
  position: absolute;
  z-index: 6;
  right: calc(24px + var(--ui-safe-right));
  bottom: calc(10px + var(--ui-safe-bottom));
  display: grid;
  gap: 6px;
  padding: 9px 11px;
  color: var(--paper-cream);
  background: transparent;
  clip-path: polygon(5px 0, 100% 0, 100% calc(100% - 5px), calc(100% - 5px) 100%, 0 100%, 0 5px);
  font-size: 12px;
  line-height: 1;
  pointer-events: none;
}
.paper-keyboard-row { display: flex; justify-content: flex-end; align-items: center; gap: 11px; }
.paper-keyboard-hint { display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; }
.paper-keyboard-hint kbd {
  display: inline-grid;
  place-items: center;
  min-width: 21px;
  height: 21px;
  padding: 0 5px;
  color: var(--paper-ink);
  background: var(--paper-cream);
  clip-path: polygon(3px 0, 100% 0, 100% calc(100% - 3px), calc(100% - 3px) 100%, 0 100%, 0 3px);
  font: 800 12px / 1 ui-monospace, SFMono-Regular, Consolas, monospace;
}

.paper-menu-decoration { position: absolute; inset: 0; pointer-events: none; }
#overlay:not([data-mode='start']) .paper-menu-decoration { display: none; }
#overlay[data-mode='start'] #overlay-panel { position: absolute; inset: var(--ui-content-top) var(--ui-safe-right) var(--ui-safe-bottom) var(--ui-safe-left); pointer-events: none; }
#overlay[data-mode='start'] #overlay-actions { pointer-events: auto; }
#overlay[data-mode='start'] .paper-menu-title { left: calc(50% - 310px); top: calc(50% - 240px); }
#overlay[data-mode='start'] .paper-menu-actions { left: calc(50% - 210px); top: calc(50% - 10px); }
#overlay .paper-menu-field { top: calc(50% - 204px); width: calc(100% + 16px); }
#overlay .paper-registration::before, #overlay .paper-registration::after { width: 100%; }
#overlay:not([data-mode='victory']) .paper-victory-rule { display: none; }

#overlay[data-mode='dead'] .paper-dialog { width: 440px; }
#overlay[data-mode='dead'] .paper-dialog-actions { display: grid; grid-template-columns: minmax(0, 1fr); }
#overlay[data-mode='dead'] .paper-dialog-actions.has-stronger-retry { grid-template-columns: minmax(0, 1fr) minmax(0, 1.5fr); }
#overlay[data-mode='dead'] .paper-button { min-width: 0; padding: 0 14px; white-space: nowrap; }
#overlay[data-mode='dead'] #stronger-retry { --button-face: var(--paper-ochre); --button-text: var(--paper-ink); }
#overlay[data-mode='dead'] #secondary { grid-column: 1 / -1; }

#vital-bars, #health-track { width: var(--health-width, 256px); }
#health { transform-origin: left top; }
.is-strengthening #hud { z-index: 4; }
.is-strengthening #overlay { background: #171715e6; }
.is-strengthening #overlay-panel { visibility: hidden; pointer-events: none; }
.is-strengthening #rage-track { visibility: hidden; }
.is-strengthening #health-fill { transition: none; }
#retry-boost-value { position: absolute; left: 0; top: -48px; color: var(--paper-cream); font-size: 30px; line-height: 1; white-space: nowrap; }
#retry-boost-gain { position: absolute; top: -4px; color: var(--paper-ochre); font-size: 29px; line-height: 1; white-space: nowrap; }
#health-boost-extension { position: absolute; z-index: 2; top: 4px; bottom: 4px; background: var(--paper-cream); pointer-events: none; }

/* Keep the settings controls readable and touchable after the game scales. */
@media (pointer: coarse), (max-width: 760px) {
  #frame {
    /* A container's top inset can include the native menu rather than a screen
       obstruction. Keep content centered while preserving the menu anchors. */
    --ui-content-top: min(var(--ui-safe-top), var(--ui-safe-bottom));
  }
  #joystick { left: 42px; bottom: 39px; transform: scale(1.2); transform-origin: left bottom; }
  #joystick::before { content: ''; position: absolute; inset: -30px; border-radius: 50%; pointer-events: auto; }
  #controls .paper-attack { transform: scale(1.2); transform-origin: right bottom; }
  #controls .paper-heavy { right: 127px; bottom: 127px; }
  #controls .paper-roll { right: 165px; bottom: 37px; }
  #controls .paper-run { right: 268px; bottom: 43px; }
  #controls .paper-ultimate { right: 37px; bottom: 165px; }
  #overlay[data-mode='dead'] .paper-dialog { width: 480px; }
  #overlay[data-mode='dead'] .paper-button {
    min-height: clamp(58px, calc(44px / var(--game-scale, 1)), 104px);
    font-size: clamp(27px, calc(19px / var(--game-scale, 1)), 38px);
  }
  #frame .paper-quick-actions { --quick-action-size: clamp(47px, calc(40px / var(--game-scale, 1)), 104px); top: calc(18px + var(--ui-safe-top)); right: calc(22px + var(--ui-safe-right)); }
  .paper-ui { --paper-modal-width: 480px; }
  .paper-settings-panel {
    --settings-title-size: clamp(26px, calc(18px / var(--game-scale, 1)), 42px);
    --settings-label-size: clamp(20px, calc(15px / var(--game-scale, 1)), 34px);
    --settings-close-size: clamp(44px, calc(40px / var(--game-scale, 1)), 104px);
    --settings-thumb-size: clamp(26px, calc(20px / var(--game-scale, 1)), 48px);
    --settings-hit-size: clamp(44px, calc(40px / var(--game-scale, 1)), 104px);
    --settings-header-size: calc(var(--settings-close-size) + 6px);
    --settings-credit-size: clamp(13px, calc(10px / var(--game-scale, 1)), 22px);
    height: max(252px, calc(var(--settings-header-size) + var(--settings-hit-size) * 2 + var(--settings-credit-size) * 1.4 + 40px));
    padding: 12px 18px;
    gap: 6px;
  }
  .paper-settings-row { grid-template-columns: 68px minmax(0, 1fr); gap: 10px; }
  .paper-settings-panel.paper-rankings-panel {
    --rank-row-size: clamp(52px, calc(42px / var(--game-scale, 1)), 96px);
    --rank-avatar-size: clamp(28px, calc(24px / var(--game-scale, 1)), 54px);
    --rank-position-size: clamp(30px, calc(26px / var(--game-scale, 1)), 60px);
    --rank-text-size: clamp(17px, calc(14px / var(--game-scale, 1)), 32px);
    height: 420px;
  }
  .paper-rank-row { gap: 8px; }
  .paper-rankings-retry { min-height: var(--settings-hit-size); font-size: var(--rank-text-size); }
  .paper-settings-panel.paper-characters-panel {
    --character-side-width: 172px;
    --character-heading-size: clamp(18px, calc(14px / var(--game-scale, 1)), 32px);
    --character-name-size: clamp(20px, calc(15px / var(--game-scale, 1)), 36px);
    --character-card-min-width: max(150px, calc(var(--character-name-size) * 4 + 24px));
    --character-text-size: clamp(16px, calc(13px / var(--game-scale, 1)), 30px);
    --character-state-size: clamp(14px, calc(11px / var(--game-scale, 1)), 26px);
    --character-button-size: var(--settings-hit-size);
    --character-avatar-size: clamp(32px, calc(24px / var(--game-scale, 1)), 54px);
    width: 720px;
    height: min(340px, calc(100% - 24px));
  }
  .paper-character-sidebar { grid-template-rows: minmax(0, 1.05fr) minmax(0, 1fr); }
  .paper-character-author { grid-template-rows: auto auto; align-content: center; gap: 6px; padding: 8px; }
  .paper-character-author > h3 { display: none; }
  .paper-character-author-link { align-self: auto; }
  .paper-character-card { gap: 6px; padding: 8px; }
  .paper-character-art > svg { height: auto; max-height: 100%; aspect-ratio: 1; }
  .paper-character-unavailable { min-height: calc(var(--character-button-size) + var(--character-name-size) * 1.2 + 10px); }
  .paper-character-video-link > img { object-fit: contain; }
  .paper-character-video-link > svg { width: 44px; height: 44px; }
}

#rotate { display: none; position: fixed; inset: 0; z-index: 100; }
@media (orientation: portrait) {
  #safe-area { visibility: hidden; }
  #rotate { display: grid; }
}
