:root {
  --paper: #f4efe3;
  --paper-deep: #e8dfce;
  --ink: #171914;
  --muted: #6d6f65;
  --line: #cfc5b2;
  --green: #175d44;
  --green-bright: #1f7958;
  --orange: #e85d35;
  --yellow: #f2c94c;
  --shadow: 0 18px 50px rgba(54, 42, 25, 0.09);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--paper);
  font-synthesis: none;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-width: 320px;
  background:
    linear-gradient(rgba(76, 67, 48, 0.045) 1px, transparent 1px),
    linear-gradient(90deg, rgba(76, 67, 48, 0.045) 1px, transparent 1px),
    var(--paper);
  background-size: 28px 28px;
}
button, input { font: inherit; }
button { color: inherit; }

header,
main,
footer {
  width: min(1080px, calc(100% - 36px));
  margin-inline: auto;
}

header {
  min-height: 76px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  border-bottom: 1px solid var(--line);
}
.back-link { width: fit-content; color: var(--green); font-size: 0.82rem; font-weight: 900; letter-spacing: 0.08em; text-decoration: none; }
.product-name { font-family: Georgia, serif; font-size: 1.35rem; font-weight: 700; letter-spacing: -0.045em; }
.product-name span { color: var(--orange); }
.quiet-button {
  justify-self: end;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 13px;
  background: rgba(255, 255, 255, 0.28);
  font-size: 0.8rem;
  font-weight: 800;
  cursor: pointer;
}

.intro { padding: 72px 0 54px; text-align: center; }
.kicker { margin: 0 0 12px; color: var(--green); font-size: 0.74rem; font-weight: 900; letter-spacing: 0.15em; text-transform: uppercase; }
h1, h2 { margin: 0; font-family: Georgia, "Times New Roman", serif; font-weight: 600; letter-spacing: -0.045em; line-height: 1.02; }
h1 { font-size: clamp(3.2rem, 8vw, 6.4rem); }
h1 em { color: var(--green); font-weight: 500; }
.intro > p:last-child { max-width: 600px; margin: 24px auto 0; color: var(--muted); font-size: 1.08rem; line-height: 1.65; }

.game-shell {
  border: 1px solid var(--line);
  border-radius: 24px;
  padding: clamp(22px, 4vw, 42px);
  background: rgba(255, 255, 255, 0.58);
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
}
.game-toolbar {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 24px;
  align-items: end;
  padding-bottom: 28px;
  border-bottom: 1px solid var(--line);
}
.game-toolbar > div { display: grid; gap: 8px; }
.game-toolbar label, .field-label { color: var(--muted); font-size: 0.72rem; font-weight: 900; letter-spacing: 0.08em; text-transform: uppercase; }
#game-name {
  width: min(100%, 420px);
  border: 0;
  border-bottom: 2px solid var(--ink);
  outline: 0;
  padding: 8px 0;
  background: transparent;
  color: var(--ink);
  font-family: Georgia, serif;
  font-size: 1.65rem;
  font-weight: 700;
}
.segmented { display: flex; border: 1px solid var(--line); border-radius: 11px; padding: 3px; background: var(--paper); }
.segment { border: 0; border-radius: 8px; padding: 9px 12px; background: transparent; font-size: 0.78rem; font-weight: 850; cursor: pointer; }
.segment.active { background: var(--green); color: white; }

.scoreboard-heading { display: flex; align-items: end; justify-content: space-between; gap: 20px; padding: 38px 0 22px; }
.round-label { margin: 0 0 5px; color: var(--orange); font-size: 0.75rem; font-weight: 900; letter-spacing: 0.12em; text-transform: uppercase; }
.scoreboard-heading h2, .history-heading h2 { font-size: clamp(2rem, 4vw, 3rem); }
.add-player { border: 0; border-bottom: 1px solid var(--green); padding: 5px 0; background: transparent; color: var(--green); font-size: 0.82rem; font-weight: 900; cursor: pointer; }

