/* Ghost Fleet — styled after an Admiralty chart: ink on pale water,
   magenta overprint for hazards, italic serif for names. */

:root {
    --ink:        #1c2a35;
    --sounding:   #5d707a;
    --magenta:    #a3165f;
    --magenta-lt: #f3dbe7;
    --water:      #e9f0f1;
    --paper:      #f8fafa;
    --land:       #ddd6c3;
    --rule:       #c9d5d8;

    --serif: "Newsreader", Georgia, serif;
    --sans:  "Public Sans", system-ui, sans-serif;

    --rail-width: 400px;
    --masthead: 52px;
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
    margin: 0;
    height: 100%;
    background: var(--water);
    color: var(--ink);
    font: 15px/1.5 var(--sans);
    font-variant-numeric: tabular-nums;
    -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-underline-offset: 2px; }
a:hover { color: var(--magenta); }

:focus-visible { outline: 2px solid var(--magenta); outline-offset: 2px; }
[tabindex="-1"]:focus:not(:focus-visible) { outline: none; }

button { font: inherit; color: inherit; }
button:disabled { opacity: 0.4; cursor: default; }

.visually-hidden {
    position: absolute; width: 1px; height: 1px; overflow: hidden;
    clip: rect(0 0 0 0); white-space: nowrap;
}

/* Masthead */

.masthead {
    height: var(--masthead);
    display: flex;
    align-items: baseline;
    gap: 20px;
    padding: 12px 20px 0;
    border-bottom: 1px solid var(--rule);
    background: var(--paper);
}

.wordmark {
    margin: 0;
    font: italic 500 26px/1 var(--serif);
    letter-spacing: -0.01em;
}

.snapshot { margin: 0; color: var(--sounding); font-size: 13px; }
.mast-nav { margin-left: auto; display: flex; gap: 16px; font-size: 13px; font-weight: 600; }
.mast-nav a { text-decoration: none; }
.mast-nav a:hover { text-decoration: underline; }

/* Layout */

.layout {
    display: grid;
    grid-template-columns: 1fr var(--rail-width);
    height: calc(100% - var(--masthead));
}

.chart { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.chart-canvas { position: relative; flex: 1; min-height: 0; }
#map { position: absolute; inset: 0; background: #cfdde2; }

/* Map controls share one chart-label look: paper, hairline rule, ink text. */

.replay-toggle,
.key {
    background: rgba(248, 250, 250, 0.95);
    border: 1px solid var(--rule);
    color: var(--ink);
}

.replay-toggle {
    position: absolute;
    top: 12px;
    left: 12px;
    z-index: 500;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px 8px 10px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: border-color 0.15s;
}
.replay-toggle::before {
    content: "";
    border-left: 8px solid var(--magenta);
    border-top: 5px solid transparent;
    border-bottom: 5px solid transparent;
}
.replay-toggle:hover { border-color: var(--ink); }
.replay-toggle[hidden] { display: none; }

.key {
    position: absolute;
    left: 12px;
    bottom: 12px;
    z-index: 500;
    display: flex;
    flex-wrap: wrap;
    gap: 6px 14px;
    max-width: calc(100% - 24px);
    padding: 7px 10px;
    font-size: 12px;
}
.key span { display: inline-flex; align-items: center; gap: 6px; }
.key-mode { font-weight: 600; }
.key-events { display: contents !important; }
.replaying .key-fleet { display: none; }

.dot, .ring, .ring-dashed, .square, .diamond { display: inline-block; flex: none; width: 10px; height: 10px; }
.dot { border-radius: 50%; }
.dot-high { background: var(--magenta); }
.dot-low { background: var(--paper); border: 1.5px solid var(--ink); }
.ring { border-radius: 50%; border: 2px solid var(--magenta); }
.ring-dashed { border-radius: 50%; border: 1.5px dashed var(--ink); }
.square { background: var(--ink); width: 8px; height: 8px; }
.diamond { width: 8px; height: 8px; background: var(--paper); border: 1.5px solid var(--magenta); transform: rotate(45deg); }
.event-icon { display: flex; align-items: center; justify-content: center; }
.cross { position: relative; width: 12px; height: 12px; }
.cross::before, .cross::after { content: ""; position: absolute; left: 5px; top: 0; width: 2px; height: 12px; background: var(--ink); box-shadow: 0 0 0 1px var(--paper); }
.cross::after { transform: rotate(90deg); }

/* Historical evidence replay: a strip docked under the map */

.replay {
    flex: none;
    padding: 12px 16px;
    background: var(--paper);
    border-top: 2px solid var(--ink);
    animation: rise 0.18s ease-out;
}
.replay-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.replay h2 {
    margin: 0;
    font: 600 12px/1.3 var(--sans);
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--sounding);
}
.replay-exit {
    padding: 4px 0;
    font-size: 13px;
    font-weight: 600;
    background: none;
    border: 0;
    text-decoration: underline;
    text-underline-offset: 2px;
    cursor: pointer;
}
.replay-exit:hover { color: var(--magenta); }

