:root {
  font-family: system-ui, sans-serif;
  color: #202a35;
  background: #edf0f3;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
}

header {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.75rem;
  padding: 1rem;
  background: white;
  border-bottom: 1px solid #cdd4dc;
}

h1 { margin: 0 auto 0 0; font-size: 1.25rem; }
#toggle-fullscreen { display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem; flex-shrink: 0; min-height: 2.5rem; min-width: 2.5rem; padding: 0.4rem 0.6rem; font: inherit; font-size: 0.8rem; color: inherit; background: white; border: 1px solid #cdd4dc; border-radius: 0.4rem; cursor: pointer; }
#toggle-fullscreen:hover, #toggle-fullscreen[aria-pressed="true"] { background: #e5f0ff; border-color: #246bb5; }
#toggle-fullscreen:focus-visible { outline: 2px solid #246bb5; outline-offset: 2px; }
#toggle-fullscreen:disabled { opacity: 0.5; cursor: default; }
#fullscreen-status { flex-basis: 100%; font-size: 0.8rem; color: #9a2525; }
:fullscreen { background: #edf0f3; }
#share-site { padding: 0; border: 0; background: none; color: inherit; font: inherit; font-weight: inherit; text-align: left; cursor: pointer; }
#share-site:hover { color: #246bb5; }
#share-site:focus-visible { outline: 2px solid #246bb5; outline-offset: 4px; border-radius: 0.2rem; }
#share-dialog { width: min(32rem, calc(100vw - 2rem)); max-height: calc(100dvh - 2rem); padding: 1.5rem; overflow-y: auto; border: 1px solid #cdd4dc; border-radius: 0.75rem; color: inherit; text-align: center; box-shadow: 0 1rem 4rem #13263c40; }
#share-dialog::backdrop { background: #15253799; }
#share-heading { margin: 0; font-size: 1.3rem; }
#share-intro, #share-status { font-size: 0.9rem; line-height: 1.4; color: #526170; }
#share-address-label { display: grid; gap: 0.4rem; margin: 1rem 0; font-size: 0.85rem; text-align: left; }
#share-qr { display: block; width: 100%; max-width: 26rem; height: auto; aspect-ratio: 1; margin: 0.75rem auto; background: white; }
#share-url { display: block; color: #164d89; font-size: 1.05rem; overflow-wrap: anywhere; }
#share-dialog .save-toolbar { justify-content: center; }

select {
  font: inherit;
  padding: 0.5rem;
  max-width: 100%;
  min-width: 0;
}

main {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 1rem;
  gap: 0.75rem;
}

.drawing-message { margin: 0; padding: 1rem; font-size: 0.85rem; color: #526170; }

.workspace {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: var(--library-width, minmax(0, min(14rem, 25%))) minmax(0, 1fr) var(--editor-width, minmax(0, min(20rem, 40%)));
  grid-template-rows: minmax(0, 1fr);
  gap: 1rem;
}
.workspace-panel { min-width: 0; min-height: 0; }
#library-panel, #shot-editor-panel { overflow: auto; }
#library-panel { grid-column: 1; grid-row: 1; }
#shot-editor-panel { grid-column: 3; grid-row: 1; }
#drawing-workspace { grid-column: 2; grid-row: 1; }
#library-panel:has(> aside > details:not([open])),
#shot-editor-panel:has(> aside > details:not([open])) { width: max-content; align-self: start; overflow: visible; }
.workspace > .workspace-panel > aside > details:not([open]) > summary { writing-mode: vertical-rl; white-space: nowrap; }
.workspace:has(#library-details:not([open])) { --library-width: max-content; }
.workspace:has(#inspector-edit:not([open])) { --editor-width: max-content; }

aside {
  width: 100%;
  max-width: none;
  overflow: auto;
  padding: 1rem;
  background: white;
  border: 1px solid #cdd4dc;
  border-radius: 0.5rem;
}

#library-panel > aside { padding: 1rem; }
#library-details > summary { cursor: pointer; }
#library-details > summary:focus-visible { outline: 2px solid #246bb5; outline-offset: 3px; }
#library-details[open] > summary { margin-bottom: 0.8rem; }
#library-panel h2 { display: inline; font-size: 1rem; margin: 0; }
#library-panel h3 { font-size: 0.9rem; }
#library-tree details { margin: 0.45rem 0; }
#library-tree summary { cursor: pointer; font-size: 0.85rem; overflow-wrap: anywhere; }
#library-tree .project-heading { min-height: 1.8rem; }
#library-tree .project-actions { display: flex; justify-content: flex-end; gap: 0.2rem; margin-top: 0.2rem; }
#library-tree .project-heading button { font-size: 0.7rem; color: #164d89; border-color: #cdd4dc; white-space: nowrap; }
#library-tree .library-link { display: inline-flex; align-items: center; justify-content: center; padding: 0.4rem; color: #164d89; border: 1px solid #cdd4dc; border-radius: 0.35rem; background: white; }
#library-tree .library-link:hover { background: #f0f5fa; }
#library-tree .library-link:focus-visible { outline: 2px solid #246bb5; outline-offset: 2px; }
.library-children { padding-left: 0.65rem; margin-top: 0.3rem; display: grid; gap: 0.2rem; }
#library-tree button { min-width: 0; text-align: left; overflow-wrap: anywhere; border: 1px solid transparent; border-radius: 0.35rem; padding: 0.4rem; background: white; font: inherit; font-size: 0.8rem; cursor: pointer; }
#library-tree button:hover { background: #f0f5fa; }
#library-tree button[aria-pressed="true"] { background: #e5f0ff; border-color: #246bb5; color: #164d89; }
.library-image-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 0.15rem; }
.library-svg-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 0.15rem; }
.library-shot-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 0.15rem; }
.library-svg-row a { color: #164d89; font-size: 0.7rem; padding: 0.4rem; }
#library-tree button[data-reference] { font-size: 0.7rem; color: #164d89; }
#library-tree button[data-reference]:disabled { opacity: 0.5; cursor: default; }
#library-tree p, #new-shot-status { font-size: 0.75rem; color: #657487; line-height: 1.4; }
#new-shot-form { border-top: 1px solid #cdd4dc; margin-top: 1rem; padding-top: 0.5rem; }
#new-shot-form label { display: flex; flex-direction: column; gap: 0.3rem; margin: 0.6rem 0; font-size: 0.75rem; }
#new-shot-form input, #new-shot-form select { min-width: 0; width: 100%; padding: 0.4rem; border: 1px solid #cdd4dc; border-radius: 0.3rem; font: inherit; }

#new-project-dialog { width: min(40rem, calc(100vw - 2rem)); max-height: calc(100dvh - 2rem); padding: 1.5rem; color: inherit; border: 1px solid #cdd4dc; border-radius: 0.75rem; box-shadow: 0 1rem 4rem #13263c40; overflow-y: auto; }
#new-project-dialog::backdrop { background: #15253799; }
#access-dialog { width: min(28rem, calc(100vw - 2rem)); padding: 1.5rem; color: inherit; border: 1px solid #cdd4dc; border-radius: 0.75rem; box-shadow: 0 1rem 4rem #13263c40; }
#access-dialog::backdrop { background: #15253799; }
#access-heading { margin: 0; font-size: 1.2rem; }
#access-form label { display: grid; gap: 0.35rem; }
#access-password { width: 100%; padding: 0.6rem; border: 1px solid #b7c3d0; border-radius: 0.35rem; font: inherit; }
#access-message { color: #9a2525; font-size: 0.85rem; }
#access-form .save-toolbar { justify-content: flex-end; }
#new-project-heading { margin: 0; font-size: 1.3rem; }
#project-read-fields { display: grid; grid-template-columns: minmax(7rem, 1fr) 3fr; gap: 0.6rem 1rem; font-size: 0.85rem; }
#project-read-fields dt { font-weight: 600; }
#project-read-fields dd { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
#new-project-intro { margin: 0.5rem 0 1.25rem; color: #526170; font-size: 0.9rem; }
#new-project-form label { display: flex; flex-direction: column; gap: 0.35rem; margin: 0.8rem 0; font-size: 0.85rem; }
#new-project-form input, #new-project-form select, #new-project-form textarea { min-width: 0; width: 100%; padding: 0.55rem; border: 1px solid #b7c3d0; border-radius: 0.35rem; font: inherit; background: white; }
#new-project-form textarea { resize: vertical; line-height: 1.4; }
.project-form-columns { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 0 1rem; }
.project-aim-widgets { border: 1px solid #b7c3d0; border-radius: 0.35rem; margin: 1rem 0; padding: 0.75rem; }
.project-aim-widgets legend { font-size: 0.85rem; font-weight: 600; padding: 0 0.3rem; }
.project-aim-choices { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.75rem; }
#new-project-form .project-aim-choice { margin: 0; padding: 0.65rem; border: 2px solid #d3dce5; border-radius: 0.35rem; cursor: pointer; }
#new-project-form .project-aim-choice:has(input:checked) { border-color: #246bb5; background: #f0f7ff; }
.project-aim-choice span { display: flex; align-items: center; gap: 0.45rem; }
#new-project-form .project-aim-choice input { width: auto; margin: 0; accent-color: #246bb5; }
.project-aim-choice img, .project-aim-preview { display: block; width: 100%; height: auto; max-width: 240px; background: white; border-radius: 0.25rem; }
.project-aim-preview { margin-top: 0.5rem; border: 1px solid #d3dce5; }
#new-project-hint, #new-project-template-hint, #new-project-status { color: #526170; font-size: 0.8rem; line-height: 1.4; margin: 0.3rem 0; }
#new-project-status { color: #9a2525; }
.project-form-actions { justify-content: flex-end; position: sticky; bottom: -1.5rem; padding: 0.75rem 0; background: white; }
#new-project-form button[type="submit"] { background: #246bb5; color: white; border-color: #246bb5; }
#new-project-form :focus-visible { outline: 2px solid #246bb5; outline-offset: 2px; }

#shot-editor-panel { overflow: auto; }
#shot-editor-panel > aside { width: 100%; max-width: none; }
#library-panel > aside, #shot-editor-panel > aside { max-height: 100%; }
#inspector-edit > summary, [data-shot-settings-section] > summary, #shot-fields > details > summary { font-weight: 600; cursor: pointer; }
#edit-status { font-size: 0.85rem; }
.save-toolbar { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 0.75rem; }
.save-toolbar button { font: inherit; font-size: 0.8rem; padding: 0.45rem 0.65rem; border: 1px solid #cdd4dc; border-radius: 0.4rem; background: white; cursor: pointer; }
#save-shot:not(:disabled) { color: white; background: #246bb5; border-color: #246bb5; }
.save-toolbar button:disabled { opacity: 0.5; cursor: default; }
#save-status { font-size: 0.75rem; color: #526170; overflow-wrap: anywhere; line-height: 1.4; }
#preview-status, #trajectory-status { margin: 0.35rem 0; font-size: 0.75rem; color: #657487; }
#preview-diagnostics { margin: 0.5rem 0; padding-left: 1rem; font-size: 0.75rem; line-height: 1.4; }
#preview-diagnostics .error { color: #9a2525; }
#preview-diagnostics .warning { color: #855700; }
#shot-fields { margin: 0.75rem 0; border-bottom: 1px solid #e2e7ed; padding-bottom: 0.75rem; }
#shot-fields, #shot-shot-settings-fields { display: grid; gap: 0.8rem; }
#shot-fields > details, #shot-shot-settings-fields > section { min-width: 0; }
#shot-fields > details > div, #shot-shot-settings-fields > section > div { margin-top: 0.6rem; }
#shot-shot-settings-fields > section > h3 { margin: 0; font-size: 0.9rem; font-weight: 600; }
#shot-fields > :where([data-shot-settings-section]) label { display: flex; flex-direction: column; gap: 0.25rem; min-width: 0; font-size: 0.75rem; color: #526170; }
#shot-fields > :where([data-shot-settings-section]) input, #shot-fields > :where([data-shot-settings-section]) select { width: 100%; min-width: 0; padding: 0.4rem; font: inherit; font-size: 0.85rem; border: 1px solid #cdd4dc; border-radius: 0.35rem; }
#shot-fields > :where([data-shot-settings-section]) input[aria-invalid="true"] { outline: 2px solid #b32727; }
#shot-fields > :where([data-shot-settings-section]) textarea { width: 100%; min-width: 0; resize: vertical; padding: 0.5rem; font: inherit; font-size: 0.85rem; line-height: 1.4; border: 1px solid #cdd4dc; border-radius: 0.35rem; }
#shot-visibility-fields { display: grid; gap: 0.6rem; }
#shot-visibility-fields fieldset { min-width: 0; margin: 0; border: 1px solid #dae1e9; border-radius: 0.35rem; display: grid; gap: 0.45rem; }
#shot-visibility-fields legend { font-size: 0.75rem; color: #526170; }
#shot-visibility-fields label { flex-direction: row; align-items: center; gap: 0.5rem; }
#shot-visibility-fields input { width: auto; margin: 0; }
#shot-visibility-fields label:has(input:disabled) { opacity: 0.5; }
.element-tree, .element-tree ul { list-style: none; padding-left: 1rem; }
.element-tree { padding-left: 0; }
.element-tree li { margin: 0.4rem 0; }
.element-tree summary { cursor: pointer; overflow-wrap: anywhere; }
.element-tree code { font-size: 0.85rem; overflow-wrap: anywhere; }

:is(#edit-tree, #artifact-list) button {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  width: 100%;
  font: inherit;
  font-size: 0.9rem;
  text-align: left;
  overflow-wrap: anywhere;
  max-width: 100%;
  padding: 0.5rem 0.65rem;
  border: 1px solid transparent;
  border-radius: 0.4rem;
  background: white;
  cursor: pointer;
}
:is(#edit-tree, #artifact-list) h3 { margin: 0.75rem 0 0.5rem; font-size: 0.95rem; }
.ball-path-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 0.4rem; }
.ball-path-row > button { min-width: 0; }
#delete-path { padding: 0.4rem 0.6rem; font: inherit; font-size: 0.85rem; color: #9a2525; background: #fff5f5; border: 1px solid #dbaaaa; border-radius: 0.4rem; cursor: pointer; }
#delete-path:hover { background: #ffe5e5; }
:is(#edit-tree, #artifact-list) > li > ul { padding-left: 0; }
:is(#edit-tree, #artifact-list) button:hover { background: #f0f5fa; }
:is(#edit-tree, #artifact-list) button:focus-visible { outline: 2px solid #246bb5; outline-offset: 2px; }
.edit-icon { display: inline-block; flex-shrink: 0; width: 1.25rem; height: 1.25rem; vertical-align: middle; margin-right: 0.4rem; }
button .edit-icon { margin-right: 0; }
.ball-icon { width: 1rem; height: 1rem; margin-left: 0.125rem; margin-right: 0.525rem; border-radius: 50%; border: 1px solid #7b8590; box-shadow: inset -2px -2px 3px #0002; }
button .ball-icon { margin-right: 0.125rem; }
.path-icon { overflow: visible; }
:is(#edit-tree, #artifact-list) button[aria-pressed="true"] { background: #dcecff; border-color: #246bb5; }
#ball-editor { margin: 1rem 0 0; min-width: 0; border: 1px solid #cdd4dc; }
#ball-editor legend { overflow-wrap: anywhere; }
#ball-editor p { font-size: 0.8rem; }
#ball-editor label { display: flex; align-items: center; gap: 0.5rem; margin: 0.5rem 0; }
#ball-editor input { width: 100%; min-width: 0; padding: 0.4rem; font: inherit; }
#ball-editor input[aria-invalid="true"] { outline: 2px solid #b32727; }
#path-editor { margin: 1rem 0 0; min-width: 0; border: 0; padding: 0; }
#path-editor legend { font-weight: 600; padding: 0; margin-bottom: 0.75rem; }
#path-editor p { font-size: 0.8rem; }
#path-editor button, #path-editor select, .add-menu > summary {
  font: inherit; font-size: 0.8rem; border: 1px solid #cdd4dc; border-radius: 0.4rem;
  background: white; color: inherit; padding: 0.45rem 0.6rem; cursor: pointer;
}
#path-editor button:hover, .add-menu > summary:hover { background: #edf4fb; }
#path-editor button:focus-visible, #path-editor summary:focus-visible { outline: 2px solid #246bb5; outline-offset: 2px; }
#path-editor button[aria-pressed="true"] { border-color: #246bb5; background: #e5f0ff; color: #164d89; }
#path-points { display: grid; gap: 0.2rem; margin-bottom: 0.8rem; }
#path-points .point-list-button { display: flex; justify-content: space-between; align-items: center; text-align: left; border-color: transparent; }
.point-list-button small { color: #657487; font-size: 0.7rem; }
#point-editor { padding: 0.8rem; border: 1px solid #dae1e9; border-radius: 0.5rem; background: #f8fafc; }
#point-editor h4 { font-size: 0.9rem; margin: 0 0 0.75rem; }
.coordinate-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 0.6rem; }
#path-editor label { display: flex; align-items: center; gap: 0.5rem; font-size: 0.8rem; }
#path-editor .coordinate-grid label { flex-direction: column; align-items: stretch; gap: 0.25rem; color: #526170; }
#path-editor input { width: 100%; min-width: 0; padding: 0.45rem; font: inherit; font-size: 0.85rem; border: 1px solid #cdd4dc; border-radius: 0.35rem; background: white; }
#path-editor input[readonly] { color: #657487; background: #edf1f5; }
#path-editor input[aria-invalid="true"] { outline: 2px solid #b32727; }
.travel-type { flex-direction: column; align-items: stretch !important; margin-top: 0.75rem; }
.handle-tabs { display: flex; gap: 0.3rem; margin-top: 0.6rem; flex-wrap: wrap; }
#path-editor .handle-tabs button { font-size: 0.7rem; padding: 0.35rem; }
.point-toolbar { display: flex; justify-content: space-between; gap: 0.5rem; align-items: flex-start; margin-top: 0.75rem; }
#path-editor .danger-button, #path-editor #delete-path { color: #9a2525; border-color: #e0baba; background: white; }
.editor-hint { color: #657487; line-height: 1.4; margin: 0.65rem 0 0; }
.add-menu { position: relative; }
.add-menu > summary { list-style: none; color: #164d89; }
.add-menu > summary::-webkit-details-marker { display: none; }
.add-menu-options { position: absolute; top: calc(100% + 0.3rem); left: 0; min-width: 9rem; z-index: 5; display: grid; padding: 0.3rem; background: white; border: 1px solid #cdd4dc; box-shadow: 0 4px 14px #20304422; border-radius: 0.4rem; }
#path-editor .add-menu-options button { text-align: left; border: 0; }
.path-advanced { margin-top: 0.75rem; padding-top: 0.65rem; border-top: 1px solid #e2e7ed; }
.path-advanced > summary { font-size: 0.8rem; color: #657487; cursor: pointer; }
#point-advanced > label { margin-top: 0.6rem; flex-wrap: wrap; }
#path-data { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 0.7rem; color: #526170; }
.segment-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem; margin: 0.6rem 0; }
.segment-actions input { max-width: 5rem; }
.path-point-number { fill: #164d89; text-anchor: middle; dominant-baseline: central; pointer-events: none; font-family: system-ui, sans-serif; }
.path-handle.chosen { fill: #cce2ff; stroke-width: 2.5; }
.path-control-guide { stroke: #246bb5; stroke-width: 1; stroke-dasharray: 4 3; vector-effect: non-scaling-stroke; pointer-events: none; }
.path-handle { fill: white; stroke: #246bb5; stroke-width: 1.5; vector-effect: non-scaling-stroke; cursor: grab; touch-action: none; }
.path-handle.control { fill: #ffd58a; }
#display path[data-editor-selected="true"] { filter: drop-shadow(0 0 2px #246bb5); }
#display[data-dragging="true"] .path-handle { cursor: grabbing; }
#display g[id="balls"] > circle { cursor: grab; touch-action: none; }
#display [data-cue-draggable] { cursor: grab; touch-action: none; }
#display[data-dragging="true"] [data-cue-draggable] { cursor: grabbing; }
#shot-cue-ball-and-aiming-fields > label:has(select[data-shot-aim]) { grid-column: 1 / -1; }
#display[data-dragging="true"], #display[data-dragging="true"] g[id="balls"] > circle { cursor: grabbing; user-select: none; }
#display circle[data-editor-selected="true"] { outline: 2px dashed #246bb5; }
#display[data-shot-editable="true"] circle[id="cue-impact"], .hit-grab-area { cursor: grab; touch-action: none; pointer-events: all; }
.hit-grab-area { fill: transparent; stroke: none; }
#display[data-shot-editable="true"] circle[id="widget-cue-ball"] { cursor: grab; touch-action: none; pointer-events: all; }
#display[data-shot-editable="true"] #target-scale-dot, #display[data-shot-editable="true"] #target-scale-grab { cursor: ew-resize; touch-action: none; pointer-events: all; }
#display[data-shot-editable="true"] #aim-widget, #display[data-shot-editable="true"] #hit-widget { touch-action: none; }
#display[data-shot-editable="true"] [data-widget-surface] { cursor: crosshair; pointer-events: all; }
#display[data-shot-editable="true"] line[id="widget-aim-line"] { pointer-events: none; }
#display[data-shot-editable="true"][data-dragging="true"] circle[id="widget-cue-ball"] { cursor: grabbing; }
#display svg[data-ball-paths-visible="false"] [data-demo-trajectories],
#display svg[data-ball-paths-visible="false"] [data-path-editor] { display: none; }
#display[data-shot-editable="true"][data-dragging="true"] circle[id="cue-impact"], #display[data-dragging="true"] .hit-grab-area { cursor: grabbing; }

#drawing-workspace { display: flex; flex-direction: column; flex: 1; min-width: 0; min-height: 0; gap: 0.6rem; }
#drawing-view-controls { display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 0.35rem; }
#drawing-view-controls button { min-width: 2.5rem; min-height: 2.5rem; padding: 0.35rem 0.65rem; border: 1px solid #cdd4dc; border-radius: 0.35rem; background: white; color: inherit; font: inherit; cursor: pointer; }
#drawing-view-controls button:disabled { opacity: 0.45; cursor: default; }
#zoom-level { min-width: 3.5rem; text-align: center; font-variant-numeric: tabular-nums; font-size: 0.85rem; }
#display[data-can-pan] > svg { cursor: grab; }
#display[data-panning] > svg, #display[data-panning] > svg * { cursor: grabbing !important; }
#drawing-panes { display: flex; flex: 1; min-height: 0; min-width: 0; gap: 0.75rem; }
#reference-panel { flex: 1; min-width: 0; min-height: 0; display: flex; flex-direction: column; padding: 0.6rem; background: white; border: 1px solid #cdd4dc; border-radius: 0.5rem; }
.reference-heading { display: flex; align-items: flex-start; gap: 0.5rem; }
#reference-name { flex: 1; margin: 0; font-size: 0.8rem; font-weight: 500; overflow-wrap: anywhere; }
#hide-reference { padding: 0.3rem 0.5rem; font: inherit; font-size: 0.75rem; border: 1px solid #cdd4dc; border-radius: 0.35rem; background: white; cursor: pointer; }
#reference-status { font-size: 0.8rem; overflow-wrap: anywhere; }
#reference-image { flex: 1; min-height: 0; margin-top: 0.5rem; }
#reference-image img { display: block; width: 100%; height: 100%; object-fit: contain; }

@media (max-width: 1100px) {
  #drawing-panes { flex-direction: column; }
  #reference-panel { order: 1; }
}

@media (max-width: 650px) {
  #new-project-dialog { padding: 1rem; }
  .project-form-columns { grid-template-columns: minmax(0, 1fr); }
  .project-aim-choices { grid-template-columns: minmax(0, 1fr); }
  .project-form-actions { bottom: -1rem; }
}

@media (orientation: portrait), (max-width: 650px) {
  .workspace {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-rows: max-content max-content;
    align-items: start;
    align-content: start;
    overflow-y: auto;
  }
  #drawing-workspace { grid-column: 1 / -1; grid-row: 1; align-self: start; width: 100%; aspect-ratio: var(--drawing-aspect, 2 / 3); min-height: 24rem; }
  #library-panel { grid-column: 1; grid-row: 2; }
  #shot-editor-panel { grid-column: 2; grid-row: 2; }
  #library-panel, #shot-editor-panel { flex: 0 0 auto; max-height: none; overflow: visible; }
  #library-panel > aside, #shot-editor-panel > aside { width: 100%; max-width: none; max-height: none; overflow: visible; }
}

@media (max-width: 500px) {
  header { gap: 0.5rem; padding: 0.75rem; }
  h1 { font-size: 1.05rem; }
  #version { font-size: 0.75rem; }
  #fullscreen-label { display: none; }
  main { padding: 0.65rem; }
  .workspace { gap: 0.65rem; }
  #library-panel > aside, #shot-editor-panel > aside { padding: 0.65rem; }
}

#display {
  flex: 1;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: white;
  border: 1px solid #cdd4dc;
  border-radius: 0.5rem;
}

#display > svg, #display > img {
  display: block;
  width: 100%;
  height: 100%;
}
#display > img { object-fit: contain; }

#show-clients { vertical-align: middle; min-width: 2rem; min-height: 2rem; padding: 0.2rem 0.45rem; border: 1px solid #cdd4dc; border-radius: 1rem; background: #e5f0ff; color: #164d89; font: 0.8rem system-ui, sans-serif; cursor: pointer; }
#show-clients:focus-visible { outline: 2px solid #246bb5; outline-offset: 2px; }
#clients-dialog { width: min(42rem, calc(100vw - 2rem)); max-height: calc(100dvh - 2rem); padding: 1.25rem; border: 1px solid #cdd4dc; border-radius: 0.75rem; color: inherit; overflow-y: auto; box-shadow: 0 1rem 4rem #13263c40; }
#clients-dialog::backdrop { background: #15253799; }
#clients-dialog h2 { margin-top: 0; }
#clients-dialog p { font-size: 0.85rem; color: #526170; }
#clients-list { list-style: none; padding: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 16rem), 1fr)); gap: 1rem; }
#clients-list li { padding: 0.75rem; border: 1px solid #cdd4dc; border-radius: 0.4rem; }
#clients-list h3 { margin: 0 0 0.5rem; font-size: 1rem; }
#clients-list dl { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 0.4rem 0.65rem; font-size: 0.8rem; margin: 0; }
#clients-list dd { margin: 0; overflow-wrap: anywhere; }

/* Empty drawing space pans the workspace. touch-scroll.ts reserves handled
   editor presses with touchstart so SVG circles also keep their drags. */
#display > svg { touch-action: auto; }
/* Power is editable in the drawing as well as in Shot settings. */
#display[data-shot-editable] [id="power-widget"] { cursor: ew-resize; touch-action: none; }
#display [id="power-widget"]:focus { outline: 2px solid #278dcc; }
#artifact-tree { margin-top: 1rem; }
.artifact-row { display: flex; align-items: center; gap: .4rem; }
.artifact-row button { flex: 1; }
#artifact-editor { margin-top: .8rem; padding: .6rem; border: 1px solid #cdd4dc; border-radius: .4rem; }
#artifact-editor label { display: grid; grid-template-columns: 1fr 1fr; align-items: center; gap: .4rem; font-size: .8rem; margin: .3rem 0; }
#artifact-editor input { width: 100%; min-width: 0; box-sizing: border-box; }
#artifact-editor p { font-size: .8rem; }
#artifact-editor input[readonly] { background: #edf1f5; color: #526170; }
.artifact-handle { fill: white; stroke: #246bb5; stroke-width: 2; vector-effect: non-scaling-stroke; cursor: grab; touch-action: none; }
.artifact-axis { stroke: #246bb5; stroke-width: 1; stroke-dasharray: 4 3; vector-effect: non-scaling-stroke; pointer-events: none; }
#display [data-artifact-id] { cursor: pointer; pointer-events: all; }
.path-comparison { display: flex; flex-wrap: wrap; gap: .75rem; margin-top: .8rem; font-size: .8rem; }
#display[data-show-source-paths="false"] [id="ball-paths"],
#display[data-show-engine-paths="false"] [id="simulated-paths"] { display: none; }
