:root {
  color-scheme: dark;
  --bg: #0b0e14;
  --panel: #151a24;
  --panel-2: #1d2430;
  --line: #2b3444;
  --text: #f5f7fb;
  --muted: #9da8b8;
  --gold: #f3bc42;
  --green: #46d48a;
  --red: #ff6b6b;
  --blue: #66a9ff;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(circle at top, #192131 0, var(--bg) 42%);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button, input, select { font: inherit; }
.shell { width: min(1180px, calc(100% - 28px)); margin: 0 auto; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 24px 0; }
.brand { display: flex; align-items: center; gap: 14px; min-width: 0; }
.shield { width: 58px; height: 58px; border-radius: 17px; display: grid; place-items: center; background: linear-gradient(145deg, #293448, #141923); border: 1px solid var(--line); font-size: 28px; overflow: hidden; }
.shield img { width: 100%; height: 100%; object-fit: cover; }
h1, h2, p { margin: 0; }
h1 { font-size: clamp(1.35rem, 4vw, 2rem); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
h2 { font-size: 1.2rem; }
.eyebrow { color: var(--gold); font-size: .72rem; font-weight: 800; letter-spacing: .15em; }
.muted { color: var(--muted); }
.primary-button { border: 0; border-radius: 12px; padding: 11px 16px; color: #1a1405; background: var(--gold); font-weight: 800; cursor: pointer; }
.primary-button:disabled { opacity: .6; cursor: wait; }
.notice { padding: 16px; border-radius: 14px; border: 1px solid var(--line); background: var(--panel); margin-bottom: 18px; }
.notice.error { border-color: rgba(255,107,107,.55); color: #ffd7d7; }
.hidden { display: none !important; }
.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.stat-card, .panel { background: rgba(21,26,36,.92); border: 1px solid var(--line); border-radius: 18px; }
.stat-card { padding: 16px; }
.stat-card span { display: block; color: var(--muted); font-size: .8rem; }
.stat-card strong { display: block; margin-top: 6px; font-size: 1.45rem; }
.panel { margin-top: 14px; padding: 18px; }
.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 16px; }
.status-pill { border: 1px solid var(--line); border-radius: 999px; padding: 6px 10px; color: var(--muted); font-size: .78rem; }
.status-pill.live { border-color: rgba(70,212,138,.55); color: var(--green); }
.war-content { display: grid; gap: 12px; }
.war-score { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 14px; }
.war-side { padding: 14px; border-radius: 14px; background: var(--panel-2); }
.war-side:last-child { text-align: right; }
.war-number { display: block; font-size: 1.6rem; color: var(--text); }
.controls { display: flex; gap: 9px; }
input, select { width: 100%; color: var(--text); background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; outline: none; }
input:focus, select:focus { border-color: var(--gold); }
.member-list { display: grid; gap: 9px; }
.member-row { display: grid; grid-template-columns: 52px minmax(170px, 1.5fr) repeat(5, minmax(84px, .65fr)); align-items: center; gap: 10px; padding: 11px; border-radius: 14px; background: var(--panel-2); border: 1px solid transparent; }
.member-row:hover { border-color: var(--line); }
.rank { color: var(--gold); font-weight: 800; text-align: center; }
.player { min-width: 0; }
.player strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player small, .metric small { color: var(--muted); }
.metric { text-align: right; }
.metric strong { display: block; }
.role { display: inline-block; margin-top: 4px; color: var(--blue); font-size: .72rem; text-transform: capitalize; }
footer { display: flex; justify-content: space-between; gap: 16px; padding: 22px 0 30px; color: var(--muted); font-size: .78rem; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; }

@media (max-width: 820px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .member-heading { align-items: stretch; flex-direction: column; }
  .controls { width: 100%; }
  .controls label { flex: 1; }
  .member-row { grid-template-columns: 42px minmax(145px, 1fr) repeat(2, minmax(75px, .55fr)); }
  .member-row .metric:nth-of-type(3), .member-row .metric:nth-of-type(4), .member-row .metric:nth-of-type(5) { display: none; }
}

@media (max-width: 520px) {
  .shell { width: min(100% - 18px, 1180px); }
  .topbar { padding: 16px 0; }
  .shield { width: 48px; height: 48px; border-radius: 14px; }
  .primary-button { padding: 9px 11px; }
  .panel { padding: 13px; border-radius: 15px; }
  .stats-grid { gap: 8px; }
  .stat-card { padding: 12px; }
  .controls { flex-direction: column; }
  .war-score { grid-template-columns: 1fr; }
  .war-side:last-child { text-align: left; }
  .war-vs { display: none; }
  .member-row { grid-template-columns: 34px minmax(130px, 1fr) 78px; gap: 7px; padding: 10px 7px; }
  .member-row .metric:nth-of-type(n+2) { display: none; }
  footer { flex-direction: column; }
}

/* Player profile details - Version 1.1 */
.member-row {
  width: 100%;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  position: relative;
}
.member-row:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
.open-profile { color: var(--gold); font-size: 1.6rem; line-height: 1; }
.modal { position: fixed; inset: 0; z-index: 1000; display: grid; place-items: center; padding: 18px; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(4, 6, 10, .82); backdrop-filter: blur(5px); }
.player-modal-card {
  position: relative;
  width: min(920px, 100%);
  max-height: min(88vh, 900px);
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: #111722;
  padding: 20px;
  box-shadow: 0 24px 80px rgba(0,0,0,.48);
}
.modal-open { overflow: hidden; }
.modal-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 16px; }
.icon-button { width: 42px; height: 42px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel-2); color: var(--text); font-size: 1.6rem; cursor: pointer; }
.profile-hero { display: flex; align-items: center; gap: 15px; padding: 15px; border-radius: 16px; background: var(--panel-2); }
.profile-icon { width: 68px; height: 68px; display: grid; place-items: center; overflow: hidden; font-size: 2rem; }
.profile-icon img { width: 100%; height: 100%; object-fit: contain; }
.profile-name { display: block; font-size: 1.35rem; }
.profile-labels { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.profile-label { display: inline-block; border: 1px solid var(--line); border-radius: 999px; padding: 4px 8px; color: var(--blue); font-size: .74rem; }
.profile-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 9px; margin-top: 14px; }
.profile-stats article { padding: 12px; border-radius: 13px; background: var(--panel-2); }
.profile-stats span { display: block; color: var(--muted); font-size: .76rem; }
.profile-stats strong { display: block; margin-top: 4px; font-size: 1.15rem; }
.profile-section { margin-top: 18px; }
.profile-section h3 { margin: 0 0 10px; }
.unit-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.unit-card { padding: 11px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel-2); }
.unit-card strong, .unit-card span, .unit-card small { display: block; }
.unit-card span { margin-top: 4px; }
.unit-card small { margin-top: 3px; color: var(--muted); }

@media (max-width: 820px) {
  .member-row { grid-template-columns: 42px minmax(145px, 1fr) repeat(2, minmax(75px, .55fr)) 22px; }
  .profile-stats { grid-template-columns: repeat(3, 1fr); }
  .unit-grid { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 520px) {
  .modal { padding: 8px; align-items: end; }
  .player-modal-card { max-height: 94vh; padding: 14px; border-radius: 18px 18px 10px 10px; }
  .member-row { grid-template-columns: 34px minmax(120px, 1fr) 70px 18px; }
  .profile-stats { grid-template-columns: repeat(2, 1fr); }
  .unit-grid { grid-template-columns: repeat(2, 1fr); }
  .profile-hero { align-items: flex-start; }
}

/* Mobile usability improvements - Version 1.2 */
html { -webkit-text-size-adjust: 100%; }
body { overflow-x: hidden; }
button, input, select { min-height: 44px; }
.member-row { -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
.member-row:active { transform: scale(.995); }
.player-modal-card { overscroll-behavior: contain; }

@media (max-width: 640px) {
  body { background: var(--bg); }
  .shell { width: 100%; padding: 0 10px; }
  .topbar {
    position: sticky;
    top: 0;
    z-index: 50;
    margin: 0 -10px;
    padding: 10px;
    background: rgba(11,14,20,.94);
    border-bottom: 1px solid var(--line);
    backdrop-filter: blur(12px);
  }
  .brand { gap: 10px; }
  .brand > div:last-child { min-width: 0; }
  .shield { flex: 0 0 44px; width: 44px; height: 44px; border-radius: 12px; }
  h1 { font-size: 1.08rem; }
  .brand .eyebrow { display: none; }
  #clanTag { font-size: .72rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .primary-button { min-width: 76px; padding: 9px 12px; }

  main { padding-top: 10px; }
  .stats-grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .stat-card { min-width: 0; }
  .stat-card strong { font-size: 1.18rem; overflow-wrap: anywhere; }
  .panel { margin-top: 10px; padding: 12px; }
  .section-heading { margin-bottom: 12px; }
  .member-heading { gap: 10px; }
  .controls { display: grid; grid-template-columns: 1fr; gap: 8px; }
  input, select { font-size: 16px; border-radius: 12px; }

  .member-list { gap: 8px; }
  .member-row {
    grid-template-columns: 34px minmax(0,1fr) auto 18px;
    grid-template-areas:
      "rank player th arrow"
      "rank player trophies arrow";
    min-height: 76px;
    gap: 4px 8px;
    padding: 10px 9px;
    border-color: var(--line);
    border-radius: 15px;
  }
  .rank { grid-area: rank; align-self: center; font-size: .9rem; }
  .player { grid-area: player; align-self: center; }
  .player strong { font-size: 1rem; }
  .player small { font-size: .68rem; }
  .role { margin-top: 2px; font-size: .66rem; }
  .member-row .metric { display: none !important; }
  .member-row .metric:nth-of-type(1) {
    display: block !important;
    grid-area: th;
    align-self: end;
  }
  .member-row .metric:nth-of-type(2) {
    display: block !important;
    grid-area: trophies;
    align-self: start;
  }
  .member-row .metric strong { font-size: .84rem; }
  .member-row .metric small { font-size: .62rem; }
  .open-profile { grid-area: arrow; align-self: center; font-size: 1.45rem; }

  .war-content { font-size: .92rem; }
  .war-side { padding: 12px; }
  .war-number { font-size: 1.35rem; }

  .modal { padding: 0; align-items: stretch; }
  .player-modal-card {
    width: 100%;
    height: 100dvh;
    max-height: none;
    border: 0;
    border-radius: 0;
    padding: 12px 12px 28px;
  }
  .modal-header {
    position: sticky;
    top: -12px;
    z-index: 5;
    margin: -12px -12px 12px;
    padding: 12px;
    background: rgba(17,23,34,.96);
    border-bottom: 1px solid var(--line);
    backdrop-filter: blur(12px);
  }
  .icon-button { flex: 0 0 46px; width: 46px; height: 46px; }
  .profile-hero { padding: 12px; }
  .profile-icon { flex: 0 0 56px; width: 56px; height: 56px; }
  .profile-name { font-size: 1.12rem; }
  .profile-stats { grid-template-columns: repeat(2, minmax(0,1fr)); gap: 7px; }
  .profile-stats article { min-width: 0; padding: 10px; }
  .profile-stats span { font-size: .7rem; }
  .profile-stats strong { font-size: 1rem; overflow-wrap: anywhere; }
  .unit-grid { grid-template-columns: repeat(2, minmax(0,1fr)); gap: 7px; }
  .unit-card { min-width: 0; padding: 9px; }
  .unit-card strong { font-size: .86rem; overflow-wrap: anywhere; }
  .unit-card span, .unit-card small { font-size: .72rem; }
  footer { padding: 16px 2px 24px; font-size: .7rem; }
}

@media (max-width: 360px) {
  .shell { padding: 0 7px; }
  .topbar { margin: 0 -7px; padding: 8px 7px; }
  .primary-button { min-width: 68px; padding-inline: 9px; font-size: .86rem; }
  .member-row { grid-template-columns: 30px minmax(0,1fr) auto 14px; padding-inline: 6px; }
  .profile-stats, .unit-grid { grid-template-columns: 1fr 1fr; }
}