.replay-status { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 16px; margin: 4px 0 8px; }
.replay-period { margin: 0; font: italic 500 24px/1.2 var(--serif); }
.replay-period small { margin-left: 6px; font: 400 12px var(--sans); color: var(--sounding); }
.replay-counts { margin: 0; font-size: 13px; }
.replay-counts b { font-weight: 600; }
.replay-kinds { display: block; color: var(--sounding); font-size: 12px; }

.replay-controls { display: flex; align-items: center; gap: 8px; }
.replay-controls button {
    min-width: 36px;
    height: 36px;
    padding: 0 10px;
    font-size: 13px;
    font-weight: 600;
    background: var(--paper);
    border: 1px solid var(--rule);
    cursor: pointer;
    transition: border-color 0.15s;
}
.replay-controls button:not(:disabled):hover { border-color: var(--ink); }
#replay-prev, #replay-next { font-size: 20px; line-height: 1; }
.replay-controls .replay-play { min-width: 72px; background: var(--ink); color: var(--paper); border-color: var(--ink); }
.replay-controls .replay-play[aria-pressed="true"] { background: var(--paper); color: var(--ink); }
.replay-track { flex: 1; min-width: 0; }
.replay-track input { display: block; width: 100%; margin: 0; accent-color: var(--magenta); }
.replay-scale { display: flex; justify-content: space-between; font-size: 11px; color: var(--sounding); }

.replay-note { margin: 8px 0 0; font-size: 12px; color: var(--sounding); max-width: 90ch; }
.replay-note a { font-weight: 600; color: var(--ink); }

/* Rail */

.rail {
    position: relative;   /* contains absolutely positioned (visually hidden) text in its own scroll area */
    overflow-y: auto;
    background: var(--paper);
    border-left: 1px solid var(--rule);
    padding: 24px 24px 16px;
}

.rail h2, .rail h3 {
    margin: 28px 0 10px;
    font: 600 13px/1.3 var(--sans);
    color: var(--sounding);
}

.lede {
    margin: 0 0 18px;
    font: italic 400 30px/1.15 var(--serif);
    letter-spacing: -0.01em;
    text-wrap: balance;
}
.lede strong { font-weight: 500; color: var(--magenta); }
.rail[aria-busy="true"] .lede { color: var(--sounding); }

