.td-recovery { box-sizing: border-box; width: min(100%, 760px); padding: 12px 16px; margin: 10px auto; border: 1px solid #557588; border-radius: 8px; background: #122733; color: #ecf6ff; font: 1rem/1.5 system-ui, sans-serif; }
.td-recovery p { margin: 6px 0 10px; }
.td-recovery button { min-height: 44px; padding: 8px 14px; margin: 3px; color: #102431; background: #d5f0ff; border: 2px solid transparent; border-radius: 6px; font: inherit; cursor: pointer; }
.td-recovery button:disabled { opacity: .6; cursor: default; }
.td-recovery button:focus-visible { outline: 3px solid #f9e275; outline-offset: 3px; }
.td-recovery progress { display: block; width: 100%; margin: 14px 0; }
dialog.td-recovery { position: fixed; margin: auto; max-width: min(560px, 92vw); }
dialog.td-recovery::backdrop { background: #000b; }
.td-save-notice { position: relative; z-index: 4; }
.td-recovery[hidden] { display: none; }

html { overflow: auto; height: auto; min-height: 100%; overscroll-behavior: auto; }
body { min-height: 100dvh; height: auto; display: flex; flex-direction: column; justify-content: flex-start; overflow: visible; font-family: system-ui, "PingFang SC", "Microsoft YaHei", sans-serif; }
button, input { font: inherit; }
button, a { touch-action: manipulation; }
button:focus-visible, a:focus-visible, [tabindex="0"]:focus-visible, input:focus-visible { outline: 3px solid #ffe083; outline-offset: 3px; }
button:not(.tower-card):not(.map-card), .td-release-nav a { min-height: 44px; }
.tower-card, .map-card { color: inherit; font: inherit; }
.tower-card canvas, .map-card canvas { pointer-events: none; }
#rotate-hint { display: none !important; }
.td-release-nav { box-sizing: border-box; width: 100%; display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 8px; padding: max(8px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) 8px max(12px, env(safe-area-inset-left)); background: #202a30; }
.td-release-nav div { display: flex; gap: 5px; }
.td-release-nav button, .td-release-nav a, #td-guide-dialog button, .td-play-guide button { box-sizing: border-box; display: inline-flex; justify-content: center; align-items: center; padding: 8px 12px; border: 1px solid #829baa; background: #263d48; color: #fff3dc; border-radius: 6px; text-decoration: none; cursor: pointer; }
[data-td-language][aria-pressed="true"] { background: #b1782c; border-color: #ffda8c; }
#td-guide-dialog { box-sizing: border-box; width: min(620px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); overflow: auto; margin: auto; padding: 20px; color: #ecf4f7; background: #202d35; border: 2px solid #dcab59; border-radius: 10px; line-height: 1.6; }
#td-guide-dialog::backdrop { background: #000b; }
#td-guide-dialog h2 { margin-top: 0; }
#td-guide-dialog li { margin: 10px 0; }
.td-guide-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.td-guide-actions button:first-child { background: #c38933 !important; color: #141c20 !important; font-weight: 700; }
.td-play-guide, .td-play-feedback, #td-preference-status { box-sizing: border-box; padding: 10px 14px; margin: 8px auto; border: 1px solid #ad8751; background: #30291d; color: #fff0d8; line-height: 1.5; }
.td-play-guide { max-width: 760px; }
.td-play-guide p { margin: 0 0 8px; }
.td-play-guide button { margin-right: 8px; }
.td-play-guide[hidden], .td-play-feedback[hidden], #td-guide-starter[hidden], #td-preference-status[hidden] { display: none; }
.td-play-guide button:disabled { opacity: .5; cursor: default; }
#td-board-scroll { flex-shrink: 0; }
.td-board-hint { display: none; }
#ui-panel > #wave-countdown { position: static; transform: none; white-space: normal; margin: 0; font-size: 16px; display: none; }
#ui-panel > #wave-countdown.visible { display: block; }
#selection-screen, #map-selection-screen { box-sizing: border-box; zoom: 1; width: min(960px, 100%); max-height: none; height: auto; overflow: visible; }
#selection-slots { max-width: 100%; box-sizing: border-box; flex-wrap: wrap; justify-content: center; padding: 8px; gap: 6px; min-height: 0; }
.slot { width: 76px; height: 90px; }
#tower-pool { min-width: 0; }
#selection-top-actions { flex-wrap: wrap; }
#game-wrapper { margin: 12px 0; }
#game-wrapper:has(.td-play-guide:not([hidden])) { height: auto; }
#modal-content, #confirm-modal-content, #abandon-confirm-content { max-height: calc(100dvh - 40px); overflow: auto; }
#preferences-content, #wiki-content, #leaderboard-content { max-height: calc(100dvh - 24px); }

/* Small screens keep controls at their actual size. A 25px tile minimum leaves
   the complete board reachable by native horizontal scrolling in portrait. */
@media (max-width: 1024px) {
  #game-wrapper { box-sizing: border-box; width: 100%; max-width: 100%; height: auto; transform: none !important; animation: none !important; margin: 0; align-self: auto; padding: 8px max(8px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left)); }
  #game-container { width: 100%; height: auto; margin: 0; display: flex; flex-direction: column; gap: 10px; align-items: stretch; }
  #settings-dock { order: 0; position: static; width: 100%; flex-direction: row; gap: 8px; }
  #pause-row, #settings-row { flex: 1; }
  #pause-button, #settings-button, #quick-restart-btn, #abandon-button { min-height: 48px; padding: 6px; display: flex; justify-content: center; box-shadow: none; }
  #pause-button svg, #settings-button svg, #quick-restart-btn svg, #abandon-button svg { width: 20px; height: 20px; }
  #pause-button span, #settings-button span, #quick-restart-btn span, #abandon-button span { font-size: 14px; }
  #td-board-scroll { order: 1; width: 100%; overflow-x: auto; overscroll-behavior-x: contain; border: 1px solid #788a94; touch-action: pan-x pan-y pinch-zoom; }
  .td-board-hint { order: 1; display: block; margin: 0; color: #d1e1e8; font-size: 14px; }
  #canvas-container { width: max(625px, calc(100vw - 24px)); min-width: 625px; max-width: none; height: auto; aspect-ratio: 25 / 18; border: 0; }
  #ui-panel { order: 2; width: 100%; height: auto !important; padding: 10px; gap: 10px; }
  .stats-display { flex-direction: row; flex-wrap: wrap; gap: 12px; padding: 10px; font-size: 14px; }
  #tower-buttons-list { flex-direction: row; flex-wrap: wrap; gap: 6px; }
  .tower-btn { min-height: 48px; flex: 1 0 140px; padding: 8px; }
  #skill-rail { order: 3; position: static; width: 100%; flex-direction: row; flex-wrap: wrap; gap: 6px; }
  #skill-rail:empty { display: none; }
  .skill-rail-slot { flex: 1 0 120px; min-height: 54px; }
  .skill-rail-icon { width: 24px; height: 24px; }
  #floating-info-panel, #floating-info-panel.modern-detail { order: 4; position: static !important; width: 100%; max-width: 100%; height: auto; max-height: none; padding: 14px; box-sizing: border-box; left: auto !important; top: auto !important; display: block; font-size: 16px; }
  #floating-info-panel.modern-detail .modern-tower-visual { display: none; }
  #floating-info-panel.modern-detail .modern-detail-content { padding: 0; height: auto; }
  #floating-info-panel.modern-detail .actions { border: 0; padding: 10px 0 0; }
  .target-selector { grid-template-columns: 44px minmax(0, 1fr) 44px; }
  .target-cycle { width: 44px; height: 44px; }
  #selection-screen, #map-selection-screen { width: 100%; height: auto; max-height: none; zoom: 1; overflow: visible; padding: 12px; }
  #selection-main { flex-direction: column; gap: 10px; }
  #selection-info { box-sizing: border-box; width: 100%; }
  #tower-pool { grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); max-height: none; overflow: visible; }
  #selection-buttons-container { position: sticky; bottom: 0; z-index: 5; background: #2c2c2c; padding: 8px 0 max(8px, env(safe-area-inset-bottom)); margin-top: 0; gap: 8px; width: 100%; }
  .selection-btn { flex: 1; padding: 10px; font-size: 16px; }
  #map-list { width: 100%; max-height: none; overflow: visible; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
  #map-selection-buttons-container { position: sticky; bottom: 0; z-index: 5; background: #2c2c2c; padding: 8px 0 max(8px, env(safe-area-inset-bottom)); gap: 8px; }
  .td-play-guide { width: 100%; margin-top: 0; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; } }
#td-pending-scores { padding: 8px 14px; overflow: auto; max-height: 32dvh; flex-shrink: 0; }
.td-pending-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin: 6px 0; }
.td-pending-row span { flex: 1 1 100px; }
.td-pending-row button { min-height: 44px; padding: 8px 12px; }
#td-score-status { font-size: .9rem; line-height: 1.5; }
#leaderboard-account { flex-wrap: wrap; overflow-wrap: anywhere; }
#leaderboard-account button { flex-shrink: 0; white-space: nowrap; }
