:root {
	--blue: #97B829;
    --blue-light: #97B829;
    --bg: #136472;
    --card: #136472;
    --card-2: #1f2c4d80;
    --text: #ffffff;
    --muted: #ffffff;
    --accent: #B8CD17;
    --green: #2e7d32;
    --red: #c62828;
    --radius: 14px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    -webkit-tap-highlight-color: transparent;
}

#app { max-width: 640px; margin: 0 auto; padding-bottom: 3rem; }

.topbar {
    position: sticky; top: 0; z-index: 10;
    background: linear-gradient(160deg, var(--blue), var(--blue-light));
    padding: env(safe-area-inset-top) 1rem 0;
    box-shadow: 0 2px 12px rgba(0,0,0,.35);
}
.topbar h1 { font-size: 1.15rem; margin: .3rem 0 .4rem; }

.tabs { display: flex; gap: .25rem; }
.tab {
    flex: 1; border: 0; background: transparent; color: #136472;
    padding: .7rem .5rem; font-size: .95rem; font-weight: 600;
    border-bottom: 3px solid transparent; cursor: pointer;
}
.tab.active { color: #fff; border-bottom-color: var(--accent); }

#main { padding: 1rem; }
.loading { text-align: center; color: var(--muted); padding: 2rem; }

.card {
    background: var(--card); border-radius: var(--radius);
    padding: 1rem; margin-bottom: 1rem; box-shadow: 0 1px 4px rgba(0,0,0,.3);
}
.card h2 { margin: 0 0 .75rem; font-size: 1.05rem; }
.muted { color: var(--muted); }
.row { display: flex; gap: .5rem; align-items: center; }
.spread { justify-content: space-between; }
.wrap { flex-wrap: wrap; }

label { display: block; font-size: .8rem; color: var(--muted); margin: .5rem 0 .25rem; }

input, select {
    width: 100%; padding: .7rem; border-radius: 10px; border: 1px solid #2c3b63;
    background: var(--card-2); color: var(--text); font-size: 1rem;
}

button {
    font-family: inherit; cursor: pointer; border: 0; border-radius: 10px;
    padding: .75rem 1rem; font-size: 1rem; font-weight: 600; color: #fff;
    background: var(--blue-light); transition: transform .05s ease, opacity .2s;
}
button:active { transform: scale(.97); }
button.secondary { background: var(--card-2); }
button.ghost { background: transparent; border: 1px solid #2c3b63; color: var(--text); }
button.danger { background: var(--red); }
button.gold { background: var(--accent); color: #1a1300; }
button:disabled { opacity: .45; cursor: not-allowed; }
button.block { width: 100%; }
.btn-sm { padding: .4rem .6rem; font-size: .85rem; }

/* Scoreboard */
.score {
    display: grid; grid-template-columns: 1fr auto 1fr; gap: .5rem; align-items: center;
    background: linear-gradient(160deg, var(--blue), var(--blue-light));
    border-radius: var(--radius); padding: 1rem; margin-bottom: 1rem;
}
.score .name { font-weight: 700; }
.score .pts { font-size: 2.6rem; font-weight: 800; line-height: 1; }
.score .vs { color: #cdd9ff; font-weight: 700; }
.score .side { text-align: center; padding: .4rem; border-radius: 10px; }
.score .side.lead { background: rgba(255,255,255,.10); }
.target-pill { text-align: center; font-size: .8rem; color: #cdd9ff; margin-top: .25rem; }

/* Player picker for dice entry */
.picker { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; margin-bottom: .75rem; }
.picker button { background: var(--card-2); padding: 1rem .5rem; }
.picker button.sel { background: var(--accent); color: #1a1300; }

/* Dice */
.dice-row { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; margin: .5rem 0; }
.dice-row label { text-align: center; }
.die-pick { display: flex; flex-wrap: wrap; gap: .35rem; justify-content: center; }
.die-pick button {
    width: 3rem; height: 3rem; padding: .2rem; background: transparent;
    display: grid; place-items: center;
}
.die-face.die-mini {
    width: 2.5rem; height: 2.5rem; padding: 12%;
    border-radius: 6px; box-shadow: none; animation: none;
}
.die-pick button.sel .die-mini { outline: 3px solid var(--accent); outline-offset: 1px; transform: scale(1.06); }

.rolls { display: flex; flex-direction: column; gap: .35rem; }
.roll-item {
    display: flex; justify-content: space-between; align-items: center;
    background: var(--card-2); border-radius: 10px; padding: .5rem .75rem;
}
.roll-item.dbl { outline: 2px solid var(--accent); }
.roll-dice { font-size: 1.6rem; letter-spacing: .2rem; }
.roll-val { font-weight: 700; }
.badge { font-size: .7rem; background: var(--accent); color: #1a1300;
         padding: .1rem .4rem; border-radius: 6px; margin-left: .4rem; }

.statgrid { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; }
.stat { background: var(--card-2); border-radius: 10px; padding: .6rem; text-align: center; }
.stat .n { font-size: 1.4rem; font-weight: 800; }
.stat .l { font-size: .72rem; color: var(--muted); }

.banner { text-align: center; padding: 1.25rem; border-radius: var(--radius);
          background: var(--green); margin-bottom: 1rem; }
.banner h2 { margin: .25rem 0; }

.list-item { display: flex; justify-content: space-between; align-items: center;
             padding: .6rem 0; border-bottom: 1px solid #233156; }
.list-item:last-child { border-bottom: 0; }

.toast {
    position: fixed; left: 50%; bottom: 1.25rem; transform: translateX(-50%);
    background: #111a30; color: #fff; padding: .7rem 1.1rem; border-radius: 10px;
    box-shadow: 0 4px 18px rgba(0,0,0,.5); z-index: 50; font-size: .9rem;
    border: 1px solid #2c3b63; max-width: 90%;
}

.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.6);
            display: grid; place-items: center; z-index: 40; padding: 1rem; }
.modal { background: var(--card); border-radius: var(--radius); padding: 1.25rem;
         width: 100%; max-width: 420px; }
.modal h2 { margin-top: 0; }
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; margin: .5rem 0; }
.seg button { background: var(--card-2); }
.seg button.sel { background: var(--accent); color: #1a1300; }
.mt { margin-top: 1rem; }
.center { text-align: center; }

/* Avatars */
.avatar {
    width: 40px; height: 40px; border-radius: 50%; flex: 0 0 40px;
    background-size: cover; background-position: center; background-color: var(--card-2);
    display: grid; place-items: center; overflow: hidden;
}
.avatar-initials { font-weight: 700; color: var(--accent); }
.avatar-lg { width: 96px; height: 96px; flex-basis: 96px; border-radius: 14px; }

/* Face cropper */
.crop-stage {
    position: relative; margin: .5rem auto; touch-action: none;
    background: #000; border-radius: 8px; overflow: hidden; user-select: none;
}
.crop-img { width: 100%; height: 100%; display: block; pointer-events: none; }
.crop-box {
    position: absolute; box-sizing: border-box; cursor: move;
    border: 2px solid var(--accent); border-radius: 4px;
    box-shadow: 0 0 0 9999px rgba(0,0,0,.45);
    touch-action: none;
}

/* Player picker name + doubles sub-line */
.pick-name { font-weight: 700; line-height: 1.1; }
.pick-sub { font-size: .72rem; opacity: .8; margin-top: .15rem; }
.picker button.sel .pick-sub { opacity: .9; }

/* Big dice roll button — glyph fills the button */
.roll-big {
    flex: 1; display: flex; align-items: center; justify-content: center;
    background: var(--card-2); padding: .25rem; line-height: 1;
    font-size: 2.6rem; min-height: 3.4rem;
}

/* Centered "this game" block with the selected player's avatar on a side */
.game-center {
    display: flex; align-items: center; justify-content: center;
    gap: 1rem; margin-top: .5rem;
}
.center-info { text-align: center; }
.ci-block { margin: .15rem 0; }

/* Game selector chips (share / view mode) */
.gs-card { padding: .6rem .7rem; }
.game-sel { display: flex; flex-wrap: wrap; gap: .4rem; justify-content: center; }
.gs-chip { padding: .35rem .7rem; font-size: .85rem; border-radius: 999px; }
.ci-k { color: var(--muted); font-weight: 600; font-size: .8rem; text-transform: lowercase; }
.ci-v { font-size: 1.5rem; font-weight: 800; line-height: 1.1; }

/* Three-way view toggle (player / both / player) */
.hist-toggle { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: .4rem; }
.hist-toggle button { padding: .55rem .4rem; }

/* Roll rows: avatar pinned to its player's edge, roll-item centered between them */
.roll-line {
    display: grid; grid-template-columns: 56px 1fr 56px;
    align-items: center; gap: .4rem;
}
.roll-side { display: flex; align-items: center; justify-content: center; }
.roll-line .roll-item { max-width: 220px; width: 100%; margin: 0 auto; }
.roll-side .avatar {
    width: 52px; height: 52px; flex-basis: 52px; border-radius: 12px; font-size: 1.4rem;
}

/* Per-match color pickers in the start form */
.color-pick {
    width: 56px; min-width: 56px; height: 46px; padding: 2px;
    border: 1px solid #2c3b63; border-radius: 10px; background: var(--card-2); cursor: pointer;
}

/* Highlight the player whose history is currently shown */
.avatar-lg.sel { transform: scale(1.07); box-shadow: 0 0 0 3px var(--bg), 0 0 0 5px var(--accent); }

/* Head-to-head comparison rows */
.h2h-row {
    display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
    gap: .5rem; padding: .55rem 0; border-bottom: 1px solid #233156;
}
.h2h-row:last-child { border-bottom: 0; }
.h2h-a, .h2h-b { font-size: 1.3rem; font-weight: 800; }
.h2h-a { text-align: right; }
.h2h-b { text-align: left; }
.h2h-l { color: var(--muted); font-size: .78rem; min-width: 96px; text-align: center; }

/* Live indicator (blinking red dot) */
.live-badge {
    display: inline-flex; align-items: center; gap: .35rem;
    color: #ff1744; font-weight: 800; font-size: .78rem; letter-spacing: .05em; vertical-align: middle;
}
.live-dot {
    width: 9px; height: 9px; border-radius: 50%; background: #ff1744;
    animation: livepulse 1.2s infinite;
}
@keyframes livepulse {
    0%   { opacity: 1; box-shadow: 0 0 0 0 rgba(255,23,68,.6); }
    70%  { opacity: .35; box-shadow: 0 0 0 7px rgba(255,23,68,0); }
    100% { opacity: 1; box-shadow: 0 0 0 0 rgba(255,23,68,0); }
}

/* Timers */
.mono { font-variant-numeric: tabular-nums; font-weight: 700; }
.link-toggle { color: var(--accent); text-decoration: underline; cursor: pointer; font-size: .9rem; }

/* Per-game analysis (match details) */
.gd-row {
    display: grid; grid-template-columns: 1fr auto 1fr; gap: .5rem; align-items: center;
    padding: .7rem 0; border-bottom: 1px solid #233156;
}
.gd-row:last-child { border-bottom: 0; }
.gd-col { text-align: center; font-weight: 600; }
.gd-pts { font-size: 1.9rem; font-weight: 800; line-height: 1; margin-bottom: .2rem; }
.gd-line { font-size: .95rem; }
.gd-center { text-align: center; min-width: 80px; }
.gd-game { font-weight: 700; margin-bottom: .15rem; }

/* H2H durations footer */
.h2h-dur {
    display: flex; justify-content: space-around; gap: .5rem; margin-top: .75rem;
    padding-top: .75rem; border-top: 1px solid #233156; text-align: center;
    font-size: .82rem; color: var(--muted);
}

/* History: highlight the winning side */
.winner-gold { color: var(--accent); font-weight: 800; }

/* Rolled-dice overlay */
.dice-overlay {
    position: fixed; inset: 0; z-index: 100; cursor: pointer;
    background: rgba(5, 10, 25, .92);
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1.5rem;
    animation: diceIn .18s ease;
}
@keyframes diceIn { from { opacity: 0; } to { opacity: 1; } }
.dice-big-wrap { display: flex; gap: 6vw; align-items: center; justify-content: center; }
.die-face {
    width: min(34vw, 200px); aspect-ratio: 1 / 1; height: auto;
    flex: 0 0 auto; box-sizing: border-box;
    background: #fafafa; border-radius: 18px; padding: 9%;
    display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr);
    box-shadow: 0 10px 40px rgba(0,0,0,.5);
    animation: dicePop .25s cubic-bezier(.2,1.4,.5,1);
}
@keyframes dicePop { from { transform: scale(.4) rotate(-12deg); } to { transform: scale(1) rotate(0); } }
.pip-cell { display: grid; place-items: center; }
.pip { width: 56%; aspect-ratio: 1 / 1; height: auto; border-radius: 50%; background: #15151f; }
.dice-double-label { color: var(--accent); font-size: 2rem; font-weight: 900; letter-spacing: .08em; }
.dice-tap-hint { color: #9fb0d0; font-size: .9rem; }

/* Voice input overlay text */
.voice-status { color: #fff; font-size: 1.5rem; font-weight: 800; text-align: center; }
.voice-hint { color: #9fb0d0; font-size: .95rem; margin-top: .5rem; text-align: center; }
#voiceOverlay .dice-big-wrap { margin: 1rem 0; }

/* In-app camera */
.cam-wrap {
    width: 80vw; max-width: 360px; aspect-ratio: 1 / 1;
    border-radius: 16px; overflow: hidden; background: #000;
    box-shadow: 0 10px 40px rgba(0,0,0,.5);
}
.cam-video { width: 100%; height: 100%; object-fit: cover; }
.cam-video.mirror { transform: scaleX(-1); }

/* Leaderboard */
.lb-row {
    display: flex; align-items: center; gap: .6rem;
    padding: .55rem 0; border-bottom: 1px solid #233156;
}
.lb-row:last-child { border-bottom: 0; }
.lb-rank { width: 1.7rem; text-align: center; font-weight: 800; color: var(--accent); font-size: 1.1rem; }
.lb-main { flex: 1; min-width: 0; }

/* Tap a thumbnail to change its colour (transparent native color input on top) */
.av-color-wrap { position: relative; display: inline-block; line-height: 0; }
.av-color-input {
    position: absolute; inset: 0; width: 100%; height: 100%;
    opacity: 0; border: 0; padding: 0; margin: 0; background: transparent; cursor: pointer;
}

/* LIVE · timer · details on one line */
.status-row { display: flex; align-items: center; gap: .5rem; margin: .35rem 0 .55rem; font-size: .8rem; }
.status-live { flex: 0 0 auto; min-width: 3rem; }
.status-timer { flex: 1; text-align: center; color: var(--muted); }
.status-details { flex: 0 0 auto; }
