/* Drill player: full-screen canvas with the HUD and overlays on top. */

html,
body.train {
    height: 100%;
    overflow: hidden;
    user-select: none;
}

#world {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    display: block;
    background: var(--bg);
}

/* ===== HUD =====
   Laid out for a 900px-tall window and scaled with the world (--hud-scale is
   set by the game on every resize), so it covers the same part of the
   battlefield on a laptop as on a large monitor. The box is sized up by the
   inverse so that, once scaled, it still fills the window exactly. */
.hud {
    position: fixed;
    top: 0;
    left: 0;
    width: calc(100% / var(--hud-scale, 1));
    height: calc(100% / var(--hud-scale, 1));
    transform: scale(var(--hud-scale, 1));
    transform-origin: 0 0;
    z-index: 10;
    pointer-events: none;
    transition: opacity 0.2s;
}

.hud.is-hidden {
    opacity: 0;
    visibility: hidden;
}

.hud-top {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: start;
    gap: 16px;
    padding: 12px 16px 28px;
    background: linear-gradient(to bottom, rgba(6, 9, 18, 0.88), rgba(6, 9, 18, 0));
}

.hud-id {
    display: flex;
    align-items: center;
    gap: 12px;
}

.hud-btn {
    width: 38px;
    height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    border: 1px solid var(--line-2);
    border-radius: 9px;
    background: var(--panel);
    cursor: pointer;
    pointer-events: auto;
}

.hud-btn span {
    width: 4px;
    height: 14px;
    border-radius: 1px;
    background: var(--ink);
}

.hud-btn:hover {
    border-color: var(--accent);
}

.hud-cat {
    font-size: 0.74rem;
    font-weight: 700;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    color: var(--accent);
}

.hud-name {
    font-size: 1.25rem;
    font-weight: 700;
    line-height: 1.1;
}

.hud-clock {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}

.clock {
    font-size: 3rem;
    font-weight: 700;
    line-height: 0.95;
    /* The clock ticks every second; fixed-width digits keep it from jittering. */
    font-variant-numeric: tabular-nums;
    text-shadow: 0 2px 14px rgba(0, 0, 0, 0.7);
}

.clock.is-low {
    color: var(--warn);
}

.banner {
    padding: 0.2rem 1rem;
    border: 1px solid var(--line-2);
    border-radius: 999px;
    background: var(--panel);
    font-size: 1.05rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    white-space: nowrap;
    opacity: 0;
    transform: translateY(-6px);
    transition: opacity 0.18s, transform 0.18s;
}

.banner.is-on {
    opacity: 1;
    transform: none;
}

.banner.is-wave,
.banner.is-bad {
    border-color: rgba(248, 113, 113, 0.7);
}

.banner.is-good {
    border-color: rgba(74, 222, 128, 0.7);
}

.hud-right {
    justify-self: end;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 6px;
}

.hud-stats {
    display: flex;
    gap: 22px;
}

.stat {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    line-height: 1.05;
}

.stat-label {
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--ink-3);
}

.stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    text-shadow: 0 2px 10px rgba(0, 0, 0, 0.7);
}

.stat.is-score .stat-value {
    font-size: 2rem;
}

.hud-res {
    display: flex;
    gap: 16px;
    padding: 0.25rem 0.8rem;
    border: 1px solid var(--line-2);
    border-radius: 9px;
    background: var(--panel);
    font-size: 1.15rem;
    font-variant-numeric: tabular-nums;
}

.res-item {
    display: inline-flex;
    align-items: center;
    gap: 7px;
}

.res-gem {
    width: 11px;
    height: 11px;
    background: #38bdf8;
    transform: rotate(45deg);
}

.res-house {
    width: 12px;
    height: 10px;
    background: #a3e635;
    clip-path: polygon(50% 0, 100% 42%, 100% 100%, 0 100%, 0 42%);
}

.res-item.is-capped b {
    color: var(--bad);
}

/* Task prompt for drills that give orders */
.prompt {
    position: absolute;
    top: 104px;
    left: 50%;
    transform: translateX(-50%);
    min-width: 320px;
    max-width: min(760px, 70vw);
    padding: 0.6rem 1.2rem;
    border: 1px solid rgba(253, 224, 71, 0.55);
    border-radius: 12px;
    background: var(--panel);
    text-align: center;
}

