/* --- preview: the graphic alone in its frame --------------------------------- */
.preview { display: grid; gap: 12px; justify-items: center; }
#preview {
  /* --ar (width / height) is set from JS; the canvas never exceeds 70% of the
     screen height on desktop and 55% on phones, so the form stays reachable */
  --ar: 0.5625;
  width: min(100%, 400px, calc(70dvh * var(--ar)));
  height: auto;
  aspect-ratio: 9 / 16; /* updated from the canvas size in JS */
  border-radius: var(--radius-md);
  background: var(--raised);
}

/* --- form: groups separated by a rule and space, no panels ------------------- */
form { display: grid; gap: 40px; }
fieldset {
  min-inline-size: 0; /* fieldsets default to min-content and can force sideways scrolling */
  border: 0;
  border-top: 1px solid var(--line);
  padding: 24px 0 0;
  margin: 0;
  display: grid;
  gap: 16px 20px;
}
legend {
  float: left; width: 100%; padding: 0; margin-bottom: 4px;
  font-size: var(--fs-lg); font-weight: 800; color: var(--text);
}
legend + * { clear: both; }
.row { display: grid; gap: 16px 20px; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); align-items: start; }
/* wide screens: the match form flows in columns of about three fields */
@media (min-width: 720px) {
  /* hints sit under their field, so labels and fields align across a row */
  #form fieldset { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); align-items: start; }
  #form fieldset > legend, #form fieldset > .hint, #form fieldset > .warning, #form fieldset > .status,
  #form fieldset > fieldset:not(.segmented), #form fieldset > ol, #form fieldset > .upload, #form fieldset > .button-row,
  #form fieldset > .check, #form fieldset > .link-btn, #form fieldset > button { grid-column: 1 / -1; }
  #form fieldset > button, #form fieldset > .link-btn { justify-self: start; }
  #form .row { display: contents; }
}
input, select, textarea { min-width: 0; }
label { display: grid; gap: 6px; font-size: var(--fs-sm); font-weight: 600; color: var(--text); }
.hint { font-weight: 400; color: var(--muted); font-size: var(--fs-sm); margin: 0; }
input[type="text"], input[type="date"], input[type="time"], input[type="email"], input[type="password"], select, textarea {
  font: inherit;
  font-size: var(--fs-md);
  font-weight: 400;
  color: var(--text);
  background: var(--raised);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  width: 100%;
  min-height: 44px;
  transition: border-color 150ms ease-out;
}
@media (hover: hover) {
  input[type="text"]:hover, input[type="date"]:hover, input[type="time"]:hover, input[type="email"]:hover,
  input[type="password"]:hover, select:hover, textarea:hover { border-color: var(--muted); }
}
input, select { font-variant-numeric: tabular-nums; }
select option { background: var(--raised); }
textarea { resize: vertical; }
::placeholder { color: var(--placeholder); opacity: 1; }

