/* Chart Room shell — Phase 1, Task 6 (board B1's top bar and chart thumbnail, B4's phone bar).
   Every rule is scoped under [data-ui="chartroom"] (on <body>) so Sjøfart never sees any of it
   (docs/chart-room/ROADMAP.md ruling 1). Tokens and materials come from tokens.css, plates and
   the focus ring from controls.css. Anything with [data-cr-depth] takes its shadow and radius
   through --cr-sh / --cr-r (tokens.css).

   The globe is not restyled: the viewport keeps every rule fleet.css gives it; this sheet only
   places its box inside the chart host (the scene re-measures on resize()). Nothing here
   animates on its own; hovers use the four Sjøfart durations. */

/* The Sjøfart shell is not part of the Chart Room. fleet-entry.js moves the globe viewport,
   its frame, the harbour credit, the fallback and the helm HUD out of #fleet-app into the
   Chart Room (the chart host while the chart is open, a hidden holder otherwise), so the
   rest of #fleet-app stays out of the way. Its controls (#btn-account, #btn-motion) still work
   when the Chart Room forwards a click to them. */
body[data-ui="chartroom"] #fleet-app { display: none; }

body[data-ui="chartroom"] #chartroom {
  position: fixed;
  inset: 0;
  display: block;
  overflow: hidden;
  background:
    radial-gradient(ellipse 70% 60% at 50% 40%, rgba(40, 84, 104, .35), rgba(10, 34, 48, 0) 70%),
    var(--cr-sea);
  color: var(--cr-ink);
  font: 400 var(--cr-t-floor)/1.4 var(--cr-body);
}
body[data-ui="chartroom"] #chartroom [hidden] { display: none !important; }

[data-ui="chartroom"] .cr-app {
  position: relative;
  height: 100%;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}
[data-ui="chartroom"] .cr-app :focus-visible { outline: 3px solid var(--cr-focus); outline-offset: 2px; }

/* ---- Top bar --------------------------------------------------------------------------- */

[data-ui="chartroom"] .cr-top {
  position: relative;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 66px;
  padding: 0 16px 0 0;
  box-sizing: border-box;
  border-bottom: 3px solid #4F6B78;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .08), 0 3px 0 rgba(0, 0, 0, .35), 0 10px 24px rgba(0, 0, 0, .35);
}
[data-ui="chartroom"] .cr-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  align-self: stretch;
  padding: 0 18px;
  background: linear-gradient(180deg, #16405A, #0C2A3A);
  border-right: 1px solid rgba(201, 151, 58, .45);
  flex-shrink: 0;
}
[data-ui="chartroom"] .cr-mark { flex-shrink: 0; }
[data-ui="chartroom"] .cr-wordmark {
  font: 800 24px/1 var(--cr-stencil);
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--cr-paper);
  white-space: nowrap;
}
[data-ui="chartroom"] .cr-brand__tab { display: none; }

[data-ui="chartroom"] .cr-nav { display: flex; align-items: center; gap: 4px; flex-shrink: 0; }
[data-ui="chartroom"] .cr-navtab {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 44px;
  padding: 0 10px;
  margin: 0;
  box-sizing: border-box;
  cursor: pointer;
  font: 700 15px/1 var(--cr-cond);
  letter-spacing: .06em;
  text-transform: uppercase;
  white-space: nowrap;
  color: #D5E2E6;
  border: 1px solid rgba(0, 0, 0, .45);
  background: linear-gradient(180deg, rgba(0, 0, 0, .28), rgba(0, 0, 0, .12));
  text-shadow: 0 -1px 0 rgba(0, 0, 0, .6);
  --cr-r: 2px;
  --cr-sh: inset 0 1px 3px rgba(0, 0, 0, .6), 0 1px 0 rgba(255, 255, 255, .09);
  transition: color var(--cr-d-snap) var(--cr-ease), background-color var(--cr-d-snap) var(--cr-ease);
}
/* The phone's More menu; on a desk the shell renders the plain row (no More), in DOM order */
[data-ui="chartroom"] .cr-nav__more { display: contents; }
[data-ui="chartroom"] .cr-navtab.cr-navtab--more { display: none; }
[data-ui="chartroom"] .cr-navtab:not(.cr-brass):hover { color: #FFF6DC; background: linear-gradient(180deg, rgba(255, 255, 255, .07), rgba(0, 0, 0, .1)); }
[data-ui="chartroom"] .cr-navtab.cr-brass {
  background: var(--cr-brass) url(../../../assets/chartroom/brass.png) center / 100% 100% no-repeat;
  color: var(--cr-brass-ink);
  border-color: var(--cr-brass-dark);
  text-shadow: 0 1px 0 rgba(255, 235, 180, .5);
  --cr-sh: inset 0 2px 6px rgba(60, 35, 5, .6), inset 0 0 0 1px var(--cr-brass-dark);
}
[data-ui="chartroom"] .cr-navtab__count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 24px;
  height: 24px;
  padding: 0 5px;
  box-sizing: border-box;
  border-radius: 12px;
  background: var(--cr-ink);
  color: #FFF6DC;
  font: 700 15px/1 var(--cr-cond);
  text-shadow: none;
  box-shadow: 0 0 0 2px #2A1D07;
}

[data-ui="chartroom"] .cr-top__end {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 14px;
  flex: 1 1 auto;
  min-width: 0;
  margin-left: auto;
}

