:root {
  --bg: #f2ece2;
  --bg-strong: #e6ddcf;
  --ink: #1c241f;
  --muted: #5f6c63;
  --accent: #d0773c;
  --accent-2: #2f6d55;
  --card: #fbf6ee;
  --card-strong: #f5efe5;
  --stroke: #d9cfc0;
  --shadow: 0 18px 40px rgba(28, 36, 31, 0.12);
  --radius: 18px;
  --radius-sm: 10px;
  --font-display: "Fraunces", "Times New Roman", serif;
  --font-body: "Space Grotesk", "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--font-body);
  color: var(--ink);
  background: radial-gradient(circle at top, #fff8ef 0%, var(--bg) 45%, var(--bg-strong) 100%);
  min-height: 100vh;
}

.auth-locked .app {
  display: none;
}

.grain {
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.25;
  background-image: repeating-linear-gradient(
      120deg,
      rgba(0, 0, 0, 0.035) 0px,
      rgba(0, 0, 0, 0.035) 1px,
      transparent 1px,
      transparent 3px
    );
  mix-blend-mode: multiply;
}

.glow {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(circle at 12% 18%, rgba(208, 119, 60, 0.18), transparent 45%),
    radial-gradient(circle at 85% 8%, rgba(47, 109, 85, 0.18), transparent 45%),
    radial-gradient(circle at 60% 70%, rgba(20, 60, 45, 0.12), transparent 55%);
}

.shell {
  max-width: 1200px;
  margin: 0 auto;
  padding: 32px 22px 60px;
  position: relative;
}

.auth-screen {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(circle at 18% 20%, rgba(208, 119, 60, 0.28), transparent 45%),
    radial-gradient(circle at 78% 12%, rgba(47, 109, 85, 0.22), transparent 45%),
    rgba(18, 20, 18, 0.72);
  padding: 24px;
  backdrop-filter: blur(6px);
}

.auth-screen.hidden {
  display: none;
}

.auth-modal {
  width: min(520px, 94vw);
  background: linear-gradient(180deg, #fbf4ea 0%, #f3eadb 100%);
  border: 1px solid rgba(217, 207, 192, 0.9);
  border-radius: calc(var(--radius) + 8px);
  padding: 26px;
  box-shadow: 0 30px 80px rgba(18, 20, 18, 0.25);
  position: relative;
  overflow: hidden;
}

.auth-modal::before {
  content: "";
  position: absolute;
  width: 240px;
  height: 240px;
  left: -120px;
  top: -120px;
  background: radial-gradient(circle, rgba(208, 119, 60, 0.35) 0%, transparent 70%);
  opacity: 0.8;
}

.auth-modal::after {
  content: "";
  position: absolute;
  width: 200px;
  height: 200px;
  right: -120px;
  bottom: -120px;
  background: radial-gradient(circle, rgba(47, 109, 85, 0.35) 0%, transparent 70%);
  opacity: 0.8;
}

.auth-modal > * {
  position: relative;
  z-index: 1;
}

.auth-brand {
  padding: 18px 18px 16px;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, rgba(208, 119, 60, 0.16), rgba(47, 109, 85, 0.12));
  border: 1px solid rgba(217, 207, 192, 0.8);
  margin-bottom: 18px;
}

.auth-brand h1 {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(2rem, 4vw, 2.6rem);
}

.auth-brand .subtitle {
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.95rem;
}

.auth-modal input {
  width: 100%;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(184, 173, 154, 0.9);
  background: #fffaf3;
  font-family: var(--font-body);
  font-size: 0.95rem;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.auth-modal input:focus {
  outline: none;
  border-color: rgba(208, 119, 60, 0.8);
  box-shadow: 0 0 0 3px rgba(208, 119, 60, 0.18);
}

.auth-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 4px;
}

.auth-actions .btn {
  justify-content: center;
}

.auth-modal .hint.warning {
  background: rgba(143, 43, 43, 0.08);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  border: 1px solid rgba(143, 43, 43, 0.18);
}

.app {
  max-width: 1200px;
  margin: 0 auto;
  padding: 28px 22px 60px;
  position: relative;
}

.app-header {
  display: grid;
  gap: 16px;
  grid-template-columns: minmax(240px, 1fr) auto;
  align-items: center;
  margin-bottom: 26px;
}

.brand-block h1 {
  font-family: var(--font-display);
  font-size: clamp(2.1rem, 3.2vw, 3rem);
  margin: 0 0 8px;
}

.header-right {
  display: grid;
  gap: 12px;
  justify-items: end;
}

.header-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
}