.prompt-title {
    font-size: 1.5rem;
    font-weight: 700;
    line-height: 1.15;
}

.prompt-line {
    font-size: 1.15rem;
    font-weight: 600;
    color: var(--ink-2);
}

.notice {
    position: absolute;
    left: 50%;
    bottom: 176px;
    transform: translateX(-50%);
    padding: 0.25rem 0.9rem;
    border: 1px solid rgba(248, 113, 113, 0.6);
    border-radius: 8px;
    background: var(--panel);
    font-weight: 700;
    white-space: nowrap;
    opacity: 0;
    transition: opacity 0.15s;
}

.notice.is-on {
    opacity: 1;
}

/* ===== Bottom bar ===== */
.hud-bottom {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: end;
    gap: 12px;
    padding: 12px;
}

.mini {
    width: 252px;
    height: 164px;
    border: 1px solid var(--line-2);
    border-radius: 10px;
    overflow: hidden;
    background: #070b14;
    pointer-events: auto;
}

.mini canvas {
    display: block;
    width: 100%;
    height: 100%;
    cursor: crosshair;
}

.sel {
    justify-self: center;
    width: min(640px, 100%);
    pointer-events: auto;
}

.groups {
    display: flex;
    gap: 4px;
    min-height: 28px;
    padding: 0 6px;
}

.group {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    height: 26px;
    padding: 0 8px;
    border: 1px solid var(--line-2);
    border-bottom: 0;
    border-radius: 7px 7px 0 0;
    background: var(--panel);
    color: var(--ink-2);
    font-size: 0.9rem;
    cursor: pointer;
}

.group b {
    color: var(--accent);
}

.group.is-active {
    border-color: var(--good);
    color: var(--ink);
}

.sel-body {
    min-height: 104px;
    padding: 9px 11px;
    border: 1px solid var(--line-2);
    border-radius: 10px;
    background: var(--panel);
}

.sel-empty {
    display: grid;
    place-items: center;
    min-height: 84px;
    color: var(--ink-3);
    font-size: 0.95rem;
}

.tiles {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.tile {
    position: relative;
    width: 34px;
    height: 40px;
    padding: 0 0 6px;
    display: grid;
    place-items: center;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #0c1424;
    cursor: pointer;
}

.tile:hover {
    border-color: var(--accent);
}

.tile-glyph {
    width: 21px;
    height: 21px;
    fill: var(--c);
}

.tile-hp {
    position: absolute;
    left: 4px;
    right: 4px;
    bottom: 4px;
    height: 3px;
    border-radius: 2px;
    background: #1e293b;
    overflow: hidden;
}

.tile-hp i {
    display: block;
    height: 100%;
    background: var(--good);
}

.tile-hp.is-warn i {
    background: var(--warn);
}

.tile-hp.is-low i {
    background: var(--bad);
}

.tile-more {
    display: grid;
    place-items: center;
    height: 40px;
    padding: 0 8px;
    color: var(--ink-3);
    font-weight: 700;
}

.info {
    display: flex;
    align-items: center;
    gap: 14px;
    min-height: 84px;
}

.info-glyph {
    width: 62px;
    height: 62px;
    display: grid;
    place-items: center;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: #0c1424;
}

.info-glyph .tile-glyph {
    width: 38px;
    height: 38px;
}

.info-name {
    font-size: 1.2rem;
    font-weight: 700;
    line-height: 1.1;
}

.info-sub {
    font-size: 0.9rem;
    color: var(--ink-3);
}

.info-sub.is-blocked {
    color: var(--bad);
    font-weight: 700;
}

.info-hp {
    font-size: 0.95rem;
    font-variant-numeric: tabular-nums;
}

.info-facts {
    font-size: 0.85rem;
    color: var(--ink-3);
}

.queue {
    display: flex;
    gap: 4px;
    margin-top: 6px;
}

.slot {
    position: relative;
    width: 34px;
    height: 34px;
    display: grid;
    place-items: center;
    border: 1px dashed var(--line-2);
    border-radius: 6px;
    overflow: hidden;
}

.slot.is-full {
    border-style: solid;
    background: #0c1424;
}

.slot-glyph {
    width: 19px;
    height: 19px;
    fill: var(--c);
}

.slot i {
    position: absolute;
    left: 0;
    bottom: 0;
    height: 4px;
    background: var(--accent);
}

.queue.is-blocked .slot.is-full:first-child {
    border-color: var(--bad);
}

.queue.is-blocked .slot i {
    width: 100% !important;
    background: var(--bad);
}

.sel-rows {
    display: grid;
    gap: 4px;
}

.sel-row {
    display: flex;
    align-items: center;
    gap: 12px;
}

.sel-row .queue {
    margin-top: 0;
}

.sel-row-name {
    width: 96px;
    font-weight: 700;
}

/* Command card */
.card {
    display: grid;
    grid-template-columns: repeat(4, 60px);
    grid-auto-rows: 54px;
    gap: 5px;
    padding: 8px;
    border: 1px solid var(--line-2);
    border-radius: 10px;
    background: var(--panel);
    pointer-events: auto;
}

.cmd {
    position: relative;
    display: grid;
    place-items: center;
    padding: 0 0 9px;
    border: 1px solid var(--line-2);
    border-radius: 8px;
    background: #0c1424;
    color: var(--ink);
    cursor: pointer;
}

.cmd:hover {
    border-color: var(--accent);
}

.cmd.is-empty {
    border-style: dashed;
    border-color: var(--line);
    background: transparent;
    cursor: default;
}

.cmd.is-armed {
    border-color: var(--warn);
    box-shadow: inset 0 0 0 1px var(--warn);
}

.cmd.is-poor {
    opacity: 0.45;
}

.cmd-key {
    position: absolute;
    top: 1px;
    left: 5px;
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--accent);
}

