/* view.css: the view screen (views.ViewPage). A routine, or a level's pair of
   routines, fills the screen without scrolling: each column's element rows
   share its height, and their text scales with the row (container query units).
   The Show menu hides parts by toggling hide-<key> classes on #view. */

:root {
  --ink: #1b1f2a;
  --muted: #6b7280;
  --line: #e5e7eb;
  --accent: #485fc7;
  --warn: #d97706;
  --met: #257953;
  --unmet: #cc0f35;
  --bg: #fff;
  --bar: #f6f7f9;
}
@media (prefers-color-scheme: dark) {
  :root {
    --ink: #eef0f4;
    --muted: #9aa3b2;
    --line: #2a2f3a;
    --accent: #8ea0ff;
    --warn: #f0a33a;
    --met: #4fbf86;
    --unmet: #ff6b81;
    --bg: #111318;
    --bar: #1a1d24;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

/* The bar: back, routine, Show menu, full screen. */
.view-bar {
  flex: none;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem max(0.75rem, env(safe-area-inset-right)) 0.35rem max(0.75rem, env(safe-area-inset-left));
  padding-top: max(0.35rem, env(safe-area-inset-top));
  background: var(--bar);
  border-bottom: 1px solid var(--line);
  font-size: 0.9rem;
  flex-wrap: wrap; /* the buttons drop to a second line on the narrowest phones */
}
.view-back { color: var(--ink); text-decoration: none; font-size: 1.15rem; padding: 0 0.25rem; }
.view-bar select, .view-bar button, .view-menu summary {
  font: inherit;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0.2rem 0.6rem;
}
#view-routine { min-width: 7rem; flex: 1 1 7rem; max-width: 20rem; }
.view-bar button { cursor: pointer; white-space: nowrap; }
.view-menu { position: relative; margin-left: auto; }
.view-menu summary { cursor: pointer; list-style: none; user-select: none; }
.view-menu summary::-webkit-details-marker { display: none; }
.view-menu summary::after { content: " ▾"; }
.view-menu[open] summary::after { content: " ▴"; }
.view-menu-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 0.3rem);
  z-index: 10;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  padding: 0.65rem 0.8rem;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.15);
  white-space: nowrap;
}
.view-menu-panel label { display: flex; gap: 0.5rem; align-items: center; cursor: pointer; }
.view-menu-columns { display: flex; flex-direction: column; gap: 0.45rem; padding-bottom: 0.55rem; margin-bottom: 0.1rem; border-bottom: 1px solid var(--line); }
.view-menu-columns label { font-weight: 600; }

/* The screen. */
#view {
  flex: 1;
  min-height: 0;
  padding: 0.75rem max(0.75rem, env(safe-area-inset-right)) max(0.75rem, env(safe-area-inset-bottom)) max(0.75rem, env(safe-area-inset-left));
}
#display { height: 100%; }
.view-loading { color: var(--muted); margin: 0; }

.display {
  height: 100%;
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(0, 1fr);
  gap: 1.5rem;
}
/* Several routines stack on a portrait screen, one above the other. */
@media (orientation: portrait) {
  .display.is-several { grid-auto-flow: row; grid-auto-rows: minmax(0, 1fr); gap: 1rem; }
}

