/* Real Madrid Foundation attendance - one stylesheet, mobile first.
 *
 * White and gold, following the Foundation's own mark. The palette is sampled
 * from the official artwork, not invented:
 *
 *   LOGO FRM 2022 Oro.png            one flat colour, #af8543
 *   09_logo_FRM_solido_Clinic_color  #c0843c gold over #060606 black
 *
 * There is no blue anywhere in RMF's marks. The navy this app first shipped
 * with came from Craig's spreadsheet, which is his own styling. Do not
 * reintroduce it.
 *
 * Gold is a mid-tone: it never carries white text at body size (3.4:1) and
 * never states anything on its own. It is structure and emphasis; meaning is
 * carried by text and by the three mark colours, all of which clear 4.5:1.
 */

:root {
  --gold: #af8543;          /* official */
  --gold-bright: #c9a15a;   /* hover and hairlines only */
  --gold-deep: #8c6a35;     /* gold text on white: 4.6:1 */
  --gold-wash: #faf5ec;     /* tinted surface */
  --gold-edge: #ecdfc7;

  --present: #177a41;
  --absent: #c0392b;
  /* Deliberately not the brand gold. A mark that reads as chrome is a mark
   * nobody trusts. */
  --excused: #b45309;

  --paper: #ffffff;
  --surface: #faf8f5;
  --line: #e8e3da;
  --ink: #14110d;
  --ink-soft: #6b655c;

  --radius: 16px;
  --radius-sm: 11px;
  --tap: 46px;

  --shadow-sm: 0 1px 2px rgba(20, 17, 13, .05);
  --shadow: 0 2px 4px rgba(20, 17, 13, .04), 0 8px 20px -12px rgba(20, 17, 13, .14);
  --shadow-lift: 0 4px 10px rgba(20, 17, 13, .07), 0 14px 32px -16px rgba(20, 17, 13, .2);
}

@media (prefers-color-scheme: dark) {
  :root {
    --gold: #c9a15a;
    --gold-bright: #dcb977;
    --gold-deep: #e0be80;
    --gold-wash: #201c15;
    --gold-edge: #3a3226;

    --present: #35b06a;
    --absent: #ef6a5c;
    --excused: #e0913a;

    --paper: #1a1815;
    --surface: #121110;
    --line: #302b24;
    --ink: #f6f3ee;
    --ink-soft: #a8a196;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow: 0 2px 4px rgba(0, 0, 0, .3), 0 8px 20px -12px rgba(0, 0, 0, .7);
    --shadow-lift: 0 4px 10px rgba(0, 0, 0, .4), 0 14px 32px -16px rgba(0, 0, 0, .8);
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--surface);
  color: var(--ink);
  font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  /* Every control has its own pressed state; the default grey flash makes a
   * fast double-tap look broken. */
  -webkit-tap-highlight-color: transparent;
}

/* Chrome on Android raises "Tap to see search results" on any tap in
 * selectable text, which fires constantly on a roster. Opt back in only where
 * a coach would genuinely want to copy something. */
@media (pointer: coarse) {
  body { -webkit-user-select: none; user-select: none; }
  input, textarea, .selectable { -webkit-user-select: text; user-select: text; }
}

a { color: inherit; }

h1, h2, h3 { letter-spacing: -.012em; }

/* ---- shell ---------------------------------------------------------- */

.topbar {
  background: var(--paper);
  color: var(--ink);
  padding: 10px 14px;
  padding-top: calc(10px + env(safe-area-inset-top));
  padding-left: calc(14px + env(safe-area-inset-left));
  padding-right: calc(14px + env(safe-area-inset-right));
  display: flex;
  align-items: center;
  gap: 11px;
  position: sticky;
  top: 0;
  z-index: 20;
  border-bottom: 1px solid var(--line);
  box-shadow: var(--shadow-sm);
}

/* A hairline of gold under the bar. Thin enough to read as a rule rather than
 * a band, which is how the mark itself uses the colour. */
.topbar::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: -1px;
  height: 2px;
  background: linear-gradient(90deg, var(--gold), var(--gold-bright) 55%, transparent);
}

.topbar img { height: 32px; width: auto; flex: none; }

.topbar h1 {
  font-size: 15.5px;
  margin: 0;
  font-weight: 650;
  line-height: 1.2;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.topbar h1 small {
  display: block;
  font-weight: 500;
  font-size: 12px;
  letter-spacing: .01em;
  color: var(--gold-deep);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.topbar .spacer { margin-left: auto; }

.backlink {
  width: 40px;
  height: 40px;
  margin-left: -6px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: var(--radius-sm);
  color: var(--gold-deep);
}
.backlink svg { width: 23px; height: 23px; }
.backlink:active { background: var(--gold-wash); }

.topbtn {
  min-height: 36px;
  padding: 0 13px;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--gold-deep);
  background: var(--gold-wash);
  border: 1px solid var(--gold-edge);
  max-width: 40vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: block;
}

.wrap {
  padding: 16px 14px 20px;
  padding-left: calc(14px + env(safe-area-inset-left));
  padding-right: calc(14px + env(safe-area-inset-right));
  max-width: 620px;
  margin: 0 auto;
}

/* ---- cards ---------------------------------------------------------- */

.card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
}