.cmd-icon {
    width: 24px;
    height: 24px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.cmd-label {
    position: absolute;
    left: 2px;
    right: 2px;
    bottom: 2px;
    overflow: hidden;
    font-size: 0.62rem;
    font-weight: 700;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    text-align: center;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--ink-3);
}

.cmd-cost {
    position: absolute;
    top: 1px;
    right: 5px;
    font-size: 0.75rem;
    font-weight: 700;
    color: #7dd3fc;
}

/* ===== Countdown ===== */
.countdown {
    position: fixed;
    inset: 0;
    z-index: 40;
    display: grid;
    place-items: center;
    pointer-events: none;
    font-size: 11rem;
    font-weight: 700;
    color: var(--ink);
    text-shadow: 0 0 60px rgba(34, 211, 238, 0.55);
}

.countdown span {
    animation: countPop 0.62s ease-out both;
}

@keyframes countPop {
    from { transform: scale(1.5); opacity: 0; }
    25% { opacity: 1; }
    to { transform: scale(0.85); opacity: 0.15; }
}

/* ===== Briefing ===== */
.brief h1 {
    font-size: 3rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.brief-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 24px;
}

.brief-tagline {
    margin-top: 0.3rem;
    font-size: 1.25rem;
    color: var(--ink-2);
}

.brief-best {
    flex: none;
    min-width: 170px;
    padding: 0.7rem 1rem;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: rgba(6, 9, 18, 0.5);
    text-align: right;
}

.brief-best-label {
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--ink-3);
}

.brief-best-value {
    font-size: 2rem;
    font-weight: 700;
    line-height: 1.1;
}

.brief-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 28px;
    margin: 22px 0;
    padding: 20px 0;
    border-top: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
}

.brief-grid h3 {
    margin: 0 0 0.3rem;
    font-size: 0.82rem;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--ink-3);
}

.brief-grid h3:not(:first-child) {
    margin-top: 1.1rem;
}

.brief-grid p,
.brief-grid li {
    font-size: 1.08rem;
    color: var(--ink-2);
}

.brief-grid ul {
    margin: 0;
    padding-left: 1.1rem;
}

.brief-grid li + li {
    margin-top: 0.25rem;
}

.keys {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem 1.1rem;
}

.key {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 1rem;
    color: var(--ink-2);
}

.brief-foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
}

.brief-meta {
    color: var(--ink-3);
    font-size: 0.98rem;
}