.account-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.icon-btn {
  border: 1px solid var(--stroke);
  background: #fff;
  border-radius: 999px;
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  cursor: pointer;
  position: relative;
  font-size: 1rem;
}

.badge {
  position: absolute;
  top: -6px;
  right: -6px;
  background: #8f2b2b;
  color: #fff;
  border-radius: 999px;
  font-size: 0.65rem;
  padding: 2px 6px;
  border: 2px solid #fff;
}

.app-nav {
  display: flex;
  gap: 12px;
  margin: 8px 0 18px;
  flex-wrap: wrap;
}

.nav-tab {
  border: 1px solid var(--stroke);
  background: #fff;
  border-radius: 999px;
  padding: 8px 16px;
  font-weight: 600;
  cursor: pointer;
  color: var(--muted);
}

.nav-tab.active {
  background: var(--accent);
  color: #fff;
  border-color: transparent;
}

.admin-popover {
  position: absolute;
  right: 22px;
  top: 118px;
  width: min(360px, 92vw);
  background: var(--card);
  border: 1px solid var(--stroke);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
  z-index: 20;
}

.admin-popover.hidden {
  display: none;
}

.popover-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.app-views {
  display: block;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.teams-layout {
  display: grid;
  grid-template-columns: minmax(240px, 320px) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.panel {
  background: var(--card);
  border: 1px solid var(--stroke);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 12px;
}

.panel-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.loading {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  font-size: 0.85rem;
  color: var(--muted);
}

.loading.hidden {
  display: none;
}

.spinner {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid rgba(28, 36, 31, 0.2);
  border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.mode-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  flex-wrap: wrap;
}

.mode-label {
  font-size: 0.7rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.18em;
}

.toggle-btn {
  border: 1px solid var(--stroke);
  background: #fff;
  border-radius: 999px;
  padding: 6px 14px;
  font-weight: 600;
  cursor: pointer;
  color: var(--muted);
}

.toggle-btn.active {
  background: var(--accent);
  color: #fff;
  border-color: transparent;
}

.optimizer-panel {
  border: 1px solid var(--stroke);
  border-radius: var(--radius-sm);
  padding: 12px;
  margin-bottom: 12px;
  background: #f9f2e8;
}

.constraints-panel {
  border: 1px dashed rgba(184, 173, 154, 0.8);
  border-radius: var(--radius-sm);
  padding: 12px;
  background: #fffaf3;
  display: grid;
  gap: 8px;
}

.constraint-group {
  border: 1px solid rgba(217, 207, 192, 0.7);
  border-radius: var(--radius-sm);
  padding: 10px;
  background: #fff;
  display: grid;
  gap: 8px;
}

.constraint-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-weight: 600;
  font-size: 0.85rem;
}

.constraint-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  align-items: stretch;
}

.constraint-row select {
  width: 100%;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--stroke);
  font-family: var(--font-body);
  background: #fff;
  min-width: 0;
}

.constraint-list .pill-row {
  background: #f7f1e7;
  width: 100%;
}

.constraint-list {
  display: grid;
  gap: 8px;
}

.constraints-panel textarea {
  width: 100%;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--stroke);
  background: #fff;
  font-family: var(--font-body);
}

.roster-panel .table-wrap {
  max-height: 52vh;
  overflow: auto;
  border-radius: var(--radius-sm);
  border: 1px solid var(--stroke);
}

.week-panel .week-grid {
  margin-top: 10px;
}

.hero {
  display: grid;
  gap: 28px;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  align-items: center;
  margin-bottom: 30px;
}

.hero-copy h1 {
  font-family: var(--font-display);
  font-size: clamp(2.4rem, 4vw, 3.6rem);
  margin: 0 0 8px;
}

.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.18em;
  font-size: 0.7rem;
  color: var(--accent-2);
  font-weight: 600;
}

.subtitle {
  margin: 0 0 18px;
  color: var(--muted);
  max-width: 480px;
}

.hero-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.meta-pill {
  background: var(--card-strong);
  border: 1px solid var(--stroke);
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 0.85rem;
}

.hero-panel {
  display: grid;
  gap: 16px;
}

.panel-card {
  background: var(--card);
  border: 1px solid var(--stroke);
  padding: 16px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.panel-card.subtle {
  background: #f7efe3;
  box-shadow: none;
}

.panel-card h3,
.panel-card h4 {
  margin: 0 0 12px;
  font-family: var(--font-display);
}

.hidden {
  display: none !important;
}

.auth-card input {
  width: 100%;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--stroke);
  background: #fff;
  font-family: var(--font-body);
}

