/* Approved Original MAGMA: portrait geometry, readable controls and phone ergonomics. */
:root {
  --control-size: 44px;
  --content-measure: 1360px;
  accent-color: var(--primary);
  caret-color: var(--primary);
  scrollbar-color: var(--line) var(--surface);
  scrollbar-width: thin;
}

html { scroll-padding-bottom: 100px; }
body { overflow-wrap: break-word; }
main { max-width: var(--content-measure); margin-inline: auto; }
button, a, input, select, textarea { touch-action: manipulation; }
input, select, textarea { caret-color: var(--primary); }
a { text-underline-offset: 4px; }
::selection { background: var(--lime); color: var(--ink); }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--surface); }
::-webkit-scrollbar-thumb { background: var(--line); border: 2px solid var(--surface); border-radius: 8px; }

.btn { min-height: var(--control-size); }
.icon-btn { width: var(--control-size); height: var(--control-size); }
.search-trigger { min-height: var(--control-size); }
.page-heading > div, .section-head > h2 { min-width: 0; }
.page-heading p:not(.greeting) { max-width: 64ch; font-size: 13px; }
.page-heading h1 { max-width: 28ch; }
.section-head { gap: 14px; }
.section-head > .text-btn { flex-shrink: 0; text-align: right; }
.page-tabs { overflow-x: auto; overscroll-behavior-x: contain; scrollbar-width: none; }
.page-tabs::-webkit-scrollbar { display: none; }
.page-tabs button { flex-shrink: 0; min-height: var(--control-size); }
.select-wrap, .field-search { min-height: var(--control-size); }
.select-wrap > input, .select-wrap > select { min-height: 42px; }
.check-pill { min-height: var(--control-size); align-content: center; }
.check-pill input { accent-color: var(--primary); }
.segmented button { min-height: 36px; }
.match-time, .profile-stats strong, .rating-points, .level-badge, .training-price { font-variant-numeric: tabular-nums; }

/* The 1254px source contains four square portraits. A square crop must stay square. */
.avatar { aspect-ratio: 1; }
.avatar img { width: 100%; height: 100%; object-fit: cover; object-position: 50% 38%; }
.player-photo { aspect-ratio: 5 / 4; padding: 0; overflow: hidden; isolation: isolate; }
.player-photo.portrait { background-image: none; }
.player-photo.portrait:not(.initials-photo)::before {
  content: '';
  position: absolute;
  z-index: 0;
  top: 50%;
  left: 0;
  width: 100%;
  aspect-ratio: 1;
  transform: translateY(-50%);
  background-image: url('./assets/portraits.webp');
  background-size: 200% 200%;
  background-position: inherit;
  background-repeat: no-repeat;
}
.player-photo > img { width: 100%; height: 100%; object-fit: cover; object-position: 50% 38%; }
.photo-level, .photo-status { z-index: 1; }
.initials-photo { background: var(--lime-soft); }
.coach-photo { aspect-ratio: 5 / 4; }
.coach-photo > .coach-portrait { aspect-ratio: 1; height: auto; }
.coach-avatar { aspect-ratio: 1; }
.hero > img, .community-hero > img, .after-card > img { object-fit: cover; }

.player-card { display: flex; flex-direction: column; }
.player-info { display: flex; flex-direction: column; flex: 1; }
.player-info > p { min-height: 0; line-height: 1.65; }
.player-tags { min-height: 0; }
.player-bottom { margin-top: auto; padding-top: 12px; }
.player-name > button { text-align: left; line-height: 1.3; }
.player-info .location-line { flex-wrap: wrap; line-height: 1.6; }
.person-mini { min-width: 0; }
.person-mini > strong { line-height: 1.4; }
.person-mini > small { font-size: 11px; line-height: 1.5; }
.person-mini .avatar { aspect-ratio: 1; }
.photo-level small, .photo-status { line-height: 1.3; }

