*,
*::before,
*::after {
    box-sizing: border-box;
}

* {
    margin: 0;
    padding: 0;
}

html,
body {
    height: 100%;
}

body {
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    background: #1a1a2e;
    overflow: hidden;
    color: #fff;
    font-family: sans-serif;
}

img,
picture,
video,
canvas,
svg {
    display: block;
    max-width: 100%;
}

input,
button,
textarea,
select {
    font: inherit;
}

p,
h1,
h2,
h3,
h4,
h5,
h6 {
    overflow-wrap: break-word;
}

:root {
    --timeline-y: 50vh;
    --card-scale: 1;
}

/* ── Viewport & canvas ───────────────────────────────────────────────────────── */

#viewport {
    width: 100%;
    height: 100%;
    overflow-x: scroll;
    overflow-y: hidden;
    cursor: grab;
    user-select: none;
}

#viewport img {
    pointer-events: none;
}

#viewport:active {
    cursor: grabbing;
}

#viewport::-webkit-scrollbar {
    display: none;
}

#viewport {
    scrollbar-width: none;
}

#canvas {
    height: 100%;
    position: relative;
}

#timeline-line {
    position: absolute;
    top: var(--timeline-y);
    left: 0;
    height: 2px;
    width: 100%;
    background: #4a90d9;
    transform: translateY(-50%);
}

/* ── Pins ─────────────────────────────────────────────────────────────────────── */

.pin {
    position: absolute;
    bottom: calc(100% - var(--timeline-y));
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    align-items: center;
}

.pin.below {
    bottom: auto;
    top: var(--timeline-y);
}

.pin .stem {
    width: 1px;
    height: 28px;
    background: #4a90d9;
    opacity: 0.6;
}

.pin .dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #5ddde0;
    border: 2px solid #1a1a2e;
    flex-shrink: 0;
    margin-bottom: -5px;
}

.pin.below .dot {
    margin-bottom: 0;
    margin-top: -5px;
}

.pin.below .card-stack {
    padding-top: 0;
    padding-bottom: 10px;
}

.card-stack {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    padding-top: 10px;
    zoom: var(--card-scale);
}

/* ── Banner group ─────────────────────────────────────────────────────────────── */

.banner-group {
    position: relative;
    border: 1px solid #4a90d9;
    border-radius: 12px;
    padding: 8px;
    padding-bottom: 22px;
    gap: 8px;
    display: grid;
    grid-template-rows: auto auto;
    grid-auto-flow: column;
    background: #12122a;
    zoom: var(--card-scale);
}

.banner-group .card .card-date {
    display: none;
}

.banner-group .group-date {
    position: absolute;
    bottom: 5px;
    right: 10px;
    font-size: 11px;
    font-weight: bold;
    color: #4a90d9;
}

.banner-group .group-date.predicted {
    font-weight: normal;
    font-style: italic;
    color: #888;
}

/* ── Cards ────────────────────────────────────────────────────────────────────── */

.card {
    position: relative;
    width: 280px;
    background: #1d1d1d;
    border: 1px solid #421111;
    border-radius: 8px;
    overflow: hidden;
    margin: 0;
    padding: 0;
}

.card::before {
    content: "";
    display: block;
    position: absolute;
    left: 0;
    top: 0;
    width: 8px;
    height: 100%;
    background: linear-gradient(to bottom, #ffb347, #ffcc33);
    border-top-left-radius: 8px;
    border-bottom-left-radius: 8px;
}

.card.trainee::before {
    background: linear-gradient(to bottom, #4caf50, #81c784);
}

.card.support::before {
    background: linear-gradient(to bottom, #4a90d9, #7ab3e8);
}

.card img {
    width: 100%;
    display: block;
    position: relative;
    z-index: 1;
}

.card.trainee img,
.card.support img {
    height: 72px;
    object-fit: cover;
    object-position: left center;
}

.card.story img {
    height: 100px;
    object-fit: cover;
    object-position: center top;
}

.card .info {
    padding: 7px 10px 8px 18px;
}

.card .info-type {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #4a90d9;
    margin-bottom: 2px;
}

.card.trainee .info-type {
    color: #81c784;
}

.card.story::before {
    background: linear-gradient(to bottom, #9b59b6, #c39bd3);
    z-index: 2;
}

.card.story img {
    margin-top: -2px;
}

.card.legend::before {
    background: linear-gradient(to bottom, #e67e22, #f39c12);
}

.legend-trainees {
    display: flex;
    flex-direction: row;
    gap: 6px;
    width: fit-content;
    margin: 2px auto 4px;
    padding: 6px;
    border: 1px solid rgba(230, 126, 34, 0.35);
    border-radius: 6px;
}

.legend-trainees img {
    width: 36px;
    height: 36px;
    border-radius: 4px;
    object-fit: cover;
    flex-shrink: 0;
}

.legend-footer {
    padding: 0 10px 8px;
}

.card.cm::before {
    background: linear-gradient(to bottom, #f1c40f, #f39c12);
}

.track {
    margin: 3px 0 1px;
}

.track-detail {
    font-size: 11px;
    color: #aaa;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.card.story .info-type {
    color: #c39bd3;
}

.card.legend .info-type {
    color: #e67e22;
}

.card.cm .info-type {
    color: #f1c40f;
}

.card.mission::before {
    background: linear-gradient(to bottom, #1abc9c, #16a085);
}

.card.mission {
    display: flex;
    flex-direction: row;
    align-items: flex-start;
    padding: 0;
}

.card.mission img {
    height: 56px;
    width: auto;
    max-width: 120px;
    flex-shrink: 0;
    object-fit: contain;
    margin-left: 4px;
    margin-top: 8px;
}

.card.mission .mission-info {
    padding: 8px 10px;
    flex: 1;
    min-width: 0;
}

.card.mission .info-type {
    color: #1abc9c;
}

.card.mission .mission-title {
    font-size: 12px;
    color: #d3d3d3;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.card .name {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 13px;
    color: #d3d3d3;
}

.card-date {
    display: block;
    text-align: right;
    font-size: 11px;
    font-weight: bold;
    color: #4a90d9;
}

.card-date.predicted {
    font-weight: normal;
    font-style: italic;
    color: #888;
}

/* ── Navbar ───────────────────────────────────────────────────────────────────── */

#navbar {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    width: 60%;
    height: 48px;
    background: #12122a;
    border: 1px solid #2a2a4a;
    border-radius: 12px;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.5);
    z-index: 2000;
}

/* ── Minimap / scrubber ───────────────────────────────────────────────────────── */

#minimap {
    position: fixed;
    bottom: 16px;
    left: 50%;
    transform: translateX(-50%);
    width: 60%;
    height: 48px;
    background: #12122a;
    border: 1px solid #2a2a4a;
    border-radius: 12px;
    overflow: hidden;
    cursor: pointer;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.5);
    z-index: 2000;
}

#minimap-line {
    position: absolute;
    top: 50%;
    left: 0;
    right: 0;
    height: 1px;
    background: #4a90d9;
    transform: translateY(-50%);
    opacity: 0.4;
}

#minimap-window {
    position: absolute;
    top: 0;
    height: 100%;
    background: rgba(74, 144, 217, 0.2);
    border-left: 2px solid #4a90d9;
    border-right: 2px solid #4a90d9;
    cursor: grab;
}

#minimap-window:active {
    cursor: grabbing;
}