:root {
  color-scheme: dark;
  font-family: "Segoe UI", system-ui, sans-serif;
  background: #101419;
  color: #f0f2f5;
  --surface: #171d24;
  --raised: #202832;
  --border: #343e4b;
  --muted: #aab5c3;
  --text: #f0f2f5;
  --accent: #ffb15e;
  --danger: #ff9c9c;
  --gutter: clamp(14px, 3vw, 52px);
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; font-size: 14px; }
body:has(.app-shell:not([hidden])) { overflow: hidden; }
button, input, select { font: inherit; }
button { color: inherit; cursor: pointer; }
button:disabled { cursor: wait; opacity: .6; }
button, input, select, a { -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
h1, h2, p { margin: 0; }
h1 { font-size: clamp(23px, 3vw, 36px); line-height: 1.1; letter-spacing: -.035em; }
h2 { font-size: 17px; line-height: 1.2; }
.muted, small { color: var(--muted); }

.app-shell {
  height: 100vh;
  height: 100dvh;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
}
.app-header {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 9px 22px;
  min-height: 62px;
  padding: 10px var(--gutter);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { color: var(--text); font-size: 23px; font-weight: 800; letter-spacing: -.06em; text-decoration: none; white-space: nowrap; }
.brand span { margin-left: 4px; color: var(--accent); }
.event-meta { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 9px; color: var(--muted); font-size: 12px; }
.event-meta strong { color: var(--text); }
.header-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 14px; margin-left: auto; }
#accountName { font-size: 12px; color: var(--muted); }
.quiet-link { border: 0; background: transparent; color: var(--text); padding: 4px 0; font-size: 12px; }
.quiet-link:hover, .quiet-link:focus-within { color: var(--accent); }
.import-backup, .dropzone { position: relative; cursor: pointer; }
.import-backup input, .dropzone input { position: absolute; opacity: 0; inset: 0; width: 100%; height: 100%; cursor: pointer; }
.import-backup:focus-within, .dropzone:focus-within { outline: 2px solid var(--accent); outline-offset: 3px; }
.nav { min-width: 0; display: flex; gap: 18px; padding: 0 var(--gutter); overflow-x: auto; border-bottom: 1px solid var(--border); scrollbar-width: thin; }
.nav-item { flex: none; min-height: 43px; border: 0; border-bottom: 2px solid transparent; background: none; padding: 0 2px; font-weight: 600; color: var(--muted); }
.nav-item:hover { color: var(--text); }
.nav-item.active { color: var(--accent); border-bottom-color: var(--accent); }
.nav-item:focus-visible { outline-offset: -3px; }
.player-account .header-tools :is(#exportData, .import-backup, #resetData),
.player-account .nav-item:not([data-view="overview"], [data-view="lineup"]) { display: none; }

.main { min-width: 0; min-height: 0; overflow: auto; overscroll-behavior: contain; scrollbar-color: #485563 var(--surface); }
.content { min-height: 100%; padding: clamp(14px, 2.7vh, 30px) var(--gutter); }
.page-head, .panel-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.page-head { margin-bottom: 16px; }
.panel-head { margin-bottom: 12px; }
.panel { min-width: 0; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: clamp(12px, 1.4vw, 22px); }
.content > .panel + .panel { margin-top: 14px; }
.input, select { width: 100%; min-width: 0; min-height: 38px; padding: 7px 10px; border: 1px solid var(--border); border-radius: 5px; background: #101419; color: var(--text); }
.input::placeholder { color: var(--muted); }
.primary-btn, .secondary-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 37px;
  padding: 7px 13px;
  border: 1px solid var(--border);
  border-radius: 5px;
  font-size: 13px;
  font-weight: 650;
}
.primary-btn { background: var(--accent); border-color: var(--accent); color: #201205; }
.primary-btn:hover { background: #ffd09d; }
.secondary-btn { background: var(--raised); color: var(--text); }
.secondary-btn:hover { border-color: var(--muted); }
.empty-state { color: var(--muted); padding: 13px 0 3px; }

.stats-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 14px; }
.stat-card { background: var(--surface); padding: 12px 15px; border: 1px solid var(--border); border-radius: 6px; }
.stat-label { display: block; color: var(--muted); font-size: 12px; }
.stat-value { display: block; padding-top: 3px; font-size: 25px; font-variant-numeric: tabular-nums; }
.overview-grid { display: grid; grid-template-columns: minmax(0, 2fr) minmax(230px, 1fr); gap: 14px; margin-bottom: 14px; }
.overview-grid:last-child { margin-bottom: 0; }
.board { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: 18px; }
.match-row { min-width: 0; display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); align-items: center; gap: 4px 7px; padding: 8px 0; border-top: 1px solid var(--border); }
.match-team, .market-team, .market-player { display: flex; align-items: center; gap: 7px; min-width: 0; }
.match-team { overflow-wrap: anywhere; font-weight: 600; }
.match-team.right { justify-content: flex-end; text-align: right; }
.team-logo { width: 23px; height: 23px; flex: none; object-fit: contain; }
.match-state { color: var(--muted); font-size: 11px; text-align: center; white-space: nowrap; font-variant-numeric: tabular-nums; }
.match-state time { color: var(--accent); font-weight: 650; }
.roster-slot { display: flex; justify-content: space-between; align-items: center; gap: 8px; min-height: 33px; border-top: 1px solid var(--border); }
.roster-total { color: var(--accent); font-size: 12px; }

.main:has([data-view="overview"].content) { overflow: clip; }
.content[data-view="overview"] {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  align-content: stretch;
  gap: clamp(6px, 1.4dvh, 14px);
  height: 100%;
  padding-block: clamp(8px, 1.8dvh, 23px);
}
.player-account .content[data-view="overview"] { grid-template-rows: auto minmax(0, 1fr); }
.content[data-view="overview"] :is(.page-head, .stats-grid, .overview-grid) { margin: 0; }
.overview-actions { display: flex; gap: 6px; }
.overview-grid > .panel { min-height: 0; }
.schedule-panel { display: grid; grid-template-rows: auto minmax(0, 1fr); }
.schedule-panel .board { grid-auto-rows: minmax(min-content, 1fr); }

.lineup-page { display: grid; grid-template-rows: auto auto minmax(min-content, 1fr) auto; gap: clamp(8px, 1.8vh, 20px); min-height: 100%; }
.content:has(.lineup-page) { display: grid; }
#selectionModal { display: contents; }
.lineup-page .page-head { margin: 0; }
.lineup-finances { display: grid; grid-template-columns: auto minmax(40px, 1fr) auto; align-items: center; gap: clamp(12px, 3vw, 40px); padding: 10px 14px; background: var(--surface); border: 1px solid var(--border); border-radius: 6px; }
.lineup-finances strong { font-size: clamp(16px, 2vw, 22px); font-variant-numeric: tabular-nums; }
.lineup-finances small { font-size: 11px; font-weight: 500; }
.lineup-balance { text-align: right; }
.lineup-balance strong { color: var(--accent); }
.lineup-balance .negative { color: var(--danger); }
.budget-meter, .progress-wrap { height: 5px; background: var(--border); border-radius: 3px; overflow: hidden; }
.budget-meter i, .progress-wrap i { display: block; height: 100%; background: var(--accent); }
.lineup-board { width: 100%; max-width: 1540px; margin: auto; display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: clamp(6px, 1.2vw, 16px); }
.lineup-player-slot {
  display: grid;
  min-width: 0;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: 30px minmax(0, 1fr) auto;
  height: clamp(145px, 46dvh, 325px);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 0;
  overflow: hidden;
  text-align: left;
  background: var(--surface);
}
.lineup-player-slot:hover { border-color: var(--accent); }
.lineup-player-slot:not(.filled) { border-style: dashed; }
.lineup-player-slot.coach-slot { border-color: #d9ad48; }
.lineup-player-slot.coach-slot:hover { border-color: #ffe08a; }
.slot-role { display: flex; align-items: center; justify-content: space-between; gap: 4px; padding: 0 10px; border-bottom: 1px solid var(--border); color: var(--muted); font-size: 12px; font-weight: 650; }
.slot-points { color: var(--text); font-size: 11px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.coach-slot .slot-role { color: var(--accent); }
.slot-portrait { position: relative; display: grid; place-items: center; min-width: 0; min-height: 0; overflow: hidden; background: #26313d; }
.lineup-avatar { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; object-position: center 24%; }
.lineup-avatar[src$="player-placeholder.svg"] { object-fit: contain; padding: 16px; }
.slot-plus { display: grid; place-items: center; width: 34px; height: 34px; border: 1px solid #546273; border-radius: 5px; font-size: 25px; font-weight: 400; line-height: 1; color: var(--accent); }
.lineup-player-slot:not(.filled) .slot-portrait { background: #141a21; }
.slot-details { display: flex; flex-direction: column; justify-content: center; gap: 3px; min-width: 0; min-height: 68px; padding: 6px 10px; border-top: 1px solid var(--border); }
.lineup-player-name, .lineup-player-team > span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lineup-player-meta { display: flex; justify-content: space-between; align-items: center; gap: 4px; min-width: 0; }
.lineup-player-team { display: flex; align-items: center; gap: 3px; min-width: 0; }
.lineup-player-team .lineup-team-logo { flex: none; margin: 0; }
.country-badge { display: inline-flex; align-items: center; gap: 4px; min-width: 0; }
.country-flag { display: block; flex: none; object-fit: contain; border-radius: 1px; }
.lineup-player-meta .country-badge { margin-left: auto; font-size: 10px; white-space: nowrap; }
.lineup-player-name { font-size: clamp(12px, 1.65vw, 23px); line-height: 1.05; }
.lineup-player-team, .lineup-player-price, .slot-select-label { font-size: 11px; }
.lineup-player-team, .slot-select-label { color: var(--muted); }
.lineup-team-logo, .selection-inline-logo { width: 15px; height: 15px; object-fit: contain; margin-right: 4px; vertical-align: middle; }
.lineup-player-price { color: var(--accent); font-weight: 700; }
.lineup-player-price small { font-size: 10px; font-weight: 500; }
.lineup-actions { display: flex; justify-content: space-between; align-items: center; gap: 10px; border-top: 1px solid var(--border); padding-top: 10px; }
.lineup-actions > span { font-size: 12px; }

.selection-modal {
  width: min(680px, calc(100% - 24px));
  max-height: min(670px, calc(100dvh - 24px));
  padding: 15px;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
}
.selection-modal[open] { display: flex; flex-direction: column; gap: 10px; }
.selection-modal::backdrop { background: #080b10c9; }
.selection-modal-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.modal-close, .selection-remove { color: var(--text); background: var(--raised); border: 1px solid var(--border); border-radius: 5px; min-height: 34px; }
.modal-close { width: 34px; font-size: 21px; }
.selection-remove { color: var(--danger); padding-inline: 10px; align-self: flex-start; }
.selection-list { min-height: 0; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); align-content: start; gap: 7px; overflow: auto; overscroll-behavior: contain; padding: 3px; }
.selection-option { display: grid; grid-template-columns: 42px minmax(0, 1fr) auto; align-items: center; gap: 8px; min-width: 0; padding: 6px; border: 1px solid var(--border); border-radius: 5px; background: var(--raised); text-align: left; }
.selection-option:hover, .selection-option.current { border-color: var(--accent); }
.selection-option-main strong, .selection-option-main small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.selection-option-name { display: flex; align-items: center; gap: 6px; }
.selection-option-name .country-badge { flex: none; }
.selection-avatar, .market-player-photo, .coach-avatar { width: 42px; height: 43px; object-fit: cover; object-position: center 22%; background: #26313d; border-radius: 3px; }
.lineup-avatar.coach-portrait, .selection-avatar.coach-portrait, .coach-avatar.coach-portrait {
  object-fit: contain;
  object-position: center bottom;
}
.lineup-avatar.coach-portrait { object-position: center; }
.selection-option-price { color: var(--accent); text-align: right; font-weight: 650; font-variant-numeric: tabular-nums; }
.selection-option-price small { display: block; font-weight: 400; }
.selection-feedback { color: var(--danger); padding: 0 3px; }
.selection-feedback:empty { display: none; }

.filter-bar, .form-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.filter-bar { margin-bottom: 10px; }
.field { display: grid; gap: 5px; align-content: start; }
.field label { font-size: 13px; color: var(--muted); }
.table-scroll { overflow: auto; }
.stat-table { width: 100%; border-collapse: collapse; }
.stat-table :is(th, td) { padding: 6px 8px; text-align: left; border-bottom: 1px solid var(--border); }
.stat-table th { background: var(--surface); color: var(--muted); font-size: 12px; }
.stat-table td { font-variant-numeric: tabular-nums; }
.stat-table tbody tr:hover { background: var(--raised); }
.price-input { width: 84px; }
.coach-market { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(185px, 100%), 1fr)); gap: 10px; }
.coach-card { border: 1px solid var(--border); padding: 8px; border-radius: 5px; }
.coach-team-head, .coach-price, .match-card-head { display: flex; align-items: center; gap: 6px; }
.coach-price, .match-card-head { justify-content: space-between; }
.coach-price { margin-top: 8px; font-size: 12px; }
.coach-team-head { margin-bottom: 5px; }
.subtle-tag, .pill-good { color: var(--muted); font-size: 12px; }
.dropzone { display: flex; flex-wrap: wrap; min-height: 84px; align-content: center; align-items: center; justify-content: center; gap: 8px 12px; background: #141a21; border: 1px dashed #5d6d7d; border-radius: 6px; padding: 14px; }
.dropzone p { color: var(--muted); }
.dropzone:hover, .dropzone.drag { border-color: var(--accent); }
.progress-wrap, .import-result:not(:empty) { margin-top: 10px; }
.match-card { padding: 9px 0; border-top: 1px solid var(--border); }

.auth-panel { width: min(400px, calc(100% - 28px)); margin: clamp(16px, 14vh, 140px) auto 16px; padding: 24px; }
.auth-panel h1 { margin-bottom: 20px; }
.auth-form { display: grid; gap: 8px; }
.auth-form h2 { margin: 0 0 6px; font-size: 16px; }
.auth-form .input { margin-bottom: 6px; }
#loginMessage { color: var(--danger); margin-top: 10px; }
#loginMessage:empty { display: none; }
.toast { position: fixed; right: var(--gutter); bottom: 16px; z-index: 3; max-width: min(380px, calc(100% - 28px)); padding: 10px 13px; background: var(--raised); border: 1px solid var(--accent); border-radius: 5px; visibility: hidden; pointer-events: none; }
.toast.show { visibility: visible; }

@media (max-width: 1000px) { .board { grid-template-columns: minmax(0, 1fr); } }
@media (max-width: 740px) {
  .header-tools { margin-left: 0; }
  .overview-grid { grid-template-columns: minmax(0, 1fr); }
  .lineup-board { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .lineup-player-slot { grid-template-rows: 22px minmax(0, 1fr) auto; height: clamp(130px, 23dvh, 185px); }
  .slot-details { min-height: 54px; padding-block: 3px; gap: 2px; }
  .slot-role, .slot-details { padding-inline: 6px; }
  .slot-points { font-size: 10px; }
  .lineup-player-name { font-size: 15px; }
  .lineup-player-meta { gap: 3px; }
  .lineup-player-meta .country-badge { gap: 3px; font-size: 9px; }
  .lineup-player-meta .country-flag { width: 13px; height: 10px; }
  .lineup-player-team .lineup-team-logo { width: 12px; height: 12px; }
  .filter-bar, .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 520px) {
  .app-header { min-height: 52px; gap: 4px 12px; padding-block: 7px; }
  .header-tools { flex-basis: 100%; }
  .nav { gap: 12px; }
  .nav-item { min-height: 36px; font-size: 12px; }
  .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .selection-list { grid-template-columns: minmax(0, 1fr); }
}
@media (max-height: 570px) and (min-width: 741px) {
  .app-header { min-height: 45px; padding-block: 5px; }
  .nav-item { min-height: 36px; }
  .lineup-player-slot { height: clamp(132px, 43dvh, 230px); }
}

@media (max-height: 780px), (max-width: 740px) {
  .content[data-view="overview"] { grid-template-rows: auto auto minmax(0, 1fr); }
  .overview-recent { display: none; }
  .overview-grid > .panel { padding-block: 8px; }
  .overview-grid .panel-head { margin-bottom: 5px; }
  .overview-grid .match-row { padding-block: 3px; }
  .overview-grid .team-logo { width: 18px; height: 18px; }
  .overview-grid .roster-slot { min-height: 25px; }
  .content[data-view="overview"] .stat-card { padding: 5px 8px; }
  .content[data-view="overview"] .stat-value { font-size: 19px; padding-top: 0; }
}

@media (max-width: 740px) {
  .overview-grid { grid-template-rows: minmax(0, 1fr) auto; gap: 7px; }
  .overview-roster .quick-roster { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 10px; }
  .overview-grid .match-team { gap: 4px; font-size: 12px; }
  .overview-roster .secondary-btn { min-height: 27px; padding-block: 2px; }
}

@media (max-height: 630px) and (max-width: 740px), (max-height: 485px) {
  .overview-roster { display: none; }
  .overview-grid { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); }
  .content[data-view="overview"] { grid-template-rows: auto minmax(0, 1fr); }
  .content[data-view="overview"] .stats-grid { display: none; }
}

@media (max-height: 470px) and (min-width: 440px) {
  .schedule-panel .board { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 8px; }
}

@media (max-height: 470px) and (max-width: 439px) {
  .overview-grid .match-row { gap: 3px; padding-block: 1px; }
  .overview-grid .match-team { font-size: 11px; line-height: 1.05; }
  .overview-grid .team-logo { width: 15px; height: 15px; }
}