/* --- logo upload ----------------------------------------------------------- */
.upload {
  display: flex; align-items: center; gap: 14px;
  padding: 12px; border: 1px dashed var(--line-strong); border-radius: var(--radius-md); cursor: pointer;
}
.upload input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.crest {
  width: 56px; height: 56px; flex: none; border-radius: 50%;
  background: var(--raised) center / 80% no-repeat; border: 1px solid var(--line);
  display: grid; place-items: center; font-weight: 800; color: var(--muted);
}
.crest.has-logo { background-color: #fff; border-color: #fff; }
.upload-text { display: grid; gap: 2px; font-size: var(--fs-md); }

/* --- buttons: one filled (the main action), one outlined, one text ---------- */
button.primary, button.secondary, button.danger, .file-btn {
  font: inherit; font-weight: 800; font-size: var(--fs-md);
  border-radius: var(--radius-md); min-height: 48px; padding: 11px 20px; cursor: pointer;
  border: 1px solid transparent;
}
button.primary { background: var(--accent); color: var(--on-accent); }
button.secondary, .file-btn { background: transparent; color: var(--text); border-color: var(--line-strong); }
button.danger { background: transparent; color: var(--danger); border-color: rgba(255, 154, 143, 0.45); }
.file-btn { position: relative; display: inline-flex; align-items: center; justify-content: center; }
.file-btn input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.link-btn {
  background: none; border: 0; padding: 0 2px; color: var(--text);
  font: inherit; font-size: var(--fs-sm); font-weight: 600; cursor: pointer;
  text-decoration: underline; text-decoration-color: var(--line-strong); text-underline-offset: 4px; text-decoration-thickness: 1px;
  justify-self: start; min-height: 44px; display: inline-flex; align-items: center;
}
button:disabled { opacity: 0.5; cursor: progress; }

/* pointer feedback: a colour step on hover (mouse only), a small press on click */
button.primary, button.secondary, button.danger, .file-btn, .link-btn {
  transition-property: background-color, border-color, color, text-decoration-color, scale;
  transition-duration: 150ms;
  transition-timing-function: ease-out;
}
@media (hover: hover) {
  button.primary:not(:disabled):hover { background: var(--accent-hover); }
  button.secondary:not(:disabled):hover, .file-btn:hover { background: var(--raised); border-color: var(--muted); }
  button.danger:not(:disabled):hover { background: rgba(255, 154, 143, 0.1); border-color: var(--danger); }
  .link-btn:not(:disabled):hover { text-decoration-color: var(--text); }
}
@media (prefers-reduced-motion: no-preference) {
  button.primary:not(:disabled):active, button.secondary:not(:disabled):active,
  button.danger:not(:disabled):active, .file-btn:active { scale: 0.96; }
}

.actions { display: grid; gap: 10px; width: 100%; max-width: 400px; }
.actions button { width: 100%; }
progress { width: 100%; height: 6px; accent-color: var(--accent); }
.status { min-height: 1.3em; font-size: var(--fs-sm); color: var(--muted); text-align: center; margin: 0; }
.button-row { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }
.form-error { color: var(--danger); font-weight: 600; font-size: var(--fs-sm); margin: 0; min-height: 1.3em; }
.warning { margin: 0; color: var(--warn); font-size: var(--fs-sm); font-weight: 600; }
.warning:empty { display: none; }
.hint a { color: var(--text); text-decoration-color: var(--line-strong); text-underline-offset: 3px; }
.empty { color: var(--muted); max-width: 52ch; margin: 0; }

/* --- segmented choice (native radios, so arrow keys work) ------------------ */
fieldset.segmented { border: 0; padding: 0; display: block; }
#form fieldset.segmented { max-width: 440px; min-width: 0; }
.segmented legend { font-size: var(--fs-sm); font-weight: 600; margin-bottom: 6px; }
.segmented-options {
  clear: both;
  display: grid; grid-template-columns: 1fr 1fr;
  border: 1px solid var(--line); border-radius: var(--radius-md); padding: 3px; gap: 3px;
}
.segmented-options label {
  position: relative;
  display: flex; align-items: center; justify-content: center; text-align: center;
  min-height: 44px; padding: 4px 8px; border-radius: calc(var(--radius-md) - 3px); cursor: pointer;
  font-size: var(--fs-md); font-weight: 600; color: var(--muted);
}
@media (hover: hover) { .segmented-options label:not(:has(:checked)):hover { color: var(--text); background: var(--raised); } }
.segmented-options input { position: absolute; opacity: 0; width: 1px; height: 1px; }
/* chosen segment: bone; only the template choice (what you are making) is yellow */
.segmented-options label:has(:checked) { background: var(--text); color: var(--on-accent); }
#templates label:has(:checked) { background: var(--accent); }
.segmented-options label:has(:focus-visible) { outline: 2px solid var(--text); outline-offset: 3px; }
.segmented-options.three { grid-template-columns: repeat(3, 1fr); }
.segmented-options.three label { font-size: var(--fs-sm); line-height: 1.15; }
/* the middle option ("Supplementare") never breaks inside the word */
.segmented-options.decision { grid-template-columns: minmax(0, 1fr) minmax(max-content, 1.3fr) minmax(0, 1fr); }
.segmented-options.four { grid-template-columns: repeat(2, 1fr); }
@media (min-width: 560px) { .segmented-options.four { grid-template-columns: repeat(4, 1fr); } }

.output-choice .segmented-options label { flex-direction: column; gap: 0; line-height: 1.2; }
.option-hint { font-size: var(--fs-sm); font-weight: 400; color: var(--muted); }
.segmented-options label:has(:checked) .option-hint { color: var(--on-accent); }
.goal-title a { color: var(--text); text-decoration-color: var(--line-strong); text-underline-offset: 3px; }

/* --- views ------------------------------------------------------------------- */
.view { display: grid; gap: 28px; }
.view-head { display: flex; flex-wrap: wrap; align-items: end; justify-content: space-between; gap: 12px 24px; }
.view-head .hint { margin: 4px 0 0; }
.view-error { color: var(--danger); font-weight: 600; }

/* --- stickers: player photos as album stickers, missing ones as numbered slots - */
.player-grid {
  list-style: none; margin: 0; padding: 0;
  display: grid; gap: 28px 20px; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
}
.player-card {
  position: relative; width: 100%; display: grid; grid-template-columns: 1fr; gap: 2px;
  padding: 0; background: none; border: 0; color: var(--text); font: inherit; text-align: left; cursor: pointer;
}
.player-thumb {
  width: 100%; height: auto; aspect-ratio: 4 / 5; display: block; margin-bottom: 10px;
  background: var(--raised); border: 6px solid var(--sticker); border-radius: var(--radius-sm);
  transition: border-color 150ms ease-out, translate 150ms ease-out;
}
.player-card.no-photo .player-thumb { background: none; border: 2px dashed var(--line-strong); }
.slot-number {
  position: absolute; left: 0; right: 0; top: 0; aspect-ratio: 4 / 5; display: grid; place-items: center;
  /* the one size outside the scale: the shirt number printed in an empty sticker slot */
  font-size: 2.75rem; font-weight: 900; font-style: italic; color: var(--line-strong); pointer-events: none;
  font-variant-numeric: tabular-nums;
}
.player-number {
  position: absolute; left: -6px; top: -8px; min-width: 30px; padding: 2px 8px; border-radius: 999px;
  background: var(--sticker); color: var(--on-accent); font-size: var(--fs-sm); font-weight: 800; text-align: center;
  font-variant-numeric: tabular-nums;
}
.player-name { font-weight: 800; overflow-wrap: anywhere; line-height: 1.3; }
.player-role { font-size: var(--fs-sm); color: var(--muted); }
@media (hover: hover) {
  .player-card:hover .player-thumb { border-color: #fff; }
  .player-card.no-photo:hover .player-thumb { border-color: var(--muted); }
}
@media (hover: hover) and (prefers-reduced-motion: no-preference) {
  .player-card:hover .player-thumb { translate: 0 -2px; }
}

.archive-tools { display: grid; gap: 12px; padding-top: 24px; border-top: 1px solid var(--line); }
.archive-tools .hint { max-width: 70ch; }
.archive-tools .status { text-align: left; }

/* --- dialogs ------------------------------------------------------------------- */
dialog {
  width: min(720px, calc(100vw - 24px)); max-height: calc(100dvh - 24px);
  padding: 0; border: 1px solid var(--line); border-radius: var(--radius-lg);
  background: var(--bg); color: var(--text);
}
dialog::backdrop { background: rgba(8, 9, 11, 0.72); }
dialog form, dialog .dialog-body { display: grid; gap: 20px; padding: 24px; }
dialog fieldset { padding-top: 20px; }
dialog .dialog-body .status, .photo-field .status { text-align: left; }
.dialog-actions { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }
.dialog-actions .spacer { flex: 1; }
.confirm-dialog { width: min(440px, calc(100vw - 24px)); }
.confirm-dialog h2 { font-size: var(--fs-lg); overflow-wrap: anywhere; }
.confirm-dialog p { margin: 0; color: var(--muted); }
.row-name { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }

/* photo strip in the player editor: small stickers, the selected one in yellow */
.photo-strip { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 12px; }
.photo-thumb {
  position: relative; display: block; width: 64px; padding: 0; cursor: pointer;
  border: 3px solid var(--sticker); border-radius: var(--radius-sm); background: var(--raised); overflow: visible;
}
.photo-thumb canvas { display: block; width: 100%; height: auto; aspect-ratio: 4 / 5; border-radius: 2px; }
.photo-thumb[aria-pressed="true"] { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
.photo-thumb[aria-pressed="true"] span { background: var(--accent); }
@media (hover: hover) { .photo-thumb:not([aria-pressed="true"]):hover { border-color: #fff; } }
.photo-thumb:focus-visible { outline-offset: 5px; }
.photo-thumb span {
  position: absolute; left: -6px; top: -8px; min-width: 22px; padding: 0 6px; border-radius: 999px;
  background: var(--sticker); color: var(--on-accent); font-size: var(--fs-sm); font-weight: 800; line-height: 20px; text-align: center;
}

/* --- photo framer ------------------------------------------------------------- */
.framer { display: grid; gap: 16px; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 560px) { .framer { grid-template-columns: minmax(0, 1fr) 190px; } }
.framer-canvas {
  width: min(100%, 360px, 44dvh); height: auto; aspect-ratio: 4 / 5; border-radius: var(--radius-md);
  touch-action: none; cursor: grab; display: block; background: var(--raised);
}
.framer-canvas.dragging { cursor: grabbing; }
.framer-canvas.wide { aspect-ratio: 1080 / 760; width: min(100%, 420px); }
.framer-side { display: grid; gap: 12px; align-content: start; }
.framer-side input[type="range"] { width: 100%; accent-color: var(--accent); min-height: 44px; }
.framer-previews { display: flex; gap: 10px; align-items: end; }
.framer-previews figure { margin: 0; display: grid; gap: 4px; flex: 1 1 0; min-width: 0; }
.framer-previews canvas { width: 100%; height: auto; border-radius: var(--radius-sm); display: block; }
.framer-previews figcaption { font-size: var(--fs-sm); color: var(--muted); }

/* --- result: period scores ------------------------------------------------------ */
fieldset.periods { border: 0; padding: 0; display: grid; gap: 8px; max-width: 360px; }
fieldset.periods legend { font-size: var(--fs-sm); font-weight: 600; margin-bottom: 4px; }
.period-row { display: grid; grid-template-columns: 1fr 72px 72px; gap: 10px; align-items: center; font-size: var(--fs-sm); }
.period-row input { text-align: center; }
.period-head span { font-size: var(--fs-sm); font-weight: 800; color: var(--muted); text-align: center; }

/* --- goals: each scorer shown as the sticker the slide will use ------------------- */
.goal-list { list-style: none; margin: 0; padding: 0; display: grid; }
.goal-list:empty { display: none; }
.goal-row {
  display: grid; gap: 8px 16px; align-items: end; padding: 16px 0; border-bottom: 1px solid var(--line);
  grid-template-columns: 52px minmax(0, 7rem) minmax(0, 1fr);
  grid-template-areas: "sticker title title" "sticker scorer scorer" "sticker minute remove" "sticker name name";
}
.goal-row:first-child { padding-top: 4px; }
.goal-sticker { grid-area: sticker; align-self: start; position: relative; width: 52px; }
.goal-sticker canvas {
  display: block; width: 100%; height: auto; aspect-ratio: 4 / 5;
  border: 3px solid var(--sticker); border-radius: var(--radius-sm); background: var(--raised);
}
.goal-sticker.empty canvas { border: 2px dashed var(--line-strong); background: none; }
.goal-sticker span {
  position: absolute; left: -6px; top: -8px; min-width: 22px; padding: 0 6px; border-radius: 999px;
  background: var(--sticker); color: var(--on-accent); font-size: var(--fs-sm); font-weight: 800; line-height: 20px; text-align: center;
}
.goal-sticker.empty span { background: var(--raised); color: var(--muted); border: 1px solid var(--line-strong); }
.goal-title { grid-area: title; font-weight: 600; font-size: var(--fs-sm); color: var(--muted); }
.goal-row label:nth-of-type(1) { grid-area: scorer; }
.goal-row label:nth-of-type(2) { grid-area: minute; }
.goal-row .goal-name { grid-area: name; }
.goal-row .link-btn { grid-area: remove; justify-self: start; }
@media (min-width: 720px) {
  .goal-row {
    grid-template-columns: 52px minmax(0, 1fr) 120px auto;
    grid-template-areas: "sticker title title title" "sticker scorer minute remove" "sticker name name name";
  }
}
label.check { display: flex; align-items: center; gap: 10px; min-height: 44px; cursor: pointer; font-size: var(--fs-md); font-weight: 400; }
label.check input { width: 20px; height: 20px; accent-color: var(--text); flex: none; }
label.check .hint { display: block; }

/* --- slide pager ----------------------------------------------------------------- */
.pager { display: flex; align-items: center; justify-content: center; gap: 14px; width: 100%; max-width: 400px; }
.pager button { min-width: 48px; padding: 8px; display: inline-grid; place-items: center; }
.pager span { font-weight: 600; font-size: var(--fs-sm); min-width: 7em; text-align: center; font-variant-numeric: tabular-nums; }
.preview-controls { display: flex; justify-content: center; width: 100%; max-width: 400px; }
.preview-controls button { min-height: 44px; padding: 8px 16px; font-size: var(--fs-sm); }

/* --- sponsors: logos on white card stock --------------------------------------------- */
.sponsor-grid {
  list-style: none; margin: 0; padding: 0;
  display: grid; gap: 28px 20px; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
}
.sponsor-card {
  width: 100%; display: grid; gap: 2px; padding: 0; text-align: left; cursor: pointer;
  background: none; border: 0; color: var(--text); font: inherit;
}
.sponsor-logo-tile {
  aspect-ratio: 16 / 9; background: #fff; display: grid; place-items: center; padding: 16px; margin-bottom: 10px;
  border-radius: var(--radius-sm); outline: 1px solid transparent; outline-offset: 3px; transition: outline-color 150ms ease-out;
}
@media (hover: hover) { .sponsor-card:hover .sponsor-logo-tile { outline-color: var(--line-strong); } }
.sponsor-logo-tile img { max-width: 100%; max-height: 100%; object-fit: contain; }
.sponsor-logo-tile .placeholder { color: var(--on-accent); font-weight: 800; font-size: var(--fs-lg); text-align: center; }
.sponsor-name { font-weight: 800; }
.sponsor-text { font-size: var(--fs-sm); color: var(--muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.logo-preview { display: grid; grid-template-columns: 1fr; max-width: 320px; }
.logo-preview img { width: 100%; aspect-ratio: 16 / 9; object-fit: contain; background: #fff; border-radius: var(--radius-sm); padding: 14px; }

/* --- phones: smaller preview so the form is reachable ---------------------------- */
@media (max-width: 979px) {
  #preview { width: min(100%, 400px, calc(55dvh * var(--ar))); }
}

/* --- account, login ------------------------------------------------------------------ */
.account { display: flex; align-items: center; gap: 4px 12px; flex-wrap: wrap; font-size: var(--fs-sm); color: var(--muted); }
.account #account-name { font-weight: 600; color: var(--text); }
.login { display: grid; place-items: center; padding: 32px 0 64px; }
.login-card {
  width: min(100%, 400px); display: grid; gap: 18px; padding: 28px;
  border: 1px solid var(--line); border-radius: var(--radius-lg);
}
.login-card p { margin: 0; }

/* --- users ----------------------------------------------------------------------- */
.user-list { list-style: none; margin: 0; padding: 0; display: grid; border-top: 1px solid var(--line); }
.user-row {
  display: grid; gap: 10px 20px; padding: 16px 0; align-items: center;
  grid-template-columns: minmax(0, 1fr); border-bottom: 1px solid var(--line);
}
@media (min-width: 760px) { .user-row { grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr) 16rem; } }
.user-row select { width: 100%; }
.user-row.inactive .user-who { opacity: 0.7; }
.user-who { display: grid; gap: 2px; min-width: 0; }
.user-name { font-weight: 800; }
.user-email, .user-meta { font-size: var(--fs-sm); color: var(--muted); overflow-wrap: anywhere; }
.user-badge {
  display: inline-block; margin-left: 8px; padding: 0 8px; border-radius: 999px; vertical-align: 1px;
  font-size: var(--fs-sm); font-weight: 800; color: var(--muted); border: 1px solid var(--line-strong);
}
.user-actions { display: flex; flex-wrap: wrap; gap: 4px 14px; align-items: center; }
.temp-password code {
  display: block; font-size: var(--fs-xl); font-weight: 800; letter-spacing: 0.06em; padding: 12px 16px;
  background: var(--raised); border: 1px solid var(--line); border-radius: var(--radius-md); user-select: all; overflow-wrap: anywhere;
}

/* --- Windows high contrast / forced colors: keep selected states visible ---------- */
@media (forced-colors: active) {
  .segmented-options label:has(:checked) { outline: 3px solid Highlight; forced-color-adjust: none; background: Highlight; color: HighlightText; }
  nav a[aria-current="page"] { outline: 2px solid Highlight; }
  .photo-thumb[aria-pressed="true"] { outline: 3px solid Highlight; }
  .player-thumb, .goal-sticker canvas, fieldset { border-color: CanvasText; }
}

/* --- reduced motion: no smooth scrolling or transitions ---------------------------- */
@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; transition: none !important; animation: none !important; }
}