/* Find a ship */
[data-ui="chartroom"] .cr-find { position: relative; flex: 0 1 220px; min-width: 120px; }
[data-ui="chartroom"] .cr-find .cr-find__toggle { display: none; }
[data-ui="chartroom"] .cr-find__box {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 44px;
  padding: 0 10px;
  box-sizing: border-box;
  background: rgba(4, 16, 24, .55);
  border: 1px solid rgba(169, 196, 204, .3);
  border-radius: 2px;
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, .5);
  color: #A9BEC6;
  cursor: text;
}
[data-ui="chartroom"] .cr-find__box:focus-within { border-color: var(--cr-brass); outline: 3px solid var(--cr-focus); outline-offset: 2px; }
[data-ui="chartroom"] .cr-app .cr-find__input:focus-visible { outline: none; }
[data-ui="chartroom"] .cr-find__input {
  flex: 1;
  min-width: 0;
  height: 42px;
  border: 0;
  padding: 0;
  background: transparent;
  color: var(--cr-paper);
  font: 500 15px var(--cr-body);
  outline: none;
}
[data-ui="chartroom"] .cr-find__input::placeholder { color: #A9BEC6; opacity: 1; }
[data-ui="chartroom"] .cr-find__pop {
  position: absolute;
  z-index: 20;
  top: calc(100% + 6px);
  left: 0;
  width: min(340px, calc(100vw - 32px));
  max-height: min(420px, 70vh);
  overflow: auto;
  --cr-r: 2px;
  --cr-sh: 0 14px 30px rgba(0, 0, 0, .5), 0 0 0 1px rgba(122, 85, 24, .6);
}
[data-ui="chartroom"] .cr-find__head {
  margin: 0;
  padding: 8px 12px;
  border-bottom: 1px solid var(--cr-rule);
  font: 700 15px/1.2 var(--cr-cond);
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--cr-ink);
}
[data-ui="chartroom"] .cr-find__list { list-style: none; margin: 0; padding: 0; }
[data-ui="chartroom"] .cr-find__opt {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 56px;
  padding: 6px 12px 6px 8px;
  border-left: 4px solid transparent;
  border-bottom: 1px solid var(--cr-rule);
  cursor: pointer;
}
[data-ui="chartroom"] .cr-find__opt:hover { background: rgba(201, 151, 58, .12); }
[data-ui="chartroom"] .cr-find__opt.is-active { background: rgba(201, 151, 58, .26); border-left-color: var(--cr-brass-dark); }
[data-ui="chartroom"] .cr-find__hull { flex-shrink: 0; width: 72px; line-height: 0; }
[data-ui="chartroom"] .cr-find__hull svg { width: 72px; height: auto; }
[data-ui="chartroom"] .cr-find__text { min-width: 0; font: 500 15px/1.25 var(--cr-body); color: var(--cr-ink-2); }
[data-ui="chartroom"] .cr-find__name { font: 700 16px var(--cr-cond); color: var(--cr-ink); }
[data-ui="chartroom"] .cr-find__class { font: 500 15px var(--cr-cond); color: var(--cr-ink-3); }
[data-ui="chartroom"] .cr-find__status { display: block; }
[data-ui="chartroom"] .cr-find mark { background: rgba(230, 181, 76, .7); color: inherit; padding: 0 1px; }

