/* Compact play layout. The desktop game and server state are unchanged. */
.mobile-game-head,
.mobile-chronicle-strip,
.mobile-tabs,
.secret-action-icon {
  display: none;
}

@media (max-width: 860px) {
  body.in-play {
    overflow: hidden;
  }

  body.in-play .app {
    z-index: auto;
    width: 100%;
    height: 100dvh;
    min-height: 0;
    padding: 0 12px;
    overflow: hidden;
  }

  body.in-play .app > header {
    display: none;
  }

  body.in-play .sound-toggle {
    top: 10px;
    right: 12px;
    min-height: 32px;
    padding: 4px 8px;
    font-size: 10px;
    background: #111d16ed;
    border: 1px solid #76836266;
    border-radius: 4px;
  }

  body.in-play .sound-panel {
    top: 48px;
    right: 12px;
  }

  body.in-play #room-toolbar {
    order: 1;
    justify-content: space-between;
    gap: 5px;
    margin: 0;
    padding: 4px 51px 6px 0;
    border-bottom: 1px solid #72846135;
    font-size: 10px;
  }

  body.in-play #room-toolbar #room-name-label,
  body.in-play #room-toolbar #room-expiry {
    display: none;
  }

  body.in-play #room-toolbar button,
  body.in-play #room-toolbar a {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 32px;
    padding: 3px 7px;
    font-size: 10px;
    letter-spacing: 0;
    text-transform: none;
  }

  body.in-play #room-toolbar a {
    text-decoration: none;
  }

  body.in-play #hero-code-notice {
    order: 2;
    flex: none;
    margin: 0;
    padding: 3px 0;
    color: #b9c4af;
    font: 9px/1.25 var(--ui);
  }

  body.in-play #game-screen {
    order: 3;
    flex: 1 1 auto;
    min-height: 0;
    padding-bottom: calc(63px + env(safe-area-inset-bottom));
  }

  body.in-play .mobile-game-head {
    display: flex;
    flex: none;
    align-items: flex-end;
    justify-content: space-between;
    min-height: 57px;
    gap: 12px;
    padding: 10px 2px 8px;
    border-bottom: 1px solid #8f9b7155;
    background: linear-gradient(90deg, #18271b, #101a14);
  }

  .mobile-game-head > div {
    min-width: 0;
  }

  .mobile-game-identity {
    flex: 1 1 auto;
  }

  .mobile-game-meta {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
    white-space: nowrap;
  }

  .mobile-game-eyebrow {
    display: block;
    color: #d8b879;
    font: 9px/1.2 var(--ui);
    letter-spacing: .14em;
  }

  #mobile-room-name {
    display: block;
    overflow: hidden;
    color: #f1ead5;
    font: normal 18px/1.15 var(--story);
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .mobile-game-progress {
    display: flex;
    flex: none;
    flex-direction: column;
    gap: 2px;
    align-items: flex-end;
    max-width: 74px;
    margin-right: 68px;
    text-align: right;
  }

  #mobile-round {
    color: #d8b879;
    font: 10px/1.2 var(--ui);
  }

  #mobile-turn {
    color: #abbca5;
    font: 9px/1.2 var(--ui);
    font-weight: normal;
  }

  body.in-play #game-screen .stage {
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    flex-wrap: nowrap;
    gap: 7px;
    min-height: 0;
    margin-top: 8px;
    overflow: hidden;
  }

  body.in-play #game-screen .party-panel {
    display: flex;
    flex: none;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
  }

  /* Story keeps the journal; the full roster remains in the Party tab. */
  body.in-play #game-screen[data-mobile-view="story"] .party-panel {
    display: none;
  }

  body.in-play #game-screen .party-panel > .section-caption {
    display: block;
    margin: 0 0 5px;
    color: #a7b89f;
    font-size: 9px;
  }

  body.in-play #game-screen .party-col {
    display: flex;
    flex: none;
    flex-direction: row;
    gap: 6px;
    width: 100%;
    max-height: 76px;
    padding: 0 0 3px;
    overflow: auto hidden;
    scrollbar-width: thin;
  }

  body.in-play #game-screen .party-col > details {
    display: none;
  }

  body.in-play #game-screen .hero-card {
    flex: 0 0 104px;
    width: 104px;
    min-width: 104px;
    min-height: 66px;
    gap: 5px;
    padding: 7px 6px;
    border-color: #75825c55;
    background: #172319e8;
  }

  body.in-play #game-screen .hero-card.me {
    border-color: #d1b67eaa;
    background: #273323f0;
  }

  body.in-play #game-screen .hero-card .avatar {
    flex: none;
    width: 23px;
    height: 23px;
  }

  body.in-play #game-screen .hero-card .who strong {
    display: block;
    max-width: 100%;
    overflow: hidden;
    font-size: 11px;
    line-height: 1.1;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  body.in-play #game-screen .hero-card .who .muted,
  body.in-play #game-screen .hero-card .hero-level,
  body.in-play #game-screen .hero-card .status,
  body.in-play #game-screen .hero-card .hero-location {
    display: none;
  }

  body.in-play #game-screen .hero-card .hp-line {
    gap: 2px;
    margin-top: 5px;
  }

  body.in-play #game-screen .hero-card .hp-bar {
    display: none;
  }

  body.in-play #game-screen .hero-card .who {
    flex: 1;
    min-width: 0;
  }

  body.in-play #game-screen .hero-card .hp-num {
    font-size: 8px;
    white-space: nowrap;
  }

  body.in-play #game-screen .hero-color-swatch {
    top: 5px;
    right: 5px;
    width: 7px;
    height: 7px;
  }

  body.in-play #game-screen .chat-panel,
  body.in-play #game-screen .side-rail {
    display: none;
  }

  body.in-play #game-screen .scene {
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
  }

  body.in-play #game-screen .adventure {
    flex: none;
    padding-bottom: 7px;
  }

  body.in-play #game-screen .adventure h2 {
    margin: 1px 0;
    font-size: 19px;
  }

  body.in-play #game-screen .adventure .location {
    margin: 4px 0 0;
    padding-right: 0;
  }

  body.in-play #game-screen[data-mobile-view="story"] #adventure-banner {
    display: none;
  }

  body.in-play #game-screen[data-mobile-view="story"] #adventure-title,
  body.in-play #game-screen[data-mobile-view="story"] #adventure-location {
    display: none;
  }

  body.in-play #game-screen #new-adventure {
    position: static;
  }

  body.in-play #game-screen .journal-heading {
    flex: none;
    padding: 9px 12px;
    font-size: 9px;
  }

  body.in-play #game-screen #log {
    flex: 1 1 auto;
    height: auto;
    min-height: 0;
    padding: 15px 14px 24px;
    overflow-y: auto;
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
    font-size: 13.5px;
    line-height: 1.45;
  }

  body.in-play #game-screen #log .game-master {
    line-height: 1.64;
    margin-bottom: 16px;
  }

  body.in-play #game-screen #log .round-title {
    margin: 18px 0 10px;
    font-size: 9px;
  }

  body.in-play #game-screen #log .quote-name,
  body.in-play #game-screen #log .system {
    font-size: 9.9px;
  }

  body.in-play #game-screen #log .dice-kicker {
    font-size: 9px;
  }

  body.in-play #game-screen #log .dice-grid span {
    font-size: 9.9px;
  }

  body.in-play #game-screen #log .dice-grid strong {
    font-size: 14.4px;
  }

  body.in-play #game-screen #log .dice-result {
    font-size: 11.7px;
  }

  body.in-play #game-screen .mobile-chronicle-strip {
    display: flex;
    flex: none;
    align-items: center;
    gap: 7px;
    min-height: 35px;
    padding: 6px 9px;
    overflow: hidden;
    border: 1px solid #74815d55;
    border-top: 0;
    border-radius: 0 0 6px 6px;
    background: #202b1eea;
    font: 10px/1.2 var(--ui);
  }

  body.in-play #game-screen[data-mobile-view="story"] .mobile-chronicle-strip {
    display: none;
  }

  body.in-play #game-screen[data-mobile-view="story"] #log {
    border-radius: 0 0 7px 7px;
  }

  .mobile-chronicle-strip > :first-child,
  .mobile-chronicle-strip strong {
    flex: none;
    color: #d8b879;
    font-weight: normal;
  }

  #mobile-chronicle-text {
    overflow: hidden;
    color: #c7d1ba;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  body.in-play #game-screen #action-form {
    position: relative;
    flex: none;
    grid-template-columns: minmax(0, 1fr);
    gap: 4px;
    min-width: 0;
    margin: 0;
    padding: 4px 0;
    background: #101a14f5;
  }

  body.in-play #game-screen[data-mobile-view="story"] #action-form > :not(.dock-line):not(#round-hint):not(#secret-action-help):not(#death-note) {
    display: none;
  }

  body.in-play #game-screen .dock-line {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 48px 30px;
    gap: 6px;
    align-items: center;
    grid-column: 1;
    min-width: 0;
  }

  body.in-play #game-screen #action-input {
    grid-column: 1;
    grid-row: 1;
    flex: initial;
    width: 100%;
    min-height: 48px;
    margin: 0;
    padding: 8px 10px;
    font-size: 16px;
  }

  body.in-play #game-screen #ready-button {
    grid-column: 1 / -1;
    grid-row: 2;
    width: 100%;
    min-width: 0;
    min-height: 40px;
    padding: 8px 10px;
    background: #b99a62;
    color: #111a12;
    font-size: 12px;
  }

  body.in-play #game-screen .dock-line .secret-action {
    grid-column: 2;
    grid-row: 1;
    align-self: stretch;
    justify-self: stretch;
    flex-direction: column;
    justify-content: center;
    gap: 2px;
    width: 48px;
    min-height: 48px;
    padding: 2px;
    border: 1px solid #74815d70;
    border-radius: 4px;
    background: #172319;
    cursor: pointer;
  }

  body.in-play #game-screen .dock-line .secret-action-text {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
  }

  body.in-play #game-screen .dock-line .secret-action-icon {
    display: block;
    order: -1;
    width: 22px;
    height: 22px;
    color: #d8b879;
  }

  body.in-play #game-screen .dock-line .secret-action input {
    accent-color: #d8b879;
  }

  body.in-play #game-screen .dock-line .secret-rule {
    grid-column: 3;
    grid-row: 1;
    justify-self: end;
  }

  body.in-play #game-screen #round-hint,
  body.in-play #game-screen #secret-action-help,
  body.in-play #game-screen #death-note {
    grid-column: 1;
    margin: 0;
    font-size: 10px;
  }

  body.in-play #game-screen[data-mobile-view="story"] #round-hint.waiting-for-offline {
    display: none;
  }

  body.in-play #game-screen #secret-rule-tooltip {
    bottom: calc(100% + 4px);
    width: min(320px, 86vw);
  }

  body.in-play #game-screen .mobile-tabs {
    position: fixed;
    z-index: 60;
    right: 0;
    bottom: 0;
    left: 0;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    height: calc(62px + env(safe-area-inset-bottom));
    padding: 2px 7px env(safe-area-inset-bottom);
    border-top: 1px solid #7b896955;
    background: #111b15f9;
    box-shadow: 0 -8px 24px #0005;
  }

  body.in-play #game-screen .mobile-tabs button {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    min-width: 0;
    min-height: 50px;
    margin: 0 2px;
    padding: 2px;
    border: 0;
    border-top: 2px solid transparent;
    background: transparent;
    color: #aebaab;
    font: 10px/1.1 var(--ui);
  }

  body.in-play #game-screen .mobile-tabs button > span {
    color: currentColor;
    font: 23px/1 var(--story);
  }

  body.in-play #game-screen .mobile-tabs button.active {
    border-top-color: #d8b879;
    color: #e5c888;
  }

  #mobile-chat-badge {
    position: absolute;
    top: 4px;
    right: 13%;
    min-width: 16px;
    height: 16px;
    padding: 0 3px;
    border-radius: 50%;
    background: #c98068;
    color: #101a13;
    font: bold 10px/16px var(--ui);
    text-align: center;
  }

  /* Chat uses the existing server-backed chat panel and form. */
  body.in-play #game-screen[data-mobile-view="chat"] .party-panel {
    flex: 1 1 auto;
  }

  body.in-play #game-screen[data-mobile-view="chat"] .party-panel > .section-caption,
  body.in-play #game-screen[data-mobile-view="chat"] .party-col,
  body.in-play #game-screen[data-mobile-view="chat"] .scene,
  body.in-play #game-screen[data-mobile-view="chat"] #action-form {
    display: none;
  }

  body.in-play #game-screen[data-mobile-view="chat"] .chat-panel {
    display: flex;
    flex: 1 1 auto;
    min-height: 0;
    height: auto;
    margin: 0;
    padding: 15px 12px;
    overflow: hidden;
  }

  body.in-play #game-screen[data-mobile-view="chat"] #chat-messages {
    overflow-y: auto;
    font-size: 14px;
  }

  body.in-play #game-screen[data-mobile-view="chat"] #chat-form {
    flex: none;
  }

  body.in-play #game-screen[data-mobile-view="chat"] #chat-input {
    min-height: 44px;
    margin-bottom: 7px;
  }

  body.in-play #game-screen[data-mobile-view="chat"] #chat-form button {
    min-height: 44px;
    background: #b99a62;
    color: #111a12;
  }

  /* The roster and compact tools share one scrollable view. */
  body.in-play #game-screen[data-mobile-view="party"] .stage {
    overflow-y: auto;
    scrollbar-color: #526046 #141b15;
    scrollbar-width: thin;
  }

  body.in-play #game-screen[data-mobile-view="party"] .party-panel {
    flex: none;
    overflow: visible;
  }

  body.in-play #game-screen[data-mobile-view="party"] .party-panel > .section-caption {
    font-size: 11px;
    margin-bottom: 9px;
  }

  body.in-play #game-screen[data-mobile-view="party"] .party-col {
    flex-direction: column;
    max-height: none;
    overflow: visible;
  }

  body.in-play #game-screen[data-mobile-view="party"] .party-col > details {
    display: block;
    width: 100%;
  }

  body.in-play #game-screen[data-mobile-view="party"] .hero-card {
    flex: none;
    width: 100%;
    min-height: 76px;
    padding: 10px 12px;
  }

  body.in-play #game-screen[data-mobile-view="party"] .hero-card .avatar {
    width: 36px;
    height: 36px;
  }

  body.in-play #game-screen[data-mobile-view="party"] .hero-card .who strong {
    font-size: 16px;
  }

  body.in-play #game-screen[data-mobile-view="party"] .hero-card .who .muted,
  body.in-play #game-screen[data-mobile-view="party"] .hero-card .hero-level,
  body.in-play #game-screen[data-mobile-view="party"] .hero-card .status,
  body.in-play #game-screen[data-mobile-view="party"] .hero-card .hero-location {
    display: block;
  }

  body.in-play #game-screen[data-mobile-view="party"] .scene {
    display: none;
  }

  body.in-play #game-screen[data-mobile-view="party"] .side-rail {
    display: grid;
    flex: none;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 8px;
    overflow: visible;
  }

  body.in-play #game-screen[data-mobile-view="party"] .side-rail > * {
    grid-column: auto;
    grid-row: auto;
  }

  body.in-play #game-screen[data-mobile-view="party"] .chronicle-panel {
    grid-column: 1 / -1;
    height: auto;
    min-height: 180px;
    max-height: 240px;
  }

  body.in-play #game-screen[data-mobile-view="party"] .die-window,
  body.in-play #game-screen[data-mobile-view="party"] .turn-window {
    display: block;
    min-height: 80px;
    text-align: center;
  }

  body.in-play #game-screen[data-mobile-view="party"] #recovery-button {
    grid-column: 1 / -1;
  }

  body.in-play #game-screen[data-mobile-view="party"] #action-form {
    max-height: 29dvh;
    padding: 8px 0;
    overflow-y: auto;
  }

  body.in-play #game-screen[data-mobile-view="party"] #action-form > label[for="action-input"],
  body.in-play #game-screen[data-mobile-view="party"] #action-form > .dock-line,
  body.in-play #game-screen[data-mobile-view="party"] #action-form > #round-hint,
  body.in-play #game-screen[data-mobile-view="party"] #action-form > #secret-action-help,
  body.in-play #game-screen[data-mobile-view="party"] #action-form > #death-note {
    display: none;
  }

  body.in-play #game-screen[data-mobile-view="party"] #action-form > * {
    grid-column: 1;
  }

  body.in-play #game-screen[data-mobile-view="party"] #host-controls {
    max-height: none;
  }

  body.in-play #game-screen[data-mobile-view="hero"] .stage,
  body.in-play #game-screen[data-mobile-view="hero"] #action-form {
    display: none;
  }

  body.in-play #profile-modal:not([hidden]) {
    z-index: 40;
    inset: 0 0 calc(62px + env(safe-area-inset-bottom));
    align-items: stretch;
    padding: 8px 12px 0;
    background: #101a14;
  }

  body.in-play #profile-card {
    width: 100%;
    height: 100%;
    max-height: none;
    padding: 16px 12px 28px;
    overflow-y: auto;
    border-radius: 6px 6px 0 0;
    box-shadow: none;
  }

  body.in-play #profile-card .icon-text {
    display: inline-flex;
    align-items: center;
    gap: 5px;
  }

  body.in-play #profile-card .attribute-list,
  body.in-play #profile-card .derived-list {
    display: grid;
    gap: 7px;
  }

  body.in-play #profile-card .attribute-row,
  body.in-play #profile-card .derived-row {
    display: grid;
    grid-template-columns: 30px minmax(0, 1fr) auto;
    align-items: center;
    gap: 7px;
    min-width: 0;
    padding: 8px 7px;
    border: 1px solid #74815d35;
    border-radius: 4px;
    background: #172118;
  }

  body.in-play #profile-card .attribute-row {
    grid-template-columns: 30px minmax(0, 1fr) auto 34px;
  }

  body.in-play #profile-card .attribute-row > .stat-icon,
  body.in-play #profile-card .derived-row > .stat-icon {
    --icon-size: 28px;
  }

  body.in-play #profile-card .attribute-description,
  body.in-play #profile-card .derived-description {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
  }

  body.in-play #profile-card .attribute-description strong,
  body.in-play #profile-card .derived-description strong {
    color: #e9e4d5;
    font: 13px/1.2 var(--story);
  }

  body.in-play #profile-card .attribute-description small,
  body.in-play #profile-card .derived-description small {
    color: #aab7a3;
    font: 10px/1.3 var(--ui);
    overflow-wrap: anywhere;
  }

  body.in-play #profile-card .attribute-value,
  body.in-play #profile-card .derived-value {
    color: #e1c68d;
    font: 15px/1 var(--ui);
    white-space: nowrap;
  }

  body.in-play #profile-card .attribute-upgrade {
    width: 34px;
    min-width: 34px;
    min-height: 34px;
    padding: 0;
    border: 1px solid #9d8a5d;
    border-radius: 4px;
    font: 18px/1 var(--ui);
  }

  body.in-play #profile-card .attribute-upgrade:disabled {
    opacity: .45;
  }
}

@media (max-width: 370px) {
  body.in-play .mobile-game-head {
    padding-right: 2px;
  }

  body.in-play #game-screen .hero-card {
    flex-basis: 94px;
    width: 94px;
    min-width: 94px;
  }
}

@media (max-width: 860px) and (max-height: 500px) {
  body.in-play,
  body.in-play .app {
    height: auto;
    min-height: 100dvh;
    overflow: auto;
  }

  body.in-play #game-screen {
    min-height: 570px;
  }

  body.in-play #game-screen .stage {
    min-height: 350px;
  }
}