.messenger { min-height: 0; height: min(700px, calc(100dvh - 200px)); }
.chat-list, .chat-thread, .chat-body { min-height: 0; }
.chat-header { flex-shrink: 0; }
.chat-header > div { min-width: 0; }
.chat-header h2 { overflow-wrap: anywhere; line-height: 1.35; }
.chat-header p { line-height: 1.5; }
.chat-body { overscroll-behavior-y: contain; scrollbar-gutter: stable; }
.bubble { max-width: min(78%, 62ch); }
.bubble p { font-size: 14px; line-height: 1.6; }
.bubble time { font-size: 10px; }
.chat-input { flex-shrink: 0; gap: 10px; padding-bottom: 12px; }
.chat-input textarea { min-height: var(--control-size); font-size: 16px; line-height: 1.5; }
.chat-input .btn { width: var(--control-size); min-height: var(--control-size); flex-shrink: 0; padding: 11px; }
.chat-empty { max-width: 40ch; margin: 36px auto; line-height: 1.7; }
.local-delivery { font-size: 10px; line-height: 1.6; }

.dialog-body { overscroll-behavior-y: contain; }
.dialog-header > h2 { min-width: 0; }
.dialog-body input:not([type='checkbox']):not([type='radio']),
.dialog-body select,
.dialog-body textarea { min-height: var(--control-size); }
.dialog-actions { flex-wrap: wrap; }
.dialog-actions > .btn { white-space: normal; }
.form-error { line-height: 1.6; }
.profile-identity > div { min-width: 0; }
.profile-identity h2 { overflow-wrap: anywhere; }
.photo-upload label { min-width: 0; }

@media (hover: hover) {
  .player-photo:hover::before { filter: brightness(1.025); }
  .player-card:has(.player-photo:hover) { border-color: oklch(.72 .025 135); }
}

@media (max-width: 1023px) and (min-width: 768px) {
  .people-strip { gap: 10px; }
  .person-mini { grid-template-columns: 44px minmax(0, 1fr); }
  .person-mini > strong { flex-wrap: wrap; gap: 4px; }
}