#view-monitor:not([hidden]), #view-dossier:not([hidden]) { animation: rise 0.18s ease-out; }
@keyframes rise { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* Trend strip */

.trend { margin: 0; }
#trend-svg { display: block; width: 100%; height: 96px; overflow: visible; }
#trend-svg .bar { fill: var(--rule); }
#trend-svg .bar.recent { fill: var(--ink); }
#trend-svg .bar.prior { fill: var(--sounding); }
#trend-svg text { font: 11px var(--sans); fill: var(--sounding); }
#trend-svg .value { fill: var(--ink); font-weight: 500; }
.trend figcaption { margin-top: 6px; font-size: 12px; color: var(--sounding); }

/* Key figures */

.figures {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px 20px;
    margin: 24px 0 0;
    padding-top: 18px;
    border-top: 1px solid var(--rule);
}
.figures > div:last-child { grid-column: 1 / -1; }
.figures dt { font-size: 12px; color: var(--sounding); }
.figures dd { margin: 2px 0 0; font-size: 22px; font-weight: 500; }
.footnote { margin: 4px 0 0; font-size: 12px; color: var(--sounding); max-width: 60ch; }

/* Ports */

.ports ol { margin: 0; padding: 0; list-style: none; columns: 2; column-gap: 20px; }
.ports li {
    display: flex; justify-content: space-between; gap: 8px;
    padding: 3px 0; font-size: 13px; break-inside: avoid;
    border-bottom: 1px dotted var(--rule);
}
.ports li span:last-child { color: var(--sounding); }

/* Vessel list */

.search input {
    width: 100%;
    padding: 8px 10px;
    font: inherit;
    color: inherit;
    background: var(--water);
    border: 1px solid var(--rule);
    border-radius: 2px;
}
.search input:focus-visible { outline-offset: 0; border-color: var(--magenta); }

#vessel-list { list-style: none; margin: 8px 0 0; padding: 0; }
#vessel-list button {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 0 12px;
    padding: 9px 4px;
    text-align: left;
    background: none;
    border: 0;
    border-bottom: 1px solid var(--rule);
    cursor: pointer;
    transition: background-color 0.12s;
}
#vessel-list button:hover { background: var(--water); }
#vessel-list button:hover .v-name { color: var(--magenta); }
#vessel-list button:focus-visible { outline-offset: -2px; background: var(--water); }
/* Explicit placement: a row-locked item is placed first, which pushed names right. */
.v-name { grid-column: 1; grid-row: 1; font: italic 500 17px/1.3 var(--serif); }
.v-meta { grid-column: 1; grid-row: 2; font-size: 12px; color: var(--sounding); }
.v-score { grid-column: 2; grid-row: 1 / span 2; align-self: center; font-weight: 600; }
.v-score.high { color: var(--magenta); }
.v-nopos { color: var(--magenta); }
.empty { padding: 12px 4px; color: var(--sounding); font-size: 13px; }

/* Dossier */

.back {
    padding: 0;
    font-size: 13px;
    color: var(--sounding);
    background: none;
    border: 0;
    cursor: pointer;
    text-decoration: underline;
    text-underline-offset: 2px;
}
.back:hover { color: var(--magenta); }

.vessel-name { margin: 14px 0 4px !important; font: italic 500 34px/1.1 var(--serif) !important; color: var(--ink) !important; }
.vessel-now { margin: 0; color: var(--sounding); }

.score { display: flex; gap: 16px; align-items: flex-start; margin-top: 20px; }
.score-number { font-size: 44px; font-weight: 600; line-height: 1; min-width: 2.2ch; }
.score-number.high { color: var(--magenta); }
.score-body { flex: 1; padding-top: 2px; }
.score-label { margin: 0 0 6px; font-size: 12px; color: var(--sounding); }
.score-bar { display: flex; height: 8px; background: var(--water); }
.score-bar span { display: block; height: 100%; }
.score-bar span + span { border-left: 2px solid var(--paper); }
.score-sum { margin: 6px 0 0; font-size: 12px; color: var(--sounding); }

/* Evidence matrix */

.evidence { width: 100%; border-collapse: collapse; font-size: 13px; }
.evidence thead th {
    padding: 0 6px 6px 0;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    text-align: left;
    color: var(--sounding);
    border-bottom: 1px solid var(--ink);
}
.evidence tbody th, .evidence tbody td {
    padding: 9px 8px 9px 0;
    vertical-align: top;
    text-align: left;
    font-weight: 400;
    border-bottom: 1px solid var(--rule);
}
.evidence .row-shared th, .evidence .row-shared > td:nth-child(2) { border-bottom-style: dotted; }
.evidence .pts { width: 56px; padding-right: 0; text-align: right; }
.evidence tbody .pts b { font-size: 15px; font-weight: 600; }
.evidence .pts-zero { color: var(--sounding); }
.evidence .pts-none { font-size: 11px; color: var(--sounding); }
.evidence tfoot th, .evidence tfoot td { padding: 8px 0 0; text-align: left; font-weight: 600; }
.evidence tfoot .pts { text-align: right; font-size: 18px; }
.ev-label { display: block; font-weight: 600; }
.ev-detail { display: block; margin-top: 2px; }
.ev-source { display: block; margin-top: 3px; font-size: 11px; color: var(--sounding); }
.ev-figure { margin: 8px 0 2px; }
.ev-figure img { display: block; width: 100%; max-width: 288px; height: auto; background: var(--ink); }
.ev-figure figcaption { margin-top: 4px; font-size: 11px; color: var(--sounding); }
.ev-lists summary { margin-top: 4px; font-size: 12px; cursor: pointer; color: var(--sounding); }
.ev-lists summary:hover { color: var(--magenta); }
.ev-lists ul { margin: 4px 0 0; padding-left: 16px; font-size: 11px; overflow-wrap: anywhere; }

