/* Device modes share one game state; only the way a player reads and acts changes. */
body.device-mobile {
  --device-cta-space: calc(86px + env(safe-area-inset-bottom, 0px));
}
body.device-mobile #app {
  width: 100%;
  max-width: none;
  margin: 0;
  border: 0;
  box-shadow: none;
}
body.device-mobile #screen-title .title-inner {
  display: block;
  max-width: 460px;
  text-align: center;
}
body.device-mobile #screen-title .logo { align-items: center; }
body.device-mobile #screen-title .menu,
body.device-mobile #screen-title .title-kicker,
body.device-mobile #screen-title #title-canvas {
  max-width: 420px;
  margin-inline: auto;
}
body.device-mobile.game-active { overflow-y: auto; }
body.device-mobile.game-active #app { height: auto; min-height: 100svh; overflow: visible; }
body.device-mobile.game-active #screen-game.active {
  display: flex;
  flex-direction: column;
  height: auto;
  min-height: 100svh;
  overflow: visible;
  gap: 0;
  padding: 0 env(safe-area-inset-right, 0px) var(--device-cta-space) env(safe-area-inset-left, 0px);
  scroll-padding-bottom: var(--device-cta-space);
}
body.device-mobile.game-active .hud {
  position: sticky;
  top: 0;
  z-index: 25;
  min-height: calc(60px + env(safe-area-inset-top, 0px));
  margin: 0;
  padding: calc(7px + env(safe-area-inset-top, 0px)) 10px 7px;
}
body.device-mobile.game-active .hud-day { font-size: 15px; }
body.device-mobile.game-active .hud-level { font-size: 12px; }
body.device-mobile.game-active .hud-money { font-size: 16px; }
body.device-mobile.game-active .scene-wrap {
  width: auto;
  height: auto;
  min-height: 0;
  margin: 0 8px;
}
body.device-mobile.game-active #scene {
  height: clamp(126px, 22svh, 180px) !important;
  min-height: 0;
  max-height: none;
  aspect-ratio: auto;
  object-fit: cover !important;
  object-position: 44% center;
}
body.device-mobile.game-active .stats {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-auto-rows: auto;
  gap: 6px 8px;
  margin: 0 8px;
  padding: 7px 8px;
}
body.device-mobile.game-active .stat-label,
body.device-mobile.game-active .stat-label b { font-size: 13px; }
body.device-mobile.game-active .stat-label { margin-bottom: 3px; }
body.device-mobile.game-active .stat-label [data-pixel-icon] { width: 18px; height: 18px; }
body.device-mobile.game-active .panel {
  display: flex;
  flex: 1 0 auto;
  margin: 0 8px;
  padding: 8px;
  overflow: visible;
}
body.device-mobile.game-active #web-tools { gap: 5px; padding-bottom: 6px; }
#web-tool-details { display: grid; gap: 7px; }
#web-tool-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  min-height: 44px;
  padding: 7px 10px;
  color: var(--px-ink);
  background: #e8dec9;
  border: 1px solid #b9a785;
  border-bottom-width: 3px;
  border-radius: 2px;
  text-align: left;
  font-size: 13px;
  font-weight: 700;
  line-height: 1.35;
}
#web-tool-toggle::after { content: '展开 ▾'; flex: none; color: #556173; font-size: 12px; }
#web-tool-toggle[aria-expanded="true"]::after { content: '收起 ▴'; }
#web-mobile-hint { display: none; margin: 0; color: #37576c; font-size: 13px; line-height: 1.45; }
body.device-mobile #web-mobile-hint { display: block; }
body.device-mobile.game-active .work-goal {
  margin: 0 0 6px;
  padding: 5px 7px;
  font-size: 13px;
  line-height: 1.4;
}
body.device-mobile.game-active .work-goal > strong { display: block; margin: 0; font-size: 13px; }
body.device-mobile.game-active .work-goal > span { display: none; }
body.device-mobile.game-active.prefs-open .work-goal > span { display: block; margin-top: 4px; }
body.device-mobile.game-active .narr { margin-bottom: 7px; font-size: 13px; line-height: 1.45; }
body.device-mobile.game-active .actions.op-desk { flex: 1 0 auto; padding: 0; border: 0; background: transparent; }
body.device-mobile.game-active .op-deck { gap: 7px; }
body.device-mobile.game-active .op-top { padding: 0 0 5px; gap: 5px; }
body.device-mobile.game-active .op-top span { font-size: 14px; }
body.device-mobile.game-active .op-top b { font-size: 12px; }
body.device-mobile.game-active .op-hand,
body.device-mobile.game-active .op-deck:not([data-count="4"]) .op-hand {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-auto-rows: minmax(64px, auto);
  gap: 6px;
}
body.device-mobile.game-active .op-card,
body.device-mobile.game-active .op-deck:not([data-count="4"]) .op-card {
  grid-column: auto;
  grid-template-columns: 32px minmax(0, 1fr);
  grid-template-areas: "ic name" "ic desc";
  min-height: 64px;
  padding: 7px;
  gap: 2px 6px;
}
body.device-mobile.game-active .op-deck[data-count="5"] .op-card:last-child { grid-column: 1 / -1; }
body.device-mobile.game-active .op-card-ic,
body.device-mobile.game-active .op-deck:not([data-count="4"]) .op-card-ic { width: 32px; height: 32px; }
body.device-mobile.game-active .op-card-name,
body.device-mobile.game-active .op-deck:not([data-count="4"]) .op-card-name { font-size: 14px; }
body.device-mobile.game-active .op-card-desc,
body.device-mobile.game-active .op-deck:not([data-count="4"]) .op-card-desc { display: -webkit-box; font-size: 12px; }
body.device-mobile.game-active .op-forecast { display: flex; gap: 3px; padding: 6px 7px; }
body.device-mobile.game-active .op-forecast .op-estimate { font-size: 13px; }
body.device-mobile.game-active .op-estimate-note { font-size: 12px; }
/* Keep the original button and its handlers, within a thumb's reach. */
body.device-mobile.game-active .op-exec {
  position: fixed;
  left: calc(10px + env(safe-area-inset-left, 0px));
  right: calc(10px + env(safe-area-inset-right, 0px));
  bottom: calc(10px + env(safe-area-inset-bottom, 0px));
  z-index: 35;
  width: auto;
  min-height: 54px;
  margin: 0;
  padding: 7px 10px;
  box-shadow: 0 0 0 8px var(--px-navy), 0 -5px 14px #10203644;
}
body.device-mobile.game-active .op-exec b { font-size: 17px; }
body.device-mobile.game-active .op-exec span { font-size: 12px; }
body.device-mobile.device-blocked .op-exec { visibility: hidden; pointer-events: none; }
body.device-mobile .modal,
body.device-mobile .mg-box.mg-app {
  max-height: calc(var(--device-viewport-height, 100dvh) - max(24px, env(safe-area-inset-top, 0px)) - max(12px, env(safe-area-inset-bottom, 0px)));
  overflow-y: auto;
}
body.device-mobile.device-keyboard #modal-layer { align-items: flex-start; overflow-y: auto; }
body.device-mobile.game-active .quickbar { gap: 6px; padding: 11px 9px 3px; }
body.device-mobile.game-active .qbtn { min-height: 44px; }
body.device-mobile.game-active .icp,
body.device-mobile.game-active #btn-mute { display: none; }
body.device-desktop #web-tool-toggle,
body.device-desktop #web-mobile-hint { display: none; }
body.device-desktop.game-active .op-exec { position: static; width: 100%; }