.brief-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.routine-steps {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 18px;
    padding-bottom: 14px;
    border-bottom: 1px solid var(--line);
    font-size: 0.95rem;
    color: var(--ink-3);
    flex-wrap: wrap;
}

.routine-steps b {
    color: var(--ink);
    margin-right: 6px;
}

.routine-step {
    padding: 0.1rem 0.6rem;
    border: 1px solid var(--line);
    border-radius: 999px;
}

.routine-step.is-done {
    color: var(--ink-2);
    border-color: var(--line-2);
}

.routine-step.is-current {
    color: var(--accent-ink);
    background: var(--accent);
    border-color: transparent;
    font-weight: 700;
}

/* ===== Pause ===== */
.pause h2 {
    font-size: 2rem;
    text-transform: uppercase;
}

.pause-actions {
    display: grid;
    gap: 8px;
    margin: 18px 0 12px;
}

.pause-note {
    font-size: 0.9rem;
    color: var(--ink-3);
}

/* ===== Results ===== */
.results {
    display: grid;
    gap: 18px;
}

.res-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
}

.res-title {
    font-size: 2rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.res-flag {
    padding: 0.3rem 0.9rem;
    border: 1px solid rgba(251, 191, 36, 0.6);
    border-radius: 999px;
    background: rgba(251, 191, 36, 0.12);
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    white-space: nowrap;
    animation: flagIn 0.5s ease-out both;
}

.res-flag.is-rank {
    border-color: rgba(34, 211, 238, 0.7);
    background: rgba(34, 211, 238, 0.14);
}

@keyframes flagIn {
    from { transform: scale(0.7); opacity: 0; }
    60% { transform: scale(1.08); }
    to { transform: none; opacity: 1; }
}

.res-main {
    display: grid;
    grid-template-columns: minmax(250px, 0.8fr) 1.2fr;
    gap: 20px;
    align-items: start;
}

.res-score-label {
    font-size: 0.82rem;
    font-weight: 700;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--ink-3);
}

.res-score-value {
    font-size: 5.2rem;
    font-weight: 700;
    line-height: 0.95;
}

.res-delta {
    margin-top: 0.3rem;
    color: var(--ink-2);
}

.delta-up {
    color: var(--good);
}

.delta-down {
    color: var(--bad);
}

.res-rank {
    margin-top: 0.8rem;
}

.rank.is-large {
    font-size: 1.5rem;
}

.res-next {
    margin-top: 0.5rem;
    display: grid;
    gap: 0.3rem;
    max-width: 300px;
}

.res-next-text {
    font-size: 0.92rem;
    color: var(--ink-3);
}

.res-tiles {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(112px, 1fr));
    gap: 8px;
}

.res-charts {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.res-chart {
    padding: 12px 14px;
    min-width: 0;
}

.res-mix {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
}

.res-mix-title {
    font-weight: 700;
    color: var(--ink-2);
    margin-right: 4px;
}

.res-coach h3 {
    margin-bottom: 0.4rem;
    font-size: 0.82rem;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--ink-3);
}

.res-coach ul {
    margin: 0;
    padding-left: 1.1rem;
    color: var(--ink-2);
    font-size: 1.05rem;
}

.res-coach li + li {
    margin-top: 0.3rem;
}

.res-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    padding-top: 16px;
    border-top: 1px solid var(--line);
}

.res-hint {
    margin-top: -8px;
    font-size: 0.9rem;
    color: var(--ink-3);
}

/* ===== Today's challenge ===== */
.brief-note {
    margin: -8px 0 16px;
    padding: 0.5rem 0.8rem;
    border: 1px solid rgba(249, 115, 22, 0.45);
    border-radius: 10px;
    background: rgba(249, 115, 22, 0.08);
    color: var(--ink-2);
}

.res-challenge {
    display: inline-block;
    margin-top: 0.6rem;
    padding: 0.25rem 0.7rem;
    border: 1px solid rgba(249, 115, 22, 0.5);
    border-radius: 8px;
    background: rgba(249, 115, 22, 0.1);
    color: var(--ink-2);
}

.res-challenge b {
    color: var(--ink);
}

/* ===== Tutorial lessons ===== */
.brief-best-note {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--ink-3);
}