/* Evidence status: fill and border style carry the meaning, never hazard magenta. */
.status {
    display: inline-block;
    padding: 1px 6px;
    font-size: 11px;
    font-weight: 600;
    line-height: 1.5;
    border: 1px solid var(--ink);
}
.st-observed { background: var(--ink); color: var(--paper); }
.st-derived { background: var(--paper); color: var(--ink); }
.st-not-observed { color: var(--sounding); border: 1px dashed var(--sounding); }
.st-model { color: var(--ink); background: var(--paper); border: 1px dotted var(--ink); font-style: italic; }
.st-unknown {
    color: var(--sounding);
    border-color: var(--rule);
    background: repeating-linear-gradient(135deg, var(--paper) 0 4px, var(--water) 4px 8px);
    font-style: italic;
}

.status-key { display: grid; gap: 4px; margin: 12px 0 0; font-size: 12px; color: var(--sounding); }
.status-key div { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 8px; }
.status-key dt, .status-key dd { margin: 0; }

.sources { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; margin: 14px 0 0; font-size: 13px; }
.source-link {
    display: inline-block;
    padding: 5px 10px;
    font-weight: 600;
    text-decoration: none;
    border: 1px solid var(--ink);
    transition: color 0.15s, border-color 0.15s;
}
.source-link::after { content: " \2197"; }
.source-link:hover { border-color: var(--magenta); }

.identities { margin: 0; padding: 0 0 0 22px; }
.identities li { padding: 4px 0 4px 4px; }
.identities li::marker { color: var(--sounding); font-size: 12px; }
.identities .id-name { font: italic 500 16px var(--serif); }
.identities .id-meta { display: block; font-size: 12px; color: var(--sounding); }
.identities li:last-child .id-name { color: var(--magenta); }

.events { list-style: none; margin: 0; padding: 0; font-size: 13px; }
.events li {
    display: grid; grid-template-columns: 104px 1fr; gap: 8px;
    padding: 4px 0; border-bottom: 1px dotted var(--rule);
}
.events time { color: var(--sounding); white-space: nowrap; }
.events button { padding: 0; background: none; border: 0; text-align: left; cursor: pointer; }
.events button:hover { color: var(--magenta); text-decoration: underline; }
.events .empty, .identities .empty { display: block; padding: 4px 0; font-style: italic; list-style: none; }

.disclaimer {
    margin-top: 32px;
    padding-top: 12px;
    border-top: 1px solid var(--rule);
    font-size: 12px;
    color: var(--sounding);
}
.disclaimer p { margin: 0 0 6px; }

.status-msg {
    margin: 0 0 18px;
    padding: 12px;
    background: var(--magenta-lt);
    font-size: 13px;
}

/* Small screens: chart on top, replay strip, then the rail */

@media (max-width: 860px) {
    html, body { height: auto; }
    .masthead { height: auto; flex-wrap: wrap; gap: 4px 16px; padding: 12px 16px; }
    .layout { display: block; height: auto; }
    .chart-canvas { flex: none; height: 56vh; }
    .rail { border-left: 0; border-top: 1px solid var(--rule); padding: 20px 16px; }
    .lede { font-size: 26px; }
    .ports ol { columns: 1; }
    .vessel-name { font-size: 30px !important; }
    .key { right: 12px; }
    .replay-period { font-size: 21px; }
    .replay-controls { flex-wrap: wrap; }
    .replay-track { order: 5; flex-basis: 100%; }
    .replay-latest { margin-left: auto; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}
