:root {
  --court: #0E3B2C; --court-2: #15513D; --ball: #D8F244; --ball-dark: #A7C21A;
  --bg: #F3F5EC; --card: #FFFFFF; --ink: #10231B; --muted: #5A6B62; --line: #DCE3D6; --soft: #E3E9DD;
  --loss: #3A4A42; --warn-bg: #F4FBCB; --warn: #6B5A00; --ok-bg: #E3EFE7; --bad: #8A3A1C; --bad-bg: #F6E4DC;
  --display: 'Oswald', 'Arial Narrow', sans-serif; --text: 'Manrope', system-ui, sans-serif;
  --nav-h: 76px; --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--text); -webkit-tap-highlight-color: transparent; -webkit-text-size-adjust: 100%; }
/* App feel: no double-tap zoom delay, no bounce of the whole page */
html { touch-action: manipulation; overscroll-behavior-y: none; }
body { min-height: 100vh; overscroll-behavior-y: none; }
a, button, .chip, .btn, label { touch-action: manipulation; }
button, .btn, .chip, nav.tabs a, .iconbtn, .seg button { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
/* Pressed state: the button reacts at once under the finger */
.btn, .chip, .iconbtn, .seg button, nav.tabs a, a.card, .starpick button { transition: transform .08s ease, opacity .08s ease; }
.btn:active, .chip:active, .iconbtn:active, .seg button:active, .starpick button:active { transform: scale(.96); opacity: .85; }
a.card:active { transform: scale(.985); }
nav.tabs a:active { transform: scale(.9); }
nav.tabs a.plus:active { transform: scale(.92); }
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--court); }
#app { max-width: 520px; margin: 0 auto; min-height: 100vh; position: relative; padding-bottom: calc(var(--nav-h) + var(--safe-b) + 16px); background: var(--bg); }
/* Loading line at the top (appears only if a screen takes longer than a moment) */
body::before { content: ''; position: fixed; top: 0; left: 0; height: 3px; width: 35%; z-index: 90; background: var(--ball); border-radius: 0 2px 2px 0; opacity: 0; pointer-events: none; }
body.loading::before { opacity: 1; animation: progress 1s ease-in-out infinite; }
@keyframes progress { from { transform: translateX(-100%); } to { transform: translateX(300%); } }
/* Portrait only: on a phone turned sideways show a "turn back" screen */
.rotate { display: none; }
html.landscape .rotate { display: flex; position: fixed; inset: 0; z-index: 200; background: var(--court); color: #fff; flex-direction: column; align-items: center; justify-content: center; gap: 14px; text-align: center; padding: 24px; font-weight: 700; }
html.landscape .rotate svg { width: 56px; height: 56px; color: var(--ball); }
html.landscape body { overflow: hidden; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* Header */
.hero { position: relative; background: var(--court); color: #fff; padding: calc(18px + env(safe-area-inset-top, 0px)) 18px 22px; overflow: hidden; }
.hero::before { content: ''; position: absolute; inset: 14px; border: 2px solid rgba(255,255,255,.08); border-bottom: 0; pointer-events: none; }
.hero::after { content: ''; position: absolute; left: 50%; top: 14px; bottom: 0; border-left: 2px solid rgba(255,255,255,.06); pointer-events: none; }
.hero > * { position: relative; z-index: 1; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.brand { display: flex; align-items: center; gap: 10px; font-family: var(--display); font-weight: 600; font-size: 21px; letter-spacing: .05em; text-transform: uppercase; color: #fff; text-decoration: none; }
.iconbtn { width: 44px; height: 44px; border-radius: 22px; border: 1px solid rgba(255,255,255,.25); background: transparent; color: inherit; display: inline-flex; align-items: center; justify-content: center; cursor: pointer; position: relative; flex-shrink: 0; text-decoration: none; }
.iconbtn.light { border-color: var(--line); background: var(--card); color: var(--ink); }
.dot { position: absolute; top: 8px; right: 9px; width: 9px; height: 9px; border-radius: 5px; background: var(--ball); }
.sub { color: #C9D8CF; font-size: 14px; }
.big { font-family: var(--display); font-weight: 700; font-size: 60px; line-height: .9; color: var(--ball); }
.pagehead { display: flex; align-items: center; gap: 12px; padding: calc(18px + env(safe-area-inset-top, 0px)) 16px 8px; }
h1.title { margin: 0; font-family: var(--display); font-weight: 600; font-size: 26px; text-transform: uppercase; letter-spacing: .03em; }
h2.h { margin: 0 0 10px; font-family: var(--display); font-weight: 600; font-size: 17px; text-transform: uppercase; letter-spacing: .04em; }

/* Layout */
.wrap { padding: 14px 16px; display: flex; flex-direction: column; gap: 12px; }
.card { background: var(--card); border-radius: 18px; padding: 14px 16px; }
.card.hl { border: 2px solid var(--ball); box-shadow: 0 2px 0 #C3DB2E; }
.card.dark { background: var(--court); color: #fff; }
.row { display: flex; align-items: center; gap: 12px; }
.row.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.muted { color: var(--muted); font-size: 13px; }
.small { font-size: 12px; }
.strong { font-weight: 700; }
.num { font-family: var(--display); font-weight: 700; }
.list > * + * { border-top: 1px solid #E8EDE3; }
.list > * { padding: 11px 0; }
.ellipsis { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.center { text-align: center; }
.mt { margin-top: 12px; }
.stat { background: rgba(255,255,255,.08); border-radius: 14px; padding: 10px 12px; }
.stat .num { font-size: 24px; line-height: 1.1; }

/* Controls */
.btn { height: 48px; padding: 0 18px; border-radius: 14px; border: none; background: var(--court); color: #fff; font-weight: 700; font-size: 15px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; cursor: pointer; text-decoration: none; }
.btn.ball { background: var(--ball); color: var(--ink); }
.btn.ghost { background: var(--card); color: var(--ink); border: 1.5px solid var(--line); }
.btn.danger { background: var(--bad-bg); color: var(--bad); }
.btn.block { width: 100%; }
.btn.sm { height: 40px; padding: 0 14px; font-size: 14px; border-radius: 12px; }
.btn:disabled { opacity: .5; cursor: default; }
.seg { background: var(--soft); border-radius: 14px; padding: 4px; display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px; }
.seg button { height: 42px; border-radius: 11px; border: none; background: transparent; color: #4C5C54; font-weight: 800; font-size: 14px; cursor: pointer; }
.seg button.on { background: var(--card); color: var(--ink); box-shadow: 0 1px 3px rgba(16,35,27,.15); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips.scroll { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin: 0 -16px; padding: 0 16px; }
.chips.scroll::-webkit-scrollbar { display: none; }
.chip { height: 38px; padding: 0 14px; border-radius: 19px; border: 1.5px solid var(--line); background: var(--card); font-weight: 700; font-size: 13px; cursor: pointer; flex-shrink: 0; white-space: nowrap; }
.chip.on { background: var(--court); border-color: var(--court); color: var(--ball); }
.chip.ball { background: var(--ball); border-color: var(--ball); color: var(--ink); }
.tag { display: inline-block; font-size: 11px; font-weight: 800; letter-spacing: .05em; padding: 4px 8px; border-radius: 6px; text-transform: uppercase; }
.tag.warn { background: var(--warn-bg); color: var(--warn); }
.tag.ok { background: var(--ok-bg); color: var(--court); }
.tag.bad { background: var(--bad-bg); color: var(--bad); }
.tag.ball { background: var(--ball); color: var(--ink); }
.tag.soft { background: #EEF2E8; color: var(--loss); text-transform: none; letter-spacing: 0; }
label.f { display: block; font-size: 12px; font-weight: 800; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; margin: 14px 0 6px; }
.input, select.input, textarea.input { width: 100%; height: 48px; border-radius: 12px; border: 1.5px solid var(--line); background: var(--card); padding: 0 14px; font-size: 16px; }
textarea.input { height: auto; min-height: 84px; padding: 12px 14px; resize: vertical; }
.input:focus { outline: 2px solid var(--ball-dark); border-color: transparent; }
/* iPhone: date fields have their own minimum width and stick out of the screen */
input[type=date].input, input[type=datetime-local].input, input[type=time].input { -webkit-appearance: none; appearance: none; display: block; min-width: 0; max-width: 100%; line-height: 46px; text-align: left; }
input[type=date]::-webkit-date-and-time-value, input[type=datetime-local]::-webkit-date-and-time-value { text-align: left; }
.grid2 > *, .grid3 > * { min-width: 0; }
.kv { display: flex; justify-content: space-between; align-items: center; min-height: 50px; gap: 10px; }

/* Avatars & form */
.av { width: 48px; height: 48px; border-radius: 50%; background: var(--court-2); color: var(--ball); font-family: var(--display); font-weight: 600; font-size: 18px; display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; overflow: hidden; }
.av img { width: 100%; height: 100%; object-fit: cover; }
.av.sm { width: 32px; height: 32px; font-size: 12px; }
.av.lg { width: 84px; height: 84px; font-size: 30px; background: var(--ball); color: var(--court); border: 3px solid #fff; }
.form { display: inline-flex; gap: 4px; }
.form b { width: 22px; height: 22px; border-radius: 6px; font-size: 11px; font-weight: 800; display: inline-flex; align-items: center; justify-content: center; background: var(--ball); color: var(--ink); }
.form b.l { background: var(--loss); color: #fff; }
.form.big { display: flex; width: 100%; }
.form.big b { width: auto; flex: 1; height: 40px; border-radius: 10px; font-family: var(--display); font-size: 18px; }
.form.hero b.l { background: transparent; border: 1.5px solid rgba(255,255,255,.45); }

/* Score grid */
.score { display: grid; grid-template-columns: 1fr repeat(var(--n), 50px); gap: 8px; align-items: center; }
.score .cell { height: 50px; border-radius: 12px; background: rgba(255,255,255,.1); border: none; color: #fff; text-align: center; font-family: var(--display); font-weight: 700; font-size: 24px; width: 100%; }
.score .cell.win { background: var(--ball); color: var(--ink); }
.score .lbl { font-size: 12px; color: #C9D8CF; font-weight: 700; text-align: center; }

/* Ranking table */
.rt-row { display: grid; grid-template-columns: 30px 1fr 40px 52px; gap: 6px; align-items: center; min-height: 56px; padding: 0 12px; border-top: 1px solid #E8EDE3; }
.rt-row.head { min-height: 34px; background: #EEF2E8; font-size: 11px; font-weight: 800; color: var(--muted); border-top: 0; }
.rt-row.top { background: #FBFDF0; }
.rt-row .p { font-family: var(--display); font-weight: 700; font-size: 18px; }

/* Nav */
nav.tabs { position: fixed; left: 0; right: 0; margin: 0 auto; bottom: 0; width: 100%; max-width: 520px; height: calc(var(--nav-h) + var(--safe-b)); padding-bottom: var(--safe-b); background: var(--card); border-top: 1px solid var(--line); display: flex; justify-content: space-around; align-items: flex-start; padding-top: 8px; z-index: 20; }
nav.tabs a { width: 64px; display: flex; flex-direction: column; align-items: center; gap: 3px; font-size: 11px; font-weight: 600; color: var(--muted); text-decoration: none; }
nav.tabs a.on { color: var(--court); font-weight: 800; }
nav.tabs a.plus { width: 58px; height: 58px; margin-top: -26px; border-radius: 29px; background: var(--ball); border: 4px solid var(--bg); color: var(--ink); justify-content: center; }

/* Overlays */
.sheet-bg { position: fixed; inset: 0; background: rgba(16,35,27,.45); z-index: 40; display: flex; align-items: flex-end; justify-content: center; animation: fade .15s; }
.sheet { width: 100%; max-width: 520px; background: var(--bg); border-radius: 22px 22px 0 0; padding: 18px 16px calc(18px + var(--safe-b)); max-height: 90vh; overflow-y: auto; }
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--nav-h) + 20px); background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 14px; font-weight: 600; font-size: 14px; z-index: 60; max-width: 90vw; box-shadow: 0 6px 20px rgba(0,0,0,.2); }
.demo-banner { background: var(--warn-bg); color: var(--warn); font-size: 12px; font-weight: 700; padding: 6px 12px; text-align: center; }
.empty { text-align: center; color: var(--muted); padding: 24px 8px; font-size: 14px; }
.stars { color: #A7C21A; letter-spacing: 1px; }
.starpick { display: flex; gap: 6px; }
.starpick button { width: 44px; height: 44px; border-radius: 12px; border: 1.5px solid var(--line); background: var(--card); font-size: 20px; cursor: pointer; }
.starpick button.on { background: var(--ball); border-color: var(--ball); }
.photo-ph { height: 180px; background: var(--court-2); display: flex; align-items: center; justify-content: center; color: var(--ball); font-weight: 800; font-size: 12px; letter-spacing: .08em; }
.photo-ph img { width: 100%; height: 100%; object-fit: cover; }
.bracket-slot { background: var(--bg); border-radius: 12px; padding: 10px; font-size: 13px; line-height: 1.55; }
.bracket-slot.me { background: #FBFDF0; border: 1.5px solid var(--ball); }
.bracket-slot .w { font-weight: 800; }
.gate { min-height: 100vh; }
@media (min-width: 521px) { body { background: #E6EADF; } }