/* Both desktop columns start their own task immediately below the header. */
@media (min-width: 768px) {
  body.device-desktop #app { width: calc(100% - 32px); max-width: 1100px; margin-block: 16px; border: 3px solid #71849f; }
  body.device-desktop.game-active #screen-game.active {
    display: grid;
    grid-template-columns: minmax(0, .94fr) minmax(0, 1.12fr);
    grid-template-rows: auto auto auto auto auto auto auto;
    grid-template-areas: "hud hud" "scene narr" "scene actions" "stats actions" "tools actions" "goal actions" "quick actions";
    gap: 12px 16px;
    align-items: start;
    align-content: start;
    min-height: calc(100svh - 40px);
    padding: 0 16px 20px;
  }
  body.device-desktop.game-active .hud { grid-area: hud; margin: 0 -16px; padding-inline: 18px; }
  body.device-desktop.game-active .panel { display: contents; }
  body.device-desktop.game-active .scene-wrap { grid-area: scene; width: 100%; height: clamp(240px, 30svh, 300px); min-height: 0; margin: 0; }
  body.device-desktop.game-active #scene { height: 100% !important; min-height: 0; max-height: none; aspect-ratio: auto; object-fit: cover !important; object-position: 40% center; }
  body.device-desktop.game-active .stats { grid-area: stats; margin: 0; padding: 10px; border: 3px solid #102036; gap: 8px; }
  body.device-desktop.game-active #web-tools { grid-area: tools; padding: 10px 12px; background: var(--px-paper); border: 2px solid #a9987e; }
  body.device-desktop.game-active .work-goal { grid-area: goal; margin: 0; padding: 9px 11px; }
  body.device-desktop.game-active .work-goal > strong { display: block; margin-bottom: 3px; font-size: 14px; }
  body.device-desktop.game-active .work-goal > span { display: block; }
  body.device-desktop.game-active .narr { grid-area: narr; margin: 0; padding: 11px 13px; color: var(--px-ink); background: var(--px-paper); border: 2px solid #a9987e; font-size: 15px; }
  body.device-desktop.game-active .actions { grid-area: actions; align-self: start; width: 100%; min-width: 0; padding: 12px; background: var(--px-paper); border: 3px solid #102036; }
  body.device-desktop.game-active .op-deck { gap: 10px; }
  body.device-desktop.game-active .op-exec { min-height: 58px; }
  body.device-desktop.game-active .quickbar { grid-area: quick; padding: 0; }
}
@media (min-width: 768px) and (max-width: 1023px) {
  body.device-desktop.game-active .op-card,
  body.device-desktop.game-active .op-deck:not([data-count="4"]) .op-card { grid-template-columns: 28px minmax(0, 1fr); gap: 3px 6px; padding: 8px; }
  body.device-desktop.game-active .op-card-ic,
  body.device-desktop.game-active .op-deck:not([data-count="4"]) .op-card-ic { width: 28px; height: 32px; }
  body.device-desktop.game-active .op-card-name,
  body.device-desktop.game-active .op-deck:not([data-count="4"]) .op-card-name { font-size: 14px; }
  body.device-desktop.game-active .stat-label { flex-wrap: wrap; }
}

/* Short portrait phones keep the day's four choices above the thumb button. */
@media (orientation: portrait) and (max-height: 700px) {
  body.device-mobile.game-active .hud {
    min-height: calc(54px + env(safe-area-inset-top, 0px));
    padding-block: calc(4px + env(safe-area-inset-top, 0px)) 4px;
  }
  body.device-mobile.game-active #scene { height: clamp(64px, 13svh, 92px) !important; object-position: 44% 40%; }
  body.device-mobile.game-active .stats { padding-block: 6px; gap: 5px 7px; }
  body.device-mobile.game-active .panel { padding: 6px; }
  body.device-mobile.game-active #web-tools { padding-bottom: 4px; gap: 4px; }
  body.device-mobile.game-active #web-mobile-hint,
  body.device-mobile.game-active .narr { display: none; }
  body.device-mobile.game-active .work-goal { margin-bottom: 5px; padding-block: 4px; }
  body.device-mobile.game-active .op-deck { gap: 5px; }
  body.device-mobile.game-active .op-top { padding-bottom: 4px; }
  body.device-mobile.game-active .op-hand,
  body.device-mobile.game-active .op-deck:not([data-count="4"]) .op-hand { grid-auto-rows: minmax(56px, auto); gap: 5px; }
  body.device-mobile.game-active .op-card,
  body.device-mobile.game-active .op-deck:not([data-count="4"]) .op-card {
    min-height: 56px;
    grid-template-columns: 26px minmax(0, 1fr);
    padding: 5px 6px;
    gap: 1px 5px;
  }
  body.device-mobile.game-active .op-card-ic,
  body.device-mobile.game-active .op-deck:not([data-count="4"]) .op-card-ic { width: 26px; height: 28px; }
  body.device-mobile.game-active .op-card-desc,
  body.device-mobile.game-active .op-deck:not([data-count="4"]) .op-card-desc { -webkit-line-clamp: 1; }
  body.device-mobile.game-active .op-forecast { padding: 5px 6px; }
}

/* A short touch screen remains a phone: compact office left, decisions right. */
@media (orientation: landscape) and (max-height: 500px) {
  body.device-mobile #screen-title { justify-content: flex-start; min-height: 100svh; padding: 10px max(16px, env(safe-area-inset-right)) 22px max(16px, env(safe-area-inset-left)); }
  body.device-mobile #screen-title .title-inner { display: grid; grid-template-columns: minmax(0, .9fr) minmax(0, 1.1fr); gap: 5px 22px; align-items: center; max-width: 860px; }
  body.device-mobile #screen-title .title-kicker { grid-column: 1 / -1; max-width: none; margin: 0 0 4px; padding-bottom: 5px; }
  body.device-mobile #screen-title #title-canvas { grid-column: 1; grid-row: 2 / 5; width: 100%; max-width: 230px; margin: 0 auto; }
  body.device-mobile #screen-title .logo { grid-column: 1; grid-row: 5; flex-direction: row; justify-content: center; align-items: baseline; gap: 7px; font-size: 34px; }
  body.device-mobile #screen-title .logo .logo-2 { font-size: .7em; }
  body.device-mobile #screen-title .subtitle { grid-column: 1; grid-row: 6; margin: 0; font-size: 12px; }
  body.device-mobile #screen-title .menu { grid-column: 2; grid-row: 2 / 7; width: 100%; max-width: none; gap: 6px; }
  body.device-mobile #screen-title .menu .btn { min-height: 44px; padding: 6px; }
  body.device-mobile #screen-title .menu #btn-new,
  body.device-mobile #screen-title .menu #btn-continue { min-height: 48px; font-size: 16px; }
  body.device-mobile #screen-title .title-tip { grid-column: 1 / -1; min-height: 0; margin: 5px 0 0; font-size: 12px; }
  body.device-mobile #screen-title .title-credit { grid-column: 1 / -1; margin-top: 0; }
  body.device-mobile.game-active #screen-game.active {
    display: grid;
    grid-template-columns: minmax(0, .84fr) minmax(0, 1.16fr);
    grid-template-rows: auto auto auto auto auto auto auto;
    grid-template-areas: "hud hud" "scene actions" "stats actions" "tools actions" "goal actions" "quick actions" "narr actions";
    gap: 7px 10px;
    align-items: start;
    align-content: start;
    padding: 0 calc(10px + env(safe-area-inset-right)) var(--device-cta-space) calc(10px + env(safe-area-inset-left));
  }
  body.device-mobile.game-active .hud { grid-area: hud; margin: 0 -10px; min-height: calc(54px + env(safe-area-inset-top)); padding-block: calc(5px + env(safe-area-inset-top)) 5px; }
  body.device-mobile.game-active .panel { display: contents; }
  body.device-mobile.game-active .scene-wrap { grid-area: scene; margin: 0; }
  body.device-mobile.game-active #scene { height: clamp(112px, 34svh, 146px) !important; }
  body.device-mobile.game-active .stats { grid-area: stats; margin: 0; padding: 6px; border: 3px solid #102036; gap: 6px; }
  body.device-mobile.game-active .stat-label { flex-wrap: wrap; }
  body.device-mobile.game-active .stat-label b { margin-left: auto; }
  body.device-mobile.game-active .stat-label [data-pixel-icon] { width: 16px; height: 16px; }
  body.device-mobile.game-active #web-tools { grid-area: tools; padding: 6px; color: var(--px-ink); background: var(--px-paper); border: 1px solid #a9987e; }
  body.device-mobile.game-active .work-goal { grid-area: goal; margin: 0; }
  body.device-mobile.game-active .quickbar { grid-area: quick; padding: 0; }
  body.device-mobile.game-active .narr { grid-area: narr; margin: 0; padding: 7px; background: var(--px-paper); border: 1px solid #a9987e; }
  body.device-mobile.game-active .actions.op-desk { grid-area: actions; width: 100%; min-width: 0; padding: 8px; color: var(--px-ink); background: var(--px-paper); border: 3px solid #102036; }
  body.device-mobile.game-active .op-hand,
  body.device-mobile.game-active .op-deck:not([data-count="4"]) .op-hand { grid-auto-rows: minmax(60px, auto); }
  body.device-mobile.game-active .op-card,
  body.device-mobile.game-active .op-deck:not([data-count="4"]) .op-card { min-height: 60px; grid-template-columns: 26px minmax(0, 1fr); padding: 6px; }
  body.device-mobile.game-active .op-card-ic,
  body.device-mobile.game-active .op-deck:not([data-count="4"]) .op-card-ic { width: 26px; height: 28px; }
  body.device-mobile.game-active .op-exec { left: calc(42% + 5px); right: calc(10px + env(safe-area-inset-right)); }
}

@media (prefers-reduced-motion: reduce) {
  #web-tool-details, #web-tool-toggle { transition: none; }
}
