/* DAG Doctor on the park guide map. Tokens, the lobe, capsules, the level stops, the concept and the result panel
   come from shared/theme.css; this file places them and draws the task graph, the Tasks list and the timeline. */

/* Wide: the Tasks list sits beside the graph, then the toolbar, then the timeline lake: source order.
   One column: graph, toolbar, timeline, Tasks list (game.js moves the list there, so source order still matches). */
@media (min-width: 961px) {
  .build { grid-template-columns: minmax(0, 724px) 296px; column-gap: 20px; }
  .build > :is(#levels, .toolbar, #gantt) { grid-column: 1 / -1; }
  .build > .stage { grid-column: 1; }
  .build > .tasks-panel { grid-column: 2; }
}

.head p { margin: 0; font-size: 17px; line-height: 1.45; }
.hint { margin: 0; font-size: 14px; line-height: 1.5; max-width: 65ch; }
#hint { min-height: 3em; margin-top: 8px; }
.stage:focus, #title:focus { outline: none; } /* focus targets of the skip link and of Next level, not controls */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: flex-end; }
#targets { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-right: auto; }

/* ---- graph: tasks are cream capsules on the lobe, dependencies are ink arrows ---- */
#graph { display: block; width: 100%; height: auto; overflow: visible; }

.node { cursor: pointer; --f: var(--water); --i: var(--ink); --bf: var(--water); --bi: var(--ink); }
.node .cap { fill: var(--f); stroke: var(--ink); stroke-width: 2; transition: fill .2s; }
.node .name { font: 700 13px var(--mono); fill: var(--i); }
.node .sub { font: 500 13px var(--font); fill: var(--i); }
.node .badge circle { fill: var(--bf); stroke: var(--ink); stroke-width: 2; }
.node .icon { fill: none; stroke: var(--bi); stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; }
.node .body, .node .badge { transform-box: fill-box; transform-origin: center; }
.node:hover .cap { stroke-width: 3; }
.s-idle .badge { opacity: 0; }
.s-queued .cap, .s-waiting .cap, .s-skipped .cap { stroke-dasharray: 6 5; }
/* running now: the capsule turns ink and its chip takes the lobe colour */
.s-running, .s-retry { --f: var(--ink); --i: var(--water); --bf: var(--accent); }
.s-running .icon { fill: var(--bi); }
.s-running .badge, .s-retry .badge { animation: beat .9s ease-in-out infinite; }
.s-success { --bf: var(--ink); --bi: var(--water); }
.s-success .icon { stroke-width: 3; }
.s-success .body { animation: pop var(--t) var(--bounce); }
/* failed: the whole capsule is coral. Finished but wrong (bad data, past the deadline): a coral chip. */
.s-failed { --f: var(--coral); --bf: var(--ink); --bi: var(--water); }
.s-late, .s-warn { --bf: var(--coral); }
.s-failed .sub, .s-late .sub, .s-warn .sub, .s-waiting .sub { font-weight: 700; }
.s-failed .body, .s-late .body, .s-warn .body { animation: shake var(--t); }
.node.cycle .cap { stroke: var(--bad); stroke-width: 3; stroke-dasharray: 5 4; }
/* chosen as the start of a new arrow */
.node.sel .cap { stroke-width: 5; }

.edge, .ekey { color: var(--ink); }
.edge { cursor: pointer; }
.edge .vis, .ekey .vis { fill: none; stroke: currentColor; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
/* keyboard stop of an arrow (after all tasks in tab order): the arrow with its remove mark, shown only while focused */
.ekey { opacity: 0; pointer-events: none; }
.ekey:focus, .ekey:focus-visible { opacity: 1; }
.edge .hit { fill: none; stroke: transparent; stroke-width: 24; }
.edge .x { opacity: 0; }
.edge .x circle, .ekey .x circle { fill: var(--ink); stroke: var(--water); stroke-width: 2; }
.edge .x path, .ekey .x path { fill: none; stroke: var(--water); stroke-width: 2.5; stroke-linecap: round; }
.edge:hover .vis { stroke-width: 5; }
.edge:hover .x { opacity: 1; }
.edge.cycle { color: var(--bad); }
.edge.cycle .vis:not(.head) { stroke-dasharray: 9 6; animation: march .5s linear infinite; }
/* a finished task sends one marker down each arrow that leaves it */
.pulse { fill: var(--water); stroke: var(--ink); stroke-width: 3; pointer-events: none; }

/* after a failed run: a dependency nobody declared */
.gap path { fill: none; stroke: var(--ink); stroke-width: 3; stroke-linecap: round; stroke-dasharray: 1 9; }
.gap text { font: 500 13px var(--font); fill: var(--ink); }
.gap .b { font-weight: 700; }

/* an outside file a task reads: not a task, a dashed slip on a dotted feeder */
.file { color: var(--ink); }
.file rect { fill: var(--water); stroke: currentColor; stroke-width: 2; stroke-dasharray: 6 5; }
.file line { stroke: currentColor; stroke-width: 3; stroke-linecap: round; stroke-dasharray: 1 8; }
.file .doc { fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linejoin: round; }
.file .name { font: 700 12px var(--mono); fill: var(--ink); }
.file .sub { font: 600 13px var(--font); fill: currentColor; }
.file.missing { color: var(--amber); }
.file.here { color: var(--good); }
.file.here rect { stroke-dasharray: none; }

@keyframes beat { 50% { transform: scale(1.25); } }
@keyframes march { to { stroke-dashoffset: -15; } }
@keyframes pop { from { transform: scale(.86); } }
@keyframes shake { 20%, 60% { transform: translateX(-5px); } 40%, 80% { transform: translateX(5px); } }

/* ---- timeline: a cream lake, one row per task, a hairline per minute, times printed underneath ---- */
#gantt { --rh: 31px; --bo: 3px; font-size: 14px; }
#gantt:empty::before { content: 'Timeline. Press Run and every task draws its bar here.'; color: var(--muted); }
.g-none { margin: 0; }
.g-head { display: flex; flex-wrap: wrap; gap: 4px 12px; justify-content: space-between; margin-bottom: 10px; }
.g-head b { font-weight: 700; }
.g-clock { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.g-body { display: grid; grid-template-columns: max-content minmax(0, 1fr); column-gap: 14px; }
.g-names { display: grid; grid-auto-rows: var(--rh); align-items: center; font: 13px var(--mono); }
.g-track { position: relative; height: calc(var(--n) * var(--rh) + 22px);
  background: repeating-linear-gradient(90deg, var(--line) 0 1px, transparent 1px 100%) 0 0 / var(--tick) 100%; }
.g-axis { grid-column: -2; position: relative; height: 20px; font: 13px/20px var(--mono); color: var(--muted); font-variant-numeric: tabular-nums; }
.g-axis span { position: absolute; transform: translateX(-50%); }
.g-axis span:first-child { transform: none; }
/* width is the time it has run so far, so no padding: the label is indented instead */
.bar { position: absolute; top: calc(var(--r) * var(--rh) + var(--bo)); height: 24px; border-radius: var(--pill); overflow: hidden; white-space: nowrap; text-indent: 10px;
  font: 600 13px/24px var(--font); color: var(--water); background: var(--ink); }
.bar.fail, .bar.late, .bar.warn { background: var(--coral); color: var(--ink); overflow: visible; } /* a short bar's word runs on past it, ink on cream */
.bar.cut { border-radius: var(--pill) 0 0 var(--pill); }
.bar.tail { border-radius: 0 var(--pill) var(--pill) 0; }
.bar.wait, .bar.skip { color: var(--ink); background: none; border: 2px dashed var(--ink); line-height: 20px; text-indent: 8px; }
.bar.skip { padding-right: 10px; }
.g-head .over { color: var(--bad); }
/* rules across the timetable: when something outside happens, the three-star time, the deadline */
.mark { position: absolute; top: 0; bottom: 0; border-left: 2px dashed var(--ink); font: 600 13px/1.3 var(--font); color: var(--ink); padding: 0 5px; display: flex; align-items: end; gap: 4px; white-space: nowrap; }
.mark.left { transform: translateX(-100%); border-left: 0; border-right: 2px dashed var(--ink); }
.mark.deadline { border-style: solid; border-width: 0 0 0 3px; }
.mark.deadline.left { border-width: 0 3px 0 0; }
.playhead { position: absolute; top: 0; bottom: 0; width: 2px; margin-left: -1px; background: var(--ink); }

/* data-date strip (level 10): one cell per day of data, under the run-date timeline */
.cov-head { margin: 14px 0 8px; justify-content: flex-start; }
.cov { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.cov-cell { border: 2px dashed var(--ink); border-radius: var(--radius); padding: 6px 10px; font-size: 13px; line-height: 1.3; display: grid; gap: 2px; min-width: 0; }
.cov-cell.some, .cov-cell.ok, .cov-cell.gap, .cov-cell.double, .cov-cell.partial { border-style: solid; }
.cov-cell.ok { background: var(--panel-2); }
.cov-cell.gap, .cov-cell.double, .cov-cell.partial { background: var(--coral); }

/* ---- result: shared .result-panel (theme.css); only the issue list and confetti are local ---- */
#verdict ul { margin: 0 0 8px; padding-left: 20px; }
#verdict li { margin: 6px 0; line-height: 1.5; }
#verdict .all-done { font-weight: 700; }
/* confetti bursts upwards from the top edge, so it never covers the result text */
.confetti i { position: absolute; left: 50%; top: 0; width: 8px; height: 8px; border-radius: 50%; background: var(--ink); opacity: 0; animation: burst 1s ease-out; pointer-events: none; }
.confetti i:nth-child(odd) { background: var(--accent); box-shadow: inset 0 0 0 1.5px var(--ink); }
@keyframes burst { from { opacity: 1; } to { transform: rotate(var(--a)) translateY(calc(-1 * var(--d))); opacity: 0; } }

/* ---- Tasks list: the keyboard / screen-reader route to every edit ---- */
.tasks-panel { padding: 14px 16px; align-self: start; }
.tasks-panel h2 { font-size: 19px; margin: 0 0 4px; }
.tasks-panel .hint { font-size: 13px; color: var(--muted); }
#tasks { margin-top: 10px; }
.task { padding: 9px 0; border-top: 1px solid var(--line); font-size: 13px; }
.task:last-child { padding-bottom: 0; }
.task .tname { font: 700 14px/1.3 var(--mono); overflow-wrap: anywhere; }
.task .tname span { font: 500 13px var(--font); margin-left: 4px; }
.task .deps, .task .sets { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 6px; }
.task .sets label { display: inline-flex; align-items: center; gap: 6px; }
.task button.chip { cursor: pointer; font: 700 12px/1.2 var(--mono); min-height: 30px; padding: 2px 9px; }
.task button.chip:hover { background: var(--ink); color: var(--water); }
.task select { font: 12px var(--mono); color: var(--ink); background: var(--water); border: 2px solid var(--ink); border-radius: 10px; padding: 3px 6px; min-height: 30px; max-width: 100%; cursor: pointer; }
.task select:hover { background: var(--panel-2); }
.task .deps select { min-width: 5.5em; }

/* phones: touch-sized controls; each timeline row carries its task's name above its bar */
@media (max-width: 640px) {
  .task button.chip, .task select { min-height: 44px; min-width: 44px; padding-inline: 12px; }
  .edge .hit { stroke-width: 44; }
  #targets { flex: 1 1 100%; } /* chips on their own line; Reset and Run share the next, Run at the right end */
  #gantt { --rh: 48px; --bo: 21px; }
  .g-body { grid-template-columns: minmax(0, 1fr); }
  .g-names, .g-track { grid-area: 1 / 1; }
  .g-names { align-items: start; position: relative; z-index: 1; pointer-events: none; }
}