.auth-card .auth-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.divider {
  height: 1px;
  background: var(--stroke);
  margin: 16px 0;
}

.field-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
}

.field-row input {
  max-width: 120px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--stroke);
  background: #fff;
  font-family: var(--font-body);
}

.pill {
  padding: 6px 12px;
  border-radius: 999px;
  background: #fff;
  border: 1px solid var(--stroke);
}

.hint {
  font-size: 0.8rem;
  color: var(--muted);
}

.grid {
  display: grid;
  gap: 22px;
}

.card {
  background: var(--card);
  border: 1px solid var(--stroke);
  padding: 20px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  animation: rise 0.7s ease forwards;
  opacity: 0;
  transform: translateY(20px);
  animation-delay: var(--delay, 0s);
}

@keyframes rise {
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.card-head {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.card-head h2 {
  margin: 0 0 6px;
  font-family: var(--font-display);
}

.card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.toolbar {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 12px;
}

.toolbar input {
  flex: 1;
  min-width: 180px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--stroke);
  background: #fff;
}

.btn {
  border: none;
  cursor: pointer;
  padding: 10px 16px;
  border-radius: 999px;
  font-weight: 600;
  font-family: var(--font-body);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.15);
}

.btn.primary {
  background: var(--accent);
  color: #fff;
}

.btn.ghost {
  background: transparent;
  border: 1px solid var(--stroke);
  color: var(--ink);
}

.btn.outline {
  background: #fff;
  border: 1px solid var(--stroke);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  box-shadow: none;
  transform: none;
}

.btn.file {
  position: relative;
  overflow: hidden;
}

.btn.file input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.week-grid {
  display: grid;
  gap: 18px;
  grid-template-columns: minmax(240px, 0.9fr) minmax(280px, 1.1fr);
  align-items: start;
}

.week-grid textarea {
  width: 100%;
  padding: 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--stroke);
  font-family: var(--font-body);
  background: #fff;
}

.section-title {
  font-weight: 600;
  margin: 10px 0 6px;
}

.week-input .section-title {
  margin-top: 18px;
}

.week-picks {
  display: grid;
  gap: 16px;
}

.week-section {
  border: 1px solid var(--stroke);
  border-radius: var(--radius-sm);
  padding: 12px;
  background: #fff;
}

.week-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.count-pill {
  padding: 4px 10px;
  border-radius: 999px;
  background: #f6efe3;
  border: 1px solid var(--stroke);
  font-size: 0.78rem;
}

.week-tools {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-bottom: 10px;
}

.week-tools input {
  flex: 1;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--stroke);
  font-family: var(--font-body);
  background: #fff;
}

.stack {
  display: grid;
  gap: 8px;
}

.stack .pill-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--stroke);
  border-radius: var(--radius-sm);
  background: #fff;
  justify-content: space-between;
}

.pill-row small {
  color: var(--muted);
}

.pill-info {
  display: grid;
  gap: 4px;
}

.pill-name {
  font-weight: 600;
}

.pill-meta {
  font-size: 0.75rem;
  color: var(--muted);
}

.table-wrap {
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 700px;
}

.data-table th,
.data-table td {
  border-bottom: 1px solid var(--stroke);
  padding: 10px 8px;
  text-align: left;
  font-size: 0.9rem;
}

.data-table th {
  color: var(--muted);
  font-weight: 600;
}

.data-table input,
.data-table select {
  width: 100%;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--stroke);
  background: #fff;
  font-family: var(--font-body);
}

.data-table .delete {
  background: transparent;
  color: #992d2d;
  border: none;
  cursor: pointer;
  font-weight: 600;
}

.teams {
  display: grid;
  gap: 16px;
}

.team-card {
  border: 1px solid var(--stroke);
  border-radius: var(--radius);
  padding: 16px;
  background: var(--card-strong);
}

.matchups-card {
  border: 1px dashed rgba(184, 173, 154, 0.8);
  border-radius: var(--radius);
  padding: 16px;
  background: #fffaf3;
}

.matchups-card h4 {
  margin: 0 0 6px;
  font-family: var(--font-display);
}

.matchups-list {
  display: grid;
  gap: 10px;
  margin-top: 10px;
}

.matchup-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--stroke);
  font-size: 0.88rem;
}

.matchup-row:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.matchup-pred {
  font-weight: 600;
  color: var(--accent-2);
}

.team-card h3 {
  margin: 0 0 6px;
  font-family: var(--font-display);
}

.team-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-bottom: 4px;
}

