:root {
  --bg: #0d1520;
  --panel: #132131;
  --muted: #9eb0c8;
  --text: #f4f8ff;
  --primary: #0f4ea8;
  --primary-strong: #1d6fe3;
  --primary-soft: #d9e8ff;
  --accent: #f2c230;
  --danger: #cf4a4a;
  --line: #24415f;
}

* {
  box-sizing: border-box;
}
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
}

h1, h2, h3 { margin: 0 0 10px; }
a { color: inherit; }

.app-header,
header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.header-main {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
}

.mobile-nav-toggle {
  display: none;
  min-width: 44px;
  min-height: 44px;
  padding: 8px 12px;
  font-size: 20px;
  line-height: 1;
}

.top-nav {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}
.top-nav a {
  color: var(--text);
  text-decoration: none;
  padding: 8px 12px;
  border: 1px solid #2f3442;
  border-radius: 10px;
}
.top-nav a.active,
.top-nav a:hover {
  border-color: var(--accent);
  background: rgba(242, 194, 48, 0.10);
}

.layout {
  display: grid;
  grid-template-columns: 1fr 1fr 1.5fr;
  gap: 12px;
  padding: 12px;
}
.layout.two-col {
  grid-template-columns: 1fr 1fr;
}
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  min-height: 300px;
}
.panel-hero {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px rgba(242, 194, 48, 0.14);
}
.section-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 10px;
}
.section-head-strong {
  margin-bottom: 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid #30384b;
}
.section-kicker {
  display: inline-block;
  margin-bottom: 6px;
  padding: 4px 8px;
  border: 1px solid rgba(242, 194, 48, 0.45);
  border-radius: 999px;
  color: #ffe08a;
  background: rgba(242, 194, 48, 0.08);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.compact-head {
  margin-top: 12px;
  margin-bottom: 8px;
}
.section-subtext {
  margin: -4px 0 0;
}
.subsection-card {
  margin-top: 12px;
  padding: 12px;
  border: 1px solid #2b3345;
  border-radius: 12px;
  background: #131823;
}
.subsection-card-tight {
  padding: 10px;
}
.subsection-title {
  margin: 0 0 10px;
  font-size: 15px;
}
.no-margin {
  margin: 0;
}
.mobile-tip-box {
  margin-bottom: 12px;
  padding: 10px 12px;
  border: 1px solid #2f3442;
  border-radius: 10px;
  background: #131823;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}
.row {
  display: flex;
  gap: 8px;
  align-items: center;
}
.row.wrap { flex-wrap: wrap; }
.col {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.mini-col { flex: 1; min-width: 120px; }
input, select, textarea, button {
  background: #0f131b;
  border: 1px solid #2f3442;
  color: var(--text);
  border-radius: 10px;
  padding: 10px 12px;
  font: inherit;
}
button { cursor: pointer; }
button:hover { border-color: var(--primary); }
button.danger { border-color: var(--danger); }
.primary-btn {
  border-color: var(--primary-strong);
  background: linear-gradient(180deg, #165dbd, #0f4ea8);
  color: #ffffff;
  box-shadow: 0 0 0 1px rgba(29, 111, 227, 0.18);
}
.primary-btn:hover {
  border-color: var(--accent);
}
.muted { color: var(--muted); font-size: 13px; }
.action-row { margin-top: 10px; }
.form-inline-mobile input {
  flex: 1 1 220px;
  min-height: 38px;
  padding: 8px 10px;
}

.players-list {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 62vh;
  overflow: auto;
}

.sequence-list {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 800px;
  overflow-y: auto;
}
.sequence-item {
  border: 1px solid #2f3442;
  border-radius: 8px;
  padding: 8px;
  background: #131823;
}
.sequence-title {
  font-weight: 600;
}

.exercise-preview-wrapper {
  margin-top: 6px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
#exercise-preview {
  max-width: 100%;
  max-height: 180px;
  border-radius: 6px;
  border: 1px solid #2f3442;
  object-fit: contain;
  display: none;
  cursor: zoom-in;
}

.image-modal {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.image-modal.show {
  display: flex;
}
.image-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.8);
}
.image-modal-img {
  position: relative;
  max-width: 95vw;
  max-height: 90vh;
  border-radius: 8px;
  border: 2px solid #fff;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.6);
}
.player-item {
  border: 1px solid #2f3442;
  border-radius: 10px;
  padding: 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  background: #131823;
}
.player-item.active {
  border-color: var(--accent);
  background: rgba(242, 194, 48, 0.10);
}
.player-chip {
  display: inline-flex;
  gap: 6px;
  align-items: center;
  border: 1px solid #3a4152;
  background: #141a26;
  border-radius: 999px;
  padding: 7px 11px;
  font-size: 13px;
  cursor: grab;
}

.pitch {
  position: relative;
  width: 100%;
  max-width: 430px;
  margin: 0 auto;
  aspect-ratio: 3/4;
  border: 1px solid #376042;
  border-radius: 10px;
  background: linear-gradient(180deg, #174d2d, #136033);
  overflow: hidden;
}
.pitch::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  height: 2px;
  background: rgba(255,255,255,0.25);
  transform: translateY(-50%);
}
.spot {
  position: absolute;
  width: 96px;
  min-height: 40px;
  border-radius: 8px;
  border: 1px dashed rgba(255,255,255,0.5);
  transform: translate(-50%, -50%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px 6px;
  text-align: center;
  color: #ecf8ee;
  touch-action: none;
}
.spot-label {
  font-size: 11px;
  opacity: 0.9;
}
.spot-role {
  font-size: 9px;
  color: var(--accent);
  text-align: center;
  margin-top: 2px;
  pointer-events: none;
}
.move-handle {
  position: absolute;
  right: 4px;
  top: 2px;
  font-size: 12px;
  opacity: 0.85;
  cursor: grab;
  user-select: none;
}
.spot.gk-fixed .move-handle {
  display: none;
}
.spot .player-chip {
  width: 100%;
  justify-content: center;
}

.bench {
  min-height: 60px;
  border: 1px dashed #4f566b;
  border-radius: 8px;
  padding: 8px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.dropzone.over {
  outline: 2px solid var(--primary);
}

hr {
  border: none;
  border-top: 1px solid var(--line);
  margin: 14px 0;
}

.auth-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 16px;
}
.auth-shell {
  width: 100%;
  max-width: 420px;
}
.auth-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 22px;
}
.auth-form { margin-top: 12px; }
.flash-stack { margin: 10px 0 14px; }
.flash {
  border: 1px solid #5a2b2b;
  background: #2a1717;
  color: #ffd8d8;
  border-radius: 10px;
  padding: 10px 12px;
}

.home-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  padding: 12px;
}
.home-card {
  display: block;
  text-decoration: none;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 18px;
}
.home-card:hover {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px rgba(242, 194, 48, 0.12);
}
.home-card p { margin: 0; color: var(--muted); }
.inline-link-button {
  text-decoration: none;
  padding: 7px 10px;
  border: 1px solid #2f3442;
  border-radius: 10px;
  color: var(--text);
  font-size: 13px;
}
.inline-link-button:hover {
  border-color: var(--accent);
  background: rgba(242, 194, 48, 0.08);
}
.deep-link-title {
  color: var(--text);
  text-decoration: none;
  font-weight: 600;
}
.deep-link-title:hover {
  color: #a9c6ff;
  text-decoration: underline;
}
.players-layout {
  grid-template-columns: 1fr 1fr;
}

@media (max-width: 1200px) {
  .layout,
  .layout.two-col,
  .trainings-layout,
  .match-layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 700px) {
  .app-header,
  header {
    padding: 12px;
    align-items: stretch;
    position: sticky;
    top: 0;
    background: rgba(15, 17, 21, 0.97);
    backdrop-filter: blur(8px);
    z-index: 20;
  }
  .header-main {
    align-items: center;
  }
  .mobile-nav-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    align-self: flex-start;
  }
  .top-nav {
    display: none;
    width: 100%;
    flex-direction: column;
    gap: 8px;
    padding-top: 2px;
  }
  .top-nav.open {
    display: flex;
  }
  .top-nav a {
    width: 100%;
    text-align: center;
  }
  .layout,
  .home-grid {
    padding: 8px;
    gap: 8px;
  }
  .home-grid {
    grid-template-columns: 1fr;
  }
  .panel,
  .home-card,
  .auth-card {
    padding: 12px;
  }
  .mobile-priority {
    order: -1;
  }
  .mobile-secondary {
    order: 1;
  }
  .pitch {
    min-height: 62vh;
  }
  .spot {
    width: 88px;
    min-height: 38px;
  }
  .player-chip {
    font-size: 12px;
    padding: 7px 10px;
  }
  .player-item {
    align-items: flex-start;
    flex-direction: column;
  }
  input, select, textarea, button {
    min-height: 44px;
  }
  .form-inline-mobile {
    flex-direction: column;
    align-items: stretch;
  }
  .form-inline-mobile input,
  .form-inline-mobile button {
    width: 100%;
  }
  .form-inline-mobile input {
    flex: 0 0 auto;
    min-height: 38px;
    padding: 8px 10px;
  }
  .sticky-mobile-actions {
    position: sticky;
    z-index: 10;
    padding: 8px;
    border: 1px solid #2f3442;
    border-radius: 12px;
    background: rgba(15, 19, 27, 0.96);
    backdrop-filter: blur(8px);
  }
  .training-add-sticky {
    top: 76px;
    bottom: auto;
    margin-bottom: 10px;
  }
  .lineup-sticky-actions {
    bottom: 8px;
  }
  .sticky-mobile-actions button {
    flex: 1 1 100%;
  }
  .section-head {
    margin-bottom: 8px;
  }
  .section-head-strong {
    margin-bottom: 10px;
    padding-bottom: 8px;
  }
  .subsection-card {
    margin-top: 10px;
    padding: 10px;
  }
  .subsection-title {
    font-size: 14px;
  }
  .mobile-tip-box {
    font-size: 12px;
  }
}

/* Modal */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
}