/* Clock, level and cash */
[data-ui="chartroom"] :is(.cr-clock, .cr-level) {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  color: #D5E2E6;
  white-space: nowrap;
}
[data-ui="chartroom"] :is(.cr-clock__ring, .cr-level__medal) { flex-shrink: 0; }
[data-ui="chartroom"] .cr-top__figs { display: flex; flex-direction: column; gap: 2px; font: 600 15px/1.1 var(--cr-cond); letter-spacing: .04em; }
[data-ui="chartroom"] .cr-top__big { font-size: 17px; font-weight: 700; color: var(--cr-cream-text); }
[data-ui="chartroom"] .cr-meter { display: none; }
[data-ui="chartroom"] .cr-cash { flex-shrink: 0; }
[data-ui="chartroom"] .cr-cash__figure {
  font: 700 27px/1 var(--cr-cond);
  letter-spacing: .02em;
  color: var(--cr-cream-text);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
[data-ui="chartroom"] .cr-cash__figure.is-negative { color: var(--cr-amber-hi); }

/* Small steel plates: chart (narrow screens), motion, account */
[data-ui="chartroom"] .cr-top__plates { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
[data-ui="chartroom"] .cr-iconplate {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 44px;
  height: 44px;
  padding: 0 10px;
  margin: 0;
  box-sizing: border-box;
  cursor: pointer;
  color: var(--cr-steel-text);
  font: 700 15px/1 var(--cr-cond);
  letter-spacing: .06em;
  text-transform: uppercase;
  border: 1px solid rgba(169, 196, 204, .45);
  background: linear-gradient(180deg, #2A4B5C, #12303F);
  --cr-r: 3px;
  --cr-sh: inset 0 1px 0 rgba(255, 255, 255, .16), inset 0 -2px 0 rgba(0, 0, 0, .35), 0 2px 3px rgba(0, 0, 0, .4);
  transition: filter var(--cr-d-snap) var(--cr-ease), transform var(--cr-d-snap) var(--cr-ease);
}
[data-ui="chartroom"] .cr-iconplate:not([aria-pressed="true"]):hover { filter: brightness(1.18) drop-shadow(0 0 6px rgba(230, 181, 76, .55)); transform: translateY(-1px); }
[data-ui="chartroom"] .cr-iconplate:active { transform: translateY(1px); }
[data-ui="chartroom"] .cr-iconplate[aria-pressed="true"] {
  color: var(--cr-brass-ink);
  border-color: var(--cr-brass-dark);
  background: var(--cr-brass) url(../../../assets/chartroom/brass.png) center / 100% 100% no-repeat;
  --cr-sh: inset 0 2px 5px rgba(60, 35, 5, .55), inset 0 0 0 1px var(--cr-brass-dark);
}
[data-ui="chartroom"] .cr-iconplate .cr-icon { width: 20px; height: 20px; }
[data-ui="chartroom"] .cr-chart-button { display: none; }

/* ---- The desk: board host and the side rail ------------------------------------------- */

[data-ui="chartroom"] .cr-desk {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 16px;
  padding: 12px 20px;
}
[data-ui="chartroom"] .cr-board {
  position: relative;
  min-height: 0;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: #8C7A5C transparent;
  outline: none;
  filter: drop-shadow(0 3px 2px rgba(0, 0, 0, .45)) drop-shadow(0 18px 22px rgba(0, 0, 0, .45));
}
[data-ui="chartroom"] .cr-sheet {
  min-height: 100%;
  box-sizing: border-box;
  padding: 28px 32px 32px;
  --cr-r: 2px;
}
/* the board placeholder shares its class with drawer.css's confirm sheet, which starts hidden */
[data-ui="chartroom"] .cr-board > .cr-sheet { width: auto; opacity: 1; transform: none; transition: none; }
[data-ui="chartroom"] .cr-sheet__title {
  margin: 0 0 6px;
  font: 700 30px/1.1 var(--cr-serif);
  color: var(--cr-ink);
}
[data-ui="chartroom"] .cr-sheet__fleet {
  margin: 0 0 18px;
  padding-bottom: 10px;
  border-bottom: 2px solid var(--cr-ink);
  font: 700 17px var(--cr-cond);
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--cr-ink);
}
[data-ui="chartroom"] .cr-sheet__what { max-width: 60ch; margin: 0 0 14px; font: 500 17px/1.45 var(--cr-body); color: var(--cr-ink-2); }
[data-ui="chartroom"] .cr-sheet__later { max-width: 60ch; margin: 0; font: 400 15px/1.5 var(--cr-body); color: var(--cr-ink-3); }
[data-ui="chartroom"] .cr-sheet__stamp {
  display: inline-block;
  margin-right: 8px;
  padding: 2px 8px;
  border: 2px solid var(--cr-teal);
  border-radius: 3px;
  color: var(--cr-teal);
  font: 700 15px var(--cr-cond);
  letter-spacing: .08em;
  text-transform: uppercase;
  transform: rotate(-1.5deg);
}

[data-ui="chartroom"] .cr-side {
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 3px;
  border: 1px solid #4F6B78;
  box-shadow: 0 18px 40px rgba(0, 0, 0, .5), inset 0 0 24px rgba(0, 0, 0, .35);
}
[data-ui="chartroom"] .cr-side__inner {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}
[data-ui="chartroom"] .cr-thumb {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  margin: 0;
  padding: 0;
  cursor: pointer;
  color: var(--cr-cream-text);
  background: #0A1C26;
  --cr-r: 2px;
  --cr-sh: 0 2px 4px rgba(0, 0, 0, .5);
  transition: filter var(--cr-d-snap) var(--cr-ease);
}
[data-ui="chartroom"] .cr-thumb__pic {
  display: block;
  height: 130px;
  border-bottom: 1px solid rgba(201, 151, 58, .45);
  background-position: center 38%;
  transition: filter var(--cr-d-move) var(--cr-ease);
}
[data-ui="chartroom"] .cr-thumb:hover .cr-thumb__pic { filter: brightness(1.15) saturate(1.1); }
[data-ui="chartroom"] .cr-thumb__label {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 0 12px;
  font: 700 16px/1 var(--cr-cond);
  letter-spacing: .1em;
  text-transform: uppercase;
}
[data-ui="chartroom"] .cr-thumb:hover .cr-thumb__label { color: #FFF6DC; }
[data-ui="chartroom"] .cr-side__slot { flex: 1; padding: 18px 16px; }
[data-ui="chartroom"] .cr-side__note { margin: 0; font: 500 15px/1.45 var(--cr-body); color: #A9BEC6; }
[data-ui="chartroom"] .cr-side__note b { display: block; margin-bottom: 4px; font: 700 15px var(--cr-cond); letter-spacing: .1em; text-transform: uppercase; color: var(--cr-cream-text); }

/* ---- The chart ------------------------------------------------------------------------- */

[data-ui="chartroom"] .cr-chart {
  position: relative;
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}
[data-ui="chartroom"] .cr-chart__bar {
  position: relative;
  z-index: 4;
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 56px;
  padding: 6px 20px;
  box-sizing: border-box;
  border-bottom: 1px solid rgba(201, 151, 58, .45);
}
[data-ui="chartroom"] .cr-chart__title {
  margin: 0;
  font: 700 22px/1 var(--cr-serif);
  color: var(--cr-cream-text);
  outline: none;
}
[data-ui="chartroom"] .cr-chart__help { margin: 0 0 0 auto; font: 500 15px var(--cr-body); color: #C5D5DA; }
[data-ui="chartroom"] .cr-chart__host {
  position: relative;
  min-height: 0;
  overflow: hidden;
  background: var(--cr-sea);
}
/* The globe viewport keeps its own rules; only its box moves into the host. */
[data-ui="chartroom"] .cr-chart__host > #fleet-viewport { position: absolute; inset: 0; z-index: 0; }
[data-ui="chartroom"] .cr-chart__host > #fleet-frame { position: absolute; inset: 24px; z-index: 1; pointer-events: none; }
[data-ui="chartroom"] .cr-chart__host > #fleet-fallback {
  position: absolute;
  z-index: 3;
  top: 24px;
  left: 50%;
  transform: translateX(-50%);
  width: min(560px, calc(100% - 32px));
  margin: 0;
  padding: 16px;
  box-sizing: border-box;
  background: var(--cr-paper);
  color: var(--cr-ink);
  font: 500 16px/1.45 var(--cr-body);
}
[data-ui="chartroom"] .cr-chart__host > #helm-hud { z-index: 3; }
[data-ui="chartroom"] .cr-viewport-holder { display: none; }

/* Signed out: the chart full-bleed under the bar, with the paper sign-in sheet */
[data-ui="chartroom"] .cr-app[data-signed="out"] :is(.cr-nav, .cr-find, .cr-clock, .cr-level, .cr-cash, .cr-chart-button, .cr-chart__bar) { display: none; }
[data-ui="chartroom"] .cr-app:not([data-signed="in"]) .cr-chart { grid-template-rows: minmax(0, 1fr); }
[data-ui="chartroom"] .cr-app:not([data-signed="in"]) .cr-chart__bar { display: none; }
[data-ui="chartroom"] .cr-app:not([data-signed="in"]) :is(.cr-nav, .cr-find, .cr-clock, .cr-level, .cr-cash, .cr-chart-button) { display: none; }
[data-ui="chartroom"] .cr-app:not([data-signed="in"]) .cr-chart__host > #fleet-frame { left: 480px; }
[data-ui="chartroom"] .cr-chart__signin { position: absolute; z-index: 4; top: 32px; left: 32px; pointer-events: none; }
[data-ui="chartroom"] .cr-signin {
  pointer-events: auto;
  width: 400px;
  box-sizing: border-box;
  padding: 26px 28px 28px;
  --cr-r: 2px;
  --cr-sh: 0 3px 2px rgba(0, 0, 0, .45), 0 18px 22px rgba(0, 0, 0, .45);
}
[data-ui="chartroom"] .cr-signin__mark { display: flex; align-items: center; gap: 10px; margin: 0 0 16px; }
[data-ui="chartroom"] .cr-signin__mark .cr-wordmark { color: var(--cr-ink); }
[data-ui="chartroom"] .cr-signin__title { margin: 0 0 10px; font: 700 28px/1.15 var(--cr-serif); color: var(--cr-ink); }
[data-ui="chartroom"] .cr-signin__text { margin: 0 0 20px; font: 500 16px/1.5 var(--cr-body); color: var(--cr-ink-2); }
[data-ui="chartroom"] .cr-signin__actions { display: flex; flex-wrap: wrap; gap: 12px; }
[data-ui="chartroom"] .cr-signin__actions .cr-plate { min-width: 150px; }
[data-ui="chartroom"] .cr-signin__note { margin: 0; font: 600 16px var(--cr-cond); color: var(--cr-ink-3); }
[data-ui="chartroom"] .cr-account__text { font: 700 15px/1 var(--cr-cond); }

/* ---- Toast ----------------------------------------------------------------------------- */

[data-ui="chartroom"] #chartroom .cr-toast {
  position: fixed;
  z-index: 40;
  left: 20px;
  bottom: 20px;
  max-width: min(520px, calc(100vw - 40px));
  padding: 10px 14px;
  box-sizing: border-box;
  background: var(--cr-steel);
  color: var(--cr-cream-text);
  border: 1px solid rgba(201, 151, 58, .6);
  border-radius: 2px;
  box-shadow: 0 10px 24px rgba(0, 0, 0, .45);
  font: 500 15px/1.35 var(--cr-body);
  visibility: hidden;
}
[data-ui="chartroom"] #chartroom .cr-toast.is-visible { visibility: visible; }
[data-ui="chartroom"] #chartroom .cr-toast.is-error { background: var(--cr-shout); border-color: #E6A08A; }

/* ---- Integration: live boards, the undo dock, the stamp strip --------------------------- */

/* A real board or sheet brings its own layout (Now has its own rail with the chart thumbnail),
   so the placeholder side column goes, and the top-bar chart plate is the way to the chart on
   every tab but Now, whose rail carries the one "Open the chart" control. */
[data-ui="chartroom"] .cr-app[data-board="live"] .cr-desk { grid-template-columns: minmax(0, 1fr); }
[data-ui="chartroom"] .cr-app[data-board="live"] .cr-side { display: none; }
[data-ui="chartroom"] .cr-app[data-board="live"][data-signed="in"]:not([data-tab="now"]) .cr-chart-button { display: inline-flex; }
[data-ui="chartroom"] .cr-app[data-board="live"] .cr-board { filter: none; }

[data-ui="chartroom"] #chartroom .cr-undo-dock {
  position: fixed;
  z-index: 41;
  right: 20px;
  bottom: 20px;
  display: grid;
  gap: 8px;
  justify-items: end;
  max-width: min(460px, calc(100vw - 40px));
}
[data-ui="chartroom"] #chartroom .cr-undo-dock:empty { display: none; }

[data-ui="chartroom"] .cr-stamps { display: grid; gap: 4px; }
[data-ui="chartroom"] .cr-stamps:empty { display: none; }
[data-ui="chartroom"] .cr-stamp {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 40px;
  padding: 0 10px 0 14px;
  border: 1px solid rgba(23, 43, 54, .35);
  box-shadow: 2px 2px 0 rgba(23, 43, 54, .15), inset 4px 0 0 #1F6664;
  background-image: repeating-linear-gradient(180deg, transparent 0 21px, rgba(31, 102, 100, .14) 21px 22px), linear-gradient(180deg, #FBF6E8, #F1E7CF);
  font: 500 15px/1.35 var(--cr-body);
  color: var(--cr-ink);
}
[data-ui="chartroom"] .cr-stamp__mark { flex-shrink: 0; color: #0B3B39; transform: rotate(-6deg); }
[data-ui="chartroom"] .cr-stamp__mark text { font: 800 16px var(--cr-stencil, 'Big Shoulders Stencil Display', 'Arial Narrow', sans-serif); letter-spacing: 1.5px; }
[data-ui="chartroom"] .cr-stamp__text { flex: 1; min-width: 0; }
[data-ui="chartroom"] .cr-stamp__text b { font: 700 16px var(--cr-cond); }
[data-ui="chartroom"] .cr-stamp__undo {
  min-height: 44px;
  min-width: 44px;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  font: 700 16px var(--cr-cond);
  color: #4A3208;
  text-decoration: underline;
}

/* ---- Narrower desks -------------------------------------------------------------------- */

@media (max-width: 1500px) {
  [data-ui="chartroom"] .cr-find { flex-basis: 180px; }
  [data-ui="chartroom"] .cr-top__end { gap: 12px; }
}
/* Six tabs: the bar gives up its wordmark, then the tab icons, then the clock and level words,
   then the Find box (an icon that opens it) as the width runs out; each step is measured by
   scripts/check-chart-room.mjs (no horizontal scroll at 1440, 1024 and 768). */
@media (max-width: 1740px) {
  [data-ui="chartroom"] .cr-app[data-signed="in"] .cr-wordmark { display: none; }
}
@media (max-width: 1560px) {
  [data-ui="chartroom"] .cr-navtab .cr-icon { display: none; }
  [data-ui="chartroom"] .cr-nav { gap: 2px; }
}
@media (max-width: 1380px) {
  [data-ui="chartroom"] .cr-desk { grid-template-columns: minmax(0, 1fr) 320px; }
}
@media (max-width: 1300px) {
  /* nothing time-critical disappears: the Day and the level stay as one compact figure */
  [data-ui="chartroom"] :is(.cr-clock, .cr-level) .cr-top__small { display: none; }
  [data-ui="chartroom"] :is(.cr-clock, .cr-level) { gap: 6px; }
}
@media (min-width: 901px) and (max-width: 1180px) {
  /* the dial and medal give way to their words ("Day 412", "Level 20") so the bar still fits */
  [data-ui="chartroom"] :is(.cr-clock__ring, .cr-level__medal) { display: none; }
}
@media (min-width: 901px) and (max-width: 1180px) {
  [data-ui="chartroom"] .cr-find { flex: none; min-width: 0; position: static; }
  [data-ui="chartroom"] .cr-find .cr-find__toggle { display: inline-flex; }
  [data-ui="chartroom"] .cr-find__field { display: none; }
  [data-ui="chartroom"] .cr-find.is-open .cr-find__field { display: block; position: absolute; z-index: 21; top: 11px; left: 16px; right: 16px; }
  [data-ui="chartroom"] .cr-find.is-open .cr-find__box { background: #06151D; border-color: var(--cr-brass); }
  [data-ui="chartroom"] .cr-find__pop { width: min(340px, calc(100vw - 32px)); }
  [data-ui="chartroom"] .cr-cash__figure { font-size: 23px; }
  [data-ui="chartroom"] .cr-top { gap: 8px; }
  [data-ui="chartroom"] .cr-top__end { gap: 8px; }
  [data-ui="chartroom"] .cr-navtab { padding: 0 8px; }
}
@media (min-width: 901px) and (max-width: 980px) {
  [data-ui="chartroom"] .cr-navtab { padding: 0 5px; letter-spacing: .03em; }
  [data-ui="chartroom"] .cr-nav { gap: 1px; }
  [data-ui="chartroom"] .cr-top { padding-right: 8px; }
}
@media (max-width: 1024px) {
  [data-ui="chartroom"] .cr-desk { grid-template-columns: minmax(0, 1fr); }
  [data-ui="chartroom"] .cr-side { display: none; }
  [data-ui="chartroom"] .cr-app[data-signed="in"] .cr-chart-button { display: inline-flex; }
  /* Now's desk rail carries the chart thumbnail: one control, not two */
  [data-ui="chartroom"] .cr-app[data-signed="in"][data-tab="now"]:has(.crb-now[data-layout="desk"] [data-cr-slot="chart"]) .cr-chart-button { display: none; }
  [data-ui="chartroom"] .cr-cash__figure { font-size: 23px; }
}

/* ---- Phone chrome (board B4's bar/nav shape): a two-row bar on top, the five tabs along the
   bottom. Below 1024px the desktop top bar (nav row + Find box + clock/level figures + cash +
   plates, all in one row) needs more width than it has — this is also the only way the shell
   fits at 768px and 900px (Phase 7 lane A). Below this the BOARD markup is still 'desk'
   (board-kit.js only switches to 'phone' layout at 600px): boards.css's own tablet block reflows
   that content its own way, without adopting the phone card layout. -------------------------- */

@media (max-width: 900px) {
  /* the bottom bar lives in the header: lift it over Now's sticky shout bar (20), so the More menu is never covered */
  [data-ui="chartroom"] .cr-top {
    z-index: 21;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto auto;
    grid-template-areas: "brand cash find plates" "clock clock clock clock"; /* the Level bar is Progress's (ruling 53) */
    gap: 6px 8px;
    min-height: 0;
    padding: 8px 12px 10px;
    border-bottom: 2px solid var(--cr-brass);
  }
  [data-ui="chartroom"] .cr-top__end { display: contents; }
  [data-ui="chartroom"] .cr-brand { grid-area: brand; padding: 0; background: none; border: 0; }
  [data-ui="chartroom"] .cr-mark { width: 26px; height: 26px; }
  [data-ui="chartroom"] .cr-app[data-signed="in"] .cr-wordmark { display: none; }
  [data-ui="chartroom"] .cr-app:not([data-signed="in"]) .cr-top { grid-template-areas: "brand brand find plates"; }
  [data-ui="chartroom"] .cr-app:not([data-signed="in"]) .cr-wordmark { font-size: 22px; }
  [data-ui="chartroom"] .cr-cash { grid-area: cash; justify-self: end; }
  [data-ui="chartroom"] .cr-cash__figure { font-size: 24px; }
  [data-ui="chartroom"] .cr-find { grid-area: find; position: static; flex: none; min-width: 0; }
  [data-ui="chartroom"] .cr-find .cr-find__toggle { display: inline-flex; }
  [data-ui="chartroom"] .cr-find__field { display: none; }
  [data-ui="chartroom"] .cr-find.is-open .cr-find__field {
    display: block;
    position: absolute;
    z-index: 21;
    top: 8px;
    left: 12px;
    right: 64px;
  }
  [data-ui="chartroom"] .cr-find.is-open .cr-find__box { background: #06151D; border-color: var(--cr-brass); }
  [data-ui="chartroom"] .cr-find__pop { width: calc(100vw - 24px); }
  [data-ui="chartroom"] .cr-top__plates { grid-area: plates; gap: 4px; }
  [data-ui="chartroom"] .cr-clock { grid-area: clock; }
  [data-ui="chartroom"] .cr-level { grid-area: level; display: none; }
  [data-ui="chartroom"] :is(.cr-clock, .cr-level) { min-width: 0; }
  [data-ui="chartroom"] :is(.cr-clock__ring, .cr-level__medal, .cr-clock .cr-top__figs, .cr-level .cr-top__figs) { display: none; }
  [data-ui="chartroom"] .cr-meter { display: grid; gap: 3px; width: 100%; min-width: 0; }
  [data-ui="chartroom"] .cr-meter__text { font: 600 15px/1.1 var(--cr-cond); letter-spacing: .04em; color: #D5E2E6; overflow: hidden; text-overflow: ellipsis; }
  [data-ui="chartroom"] .cr-meter__bar { display: block; height: 5px; border-radius: 3px; background: rgba(0, 0, 0, .45); overflow: hidden; }
  [data-ui="chartroom"] .cr-meter__bar > i { display: block; height: 100%; background: #6FB7B4; }
  [data-ui="chartroom"] .cr-meter__bar--level > i { background: var(--cr-paper); }

  [data-ui="chartroom"] .cr-nav {
    position: fixed;
    z-index: 6;
    left: 0;
    right: 0;
    bottom: 0;
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 0;
    padding-bottom: env(safe-area-inset-bottom, 0);
    background: linear-gradient(180deg, #123549, #081C27);
    border-top: 2px solid var(--cr-brass);
  }
  [data-ui="chartroom"] .cr-navtab {
    flex-direction: column;
    justify-content: center;
    gap: 3px;
    height: 64px;
    padding: 0 2px;
    border: 0;
    border-right: 1px solid rgba(0, 0, 0, .35);
    background: none;
    --cr-r: 0;
    --cr-sh: none;
  }
  [data-ui="chartroom"] .cr-navtab .cr-icon { display: block; width: 22px; height: 22px; }
  [data-ui="chartroom"] .cr-navtab__count { position: absolute; top: 4px; left: calc(50% + 6px); }
  [data-ui="chartroom"] .cr-navtab__why { margin-left: auto; font: 600 15px/1 var(--cr-cond); letter-spacing: .04em; color: var(--cr-cream-text, #F2E8D0); }
  [data-ui="chartroom"] .cr-navtab__tag { position: absolute; top: 3px; right: 3px; padding: 2px 5px; border-radius: 8px; font: 700 11px/1 var(--cr-cond); letter-spacing: .04em; white-space: nowrap; color: var(--cr-cream-text, #F2E8D0); background: var(--cr-ink); box-shadow: 0 0 0 1.5px var(--cr-brass, #C9973A); }
  /* Ruling 83: every More-sheet row is one line (icon, name, figure); the plain words stay for screen readers and the title */
  [data-ui="chartroom"] .cr-nav__more .cr-navtab { position: relative; flex-wrap: nowrap; white-space: nowrap; overflow: hidden; }
  [data-ui="chartroom"] .cr-nav__more .cr-navtab__sub { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  [data-ui="chartroom"] .cr-nav__more .cr-navtab__count { position: static; margin-left: auto; flex: none; }
  [data-ui="chartroom"] .cr-nav__more .cr-navtab__count + .cr-navtab__why { margin-left: 0; }
  [data-ui="chartroom"] .cr-find.cr-find--folded .cr-find__toggle { display: none; }
  /* Four boards and "More" on the bar; Maintain and Company open from More, above the bar */
  [data-ui="chartroom"] .cr-navtab.cr-navtab--more { display: inline-flex; }
  [data-ui="chartroom"] .cr-nav__more { display: none; }
  /* While the More sheet is open a scrim dims the page above the bar; a press on it closes the sheet */
  [data-ui="chartroom"] .cr-nav__scrim { position: fixed; z-index: -1; left: 0; right: 0; top: 0; bottom: var(--cr-phone-nav, 66px); background: rgba(2, 8, 12, .78); backdrop-filter: blur(2px); }
  [data-ui="chartroom"] .cr-nav__more.is-open {
    position: fixed; z-index: 7; display: flex; flex-direction: column;
    right: 8px; bottom: calc(var(--cr-phone-nav, 66px) + 6px); width: min(240px, calc(100vw - 16px));
    background: linear-gradient(180deg, #123549, #081C27); border: 2px solid var(--cr-brass);
    box-shadow: 0 0 0 1px rgba(0, 0, 0, .6), 0 -14px 34px rgba(0, 0, 0, .75);
  }
  [data-ui="chartroom"] .cr-nav__more .cr-navtab { flex-direction: row; justify-content: flex-start; gap: 12px; height: 48px; padding: 0 16px; border-right: 0; border-bottom: 1px solid rgba(0, 0, 0, .35); font-size: 17px; }
  [data-ui="chartroom"] .cr-nav__more .cr-navtab:last-child { border-bottom: 0; }
  /* The bottom tab bar's height: anything sticky at the foot of a board (Now's shout bar) sits
     above it, never under it. */
  [data-ui="chartroom"] { --cr-phone-nav: calc(66px + env(safe-area-inset-bottom, 0px)); } /* 64px tabs + the 2px brass rule */
  [data-ui="chartroom"] .cr-app[data-signed="in"] { padding-bottom: var(--cr-phone-nav); box-sizing: border-box; }

  [data-ui="chartroom"] .cr-desk { padding: 8px; }
  [data-ui="chartroom"] .cr-sheet { padding: 20px 18px 24px; }
  [data-ui="chartroom"] .cr-sheet__title { font-size: 26px; }
  [data-ui="chartroom"] .cr-chart__bar { padding: 4px 12px; min-height: 52px; }
  [data-ui="chartroom"] .cr-chart__help { display: none; }
  [data-ui="chartroom"] .cr-chart__host > #fleet-frame { inset: 8px; }
  [data-ui="chartroom"] .cr-app:not([data-signed="in"]) .cr-chart__host > #fleet-frame { left: 8px; bottom: 46%; }
  [data-ui="chartroom"] .cr-chart__signin { top: auto; left: 12px; right: 12px; bottom: 12px; }
  [data-ui="chartroom"] .cr-signin { width: auto; padding: 18px 18px 20px; }
  [data-ui="chartroom"] .cr-signin__mark { display: none; }
  [data-ui="chartroom"] .cr-signin__title { font-size: 24px; }
  [data-ui="chartroom"] .cr-signin__text { font-size: 15px; margin-bottom: 14px; }
  [data-ui="chartroom"] #chartroom .cr-toast { left: 12px; right: 12px; bottom: calc(var(--cr-phone-nav) + 12px); max-width: none; }
  [data-ui="chartroom"] #chartroom .cr-undo-dock { left: 12px; right: 12px; bottom: calc(var(--cr-phone-nav) + 12px); max-width: none; }
}

/* ---- The helm on a phone ---------------------------------------------------------------
   helm-hud.css compacts the HUD only inside Sjøfart's .pc-app.is-helm stage. In the Chart Room
   the HUD lives in the chart host, so the same compact layout is applied here while the helm
   is taken (body[data-helm]): the host goes full-screen over the bars, and the HUD keeps its
   own palette (it is globe-owned; only its layout is set). */
@media (max-width: 900px) {
  body[data-ui="chartroom"][data-helm] #cr-chart-host { position: fixed; inset: 0; z-index: 60; }
  body[data-ui="chartroom"][data-helm] #cr-chart-host .pc-helm { padding: max(6px, env(safe-area-inset-top)) 6px max(6px, env(safe-area-inset-bottom)); gap: 6px;
    grid-template-rows: auto minmax(0, 1fr) auto; }
  body[data-ui="chartroom"][data-helm] #cr-chart-host .pc-helm-task { padding: 7px 9px; gap: 5px; background: rgba(4, 16, 20, .72); }
  body[data-ui="chartroom"][data-helm] #cr-chart-host :is(.pc-helm-tasks, .pc-helm-brief, .pc-helm-note) { display: none; }
  body[data-ui="chartroom"][data-helm] #cr-chart-host .pc-helm-title { font-size: 13.5px; }
  body[data-ui="chartroom"][data-helm] #cr-chart-host .pc-helm-checks { display: flex; flex-wrap: wrap; gap: 4px; grid-template-columns: none; } /* wraps: no chip is cut off at the edge */
  body[data-ui="chartroom"][data-helm] #cr-chart-host .pc-helm-checks li { flex: 0 0 auto; max-width: 100%; padding: 3px 7px; font-size: 10.5px; min-height: 0; gap: 4px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  body[data-ui="chartroom"][data-helm] #cr-chart-host .pc-helm-checks li svg { width: 12px; height: 12px; }
  body[data-ui="chartroom"][data-helm] #cr-chart-host .pc-helm-meta { font-size: 10px; gap: 10px; }
  body[data-ui="chartroom"][data-helm] #cr-chart-host .pc-helm-console { grid-template-columns: 1fr; gap: 6px; padding: 7px 8px; background: rgba(4, 16, 20, .78); }
  body[data-ui="chartroom"][data-helm] #cr-chart-host .pc-helm-readouts { grid-template-columns: repeat(2, auto); justify-content: start; gap: 2px 18px; }
  body[data-ui="chartroom"][data-helm] #cr-chart-host .pc-helm-readouts output { font-size: 16px; }
  body[data-ui="chartroom"][data-helm] #cr-chart-host .pc-helm-block { gap: 4px; }
  body[data-ui="chartroom"][data-helm] #cr-chart-host .pc-helm-steps { grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 2px; }
  body[data-ui="chartroom"][data-helm] #cr-chart-host .pc-helm-step { min-height: 40px; padding: 2px 1px; font-size: 9.5px; line-height: 1.15; white-space: normal; }
  body[data-ui="chartroom"][data-helm] #cr-chart-host .pc-helm-rudder-row .pc-btn { min-height: 40px; padding: 2px 10px; font-size: 12px; }
  body[data-ui="chartroom"][data-helm] #cr-chart-host .pc-helm-rudder-row + .pc-helm-rudder-row { display: none; }
  body[data-ui="chartroom"][data-helm] #cr-chart-host .pc-helm-actions { grid-template-columns: 1fr 1fr; gap: 4px; }
  body[data-ui="chartroom"][data-helm] #cr-chart-host .pc-helm-actions .pc-btn { min-height: 36px; font-size: 12px; justify-content: center; }
  body[data-ui="chartroom"][data-helm] #cr-chart-host .pc-helm-ff { display: none; }
}

/* ---- Forced colours: the selected tab and pressed plates stay visible ------------------ */

@media (forced-colors: active) {
  [data-ui="chartroom"] :is(.cr-navtab, .cr-iconplate, .cr-thumb) { border: 1px solid ButtonText; }
  [data-ui="chartroom"] :is(.cr-navtab[aria-current="page"], .cr-iconplate[aria-pressed="true"]) {
    forced-color-adjust: none;
    background: Highlight;
    color: HighlightText;
    outline: 3px solid Highlight;
  }
  [data-ui="chartroom"] .cr-find__opt.is-active { forced-color-adjust: none; background: Highlight; color: HighlightText; }
  [data-ui="chartroom"] .cr-find__opt.is-active * { color: HighlightText; }
}

@media (prefers-reduced-motion: reduce) {
  [data-ui="chartroom"] :is(.cr-navtab, .cr-iconplate, .cr-thumb, .cr-thumb__pic) { transition-duration: 0ms; }
}

/* ---- The one-time "New: …" note (ux-flow ruling 5): a brass-edged strip under the top bar ------ */
/* In the flow: the first desk row, above the board and the rail, never over content (ruling 26). */
[data-ui="chartroom"] .cr-desk { position: relative; grid-template-rows: auto minmax(0, 1fr); row-gap: 0; column-gap: 16px; }
[data-ui="chartroom"] .cr-desk > .cr-board, [data-ui="chartroom"] .cr-desk > .cr-side { grid-row: 2; }
[data-ui="chartroom"] .cr-new {
  grid-column: 1 / -1; grid-row: 1; margin: 0 0 8px;
  display: flex; align-items: stretch; min-width: 0;
  background: var(--cr-sea, #0A2230); color: var(--cr-ink-on-dark, #F2E8D0);
  border: 1px solid #C9973A; border-radius: 4px;
}
[data-ui="chartroom"] .cr-new__go { flex: 1 1 auto; min-width: 0; }
[data-ui="chartroom"] .cr-new__go, [data-ui="chartroom"] .cr-new__x {
  min-height: 44px; background: none; border: 0; color: inherit; cursor: pointer;
  font: 600 var(--cr-t-floor, 15px)/1.3 var(--cr-body);
}
[data-ui="chartroom"] .cr-new__go { padding: 0 14px; text-align: left; }
[data-ui="chartroom"] .cr-new__x { min-width: 44px; font-size: 22px; border-left: 1px solid rgba(201, 151, 58, .45); }
[data-ui="chartroom"] .cr-new__go:hover, [data-ui="chartroom"] .cr-new__x:hover { background: rgba(201, 151, 58, .18); }
@media (forced-colors: active) { [data-ui="chartroom"] .cr-new { border-color: CanvasText; } }

/* Round 13 lane G2: a zero-decision phone Now tab remains a readable state, not a blank badge. */
[data-ui="chartroom"] .cr-navtab__calm { display: none; }
@media (max-width: 900px) {
  [data-ui="chartroom"] .cr-navtab__calm { display: block; margin-top: 1px; color: #B9DED8; font: 600 12px/1 var(--cr-cond); letter-spacing: .02em; }
  [data-ui="chartroom"] .cr-navtab:has(.cr-navtab__calm) { min-width: 88px; }
}
