:root {
  color-scheme: light;
  --bg: #f6f7fb;
  --card: #ffffff;
  --text: #1e2430;
  --muted: #657089;
  --line: #dde3ef;
  --primary: #d32f2f;
  --primary-dark: #a81f1f;
  --secondary: #edf1f8;
  --danger: #b42318;
  --success: #147d64;
  --shadow: 0 12px 28px rgba(18, 38, 63, 0.08);
  --radius: 20px;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: linear-gradient(180deg, #fff1f1 0%, var(--bg) 18%, var(--bg) 100%);
  color: var(--text);
}
button, input, select { font: inherit; }
button {
  border: none;
  border-radius: 14px;
  padding: 0.8rem 1rem;
  cursor: pointer;
  background: var(--primary);
  color: white;
  transition: transform 0.15s ease, background 0.2s ease, opacity 0.2s ease;
}
button:hover:not(:disabled) { background: var(--primary-dark); transform: translateY(-1px); }
button:disabled, input:disabled, select:disabled { opacity: 0.6; cursor: not-allowed; }
button.secondary, .file-label.secondary { background: var(--secondary); color: var(--text); }
button.secondary:hover:not(:disabled), button.ghost:hover, .file-label.secondary:hover { background: #dfe7f5; }
button.danger { background: var(--danger); }
button.ghost { background: transparent; color: var(--muted); padding: 0.4rem 0.7rem; }
.hidden { display: none; }
input, select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0.85rem 0.95rem;
  background: #fff;
}
input:focus, select:focus { outline: 2px solid rgba(211, 47, 47, 0.2); border-color: var(--primary); }

.app-shell { width: min(1280px, calc(100% - 2rem)); margin: 0 auto; padding: 1rem 0 2.5rem; }
.app-header {
  display: flex; gap: 1rem; justify-content: space-between; align-items: flex-start; padding: 1rem 0 1.5rem;
}
.eyebrow { margin: 0; color: var(--primary); font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; font-size: 0.78rem; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 0.4rem; font-size: clamp(2rem, 5vw, 3rem); }
h2 { margin-bottom: 0.35rem; }
.subtitle, .section-text, .hint { margin-bottom: 0; color: var(--muted); }
.hint + .hint { margin-top: 0.75rem; }
.layout {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 1rem;
  align-items: start;
}
.content-column { display: grid; gap: 1rem; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
.card {
  background: var(--card);
  border: 1px solid rgba(221, 227, 239, 0.8);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.1rem;
}
.sidebar-card { position: sticky; top: 1rem; }
.card-header { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin-bottom: 1rem; }
.stack-mobile { align-items: flex-start; }
.inline-form { display: grid; grid-template-columns: 1fr auto; gap: 0.75rem; margin-bottom: 1rem; }
.players-list { list-style: none; padding: 0; margin: 0; }
.player-item, .score-item {
  display: flex; justify-content: space-between; gap: 1rem; align-items: center; padding: 0.9rem 0; border-bottom: 1px solid var(--line);
}
.player-item:last-child, .score-item:last-child { border-bottom: none; }
.player-name, .score-name { font-weight: 700; }
.field, .loser-row { margin-bottom: 1rem; }
.field label, .field-label { display: block; margin-bottom: 0.45rem; font-size: 0.95rem; font-weight: 600; }
.loser-inputs, .night-list, .preview-grid, .score-grid, .history { display: grid; gap: 0.85rem; }
.loser-row { display: grid; grid-template-columns: 1fr 140px; gap: 0.75rem; align-items: center; margin-bottom: 0; }
.player-chip {
  display: inline-flex; align-items: center; min-height: 46px; padding: 0 0.9rem; border-radius: 14px; background: #f7f9fc; border: 1px solid var(--line); font-weight: 600;
}
.round-form { display: grid; gap: 0.75rem; }
.round-preview, .empty-box {
  padding: 0.95rem 1rem; border-radius: 16px; background: #f7f9fc; border: 1px solid var(--line); color: var(--muted);
}
.preview-row, .score-item {
  display: grid; grid-template-columns: 1fr auto; gap: 1rem; align-items: center;
}
.score-points { font-weight: 800; font-variant-numeric: tabular-nums; }
.plus { color: var(--success); }
.minus { color: var(--danger); }
.badge {
  display: inline-flex; align-items: center; justify-content: center; min-width: 86px; padding: 0.45rem 0.8rem; border-radius: 999px; background: #fff1f1; color: var(--primary); font-weight: 700;
}
.empty { color: var(--muted); }
.history-card {
  border: 1px solid var(--line); border-radius: 18px; padding: 1rem; background: #fcfdff;
}
.history-head {
  display: flex; justify-content: space-between; gap: 1rem; align-items: flex-start; margin-bottom: 0.85rem;
}
.history-title { font-weight: 700; }
.history-subtitle { color: var(--muted); font-size: 0.95rem; }
.night-item {
  width: 100%;
  display: grid;
  text-align: left;
  gap: 0.25rem;
}
.night-item.active {
  outline: 2px solid rgba(211, 47, 47, 0.2);
}
.night-name { font-weight: 700; }
.night-meta { opacity: 0.9; font-size: 0.92rem; }
.button-row { display: flex; gap: 0.75rem; }
.wrap { flex-wrap: wrap; }
.file-label {
  display: inline-flex; align-items: center; gap: 0.5rem; border-radius: 14px; padding: 0.8rem 1rem; cursor: pointer;
}
.file-label input { display: none; }

@media (max-width: 980px) {
  .layout, .grid-2 { grid-template-columns: 1fr; }
  .sidebar-card { position: static; }
}

@media (max-width: 640px) {
  .app-shell { width: min(100%, calc(100% - 1rem)); }
  .app-header, .card-header, .history-head, .inline-form { grid-template-columns: 1fr; display: grid; }
  .loser-row { grid-template-columns: 1fr; }
}