.modal-overlay.hidden {
  display: none;
}

.modal-content {
  background: var(--panel);
  border-radius: 12px;
  max-width: 400px;
  width: 100%;
  max-height: 80vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

.modal-header h3 {
  margin: 0;
  font-size: 18px;
}

.modal-close {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 28px;
  cursor: pointer;
  padding: 0;
  line-height: 1;
}

.modal-close:hover {
  color: var(--text);
}

.modal-body {
  padding: 16px;
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--line);
}

.picker-options {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.picker-player {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px;
  background: var(--bg);
  border-radius: 8px;
  cursor: pointer;
  border: 2px solid transparent;
}

.picker-player:hover {
  border-color: var(--primary);
}

.picker-player.active {
  border-color: var(--primary-strong);
  background: var(--primary-soft);
  color: var(--bg);
}

.picker-player.active .picker-player-info {
  color: var(--bg);
}

.picker-player-name {
  font-weight: 500;
}

.picker-player-info {
  font-size: 13px;
  color: var(--muted);
}

.secondary-btn {
  width: 100%;
  padding: 12px;
  background: var(--line);
  border: none;
  border-radius: 8px;
  color: var(--text);
  font-size: 15px;
  cursor: pointer;
}

.secondary-btn:hover {
  background: var(--muted);
  color: var(--bg);
}

@media print {
  body { background: #fff; color: #000; }
  .app-header, header, #players-panel, #editor-panel, .muted, .row, .mobile-tip-box { display: none !important; }
  .layout { display: block; padding: 0; }
  #lineup-panel { border: none; background: #fff; padding: 0; box-shadow: none; }
  .pitch { border: 1px solid #000; break-inside: avoid; }
}
