:root {
  color-scheme: light;
  --bg: #fbf6ee;
  --panel: #ffffff;
  --ink: #182025;
  --muted: #667077;
  --line: #eae1d4;
  --teal: #0f766e;
  --teal-dark: #115e59;
  --coral: #d05b4c;
  --coral-hover: rgba(208, 91, 76, 0.06);
  --green: #15803d;
  --red: #b91c1c;
  --shadow: 0 4px 12px rgba(24, 32, 37, 0.03);
  --radius-card: 12px;
  --radius-btn: 8px;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  min-height: 100vh;
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  letter-spacing: -0.01em;
}

/* App Shell Grid */
.app-shell {
  width: 100%;
  max-width: 100%;
  margin: 0;
  padding: 0;
}

/* Centering Paddings on Layouts */
.topbar {
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  padding: 20px max(16px, calc((100vw - 1140px) / 2));
}

.tabs {
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  padding: 0 max(16px, calc((100vw - 1140px) / 2));
}

main {
  padding: 24px max(16px, calc((100vw - 1140px) / 2)) 40px;
}

/* Header & Brand Identity */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 16px;
}

.brand-logo {
  width: 48px;
  height: 48px;
  flex-shrink: 0;
}

.brand-logo svg {
  width: 100%;
  height: 100%;
}

.brand-text {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.brand-text h1 {
  margin: 0;
  font-size: 24px;
  font-weight: 700;
  color: var(--ink);
  line-height: 1.15;
  letter-spacing: -0.02em;
}

.session-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
  font-weight: 500;
}

.meta-dot {
  color: var(--line);
  font-weight: 700;
}

/* Navigation Tabs */
.tabs {
  display: flex;
  gap: 24px;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}

.tabs::-webkit-scrollbar {
  display: none;
}

.tab {
  min-height: auto;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 15px;
  font-weight: 600;
  padding: 14px 4px;
  cursor: pointer;
  border-bottom: 3px solid transparent;
  border-radius: 0;
  white-space: nowrap;
  transition: all 0.2s ease;
}

.tab:hover:not(:disabled) {
  color: var(--teal);
  border-bottom-color: transparent;
}

.tab.active {
  color: var(--teal);
  border-bottom-color: var(--teal);
  box-shadow: none;
}

.tab:disabled,
button:disabled,
input:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

/* Views */
.view {
  display: none;
}

.view.active {
  display: block;
}

/* Section Headings */
.section-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 16px;
  margin-bottom: 20px;
}

.section-head h2 {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 0;
  color: var(--ink);
}

.eyebrow {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin: 0 0 4px 0;
}

.summary {
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 4px;
}

/* Buttons */
button {
  font: inherit;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: var(--radius-btn);
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
  padding: 8px 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 500;
  transition: all 0.2s ease;
}

button:hover:not(:disabled) {
  border-color: var(--teal);
  color: var(--teal);
}

.row-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: flex-end;
}

.primary {
  background: var(--teal);
  border: 1px solid var(--teal);
  color: #ffffff;
  font-weight: 600;
  font-size: 15px;
  border-radius: var(--radius-btn);
  padding: 10px 20px;
  cursor: pointer;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.primary:hover:not(:disabled) {
  background: var(--teal-dark);
  border-color: var(--teal-dark);
  color: #ffffff;
}

.danger {
  border: 1px solid var(--coral);
  color: var(--coral);
  background: transparent;
  border-radius: var(--radius-btn);
  font-weight: 600;
  font-size: 14px;
  padding: 8px 16px;
  cursor: pointer;
  min-height: auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.danger:hover:not(:disabled) {
  background: var(--coral-hover);
  border-color: var(--coral);
  color: var(--coral);
}

/* Card Elements */
.round-panel,
.match-card,
.history-card,
.team-card,
.table-wrap {
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  background: var(--panel);
  box-shadow: var(--shadow);
  padding: 20px;
}

/* Form Elements */
.tool-row,
.generator-grid {
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  background: var(--panel);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 24px;
}

.tool-row {
  display: flex;
  align-items: flex-end;
  gap: 16px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex-grow: 1;
}

.field span {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.field input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius-btn);
  background: #ffffff;
  color: var(--ink);
  padding: 10px 14px;
  font-size: 15px;
  min-height: 44px;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.field input:focus {
  outline: none;
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.1);
}

.tool-row button {
  min-height: 44px;
  flex-shrink: 0;
}

.generator-grid {
  display: grid;
  grid-template-columns: 1.2fr 1.2fr 2fr auto;
  gap: 16px;
  align-items: flex-end;
  margin-bottom: 16px;
}

.selection-actions {
  display: flex;
  gap: 10px;
  margin: 16px 0;
}

.selection-actions button {
  min-height: auto;
  font-size: 13px;
  font-weight: 600;
  padding: 8px 14px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  border-radius: var(--radius-btn);
  cursor: pointer;
  transition: all 0.2s;
}

.selection-actions button:hover:not(:disabled) {
  border-color: var(--teal);
  color: var(--teal);
}

/* Active Player Selection Grid */
.selection-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}