.display-column { min-width: 0; min-height: 0; display: flex; flex-direction: column; }
/* Every header is the same height, so the columns' rows line up. */
.display-head {
  flex: none;
  height: clamp(2.6rem, 7vmin, 4.6rem);
  overflow: hidden;
  display: flex;
  align-items: flex-end;
  gap: 0.75rem;
  padding-bottom: 0.35rem;
  border-bottom: 2px solid var(--ink);
}
.display-title { flex: 1; min-width: 0; }
.display-title h2 {
  margin: 0;
  font-size: clamp(1rem, 3.2vmin, 2rem);
  line-height: 1.15;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.display-level { margin: 0.1rem 0 0; color: var(--muted); font-size: clamp(0.75rem, 1.8vmin, 1.1rem); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.display-met {
  flex: none;
  align-self: center;
  font-size: clamp(0.7rem, 1.7vmin, 1rem);
  font-weight: 600;
  color: var(--unmet);
  border: 1px solid currentColor;
  border-radius: 999px;
  padding: 0.1em 0.6em;
}
.display-met.is-met { color: var(--met); }
.display-total {
  flex: none;
  margin: 0;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  font-size: clamp(1.25rem, 5vmin, 3rem);
  line-height: 1;
}
.display-none { font-size: 0.45em; font-weight: 400; color: var(--muted); }

/* Element rows share the column's height; text scales with a row. */
.display-rows {
  flex: 1;
  min-height: 0;
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  grid-template-rows: repeat(var(--rows), minmax(0, 1fr));
  grid-template-columns: minmax(0, 1fr); /* rows fit the column, so long names shorten instead of pushing difficulty off screen */
  container-type: size;
}
.display-row {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 0.6em;
  min-height: 0;
  padding: 0 0.2em;
  border-bottom: 1px solid var(--line);
  font-size: min(calc(100cqh / var(--rows) * 0.5), 6.5cqw);
  line-height: 1.1;
}
.display-row.is-blank { border-bottom-style: dashed; }
.d-num { flex: none; width: 1.5em; color: var(--muted); font-variant-numeric: tabular-nums; }
.d-name { flex: 1 1 auto; min-width: 0; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* Short of room, the notation gives way long before the name. */
.d-fig {
  flex: 0 20 auto;
  min-width: 0;
  overflow: hidden;
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.85em;
  white-space: nowrap;
}
.d-req { flex: none; width: 0.7em; color: var(--accent); font-weight: 700; }
.d-diff { flex: none; width: 2.3em; text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }
.d-warn { flex: none; width: 1.1em; text-align: center; color: var(--warn); font-size: 0.85em; }
.not-counted .d-name, .not-counted .d-diff { color: var(--muted); text-decoration: line-through; }
.unscored .d-diff { color: var(--muted); font-weight: 400; }

/* What the Show menu hides. */
.hide-names .d-name { display: none; }
.hide-names .d-fig { flex: 1; }
.hide-fig .d-fig,
.hide-diff .d-diff,
.hide-total .display-total,
.hide-level .display-level,
.hide-req .d-req,
.hide-req .display-met,
.hide-warnings .d-warn { display: none; }

/* The share dialog (static/js/share.js), which elsewhere uses Bulma's modal. */
.share-modal { position: fixed; inset: 0; z-index: 30; display: flex; align-items: center; justify-content: center; }
.share-modal .modal-background { position: absolute; inset: 0; background: rgba(10, 10, 10, 0.6); }
.share-modal .modal-card {
  position: relative; width: calc(100% - 2rem); max-width: 28rem; max-height: calc(100dvh - 3rem); overflow-y: auto;
  background: var(--bg); color: var(--ink); border-radius: 10px; padding: 1rem 1.1rem; font-size: 0.95rem;
}
.share-modal p { margin: 0; }
.share-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.5rem; }
.share-modal .title { font-size: 1.15rem; font-weight: 600; }
.share-modal .delete {
  width: 1.6rem; height: 1.6rem; border: 0; border-radius: 50%; background: var(--line); color: var(--ink); cursor: pointer; font-size: 0;
}
.share-modal .delete::before { content: "✕"; font-size: 0.85rem; }
.share-intro { font-size: 0.9rem; color: var(--muted); margin-bottom: 0.6rem !important; }
.share-choices { display: flex; flex-direction: column; gap: 0.35rem; margin-bottom: 0.75rem; max-height: 14rem; overflow-y: auto; }
.share-choice { display: flex; align-items: flex-start; gap: 0.5rem; padding: 0.45rem 0.6rem; border: 1px solid var(--line); border-radius: 6px; cursor: pointer; }
.share-choice:has(input:checked) { border-color: var(--accent); }
.share-choice input { margin-top: 0.25rem; }
.share-choice-name { display: block; font-weight: 600; }
.share-choice-detail { display: block; font-size: 0.8rem; color: var(--muted); }
.share-buttons { display: flex; gap: 0.5rem; margin-bottom: 0.5rem; }
.share-buttons .button {
  font: inherit; padding: 0.4rem 0.9rem; border-radius: 6px; border: 1px solid var(--line); background: var(--bar); color: var(--ink); cursor: pointer;
}
.share-buttons .button.is-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.share-buttons .button:disabled { opacity: 0.5; cursor: default; }
.share-link { width: 100%; font: inherit; font-size: 0.75rem; padding: 0.35rem 0.5rem; border: 1px solid var(--line); border-radius: 6px; background: var(--bar); color: var(--muted); }
.share-status { font-size: 0.8rem; color: var(--muted); margin-top: 0.35rem !important; }
.share-qr { display: flex; justify-content: center; margin-top: 0.75rem; }
.share-qr svg { width: min(14rem, 70vw); height: auto; background: #fff; padding: 0.4rem; border-radius: 6px; }
.share-note { text-align: center; font-size: 0.8rem; color: var(--muted); margin-top: 0.25rem !important; }

/* Printed, the routines only: no toolbar. */
@media print {
  .view-bar { display: none; }
}