.team-title {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.team-title::before {
  content: "";
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
  background: #d1c5b5;
}

.team-title.orange::before {
  background: #d0773c;
}

.team-title.blue::before {
  background: #3c6fd0;
}

.team-title.yellow::before {
  background: #d7b33c;
}

.team-title.pink::before {
  background: #d0668e;
}

.team-meta {
  display: grid;
  gap: 6px;
  margin-bottom: 12px;
  font-size: 0.9rem;
  color: var(--muted);
}

.team-visuals {
  display: grid;
  grid-template-columns: minmax(190px, 240px) minmax(260px, 1fr);
  gap: 16px;
  margin-bottom: 16px;
  align-items: start;
}

.pitch {
  border: 1px solid var(--stroke);
  border-radius: var(--radius);
  overflow: hidden;
  background: #efe6d7;
  display: grid;
  grid-template-rows: repeat(3, 1fr);
  min-height: 240px;
  position: relative;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.55);
}

.pitch-third {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-weight: 600;
  color: rgba(28, 36, 31, 0.75);
  border-bottom: 1px solid rgba(255, 255, 255, 0.45);
  background: rgba(var(--heat-color), calc(0.12 + var(--heat, 0) * 0.72));
}

.pitch-third:last-child {
  border-bottom: none;
}

.pitch-def {
  --heat-color: 47, 109, 85;
}

.pitch-mid {
  --heat-color: 143, 123, 84;
}

.pitch-att {
  --heat-color: 208, 119, 60;
}

.third-lists {
  display: grid;
  gap: 10px;
}

.third-block {
  border: 1px solid var(--stroke);
  border-radius: var(--radius-sm);
  padding: 10px;
  background: #f9f3ea;
}

.third-block h4 {
  margin: 0 0 8px;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--muted);
}

.third-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 6px;
  font-size: 0.78rem;
}

.third-list li {
  display: grid;
  gap: 4px;
}

.third-line {
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.spark {
  height: 4px;
  border-radius: 999px;
  background: rgba(28, 36, 31, 0.12);
  position: relative;
  overflow: hidden;
}

.spark::after {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: var(--spark, 0%);
  background: rgba(208, 119, 60, 0.65);
}

.spark.def::after {
  background: rgba(47, 109, 85, 0.7);
}

.spark.mid::after {
  background: rgba(143, 123, 84, 0.7);
}

.spark.att::after {
  background: rgba(208, 119, 60, 0.7);
}

.third-block.def h4 {
  color: rgba(47, 109, 85, 0.9);
}

.third-block.mid h4 {
  color: rgba(143, 123, 84, 0.95);
}

.third-block.att h4 {
  color: rgba(208, 119, 60, 0.95);
}

.third-list .empty {
  color: var(--muted);
}

.team-table {
  width: 100%;
  border-collapse: collapse;
}

.team-table.compact {
  table-layout: fixed;
}

.team-table.compact td {
  width: 50%;
  padding: 6px 6px 10px;
  vertical-align: top;
  border-bottom: 1px dashed var(--stroke);
}

.player-cell {
  display: grid;
  gap: 4px;
}

.player-name {
  font-weight: 600;
  font-size: 0.9rem;
}

.player-meta {
  font-size: 0.75rem;
  color: var(--muted);
}

.warning {
  color: #8f2b2b;
  font-weight: 600;
}

.admin-request {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--stroke);
  background: #fbf7f0;
}

.admin-request + .admin-request {
  margin-top: 10px;
}

.admin-request-meta {
  display: grid;
  gap: 2px;
  font-size: 0.78rem;
  color: var(--muted);
}

.admin-request-meta strong {
  color: var(--ink);
  font-size: 0.9rem;
}

.admin-request-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.btn.small {
  padding: 6px 12px;
  font-size: 0.72rem;
}

@media (max-width: 900px) {
  .teams-layout {
    grid-template-columns: 1fr;
  }

  .week-grid {
    grid-template-columns: 1fr;
  }

  .roster-panel .table-wrap {
    max-height: none;
  }
}

@media (max-width: 720px) {
  .app-header {
    grid-template-columns: 1fr;
  }

  .header-right {
    justify-items: start;
  }

  .header-stats {
    justify-content: flex-start;
  }

  .panel-head {
    flex-direction: column;
    align-items: flex-start;
  }

  .data-table {
    min-width: 640px;
  }

  .team-visuals {
    grid-template-columns: 1fr;
  }

  .auth-actions {
    grid-template-columns: 1fr;
  }

  .constraint-row {
    grid-template-columns: 1fr;
  }

  .team-table.compact td {
    width: 100%;
    display: block;
  }
}
