:root {
  color-scheme: light;
  --bg: #f5f7f4;
  --surface: #ffffff;
  --surface-muted: #eef3ed;
  --line: #d8dfd5;
  --text: #172018;
  --muted: #627063;
  --accent: #1d6b4f;
  --accent-strong: #144c38;
  --accent-soft: #dcece5;
  --danger: #9a2f2f;
  --danger-soft: #f3dfdf;
  --shadow: 0 16px 40px rgba(23, 32, 24, 0.08);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--text);
}

.hidden {
  display: none !important;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled,
input:disabled {
  cursor: not-allowed;
  opacity: 0.62;
}

.app-shell {
  min-height: 100vh;
}

.auth-screen {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
}

.auth-card {
  display: grid;
  gap: 18px;
  width: min(100%, 420px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 24px;
}

.auth-card img {
  width: 165px;
  height: auto;
}

.auth-form {
  display: grid;
  gap: 12px;
}

.auth-form label,
.invite-date,
.match-date,
.roster-field {
  display: grid;
  gap: 5px;
}

.auth-form span,
.invite-date span,
.match-date span,
.roster-field span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.auth-form input,
.invite-date input,
.match-date input,
.roster-field input {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 10px;
  background: #fbfcfb;
  color: var(--text);
}

.auth-form input:focus,
.invite-date input:focus,
.match-date input:focus,
.roster-field input:focus {
  border-color: var(--accent);
  outline: 3px solid rgba(29, 107, 79, 0.16);
}

.primary-button {
  min-height: 42px;
  border: 1px solid var(--accent);
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-weight: 800;
}

.auth-hint,
.auth-message p,
.auth-error {
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.45;
}

.auth-error {
  min-height: 1.3em;
  color: var(--danger);
  font-weight: 750;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 20px clamp(16px, 4vw, 40px);
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(16px);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  display: flex;
  align-items: center;
  gap: 16px;
  min-width: 0;
}

.brand img {
  width: clamp(112px, 18vw, 170px);
  height: auto;
  flex: 0 0 auto;
}

.kicker {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 750;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(1.55rem, 4vw, 2.35rem);
  line-height: 1.08;
}

h2 {
  margin-bottom: 0;
  font-size: 1.35rem;
}

h3 {
  margin-bottom: 0;
  font-size: 1rem;
}

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

.user-chip {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  background: var(--surface-muted);
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 750;
}

.icon-button,
.danger-button,
.clear-match,
.request-change,
.invite-match,
.match-options button,
.tab-button,
.group-button {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  min-height: 40px;
  padding: 0 14px;
  font-weight: 700;
}

.icon-button:hover,
.clear-match:hover,
.request-change:hover,
.invite-match:hover,
.tab-button:hover,
.group-button:hover {
  border-color: var(--accent);
  color: var(--accent-strong);
}

.danger-button {
  color: var(--danger);
  border-color: #e3b8b8;
  background: var(--danger-soft);
}

.file-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.file-button input {
  inline-size: 1px;
  block-size: 1px;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  overflow: hidden;
  position: absolute;
  white-space: nowrap;
}

.layout {
  display: grid;
  grid-template-columns: minmax(220px, 300px) minmax(0, 1fr);
  gap: 24px;
  padding: 24px clamp(16px, 4vw, 40px) 40px;
}

.sidebar {
  align-self: start;
  position: sticky;
  top: 96px;
}

.sidebar-head,
.group-header,
.match-title,
.match-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.sidebar-head {
  margin-bottom: 12px;
}

.sidebar output,
.group-progress span,
.match-state {
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 700;
  white-space: nowrap;
}

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

.group-button {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 12px;
  text-align: left;
}

.group-button.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.group-button small {
  color: var(--muted);
  font-weight: 750;
}

.content {
  min-width: 0;
}

.group-header {
  margin-bottom: 18px;
}

.group-progress {
  min-width: 180px;
}

.progress-track {
  overflow: hidden;
  height: 8px;
  margin-top: 8px;
  border-radius: 999px;
  background: var(--line);
}

.progress-track div {
  height: 100%;
  width: 0%;
  border-radius: inherit;
  background: var(--accent);
  transition: width 180ms ease;
}

.tabs {
  display: inline-grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 4px;
  padding: 4px;
  margin-bottom: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-muted);
}

.tab-button {
  min-height: 36px;
  border-color: transparent;
  background: transparent;
}

.tab-button.active {
  background: var(--surface);
  border-color: var(--line);
  box-shadow: 0 3px 10px rgba(23, 32, 24, 0.06);
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.match-list {
  display: grid;
  gap: 14px;
}

.readonly-note {
  margin-bottom: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-muted);
  padding: 12px 14px;
  color: var(--muted);
  font-weight: 750;
}

.match-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 16px;
}

