@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;600;700&family=Manrope:wght@600;700;800&display=swap');

:root {
  color-scheme: light;
  --ink: #17251f;
  --muted: #69736e;
  --paper: #f7f4ed;
  --surface: #fffdf8;
  --line: #deddd5;
  --green: #2f6651;
  --green-dark: #1f4939;
  --lime: #d8ef84;
  --coral: #ef765f;
  --yellow: #f2c14e;
  --shadow: 0 18px 50px rgba(29, 45, 37, .1);
  --radius: 22px;
  font-family: "DM Sans", system-ui, sans-serif;
  background: var(--paper);
  color: var(--ink);
}

* { box-sizing: border-box; }
html { min-height: 100%; overflow-x: hidden; }
body { margin: 0; min-width: 320px; min-height: 100%; min-height: 100dvh; overflow-x: hidden; background: var(--paper); }
button, input { font: inherit; }
button { color: inherit; }
.app-shell { width: min(100%, 720px); min-height: 100dvh; margin: 0 auto; background: var(--paper); position: relative; }
.topbar { height: 72px; padding: max(14px, env(safe-area-inset-top)) 20px 10px; display: flex; align-items: center; justify-content: space-between; }
.brand { border: 0; background: none; display: flex; align-items: center; gap: 10px; font: 800 21px/1 Manrope, sans-serif; cursor: pointer; }
.brand-mark { display: flex; align-items: end; gap: 2px; height: 22px; }
.brand-mark i { display: block; width: 7px; border-radius: 4px 4px 2px 2px; transform: rotate(-4deg); }
.brand-mark i:nth-child(1) { height: 15px; background: var(--coral); }
.brand-mark i:nth-child(2) { height: 22px; background: var(--lime); }
.brand-mark i:nth-child(3) { height: 18px; background: var(--yellow); }
.icon-button { border: 1px solid var(--line); background: var(--surface); border-radius: 50%; width: 42px; height: 42px; cursor: pointer; }
.header-actions { display: flex; align-items: center; gap: 8px; }
.account-button { min-height: 42px; border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 0 13px; display: inline-flex; align-items: center; gap: 7px; color: var(--green-dark); font-size: 13px; font-weight: 700; cursor: pointer; }
.account-button.synced { background: #edf5d7; border-color: #d4e5a6; }
.sync-code { margin: 16px 0; padding: 16px; border: 1px dashed var(--green); border-radius: 16px; background: #edf5d7; color: var(--green-dark); text-align: center; font: 800 18px/1.5 ui-monospace, SFMono-Regular, Consolas, monospace; letter-spacing: .04em; overflow-wrap: anywhere; user-select: all; }
.account-divider { display: flex; align-items: center; gap: 12px; margin: 20px 0; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .08em; }
.account-divider::before, .account-divider::after { content: ''; flex: 1; height: 1px; background: var(--line); }
.sync-note { display: flex; align-items: flex-start; gap: 9px; padding: 12px 14px; margin: 14px 0; border-radius: 14px; background: #eeeae2; color: var(--muted); font-size: 13px; line-height: 1.45; }
main { min-height: calc(100dvh - 150px); padding: 18px 20px calc(150px + env(safe-area-inset-bottom)); }
.bottom-nav { position: fixed; z-index: 5; left: 50%; bottom: 0; transform: translateX(-50%); width: min(100%, 720px); display: grid; grid-template-columns: repeat(3, 1fr); padding: 9px 18px max(10px, env(safe-area-inset-bottom)); border-top: 1px solid rgba(23,37,31,.08); background: rgba(247,244,237,.94); backdrop-filter: blur(16px); }
.bottom-nav button { border: 0; background: none; min-height: 54px; color: var(--muted); display: grid; place-items: center; gap: 1px; font-size: 12px; font-weight: 600; cursor: pointer; }
.bottom-nav button span { font-size: 22px; line-height: 1; }
.bottom-nav button.active { color: var(--green-dark); }
h1, h2, h3, p { margin-top: 0; }
h1 { font: 800 clamp(32px, 9vw, 48px)/1.05 Manrope, sans-serif; letter-spacing: -.045em; margin-bottom: 12px; }
h2 { font: 800 25px/1.15 Manrope, sans-serif; letter-spacing: -.025em; }
h3 { font: 700 16px/1.2 Manrope, sans-serif; }
.eyebrow { color: var(--green); font-size: 12px; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; margin-bottom: 10px; }
.subhead { color: var(--muted); font-size: 17px; line-height: 1.5; max-width: 470px; }
.hero { padding: 24px 0 28px; }
.hero-art { height: 176px; margin: 26px 0 22px; position: relative; display: grid; place-items: center; }
.score-card { position: absolute; width: 116px; height: 154px; border-radius: 18px; box-shadow: var(--shadow); display: grid; place-items: center; font: 800 53px Manrope; border: 5px solid rgba(255,255,255,.55); }
.score-card:nth-child(1) { background: var(--coral); transform: translateX(-76px) rotate(-10deg); }
.score-card:nth-child(2) { background: var(--lime); z-index: 2; transform: translateY(-8px) rotate(2deg); }
.score-card:nth-child(3) { background: var(--yellow); transform: translateX(78px) rotate(12deg); }
.button { width: 100%; min-height: 56px; border: 0; border-radius: 16px; padding: 14px 18px; font-weight: 700; cursor: pointer; transition: transform .15s, background .15s; }
.button:active { transform: scale(.985); }
.button.primary { background: var(--green-dark); color: white; box-shadow: 0 10px 24px rgba(31,73,57,.2); }
.button.secondary { background: var(--surface); border: 1px solid var(--line); }
.button.ghost { background: transparent; color: var(--green-dark); }
.button.danger { color: #9c3527; background: #fff0eb; }
.button:disabled { opacity: .42; cursor: not-allowed; }
.quick-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 12px; }
.quick-actions .button { min-height: 48px; }
.section-head { display: flex; justify-content: space-between; align-items: end; margin: 30px 0 14px; }
.section-head h2 { margin: 0; }
.text-button { border: 0; background: none; color: var(--green); font-weight: 700; cursor: pointer; }
.card { background: var(--surface); border: 1px solid rgba(23,37,31,.08); border-radius: var(--radius); box-shadow: 0 5px 20px rgba(29,45,37,.04); }
.empty { text-align: center; padding: 28px 22px; color: var(--muted); }
.empty strong { display: block; color: var(--ink); margin-bottom: 5px; }
.game-row { padding: 16px; display: flex; align-items: center; gap: 13px; margin-bottom: 10px; cursor: pointer; }
.game-badge { width: 46px; height: 46px; border-radius: 14px; background: #e9f0d1; display: grid; place-items: center; font-weight: 800; color: var(--green-dark); }
.game-row-main { flex: 1; min-width: 0; }
.game-row h3 { margin: 0 0 3px; }
.meta { color: var(--muted); font-size: 13px; }
.winner { color: var(--green); font-weight: 700; font-size: 13px; }
.form-stack { display: grid; gap: 14px; margin: 26px 0; }
.field label { display: block; font-size: 13px; font-weight: 700; margin: 0 0 7px 4px; }
.input { width: 100%; min-height: 56px; border: 1.5px solid var(--line); background: var(--surface); border-radius: 16px; padding: 0 16px; font-size: 17px; color: var(--ink); outline: none; }
.input:focus { border-color: var(--green); box-shadow: 0 0 0 4px rgba(47,102,81,.1); }
.player-input { display: flex; gap: 8px; }
.remove-player { flex: 0 0 48px; border: 0; border-radius: 14px; background: #eeeae2; color: var(--muted); cursor: pointer; font-size: 20px; }
.helper { color: var(--muted); font-size: 13px; line-height: 1.45; }
.sticky-actions { position: fixed; z-index: 4; left: 50%; bottom: 0; transform: translateX(-50%); width: min(100%, 720px); padding: 20px 20px max(18px, env(safe-area-inset-bottom)); background: linear-gradient(transparent 0, var(--paper) 30%); pointer-events: none; }
.sticky-actions .button { pointer-events: auto; }
.game-view { padding-bottom: 156px; }
#setup-form, #round-form { padding-bottom: 118px; }
.scoreboard { overflow: hidden; }
.score-head, .score-line { display: grid; grid-template-columns: 1fr 70px 66px; align-items: center; gap: 8px; padding: 13px 16px; }
.score-head { background: var(--green-dark); color: white; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; }
.score-line + .score-line { border-top: 1px solid var(--line); }
.score-line.leader { background: #f1f6df; }
.rank { display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; background: #ecebe4; margin-right: 8px; font-size: 12px; font-weight: 800; }
.leader .rank { background: var(--lime); }
.total { font: 800 24px Manrope; text-align: right; }
.trend { text-align: right; color: var(--muted); font-size: 13px; }
.round-list { margin-top: 26px; }
.round-row { display: grid; grid-template-columns: 72px 1fr; gap: 12px; padding: 13px 0; border-bottom: 1px solid var(--line); }
.round-scores { display: flex; flex-wrap: wrap; gap: 6px 12px; font-size: 13px; }
.penalty { color: #b34231; font-weight: 700; }
.score-entry { display: grid; gap: 10px; }
.score-input-row { display: grid; grid-template-columns: 1fr 112px; gap: 12px; align-items: center; padding: 12px 14px; }
.score-input-row .input { text-align: center; font: 800 22px Manrope; padding: 0 8px; }
.ender-options { display: grid; grid-template-columns: repeat(2, 1fr); gap: 9px; }
.ender-option { min-height: 49px; border: 1.5px solid var(--line); background: var(--surface); border-radius: 14px; font-weight: 700; cursor: pointer; }
.ender-option.selected { border-color: var(--green); background: #eaf3d1; color: var(--green-dark); }
.review-banner { padding: 15px; border-radius: 16px; background: #fff1ec; color: #843729; margin: 16px 0; line-height: 1.45; }
.review-banner.safe { background: #edf5d7; color: var(--green-dark); }
.review-grid { overflow: hidden; margin: 18px 0; }
.review-line { display: grid; grid-template-columns: 1fr auto auto; gap: 13px; align-items: center; padding: 14px 16px; }
.review-line + .review-line { border-top: 1px solid var(--line); }
.raw-score { color: var(--muted); font-size: 13px; }
.final-score { font: 800 21px Manrope; }
.champion { text-align: center; padding: 25px 12px 15px; }
.trophy { width: 82px; height: 82px; border-radius: 28px; background: var(--yellow); display: grid; place-items: center; margin: 0 auto 18px; font-size: 38px; transform: rotate(-4deg); }
.champion h1 { font-size: 40px; }
.podium { margin: 22px 0; overflow: hidden; }
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.stat-card { padding: 17px; }
.stat-value { font: 800 29px Manrope; }
.stat-label { color: var(--muted); font-size: 12px; margin-top: 3px; }
.player-stat { padding: 17px; margin-bottom: 11px; }
.player-stat-head { display: flex; justify-content: space-between; gap: 12px; }
.pill { display: inline-flex; padding: 5px 9px; border-radius: 999px; background: #eaf3d1; color: var(--green-dark); font-size: 12px; font-weight: 700; }
.modal-backdrop { position: fixed; z-index: 20; inset: 0; background: rgba(11,22,17,.5); display: grid; align-items: end; }
.modal { width: min(100%, 720px); margin: 0 auto; background: var(--paper); border-radius: 28px 28px 0 0; padding: 24px 20px max(24px, env(safe-area-inset-bottom)); box-shadow: var(--shadow); }
.modal .button + .button { margin-top: 9px; }
.toast { position: fixed; z-index: 30; left: 50%; bottom: 92px; transform: translate(-50%, 20px); background: var(--ink); color: white; border-radius: 999px; padding: 10px 16px; opacity: 0; pointer-events: none; transition: .2s; font-size: 14px; white-space: nowrap; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

@media (min-width: 650px) {
  body { background: #e8e5dc; }
  .app-shell { box-shadow: 0 0 70px rgba(23,37,31,.13); }
  main { padding-inline: 34px; }
  .sticky-actions { padding-inline: 34px; }
}

@media (max-width: 390px) {
  .account-label { display: none; }
  .account-button { width: 42px; justify-content: center; padding: 0; }
}

@media (prefers-reduced-motion: no-preference) {
  main > * { animation: enter .28s ease-out both; }
  @keyframes enter { from { opacity: 0; transform: translateY(8px); } }
}
