/* Graph cards, number-line cards, tick-label overlay and print rules.
   Owned by the graph-card code (graph_card.rs, numberline.rs, labels.rs, export.rs).
   A card is: head (title + 1D/2D/3D control), the graph "plate" (always white), a toolbar and
   quiet detail rows. Tokens come from style.css. */

.graph-card {
  display: flex; flex-direction: column; min-width: 0;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg);
  box-shadow: var(--shadow-1);
  transition: box-shadow var(--dur-2) var(--ease), border-color var(--dur-2) var(--ease);
}
.graph-card:hover { box-shadow: var(--shadow-2); }
.graph-card.tweaking { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent), var(--shadow-1); }

.graph-card-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s-3); padding: var(--s-3) var(--s-4) var(--s-2); }
.graph-card-head h3, .gc-title-input {
  min-width: 0; flex: 1; margin: 0;
  font-family: var(--font-display); font-size: var(--fs-lg); font-weight: 600; line-height: 1.25; color: var(--text);
}
.graph-card-head h3 { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gc-title-input {
  padding: 4px 8px; margin-left: -8px; border: 1px solid transparent; border-radius: var(--r-sm);
  background: transparent; text-overflow: ellipsis;
  transition: background var(--dur-1) var(--ease), border-color var(--dur-1) var(--ease);
}
.gc-title-input:hover { background: var(--sunken); }
.gc-title-input:focus-visible { background: var(--surface); border-color: var(--border-strong); outline-offset: 1px; }

/* The 1D / 2D / 3D control: the product's signature, so it is the loudest thing on the card. */
.mode-seg { display: inline-flex; flex-shrink: 0; padding: 3px; gap: 2px; background: var(--sunken); border-radius: var(--r-md); }
.mode-btn {
  min-width: 40px; padding: 5px 10px; border: 0; border-radius: 8px; background: transparent;
  font-size: var(--fs-sm); font-weight: 700; letter-spacing: 0.02em; color: var(--text-2);
  transition: background var(--dur-1) var(--ease), color var(--dur-1) var(--ease), box-shadow var(--dur-1) var(--ease);
}
.mode-btn:hover:not(.active) { color: var(--text); background: var(--border); }
.mode-btn.active { background: var(--accent); color: var(--accent-ink); box-shadow: var(--shadow-1); }

/* The graph surface is always light so exports and prints do not depend on the page theme; it is
   framed like a sheet of paper laid on the card, with a hairline edge that holds in dark mode. */
.gc-white { background: var(--plate); color: var(--plate-ink); }
.gc-stage {
  position: relative; overflow: hidden; touch-action: none; user-select: none; -webkit-user-select: none;
  margin: 0 var(--s-3); aspect-ratio: 3 / 2; min-height: 240px; max-height: 72vh;
  border: 1px solid var(--plate-edge); border-radius: var(--r-md);
  box-shadow: inset 0 0 0 1px rgb(0 0 0 / 0.02);
}
.gc-stage.plotting { cursor: crosshair; }
.number-line-card { align-self: start; }
.number-line-card .graph-card-head { padding-bottom: var(--s-2); }
.gc-nl { display: flex; justify-content: center; padding: var(--s-2); overflow-x: auto; margin: 0 var(--s-3) var(--s-3); border: 1px solid var(--plate-edge); border-radius: var(--r-md); }
.gc-nl svg { max-width: 100%; height: auto; }

.gc-canvas, .gc-snap, .gc-print { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.gc-canvas { opacity: 0; outline-offset: -3px; }
.gc-canvas.ready { opacity: 1; }
.gc-snap { object-fit: fill; pointer-events: auto; }
.gc-snap:focus-visible, .gc-canvas:focus-visible { outline: 2px solid var(--plate-accent); outline-offset: -3px; }
.gc[data-state="live"] .gc-snap { visibility: hidden; }
.gc-print { display: none; }
.gc-pending { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; margin: 0; color: var(--plate-ink-2); font-size: var(--fs-sm); }

/* Tick labels (HTML over the canvas; see labels.rs) */
.gc-labels { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.lbl-tick {
  position: absolute; left: 0; top: 0;
  font-family: var(--font); font-size: 11px; font-weight: 400; line-height: 1;
  color: var(--plate-ink-2); white-space: nowrap; pointer-events: none; font-variant-numeric: tabular-nums;
  text-shadow: 0 0 3px #fff, 0 0 3px #fff;
}
.lbl-tick.inset { font-size: 10px; color: var(--plate-ink-2); }
.gc-axis { position: absolute; font-size: 12px; color: var(--plate-ink); pointer-events: none; }
.gc:not([data-state="live"]) .gc-axis { display: none; } /* snapshots have the captions baked in */
.gc-axis-x { right: 8px; bottom: 4px; text-align: right; }
.gc-axis-y { left: 6px; top: 4px; }

/* ---------- Toolbar ---------- */

.gc-toolbar { position: relative; display: flex; align-items: center; gap: 2px; padding: var(--s-2) var(--s-3) var(--s-2); container-type: inline-size; }
.gc-tools { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 2px; flex-shrink: 0; }
.gc-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; flex-shrink: 0;
  min-width: 34px; height: 34px; padding: 0 8px; border: 0; border-radius: var(--r-md);
  font-size: var(--fs-sm); font-weight: 600; line-height: 1; white-space: nowrap;
  background: transparent; color: var(--text-2);
  transition: background var(--dur-1) var(--ease), color var(--dur-1) var(--ease);
}
.gc-btn:hover:not(:disabled) { background: var(--sunken); color: var(--text); }
.gc-btn.active { background: var(--accent-soft); color: var(--accent-text); }
.gc-btn.labeled { padding: 0 12px 0 10px; background: var(--accent-soft); color: var(--accent-text); }
.gc-btn.labeled:hover:not(:disabled) { background: var(--accent-soft); box-shadow: inset 0 0 0 1px var(--accent); color: var(--accent-text); }
.gc-btn.labeled.active { background: var(--accent); color: var(--accent-ink); }
.gc-btn.danger { color: var(--danger); }
.gc-btn.danger:hover:not(:disabled) { background: var(--danger-soft); color: var(--danger); }
.gc-count-btn { font-family: var(--mono); font-size: var(--fs-xs); }
.gc-sep { width: 1px; height: 18px; margin: 0 var(--s-1); background: var(--border); flex-shrink: 0; }
.gc-grow { flex: 1; min-width: 0; }
.gc-panel-bar .gc-btn.labeled { background: transparent; color: var(--text-2); box-shadow: inset 0 0 0 1px var(--border-strong); }

/* Narrow cards keep the essentials and move the rest into the "More" menu. */
.gc-more { position: relative; display: none; }
@container (max-width: 559px) {
  .gc-t2 { display: none; }
  .gc-more { display: block; }
}
.gc-menu-scrim { position: fixed; inset: 0; z-index: 40; }
.gc-menu {
  position: absolute; right: 0; bottom: calc(100% + 6px); z-index: 41; min-width: 220px; padding: 4px;
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--r-md); box-shadow: var(--shadow-2);
  animation: pop var(--dur-1) var(--ease);
}
.gc-menu-item {
  display: flex; align-items: center; gap: var(--s-3); width: 100%; min-height: 38px; padding: 6px 12px;
  border: 0; border-radius: var(--r-sm); background: transparent; text-align: left; color: var(--text); font-size: var(--fs-sm);
}
.gc-menu-item:hover:not(:disabled), .gc-menu-item:focus-visible { background: var(--accent-soft); }
.gc-menu-item.danger { color: var(--danger); }
.gc-menu-item.danger:hover { background: var(--danger-soft); }

/* ---------- Details under the graph ---------- */

.gc-error {
  margin: 0 var(--s-3) var(--s-2); padding: var(--s-2) var(--s-3); font-size: var(--fs-sm);
  background: var(--danger-soft); color: var(--danger); border-radius: var(--r-sm);
}
.gc-notice { padding: 0 var(--s-4) var(--s-3); font-size: var(--fs-sm); color: var(--text-2); }
.gc-notice summary { cursor: pointer; font-weight: 600; color: var(--warn-text); width: fit-content; padding: 2px 0; border-radius: var(--r-sm); }
.gc-notice .chips { margin-top: var(--s-2); }
.gc-eqs { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 var(--s-4) var(--s-4); }
.gc-eqs code {
  display: inline-block; max-width: 100%; padding: 3px 9px; border-radius: var(--r-sm);
  font-family: var(--mono); font-size: var(--fs-sm); color: var(--text-2); background: var(--sunken);
  overflow-wrap: anywhere;
}
.gc-eqs code.muted { color: var(--text-3); }

/* ---------- Expanded card ---------- */

.graph-grid[data-focused="true"] { display: flex; flex-direction: column; align-items: stretch; flex: 1; min-height: 0; }
.graph-grid[data-focused="true"] .graph-card:not(.focused), .graph-grid[data-focused="true"] .number-line-card { display: none; }
.graph-grid[data-focused="true"] .graph-card.focused { flex: 1; min-height: 0; }
.graph-grid[data-focused="true"] .graph-card.focused .gc-stage { flex: 1; aspect-ratio: auto; max-height: none; min-height: 320px; }
.graph-card.focused { border-color: var(--border-strong); }

/* ---------- Small screens ---------- */

@media (max-width: 767px) {
  .graph-card-head { padding: var(--s-3) var(--s-3) var(--s-2); }
  .gc-stage { margin: 0 var(--s-2); min-height: 220px; }
  .gc-toolbar { padding: var(--s-2) var(--s-2); gap: 0; }
  .gc-sep { display: none; }
  .gc-notice, .gc-eqs { padding-left: var(--s-3); padding-right: var(--s-3); }
  .gc-error { margin-left: var(--s-2); margin-right: var(--s-2); }
}
@media (pointer: coarse) {
  .gc-btn { min-width: var(--touch); height: var(--touch); }
  .mode-btn { min-width: var(--touch); min-height: var(--touch); }
  .gc-menu-item { min-height: var(--touch); }
  .gc-title-input { min-height: var(--touch); }
  .gc-notice summary { min-height: var(--touch); display: flex; align-items: center; }
}

/* ---------- Print: graphs only ---------- */
@media print {
  /* Everything outside the graph column goes away. */
  .app-header, .left, .resizer, .skip-link, .gc-panel-bar, .gc-tools, .gc-toolbar, .gc-notice, .mode-seg { display: none !important; }
  html, body, .app, .app-main, .right { height: auto !important; overflow: visible !important; display: block !important; background: #fff !important; }
  .graph-panel { padding: 0; display: block; }
  .graph-grid, .graph-grid[data-focused="true"] { display: block; }
  .graph-grid[data-focused="true"] .graph-card:not(.focused), .graph-grid[data-focused="true"] .number-line-card { display: block; }
  .graph-card { break-inside: avoid; page-break-inside: avoid; box-shadow: none !important; border: 1px solid #ccc; margin: 0 0 12px; background: #fff; color: #000; }
  .graph-card h3, .gc-title-input { color: #000; }
  /* A single card was asked for: hide the others. */
  body[data-print="one"] .graph-card:not([data-print-target]), body[data-print="one"] .graph-grid[data-focused="true"] .graph-card:not([data-print-target]) { display: none !important; }
  /* WebGL canvases can print blank: print the composited picture instead. */
  .gc-canvas, .gc-snap, .gc-labels, .gc-axis, .gc-pending { display: none !important; }
  .gc-print { display: block; position: static; width: 100%; height: auto; }
  .gc-stage { overflow: visible; height: auto; aspect-ratio: auto; max-height: none; margin: 0; border: 0; }
  .gc-eqs code { background: #fff; color: #000; }
  .gc-card-head, .graph-card-head { background: #fff; }
}