.match-label {
  margin-bottom: 3px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 750;
}

.score-grid {
  display: grid;
  grid-template-columns: minmax(120px, 1fr) repeat(3, minmax(58px, 76px));
  gap: 8px;
  align-items: center;
  margin-top: 16px;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 750;
}

.player-name {
  overflow-wrap: anywhere;
  color: var(--text);
}

.score-grid input {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
  color: var(--text);
  text-align: center;
  font-weight: 800;
}

.score-grid input:focus {
  border-color: var(--accent);
  outline: 3px solid rgba(29, 107, 79, 0.16);
}

.score-grid input:disabled {
  color: var(--muted);
  background: var(--surface-muted);
}

.match-options {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
}

.match-options span {
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 750;
}

.match-options button {
  position: relative;
  overflow: hidden;
  min-height: 34px;
  padding: 0 12px;
}

.match-options button.wo-loser {
  border-color: #d69b9b;
  background: #f7e4e4;
  color: #7d2626;
}

.match-options button.wo-winner {
  border-color: #9fc8b7;
  background: #e2f1e9;
  color: var(--accent-strong);
}

.wo-label {
  position: relative;
  z-index: 1;
}

.wo-stamp {
  display: none;
}

.wo-loser .wo-stamp {
  display: block;
  position: absolute;
  inset: 50% auto auto 50%;
  z-index: 2;
  transform: translate(-50%, -50%) rotate(-10deg);
  color: rgba(154, 47, 47, 0.34);
  font-size: 1.55rem;
  font-weight: 900;
  letter-spacing: 0;
  pointer-events: none;
}

.match-date {
  display: inline-grid;
  margin-top: 12px;
}

.invite-row {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 10px;
  margin-top: 12px;
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.invite-date {
  min-width: min(100%, 240px);
}

.invite-match {
  min-height: 40px;
  padding: 0 12px;
  color: var(--accent-strong);
  background: var(--accent-soft);
  border-color: var(--accent);
}

.message-actions,
.calendar-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.accept-invite,
.message-jump,
.message-resolve {
  min-height: 34px;
  border: 1px solid var(--accent);
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  padding: 0 12px;
  font-weight: 800;
}

.message-jump {
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.message-resolve {
  border-color: var(--line);
  background: var(--surface);
  color: var(--text);
}

.unread-dot {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  border-radius: 999px;
  padding: 0 10px;
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 0.78rem;
  font-weight: 900;
}

.match-card.target-match {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(29, 107, 79, 0.18), var(--shadow);
}

.match-footer {
  flex-wrap: wrap;
  margin-top: 12px;
}

.result-hint {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 0.88rem;
}

.result-hint.complete {
  color: var(--accent-strong);
  font-weight: 750;
}

.result-hint.invalid {
  color: var(--danger);
  font-weight: 750;
}

.clear-match {
  min-height: 34px;
  padding: 0 12px;
}

.request-change {
  min-height: 34px;
  padding: 0 12px;
  color: var(--accent-strong);
  background: var(--accent-soft);
  border-color: var(--accent);
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

table {
  width: 100%;
  min-width: 720px;
  border-collapse: collapse;
}

th,
td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
}

th {
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
}

tbody tr:last-child td {
  border-bottom: 0;
}

.qualified-row {
  background: rgba(29, 107, 79, 0.07);
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  border-radius: 999px;
  padding: 0 10px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: 0.78rem;
  font-weight: 800;
}

.contact-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 12px;
}

.message-list {
  display: grid;
  gap: 12px;
}

.message-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 10px;
  margin-bottom: 2px;
}

