:root {
  color-scheme: light;
  --bg: #f5f7f4;
  --surface: #ffffff;
  --surface-strong: #edf3ee;
  --text: #1d2520;
  --muted: #617066;
  --line: #dbe4dc;
  --accent: #167a55;
  --accent-dark: #0f5e42;
  --warn: #b83b35;
  --shadow: 0 14px 34px rgba(29, 37, 32, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 44px;
}

.topbar,
.section-heading,
.actions,
.account {
  display: flex;
  align-items: center;
}

.topbar {
  justify-content: space-between;
  gap: 20px;
  padding: 18px 0 24px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 34px;
  line-height: 1.15;
}

h2 {
  font-size: 22px;
  line-height: 1.25;
}

.eyebrow {
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.account {
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.layout {
  display: grid;
  grid-template-columns: minmax(260px, 0.7fr) minmax(0, 1.1fr) minmax(320px, 0.9fr);
  gap: 18px;
  align-items: start;
}

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

.record-panel {
  grid-row: span 2;
}

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

.section-heading {
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.match-form {
  display: grid;
  gap: 16px;
}

.room-form {
  display: grid;
  gap: 10px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  padding: 11px 12px;
}

textarea {
  resize: vertical;
}

.players-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.player-card {
  min-inline-size: 0;
  min-width: 0;
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  display: grid;
  gap: 12px;
  background: var(--surface-strong);
}

.player-card legend {
  padding: 0 6px;
  font-weight: 800;
}

.player-card > * {
  min-width: 0;
}

.primary-button,
.secondary-button,
.ghost-button,
.danger-button,
.status-pill {
  min-height: 40px;
  border-radius: 8px;
  border: 1px solid transparent;
  padding: 0 14px;
  font-weight: 800;
  white-space: nowrap;
}

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

.primary-button:hover {
  background: var(--accent-dark);
}

.secondary-button,
.ghost-button {
  background: #fff;
  color: var(--text);
  border-color: var(--line);
}

.autofill-winner-button {
  width: 100%;
  min-width: 0;
  min-height: 48px;
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: keep-all;
  line-height: 1.35;
  padding: 8px 10px;
}

.danger-button {
  background: #fff4f2;
  color: var(--warn);
  border-color: #f0c8c4;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  background: #e8f5ef;
  color: var(--accent-dark);
  border-color: #c9e5d8;
}

.stats-grid,
.history-list,
.room-list {
  display: grid;
  gap: 10px;
}

.stats-grid {
  margin-bottom: 16px;
}

.chart-box {
  display: grid;
  gap: 10px;
  margin-bottom: 16px;
}

#trendChart {
  width: 100%;
  height: 240px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.rating-trend-box {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

#ratingTrendChart {
  width: 100%;
  height: 220px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  color: var(--muted);
  font-size: 12px;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.legend-swatch {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  flex: 0 0 auto;
}

.settlement-actions,
.rating-box {
  margin-bottom: 16px;
}

.toggle-row {
  display: flex;
  grid-template-columns: none;
  align-items: center;
  gap: 8px;
  color: var(--text);
  font-size: 14px;
}

.toggle-row input {
  width: auto;
}

.beta-note {
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
}

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

.rating-card {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: #fff;
}

.rating-card span {
  color: var(--muted);
  font-size: 12px;
}

.stat-card,
.history-card,
.room-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #fff;
}

.room-card {
  display: grid;
  gap: 10px;
}

.room-card.active {
  border-color: var(--accent);
  background: #f1fbf6;
}

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

.invite-link {
  overflow-wrap: anywhere;
  color: var(--muted);
  font-size: 12px;
}

.active-room {
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 12px;
  background: var(--surface-strong);
}

.stat-card {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px 12px;
}

.stat-card strong {
  font-size: 16px;
}

.stat-card span,
.history-meta {
  color: var(--muted);
  font-size: 13px;
}

.history-card {
  display: grid;
  gap: 10px;
}

.history-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.result-list {
  display: grid;
  gap: 6px;
  padding: 0;
  margin: 0;
  list-style: none;
}

.result-list li {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
}

.empty-state {
  color: var(--muted);
  padding: 24px 0;
  text-align: center;
}

.hidden {
  display: none !important;
}

@media (max-width: 860px) {
  .app-shell {
    width: min(100% - 24px, 680px);
    padding-top: 18px;
  }

  .topbar,
  .layout,
  .players-grid {
    display: grid;
    grid-template-columns: 1fr;
  }

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

  .record-panel {
    grid-row: auto;
  }
}
