.helm-options { display: contents; }
.touch-helm, .sea-mobile-bar, .sea-mobile-shore, .sea-voyage .sea-mobile-note { display: none; }

@media (max-width: 600px), (orientation: landscape) and (max-width: 1024px) and (max-height: 540px) {
  :root {
    --phone-top: calc(52px + env(safe-area-inset-top, 0px));
    --phone-bottom: calc(56px + env(safe-area-inset-bottom, 0px));
    --phone-left: max(10px, env(safe-area-inset-left, 0px));
    --phone-right: max(10px, env(safe-area-inset-right, 0px));
    -webkit-text-size-adjust: 100%;
  }

  body:not(.world-page) { min-width: 0; padding-bottom: var(--phone-bottom); }
  body.world-page { overscroll-behavior: none; }
  .topbar, .world-page .topbar { height: var(--phone-top); }
  .top-inner, .world-page .top-inner {
    flex-wrap: nowrap;
    padding: env(safe-area-inset-top, 0px) var(--phone-right) 0 var(--phone-left);
  }
  .brand { gap: 8px; }
  .brand small { display: none; }
  .top-right { gap: 8px; }
  .settings-button { width: 44px; height: 44px; }
  .topbar .navigation {
    position: fixed;
    z-index: 8;
    inset: auto 0 0;
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    height: var(--phone-bottom);
    padding: 0 var(--phone-right) env(safe-area-inset-bottom, 0px) var(--phone-left);
    background: #f3eee2;
    border-top: 1px solid #c7baa0;
  }
  .navigation a {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-height: 48px;
    padding: 4px 0 3px;
    font-size: 12px;
  }
  .topbar .navigation .ui-icon { width: 19px; height: 19px; }
  .navigation a[aria-current="page"] { background: #e8e3d4; }
  .navigation a[aria-current="page"]::after { inset: -1px 23% auto; height: 2px; }

  body:not(.world-page) .workspace { padding: 10px var(--phone-right) 0 var(--phone-left); }
  .workspace .masthead { display: none; }
  .workspace .masthead.masthead--calendar {
    display: flex;
    background-color: #ece5d5;
    background-position: right 53%;
    min-height: 0;
  }
  .masthead--calendar .masthead-shade {
    background: linear-gradient(90deg, #f4edddfc, #f4eddde3 55%, #f4edddab);
  }
  .masthead-calendar {
    grid-template-columns: minmax(108px, 1fr) minmax(188px, 1.25fr);
    gap: 10px;
    margin: 8px 10px;
    padding-block: 5px 7px;
    width: min(calc(100% - 20px), 346px);
  }
  .masthead-calendar .calendar-era select { font-size: 16px; padding-inline: 9px 24px; }
  .calendar-era-control::after { right: 10px; }
  .calendar-season-choice span { font-size: 18px; }
  body:not(.world-page) .workspace .desk { margin-top: 10px; }
  .world-page .main-panel:is(.sea-panel,.deck-panel) {
    height: calc(100vh - var(--phone-top) - var(--phone-bottom));
    height: calc(100dvh - var(--phone-top) - var(--phone-bottom));
  }
  .sea-world > canvas { min-height: 0 !important; }
  .sea-overlay {
    display: grid;
    grid-template-rows: 44px minmax(0, 1fr) auto auto;
    align-items: start;
    padding: 8px var(--phone-right) 8px var(--phone-left);
  }
  .sea-mobile-bar {
    grid-row: 1;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto auto;
    gap: 5px;
  }
  .sea-mobile-bar .btn {
    min-width: 48px;
    min-height: 44px;
    padding: 0 8px;
    background: #f3edde;
  }
  .sea-mobile-bar .btn[aria-expanded="true"] { background: #e7dbc1; border-color: #9f8864; }
  .sea-mobile-bar .sea-mobile-reading {
    display: flex;
    min-width: 0;
    justify-content: flex-start;
    gap: 7px;
    padding-inline: 10px;
  }
  .sea-mobile-reading strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
  #sea-mobile-speed { flex: none; color: #43574c; font-size: 12px; font-variant-numeric: tabular-nums; }
  .sea-disclosure-mark {
    flex: none;
    width: 6px;
    height: 6px;
    margin-left: auto;
    border: solid #705a43;
    border-width: 0 1px 1px 0;
    transform: translateY(-2px) rotate(45deg);
  }
  .sea-mobile-reading[aria-expanded="true"] .sea-disclosure-mark { transform: translateY(2px) rotate(225deg); }

  .sea-overlay :is(.sea-voyage, .sea-view-modes, .helm-options) {
    position: absolute;
    z-index: 2;
    inset: 57px var(--phone-right) auto var(--phone-left);
    width: auto;
    max-width: 390px;
    max-height: calc(100% - 127px);
    display: none;
    overflow-y: auto;
    overscroll-behavior: contain;
    pointer-events: auto;
    padding: 9px 10px;
  }
  .sea-overlay[data-sea-panel="voyage"] .sea-voyage,
  .sea-overlay[data-sea-panel="helm"] #helm-options { display: block; }
  .sea-overlay[data-sea-panel="views"] .sea-view-modes { display: grid; }
  .sea-voyage h2 { margin-block: 2px 3px; font-size: 21px; }
  .sea-voyage p:first-child, .sea-voyage small { font-size: 12px; }
  .sea-dials { margin-top: 7px; padding-top: 6px; }
  .sea-dials dd { font-size: 15px; }
  .sea-voyage .sea-mobile-note { display: block; margin-top: 8px; color: #5b5145; }
  .sea-view-modes { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 5px; }
  .sea-view-modes .btn { min-height: 44px; min-width: 0; padding-inline: 4px; }
  .sea-view-modes .sea-mobile-shore { display: inline-flex; }
  .sea-orbit-hint {
    grid-column: 1 / -1;
    position: static;
    padding: 4px 1px 0;
    color: #43554c;
    background: transparent;
    border: 0;
    white-space: normal;
  }
  .sea-station #helm-options { background: #f3edde; border: 1px solid #c5b598; box-shadow: 0 4px 16px #1727213f; }
  .helm-options [data-action="helm-turn"], .helm-options [data-action="helm-trim"],
  .helm-options [data-action="helm-anchor"], .helm-options .speed-controls { display: none; }
  .sea-notice { position: static; grid-row: 3; justify-self: center; transform: none; margin-bottom: 5px; max-width: 100%; }
  .sea-notice .btn { min-height: 44px; max-width: 100%; white-space: normal; }
  .sea-station {
    grid-row: 4;
    position: static;
    transform: none;
    width: min(100%, 355px);
    justify-self: center;
    padding: 0;
    background: transparent;
    border: 0;
    box-shadow: none;
    pointer-events: none;
  }
  .sea-station :is(.btn,select) { min-height: 44px; }
  .sea-keys { display: none; }
  .touch-helm { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 5px; }
  .touch-assist { grid-column: 1 / -1; justify-self: end; }
  .touch-assist .btn { padding-inline: 11px; box-shadow: 0 2px 8px #152b2466; }
  .touch-steering, .touch-commands {
    display: grid;
    gap: 3px;
    padding: 3px;
    background: #eee7d6ed;
    border-radius: 4px;
    box-shadow: 0 3px 12px #182e2852;
  }
  .touch-steering { grid-template-columns: repeat(2, 44px); }
  .touch-steering .touch-rudder {
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    color: #fff8e7;
    background: #46584d;
    border-color: #46584d;
    padding: 0;
    font-size: 29px;
    line-height: 1;
  }
  .touch-rudder:active { background: #2c3f36; }
  .touch-commands { grid-template-columns: minmax(57px, 1fr) minmax(112px, 1.54fr); }
  .touch-commands > [data-action="helm-anchor"] { padding: 2px 3px; font-size: 12px; white-space: normal; }
  .touch-commands > [data-action="helm-anchor"] .ui-icon { display: none; }
  .touch-commands .speed-controls { grid-template-columns: 44px minmax(22px, 1fr) 44px; gap: 0; border-block: 0; }
  .touch-commands .speed-order { padding-inline: 0; font-size: 11px; }
  .touch-sail { display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: center; gap: 4px; padding-left: 4px; font-size: 12px; }
  .touch-sail select { min-width: 0; width: 100%; padding-inline: 3px; }
  .world-page .toast { bottom: calc(var(--phone-bottom) + 105px); }

  .main-panel.chart-panel { min-height: 0; }
  .chart-host { height: clamp(280px, 48svh, 390px); }
  .sidebar { grid-template-columns: minmax(0, 1fr); }
  .card .btn, .ship-card .btn, .journal-tabs button, .time-panel .btn, .nav-destination, .sailing-difficulty select { min-height: 44px; }
  .time-panel .btn { font-size: 13px; }
  .time-date .ui-icon { display: none; }

  dialog {
    width: min(600px, calc(100% - var(--phone-left) - var(--phone-right)));
    max-width: none;
    max-height: calc(100dvh - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px) - 16px);
    overscroll-behavior: contain;
    margin: auto auto max(8px, env(safe-area-inset-bottom, 0px));
  }
  .dialog-heading { position: sticky; top: 0; z-index: 2; }
  .dialog-heading h2 { font-size: 24px; }
  .dialog-heading .icon-button, .dialog-body :is(.btn,.choice,.crew-row) { min-height: 44px; }
  .dialog-heading .icon-button { min-width: 44px; }
  .dialog-body :is(input,textarea,select), .sea-station select { font-size: 16px; }
  .dialog-body .chat-log { max-height: min(205px, 30dvh); }
  .dialog-body .quick-prompts .btn { font-size: 12px; }
}

@media (max-width: 379px) {
  .masthead-calendar { grid-template-columns: 1fr; gap: 7px; }
  .calendar-era, .calendar-season { grid-template-columns: 42px minmax(0, 1fr); align-items: center; }
}

@media (orientation: landscape) and (max-width: 1024px) and (max-height: 540px) {
  :root { --phone-top: calc(46px + env(safe-area-inset-top, 0px)); --phone-bottom: calc(46px + env(safe-area-inset-bottom, 0px)); }
  .navigation a { min-height: 44px; flex-direction: row; gap: 5px; }
  .sea-mobile-reading { justify-self: start; width: min(100%, 255px); }
  .sea-overlay :is(.sea-view-modes, #helm-options) { left: auto; width: min(350px, calc(100% - var(--phone-left) - var(--phone-right))); }
}