.message-folders {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-muted);
  padding: 4px;
}

.message-folders button {
  min-height: 34px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  padding: 0 12px;
  font-weight: 800;
}

.message-folders button.active {
  border-color: var(--line);
  background: var(--surface);
  color: var(--accent-strong);
}

.message-toolbar label {
  display: grid;
  gap: 5px;
  min-width: min(100%, 180px);
}

.message-toolbar span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.message-toolbar select {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
  color: var(--text);
  padding: 0 10px;
}

.calendar-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 14px;
}

.calendar-tools label {
  display: grid;
  gap: 5px;
  min-width: min(100%, 220px);
}

.calendar-tools span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.calendar-tools select {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
  color: var(--text);
  padding: 0 10px;
}

.calendar-list {
  display: grid;
  gap: 10px;
}

.calendar-day {
  display: grid;
  gap: 8px;
}

.calendar-day h3 {
  margin-bottom: 0;
  color: var(--accent-strong);
}

.calendar-event {
  display: grid;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 12px 14px;
}

.calendar-event header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px;
}

.calendar-event strong {
  overflow-wrap: anywhere;
}

.calendar-event p {
  margin-bottom: 0;
  color: var(--muted);
}

.message-card {
  display: grid;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 14px;
}

.message-card.unread {
  border-color: var(--accent);
  background: #fbfffd;
}

.message-card header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

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

.message-card h3 {
  margin-bottom: 0;
}

.message-card p {
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.45;
}

.message-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 750;
}

.roster-editor {
  display: grid;
  gap: 12px;
  margin-bottom: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 16px;
}

.roster-head h3 {
  margin-bottom: 4px;
}

.roster-head p {
  margin-bottom: 0;
  color: var(--muted);
}

.roster-grid {
  display: grid;
  grid-template-columns: minmax(160px, 1fr) minmax(140px, 0.7fr);
  gap: 10px;
}

.contact-item {
  display: grid;
  gap: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 14px;
}

.contact-empty {
  color: var(--muted);
  background: var(--surface-muted);
}

.contact-item strong {
  overflow-wrap: anywhere;
}

.contact-item a {
  color: var(--accent-strong);
  font-weight: 750;
  text-decoration: none;
}

.rules-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 12px;
}

.rule-card {
  display: grid;
  gap: 7px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 16px;
}

.rule-card span {
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.rule-card strong {
  font-size: 1.02rem;
}

.rule-card p {
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.45;
}

.empty-state {
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.55);
  padding: 18px;
  color: var(--muted);
}

@media (max-width: 840px) {
  .topbar,
  .group-header {
    align-items: stretch;
    flex-direction: column;
  }

  .actions {
    justify-content: flex-start;
  }

  .brand {
    align-items: flex-start;
  }

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

  .sidebar {
    position: static;
  }

  .group-list {
    grid-template-columns: repeat(auto-fit, minmax(128px, 1fr));
  }
}

@media (max-width: 560px) {
  .brand {
    flex-direction: column;
    gap: 10px;
  }

  .brand img {
    width: 132px;
  }

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

  .score-grid {
    grid-template-columns: minmax(88px, 1fr) repeat(3, minmax(44px, 1fr));
    gap: 6px;
  }

  .match-card {
    padding: 12px;
  }

  .icon-button,
  .danger-button {
    flex: 1 1 128px;
  }
}

@media print {
  .topbar,
  .sidebar,
  .tabs,
  .actions,
  .match-options,
  .match-date,
  .invite-row,
  .clear-match {
    display: none !important;
  }

  body {
    background: white;
  }

  .layout {
    display: block;
    padding: 0;
  }

  .view {
    display: block;
    margin-bottom: 24px;
  }

  .match-card,
  .table-wrap,
  .contact-item {
    box-shadow: none;
  }
}