.players { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 13px; }
.player-card { position: relative; border: 1px solid var(--line); border-radius: 17px; padding: 18px; background: var(--paper); }
.player-card.leader { border-color: var(--green); box-shadow: inset 0 0 0 1px var(--green); }
.player-card.leader::after { content: "LEADING"; position: absolute; top: -8px; right: 14px; border-radius: 999px; padding: 4px 8px; background: var(--yellow); font-size: 0.6rem; font-weight: 950; letter-spacing: 0.1em; }
.player-top { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.player-name { min-width: 0; border: 0; border-bottom: 1px solid transparent; outline: 0; background: transparent; font-weight: 900; }
.player-name:focus { border-color: var(--orange); }
.remove-player { width: 28px; height: 28px; border: 0; border-radius: 50%; background: transparent; color: var(--muted); font-size: 1.2rem; cursor: pointer; }
.remove-player:hover { background: var(--paper-deep); color: var(--orange); }
.total-row { display: flex; align-items: end; justify-content: space-between; margin: 24px 0 18px; }
.total-row span { color: var(--muted); font-size: 0.75rem; font-weight: 800; text-transform: uppercase; }
.player-total { font-family: Georgia, serif; font-size: 3.25rem; line-height: 0.8; }
.round-input-label { display: grid; grid-template-columns: 1fr 116px; align-items: center; gap: 12px; color: var(--muted); font-size: 0.76rem; font-weight: 850; text-transform: uppercase; }
.round-score { min-width: 0; width: 100%; border: 1px solid var(--line); border-radius: 10px; outline: 0; padding: 10px; background: rgba(255, 255, 255, 0.62); color: var(--ink); text-align: right; font-size: 1.05rem; font-weight: 850; }
.round-score:focus { border-color: var(--orange); box-shadow: 0 0 0 3px rgba(232, 93, 53, 0.1); }

.round-actions { display: flex; gap: 10px; margin-top: 20px; }
.save-round, .undo-round { min-height: 50px; border-radius: 12px; padding: 0 20px; font-weight: 900; cursor: pointer; }
.save-round { flex: 1; border: 0; background: var(--green); color: white; }
.save-round:hover { background: var(--green-bright); }
.undo-round { border: 1px solid var(--line); background: transparent; }
.undo-round:disabled { cursor: not-allowed; opacity: 0.35; }
.save-status { min-height: 1.2em; margin: 10px 0 0; color: var(--green); font-size: 0.82rem; text-align: center; }

.history-section { padding: 76px 0 92px; }
.history-heading { display: flex; align-items: end; justify-content: space-between; gap: 30px; margin-bottom: 24px; }
.history-heading > p { margin: 0; color: var(--muted); font-size: 0.85rem; }
.history-wrap { overflow-x: auto; border-top: 1px solid var(--line); }
.empty-history { margin: 0; padding: 30px 0; color: var(--muted); }
table { width: 100%; border-collapse: collapse; }
th, td { border-bottom: 1px solid var(--line); padding: 14px 12px; text-align: right; }
th:first-child, td:first-child { padding-left: 0; text-align: left; }
th { color: var(--muted); font-size: 0.7rem; letter-spacing: 0.08em; text-transform: uppercase; }
tfoot td { border-bottom: 0; font-weight: 950; }

footer { display: flex; justify-content: space-between; gap: 20px; border-top: 1px solid var(--line); padding: 30px 0 42px; color: var(--muted); font-size: 0.8rem; }
footer a { color: var(--green); font-weight: 850; }

@media (min-width: 760px) {
  .players.three-plus { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .players.five-plus { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .players.five-plus .round-input-label { grid-template-columns: 1fr; }
}

@media (max-width: 680px) {
  header, main, footer { width: min(100% - 24px, 1080px); }
  header { grid-template-columns: 1fr auto; }
  .product-name { display: none; }
  .intro { padding: 52px 0 38px; text-align: left; }
  h1 { font-size: clamp(3.1rem, 15vw, 4.8rem); }
  .game-toolbar { grid-template-columns: 1fr; }
  .segmented { width: fit-content; }
  .players { grid-template-columns: 1fr; }
  .round-actions { flex-direction: column; }
  .undo-round { min-height: 46px; }
  .history-heading { display: block; }
  .history-heading > p { margin-top: 10px; }
  footer { display: block; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0.01ms !important; }
}