.prompt .kbd {
    margin: 0 0.1em;
    font-size: 0.82em;
}

/* The correction a lesson adds when the player is stuck */
.prompt-hint {
    margin-top: 0.3rem;
    padding-top: 0.3rem;
    border-top: 1px solid var(--line);
    color: var(--warn);
}

.lesson-done {
    width: min(760px, 100%);
}

.lesson-time {
    padding-top: 0.4rem;
    color: var(--ink-3);
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.lesson-covered h3,
.lesson-next h3 {
    margin-bottom: 0.5rem;
}

.lesson-covered h3 {
    font-size: 0.82rem;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--ink-3);
}

.lesson-list {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.35rem 1.6rem;
    margin: 0;
    padding: 0;
    list-style: none;
    font-size: 1.05rem;
    color: var(--ink-3);
}

.lesson-list li {
    position: relative;
    padding-left: 1.6rem;
}

/* An empty ring for a step not reached, a filled tick for one that is done */
.lesson-list li::before {
    content: "";
    position: absolute;
    left: 0.1rem;
    top: 0.32em;
    width: 0.8rem;
    height: 0.8rem;
    border: 1.5px solid var(--ink-3);
    border-radius: 50%;
}

.lesson-list li.is-done {
    color: var(--ink-2);
}

.lesson-list li.is-done::before {
    border-color: var(--good);
    background: var(--good);
}

.lesson-list li.is-done::after {
    content: "";
    position: absolute;
    left: 0.36rem;
    top: 0.46em;
    width: 0.28rem;
    height: 0.5rem;
    border: solid #052e16;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}

.lesson-next {
    padding: 14px 16px;
}

.lesson-next h3 {
    margin-top: 0.2rem;
    font-size: 1.5rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.lesson-next p {
    color: var(--ink-2);
}

/* ===== Routine summary (shares the results layout) ===== */
.res-score-value small {
    font-size: 1.3rem;
    font-weight: 600;
    color: var(--ink-3);
}

.routine-done .res-tiles {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.rt-wrap {
    overflow-x: auto;
}

.rt-table {
    width: 100%;
    border-collapse: collapse;
}

.rt-table th,
.rt-table td {
    padding: 0.5rem 0.9rem;
    text-align: left;
    border-bottom: 1px solid var(--line);
    white-space: nowrap;
}

.rt-table tbody tr:last-child td {
    border-bottom: 0;
}

.rt-table th {
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--ink-3);
}

.rt-table .num {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.rt-table th.num:first-child,
.rt-table td.num:first-child {
    width: 2.2em;
    color: var(--ink-3);
}

.rt-name {
    font-weight: 700;
}

.rt-muted,
.rt-table .is-skipped td {
    color: var(--ink-3);
}

.rt-table .rank {
    font-size: 0.9rem;
}

/* The rating as a bar in the rank's colour, with the number beside it */
.rt-rating {
    display: grid;
    grid-template-columns: minmax(90px, 1fr) 2.4em;
    align-items: center;
    gap: 10px;
    min-width: 170px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.rt-rating span {
    text-align: right;
}

.rt-best {
    margin-left: 8px;
    padding: 0.05rem 0.5rem;
    border: 1px solid rgba(251, 191, 36, 0.6);
    border-radius: 999px;
    background: rgba(251, 191, 36, 0.12);
    font-size: 0.74rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.rt-coach {
    align-self: center;
}

/* Touch devices and narrow windows cannot play a drill */
.desktop-only {
    display: none;
}

@media (max-width: 760px), (pointer: coarse) {
    .desktop-only {
        position: fixed;
        inset: 0;
        z-index: 100;
        display: grid;
        place-items: center;
        padding: 20px;
        background: var(--bg);
    }

    .desktop-only .sheet {
        display: grid;
        gap: 12px;
    }
}

@media (max-width: 980px) {
    .brief-grid,
    .res-main,
    .res-charts {
        grid-template-columns: 1fr;
    }

    .sel {
        display: none;
    }
}

@media (max-height: 760px) {
    .res-score-value {
        font-size: 3.8rem;
    }

    .sheet {
        padding: 20px 24px;
    }
}