.card h2 {
  margin: 0 0 3px;
  font-size: 17.5px;
  font-weight: 650;
}
.meta { color: var(--ink-soft); font-size: 13.5px; margin: 0; }

.sectionlabel {
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--gold-deep);
  margin: 22px 4px 9px;
}
.sectionlabel:first-child { margin-top: 4px; }

/* ---- today ---------------------------------------------------------- */

.sessions { display: grid; gap: 12px; }

.sessioncard {
  display: flex;
  align-items: center;
  gap: 13px;
  text-decoration: none;
  margin-bottom: 0;
  transition: transform .12s ease, box-shadow .12s ease, border-color .12s ease;
}
.sessioncard:hover { border-color: var(--gold-edge); box-shadow: var(--shadow-lift); }
.sessioncard:active { transform: scale(.99); }

.sessioncard .age {
  /* Deeper than --gold on purpose: this carries white text at 17px bold,
   * which is just under WCAG's large-text threshold and so gets no allowance.
   * White on --gold is 3.4:1; on this it is 5:1. */
  background: linear-gradient(160deg, #8c6a35, #7a5c2d);
  color: #fff;
  font-weight: 750;
  font-size: 17px;
  letter-spacing: -.02em;
  border-radius: var(--radius-sm);
  padding: 13px 10px;
  min-width: 62px;
  text-align: center;
  flex: none;
}
.sessioncard .grow { flex: 1; min-width: 0; }
.sessioncard .chev { color: var(--gold); flex: none; width: 20px; height: 20px; }

.progress {
  /* display:block matters - this is a <span>, and an inline box ignores
   * height, so the bar silently collapsed to nothing. */
  display: block;
  height: 7px;
  background: var(--line);
  border-radius: 99px;
  overflow: hidden;
  margin-top: 9px;
}
.progress i {
  display: block;
  height: 100%;
  border-radius: 99px;
  background: linear-gradient(90deg, var(--gold), var(--gold-bright));
  transition: width .3s ease;
}

/* ---- roster --------------------------------------------------------- */

.rosterhead {
  display: flex;
  align-items: center;
  gap: 11px;
  padding-bottom: 13px;
  margin-bottom: 3px;
  border-bottom: 1px solid var(--line);
}
.rosterhead .grow { flex: 1; min-width: 0; }
.rosterhead h2 { margin: 0; }
.rosterhead .btn { flex: none; font-size: 13.5px; padding: 0 14px; min-height: 40px; }

.player {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 0;
  border-bottom: 1px solid var(--line);
}
.player:last-child { border-bottom: 0; padding-bottom: 2px; }
.player .grow { flex: 1; min-width: 0; }
.player .name {
  font-weight: 600;
  font-size: 15.5px;
  /* Wrap to two lines rather than truncate. At 390px the name column is only
   * ~150px once the avatar and three 46px buttons have taken theirs, and
   * "Amahle Mahlangu" does not fit on one line. Shrinking the buttons to make
   * room would be the wrong trade - a coach has to be able to read the whole
   * name, and the row can afford a second line. */
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  overflow-wrap: break-word;
  line-height: 1.28;
}
/* The name is only ~24px tall, a poor target beside a 46px button. Padding
 * plus an equal negative margin grows the hit box without moving anything. */
.player a.name { text-decoration: none; display: block; padding: 8px 0; margin: -8px 0; }

.avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  flex: none;
  display: grid;
  place-items: center;
  font-size: 13.5px;
  font-weight: 700;
  letter-spacing: .01em;
  color: #fff;
  background: linear-gradient(160deg, #8c6a35, #7a5c2d) center/cover no-repeat;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .22), var(--shadow-sm);
  text-decoration: none;
}
.avatar.haspic { color: transparent; }
.avatar.big { width: 62px; height: 62px; font-size: 19px; }

.flags { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 4px; }
.flag {
  font-size: 11px;
  padding: 2.5px 8px;
  border-radius: 99px;
  background: #fdecea;
  color: #a02a1c;
  border: 1px solid #f3c3bd;
  font-weight: 650;
  letter-spacing: .01em;
}
.flag.consent {
  background: var(--gold-wash);
  color: var(--gold-deep);
  border-color: var(--gold-edge);
}
@media (prefers-color-scheme: dark) {
  .flag { background: #3a1a16; color: #ffb4a8; border-color: #5c2a23; }
}

/* The mark buttons are the whole product: large, all three always visible, and
 * unmistakable at arm's length in sunlight. */
.marks { display: flex; gap: 6px; flex: none; }
.marks button {
  width: var(--tap);
  height: var(--tap);
  border-radius: 13px;
  border: 1.5px solid var(--line);
  background: var(--paper);
  color: var(--ink-soft);
  font-weight: 750;
  font-size: 17px;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform .07s ease, background-color .14s ease,
              border-color .14s ease, color .14s ease, box-shadow .14s ease;
}
.marks button:hover { border-color: var(--gold-edge); color: var(--ink); }
.marks button:active { transform: scale(.93); }
.marks button[aria-pressed="true"] {
  color: #fff;
  border-color: transparent;
  box-shadow: var(--shadow-sm);
}
.marks button[data-mark="P"][aria-pressed="true"] { background: var(--present); }
.marks button[data-mark="A"][aria-pressed="true"] { background: var(--absent); }
.marks button[data-mark="E"][aria-pressed="true"] { background: var(--excused); }
.marks button:disabled { opacity: .5; }

@media (prefers-color-scheme: dark) {
  .marks button[aria-pressed="true"] { color: #12100e; }
  /* The chip and avatar are hardcoded deep gold for contrast in light mode;
   * against a dark surface they can use the lighter brand gold with a dark
   * label instead. */
  .sessioncard .age,
  .avatar { background: linear-gradient(160deg, var(--gold-bright), var(--gold)); color: #17130c; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
  .marks button:active, .sessioncard:active { transform: none; }
}

/* ---- forms and buttons ---------------------------------------------- */

.input, textarea.input {
  width: 100%;
  min-width: 0;
  min-height: var(--tap);
  padding: 11px 13px;
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--paper);
  color: var(--ink);
  font: inherit;
  transition: border-color .14s ease, box-shadow .14s ease;
}
.input:focus, textarea.input:focus {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(175, 133, 67, .16);
}
textarea.input { min-height: 100px; resize: vertical; line-height: 1.5; }

label {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: .02em;
  color: var(--ink-soft);
  margin: 13px 0 5px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: var(--tap);
  padding: 0 20px;
  border: 1.5px solid transparent;
  border-radius: var(--radius-sm);
  background: var(--ink);
  color: var(--paper);
  font: inherit;
  font-weight: 650;
  cursor: pointer;
  text-decoration: none;
  transition: filter .14s ease, transform .07s ease, box-shadow .14s ease;
}
.btn:active { transform: scale(.985); filter: brightness(.94); }

/* Gold carries a near-black label, never white: white on #af8543 is 3.4:1 and
 * this is 6:1. It also looks more like the mark. */
.btn.gold {
  background: linear-gradient(160deg, var(--gold-bright), var(--gold));
  color: #1a1206;
  box-shadow: var(--shadow-sm);
}
.btn.gold:hover { box-shadow: var(--shadow-lift); }
.btn.ghost {
  background: var(--paper);
  color: var(--gold-deep);
  border-color: var(--gold-edge);
}
.btn.ghost:hover { background: var(--gold-wash); }
.btn.block { width: 100%; }
.btn:disabled { opacity: .55; cursor: default; box-shadow: none; }
.btn:disabled:active { transform: none; }

/* ---- misc ----------------------------------------------------------- */

.flash {
  border-radius: var(--radius-sm);
  padding: 11px 13px;
  margin-bottom: 13px;
  background: #fdecea;
  color: #a02a1c;
  font-size: 14px;
  border: 1px solid #f3c3bd;
}
.flash.ok { background: #e9f6ed; color: #14603a; border-color: #bfe3cc; }
@media (prefers-color-scheme: dark) {
  .flash { background: #3a1a16; color: #ffb4a8; border-color: #5c2a23; }
  .flash.ok { background: #14301f; color: #a8e0bf; border-color: #23543a; }
}

.pill {
  display: inline-block;
  font-size: 11.5px;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 99px;
  background: var(--gold-wash);
  color: var(--gold-deep);
  border: 1px solid var(--gold-edge);
  vertical-align: middle;
}

.kv {
  display: grid;
  grid-template-columns: minmax(96px, .85fr) 1.4fr;
  gap: 9px 14px;
  font-size: 14.5px;
}
.kv dt { color: var(--ink-soft); font-size: 13px; }
.kv dd { margin: 0; font-weight: 550; }
.kv > * { min-width: 0; overflow-wrap: break-word; }

.grid-history { display: flex; flex-wrap: wrap; gap: 7px; }
.grid-history .cell {
  width: 48px;
  text-align: center;
  font-size: 11px;
  color: var(--ink-soft);
}
.grid-history .cell b {
  display: block;
  margin-top: 3px;
  border-radius: 9px;
  padding: 6px 0;
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--ink-soft);
  font-size: 13px;
}
.grid-history .cell b.P { background: var(--present); border-color: transparent; color: #fff; }
.grid-history .cell b.A { background: var(--absent); border-color: transparent; color: #fff; }
.grid-history .cell b.E { background: var(--excused); border-color: transparent; color: #fff; }

/* A coach needs to know their marks are held safely, not wonder whether the
 * tap registered. */
.syncbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  background: var(--ink);
  color: var(--paper);
  padding: 12px 16px;
  padding-bottom: calc(12px + env(safe-area-inset-bottom));
  font-size: 13.5px;
  font-weight: 550;
  display: none;
  align-items: center;
  gap: 10px;
  z-index: 30;
  box-shadow: 0 -6px 20px -10px rgba(20, 17, 13, .35);
}
.syncbar.show { display: flex; }
.syncbar .dot {
  width: 9px; height: 9px; border-radius: 99px;
  background: var(--gold-bright); flex: none;
  box-shadow: 0 0 0 0 rgba(201, 161, 90, .6);
  animation: pulse 1.8s infinite;
}
@keyframes pulse {
  70% { box-shadow: 0 0 0 7px rgba(201, 161, 90, 0); }
  100% { box-shadow: 0 0 0 0 rgba(201, 161, 90, 0); }
}
body.has-syncbar .wrap { padding-bottom: calc(84px + env(safe-area-inset-bottom)); }

.empty { text-align: center; color: var(--ink-soft); padding: 30px 14px; }
.empty strong { color: var(--ink); }

/* Sandbox marker. Deliberately loud: mistaking demo players for the real
 * register is the worst confusion this app could cause. */
.demobar {
  background: linear-gradient(90deg, var(--gold-bright), var(--gold));
  color: #1a1206;
  font-size: 11px;
  font-weight: 750;
  letter-spacing: .09em;
  text-transform: uppercase;
  text-align: center;
  padding: 7px 12px;
}

/* ---- sign in -------------------------------------------------------- */

.signin { max-width: 400px; margin: 0 auto; }
.signin .hero { text-align: center; padding: 26px 0 4px; }
.signin .hero img { width: 96px; height: auto; }
.signin .hero h2 { margin: 16px 0 2px; font-size: 21px; font-weight: 700; }
.signin .hero p { margin: 0; color: var(--ink-soft); font-size: 14px; }

/* ---- narrow phones --------------------------------------------------- */

/* The roster row is avatar + name + three 46px buttons: 200px of fixed width
 * before the name gets any. Below 360px the marks take their own line rather
 * than crushing the name to nothing. */
@media (max-width: 359px) {
  .player { flex-wrap: wrap; }
  .player .grow { flex-basis: calc(100% - 53px); }
  .marks { width: 100%; justify-content: flex-end; margin-top: 8px; }
  .rosterhead { flex-wrap: wrap; }
  .rosterhead .btn { width: 100%; }
}

/* ---- wide screens ---------------------------------------------------- */

/* Built for a phone, but opened on a laptop by whoever runs the programme.
 * Give that a considered layout rather than a phone column stranded in the
 * middle of a monitor. */
@media (min-width: 680px) {
  .wrap { max-width: 940px; padding: 24px 24px 32px; }
  .topbar { padding: 12px 24px; }
  .topbar img { height: 36px; }
  .topbar h1 { font-size: 17px; }
  .topbar h1 small { font-size: 12.5px; }

  .card { padding: 22px 24px; border-radius: 18px; }
  .card h2 { font-size: 19px; }

  .sessions { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
  .sessioncard .age { min-width: 68px; font-size: 18px; }

  .player { padding: 13px 0; }
  .player .name { font-size: 16px; }

  .kv { grid-template-columns: minmax(120px, .6fr) 1.4fr; font-size: 15px; }

  .signin { margin-top: 20px; }
  .signin .hero img { width: 118px; }
  .signin .hero h2 { font-size: 24px; }

  .syncbar {
    left: auto;
    right: 24px;
    bottom: 24px;
    border-radius: 99px;
    padding: 12px 20px;
    box-shadow: var(--shadow-lift);
  }
  body.has-syncbar .wrap { padding-bottom: 32px; }
}

@media (min-width: 1040px) {
  .wrap { max-width: 1040px; }
  .profilegrid {
    display: grid;
    grid-template-columns: 1.15fr .85fr;
    gap: 0 18px;
    align-items: start;
  }
  .profilegrid > .full { grid-column: 1 / -1; }
}