@media (max-width: 767px) {
  html { scroll-padding-top: 82px; scroll-padding-bottom: calc(90px + env(safe-area-inset-bottom)); }
  main { padding-inline: 18px; }
  .topbar { padding-inline: 16px; gap: 12px; }
  .header-actions { gap: 3px; }
  .header-actions .icon-btn, .header-actions .avatar-btn, .header-actions .search-trigger {
    width: var(--control-size);
    height: var(--control-size);
    min-width: var(--control-size);
    display: inline-flex;
    justify-content: center;
    align-items: center;
  }
  .header-actions .avatar.sm { width: 30px; height: 30px; }
  .demo-strip { padding-top: 14px; gap: 10px; align-items: center; }
  .demo-strip > span { font-size: 10px; line-height: 1.5; }
  .demo-strip .text-btn { min-width: var(--control-size); min-height: var(--control-size); justify-content: center; }
  .view-content { padding-top: 20px; }
  .page-heading { margin-bottom: 24px; gap: 16px; }
  .page-heading h1 { font-size: clamp(27px, 7.4vw, 33px); line-height: 1.18; max-width: 24ch; }
  .page-heading p:not(.greeting) { max-width: 42ch; font-size: 13px; line-height: 1.65; }
  .page-heading > .btn { min-height: var(--control-size); font-size: 12px; }
  .hero { min-height: 340px; }
  .hero-content { padding: 27px 24px; }
  .hero h2 { font-size: clamp(40px, 11.2vw, 48px); }
  .hero .btn { min-height: var(--control-size); }
  .hero-caption { letter-spacing: .7px; }
  .home-filters { flex-wrap: wrap; align-items: stretch; gap: 10px; }
  .home-filters .select-wrap { flex: 1 1 100%; max-width: none; padding-inline: 12px; }
  .home-filters .select-wrap > select { width: 100%; max-width: none; }
  .home-filters .segmented { width: 100%; }
  .segmented button { flex: 1; min-height: 40px; font-size: 12px; padding: 8px 10px; }
  .select-wrap > input, .select-wrap > select, .filter-bar .select-wrap select, .filter-bar .select-wrap input, .field-search input { font-size: 16px; }
  .filter-bar .select-wrap, .field-search { padding-inline: 11px; }
  .check-pill { font-size: 12px; }
  .section-head > .text-btn { min-height: var(--control-size); font-size: 12px; }
  .section-description { font-size: 12px; line-height: 1.65; }
  .match-bottom .btn, .wide .match-bottom .btn { min-height: var(--control-size); }
  .match-bottom small, .wide .match-bottom small { font-size: 10px; }
  .person-mini { grid-template-columns: 48px minmax(0, 1fr); gap: 0 10px; padding: 10px 4px; }
  .person-mini .avatar { width: 48px; height: 48px; }
  .person-mini > strong { flex-wrap: wrap; gap: 4px; }
  .person-mini > small { font-size: 10px; }
  .players-grid { gap: 16px; }
  .player-photo { aspect-ratio: 5 / 4; }
  .player-info { padding: 18px; }
  .player-name > button { font-size: 22px; min-height: 36px; }
  .player-info .location-line { font-size: 12px; gap: 5px; }
  .player-info > p { font-size: 13px; margin-top: 12px; }
  .player-tags { margin: 16px 0; gap: 6px; }
  .player-tags .badge { font-size: 10px; padding: 6px 8px; white-space: normal; }
  .player-bottom { gap: 12px; }
  .player-bottom > span { font-size: 11px; line-height: 1.5; }
  .player-bottom .icon-btn { width: var(--control-size); height: var(--control-size); }
  .photo-status { font-size: 10px; top: 12px; right: 12px; padding: 6px 8px; }
  .photo-level { left: 12px; bottom: 12px; font-size: 18px; padding: 7px 9px; }
  .photo-level small { font-size: 9px; }
  .profile-identity { flex-wrap: wrap; }
  .profile-identity > .badge { margin-top: 4px; }
  .profile-attributes strong { line-height: 1.6; }
  .messenger { height: min(700px, calc(100dvh - 210px - env(safe-area-inset-bottom))); min-height: 320px; max-height: none; }
  .chat-list { padding: 8px; gap: 6px; overscroll-behavior-x: contain; }
  .chat-item { min-height: 48px; min-width: 118px; }
  .chat-item strong { font-size: 12px; }
  .chat-thread { flex: 1 1 0; }
  .chat-header { padding: 13px 14px; }
  .chat-header h2 { font-size: 14px; }
  .chat-header p { font-size: 11px; max-width: none; }
  .chat-body { padding: 16px 12px; }
  .chat-date { font-size: 11px; }
  .chat-context { margin-bottom: 20px; }
  .chat-context strong { font-size: 12px; }
  .chat-context span { font-size: 11px; }
  .bubble { max-width: 86%; padding: 10px 12px; }
  .bubble p { font-size: 14px; }
  .bubble-wrap { margin-block: 14px; }
  .bubble-wrap > .avatar { width: 26px; height: 26px; }
  .chat-input { padding: 9px 10px; gap: 8px; }
  .chat-input textarea { padding: 10px 4px; font-size: 16px; }
  .local-delivery { font-size: 10px; padding: 0 14px 10px; }
  .mobile-nav { padding-bottom: calc(8px + env(safe-area-inset-bottom)); }
  .mobile-nav a, .mobile-nav .mobile-more { min-height: 48px; font-size: 10px; gap: 4px; justify-content: center; }
  .page-footer { font-size: 10px; line-height: 1.6; flex-wrap: wrap; gap: 8px; padding-bottom: calc(100px + env(safe-area-inset-bottom)); }
  .dialog-body form > label, .form-grid > label { font-size: 12px; }
  .dialog-body .text-btn { min-height: var(--control-size); }
  .dialog-actions > .btn { min-height: var(--control-size); font-size: 12px; }
  #toast { bottom: calc(86px + env(safe-area-inset-bottom)); font-size: 12px; line-height: 1.5; }
}

@media (max-width: 540px) {
  .players-grid { grid-template-columns: minmax(0, 1fr); }
  .home-aside { grid-template-columns: minmax(0, 1fr); gap: 18px; }
  .level-panel, .next-game { padding: 22px; }
  .level-heading { font-size: 10px; }
  .level-scale { font-size: 9px; }
  .level-panel .profile-stats strong { font-size: 25px; }
  .level-panel .profile-stats span { font-size: 11px; }
  .my-level > span { font-size: 12px; max-width: none; }
  .level-panel .text-btn, .next-game .btn { min-height: var(--control-size); font-size: 12px; }
  .level-note { font-size: 10px; line-height: 1.6; }
  .next-game .section-head h2 { font-size: 18px; }
  .next-game > p { font-size: 12px; }
  .next-game .booking-note { font-size: 11px; }
  .after-card { grid-column: auto; }
  .after-card > div { padding: 20px 16px; }
  .after-card > img { min-height: 230px; object-position: 48% center; }
  .after-card h3 { font-size: 21px; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
}