.select-chip {
  display: flex;
  align-items: center;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  background: var(--panel);
  padding: 12px 16px;
  cursor: pointer;
  user-select: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.select-chip:hover {
  border-color: var(--teal);
}

.select-chip input {
  width: 18px;
  height: 18px;
  margin: 0;
  accent-color: var(--teal);
  cursor: pointer;
  flex-shrink: 0;
}

.select-chip span {
  font-size: 15px;
  color: var(--ink);
  display: inline-flex;
  align-items: baseline;
  gap: 4px;
}

.select-chip span strong {
  font-weight: 600;
}

/* Tables Styles */
.table-wrap {
  overflow-x: auto;
  padding: 0; /* Clear inner padding for table bleed */
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
}

th,
td {
  padding: 14px 20px;
  vertical-align: middle;
}

th {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  border-bottom: 1.5px solid var(--line);
}

td {
  font-size: 15px;
  color: var(--ink);
  border-bottom: 1px solid var(--line);
}

tr:last-child td {
  border-bottom: none;
}

.player-name {
  font-weight: 600;
  color: var(--ink);
}

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

.empty {
  border: 1.5px dashed var(--line);
  border-radius: var(--radius-card);
  background: rgba(255, 255, 255, 0.4);
  color: var(--muted);
  padding: 32px;
  text-align: center;
  font-weight: 500;
  font-size: 15px;
}

/* Score Progress Bar */
.score-line {
  display: flex;
  align-items: center;
  gap: 12px;
}

.score-number {
  font-size: 16px;
  font-weight: 700;
  color: var(--ink);
  min-width: 28px;
}

.score-track {
  position: relative;
  flex-grow: 1;
  max-width: 120px;
  height: 8px;
  border-radius: 99px;
  background: #ede9dd;
  overflow: hidden;
}

.score-fill {
  display: block;
  height: 100%;
  border-radius: 99px;
  background: var(--teal);
}

/* Status Pill */
.status-pill {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 600;
  border-radius: 99px;
  background: #ede9dd;
  color: var(--muted);
  white-space: nowrap;
}

.status-pill.active {
  background: rgba(15, 118, 110, 0.1);
  color: var(--teal);
}

.status-pill.voided {
  background: rgba(208, 91, 76, 0.1);
  color: var(--coral);
}

/* Generator & Round Layouts */
.round-layout {
  display: grid;
  grid-template-columns: 1fr 1.2fr;
  gap: 20px;
  align-items: start;
}

.round-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
}

.team-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

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

.team-title strong {
  font-size: 16px;
  font-weight: 700;
  color: var(--ink);
}

.team-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: 14px;
  color: var(--muted);
}

.team-list li {
  font-weight: 500;
}

/* Match Grid */
.match-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}

.match-card {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

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

.match-title strong {
  font-size: 16px;
  font-weight: 700;
  color: var(--ink);
}

.match-teams {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 16px;
  align-items: center;
  text-align: center;
}

.versus {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.team-side {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.team-side .name {
  font-weight: 700;
  color: var(--ink);
  font-size: 15px;
}

.team-side .players {
  font-size: 13px;
  color: var(--muted);
}

.winner-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

/* History Cards */
.history-list {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.history-card {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}

.history-card > div {
  min-width: 0;
}

.history-meta {
  font-size: 13px;
  color: var(--muted);
  line-height: 1.45;
}

/* Toast Messages */
.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 999;
  max-width: 360px;
  background: var(--ink);
  color: #ffffff;
  padding: 12px 18px;
  font-size: 14px;
  font-weight: 600;
  border-radius: var(--radius-btn);
  box-shadow: 0 4px 16px rgba(24, 32, 37, 0.15);
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

/* Responsive Overrides */
@media (max-width: 768px) {
  .topbar {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
    padding: 16px;
  }
  
  .brand-logo {
    width: 40px;
    height: 40px;
  }
  
  .brand-text h1 {
    font-size: 20px;
  }
  
  .session-meta {
    font-size: 12px;
    flex-wrap: wrap;
  }
  
  .tabs {
    padding: 0 16px;
    gap: 16px;
  }
  
  .tab {
    font-size: 14px;
    padding: 12px 2px;
  }
  
  main {
    padding: 16px 16px 30px;
  }
  
  .tool-row {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }
  
  .generator-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }
  
  .generator-grid button {
    width: 100%;
  }
  
  .round-layout {
    grid-template-columns: 1fr;
    gap: 16px;
  }
  
  .match-teams {
    grid-template-columns: 1fr;
    gap: 8px;
  }
  
  .versus {
    padding: 4px 0;
  }
  
  .winner-actions {
    grid-template-columns: 1fr;
    gap: 8px;
  }
  
  .history-card {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }
  
  .danger {
    width: 100%;
    text-align: center;
  }
}
