/* Mini-golf 3D — 9 holes, 1-4 players on one device or against the phone (js/mini-golf.js).
   Theme-aware like the other game pages: tokens on :root, redefined under body.dark-theme.
   The 3D scene reads the theme from body.dark-theme (day course / evening course). */
:root {
    --mg-accent: #16a34a;
    --mg-accent-2: #0ea5e9;
    --mg-page-bg: #f1f5f9;
    --mg-card-bg: #ffffff;
    --mg-card-border: #e2e8f0;
    --mg-muted: #64748b;
    --mg-shadow: 0 10px 30px rgba(15, 23, 42, .12);
    --mg-stage-bg: #bfe3f7;
    --mg-overlay: rgba(241, 245, 249, .62);
    --mg-hud-bg: rgba(255, 255, 255, .86);
    --mg-hud-text: #0f172a;
    --mg-row-hi: rgba(22, 163, 74, .12);
    --mg-good: #16a34a;
    --mg-bad: #dc2626;
}

body.dark-theme {
    --mg-accent: #4ade80;
    --mg-accent-2: #38bdf8;
    --mg-page-bg: #0b1120;
    --mg-card-bg: #1e293b;
    --mg-card-border: #334155;
    --mg-muted: #94a3b8;
    --mg-shadow: 0 10px 30px rgba(0, 0, 0, .45);
    --mg-stage-bg: #0f1d2e;
    --mg-overlay: rgba(7, 11, 20, .62);
    --mg-hud-bg: rgba(15, 23, 42, .84);
    --mg-hud-text: #e2e8f0;
    --mg-row-hi: rgba(74, 222, 128, .14);
    --mg-good: #4ade80;
    --mg-bad: #f87171;
}

/* clip, not hidden: the site-wide `body { overflow-x: hidden }` makes <body> a scroll
   container that never scrolls, which silently kills any position: sticky inside. */
.mg-body, body.mg-body#page-top {
    font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
    background: var(--mg-page-bg);
    color: var(--text-color);
    min-height: 100vh;
    overflow-x: clip;
}
body.mg-max { overflow: hidden; }

.mg-main { padding-top: 92px; padding-bottom: 32px; }

/* ---- hero ---- */
.mg-hero { text-align: center; padding: 4px 0 12px; }
.mg-hero h1 { font-weight: 800; font-size: clamp(1.6rem, 4vw, 2.3rem); margin-bottom: 6px; }
.mg-hero h1 svg, .mg-hero h1 i { color: var(--mg-accent); }
.mg-lead { max-width: 640px; margin: 0 auto; color: var(--mg-muted); font-size: 1rem; line-height: 1.55; }

/* ---- the stage ---- */
.mg-stage {
    --mg-h: min(78vh, 720px);
    position: relative;
    width: min(100%, 1120px);
    height: var(--mg-h);
    min-height: 420px;
    margin: 0 auto;
    background: var(--mg-stage-bg);
    border-radius: 18px;
    overflow: hidden;
    box-shadow: var(--mg-shadow);
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
}
@media (max-width: 575.98px) {
    .mg-stage { --mg-h: calc(100vh - 80px); border-radius: 0; width: 100%; }
    .mg-lead { font-size: .93rem; }
}
@supports (height: 100svh) {
    @media (max-width: 575.98px) { .mg-stage { --mg-h: calc(100svh - 80px); } }
}

.mg-canvas {
    position: absolute;
    inset: 0;
    display: block;
    width: 100%;
    height: 100%;
    touch-action: none;
    cursor: crosshair;
}
.mg-stage[data-phase="roll"] .mg-canvas, .mg-stage[data-phase="think"] .mg-canvas { cursor: default; }

/* real fullscreen, and the iPhone fallback that just covers the window */
.mg-stage:fullscreen { width: 100%; height: 100%; min-height: 0; border-radius: 0; }
.mg-stage:-webkit-full-screen { width: 100%; height: 100%; min-height: 0; border-radius: 0; }
.mg-stage.is-max {
    position: fixed;
    inset: 0;
    z-index: 1052;          /* over the site header (1050), under the site's dialogs (1055) */
    width: 100vw;
    height: 100vh;
    min-height: 0;
    border-radius: 0;
    margin: 0;
}
@supports (height: 100dvh) {
    .mg-stage.is-max { height: 100dvh; }
}

/* ---- HUD ---- */
.mg-hud[hidden] { display: none; }
.mg-hud { position: absolute; inset: 0; pointer-events: none; z-index: 2; }
.mg-col {
    position: absolute;
    top: 10px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
}
.mg-col-left { left: 10px; }
.mg-col-right { right: 10px; }
.mg-round {
    pointer-events: auto;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: 1px solid var(--mg-card-border);
    background: var(--mg-hud-bg);
    color: var(--mg-hud-text);
    display: grid;
    place-items: center;
    font-size: 17px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, .18);
    touch-action: manipulation;
    cursor: pointer;
    transition: transform .1s, border-color .15s;
}
.mg-round:hover, .mg-round:focus-visible { border-color: var(--mg-accent); }
.mg-round:active { transform: scale(.94); }
.mg-round[aria-pressed="true"]#mg-view-btn { border-color: var(--mg-accent); }
.mg-round span[hidden] { display: none; }

.mg-info {
    position: absolute;
    top: 10px;
    left: 50%;
    transform: translateX(-50%);
    max-width: calc(100% - 128px);
    padding: 6px 14px;
    border-radius: 14px;
    background: var(--mg-hud-bg);
    color: var(--mg-hud-text);
    box-shadow: 0 2px 10px rgba(0, 0, 0, .16);
    text-align: center;
    font-size: .9rem;
    line-height: 1.35;
    white-space: nowrap;
}
.mg-info-hole { font-weight: 700; }
.mg-info-player { display: flex; align-items: center; justify-content: center; gap: 5px; min-width: 0; }
.mg-sep { opacity: .5; margin: 0 4px; }
.mg-info-player .mg-sep { margin: 0 1px; }
.mg-dot {
    flex: 0 0 auto;
    display: inline-block;
    width: 13px;
    height: 13px;
    border-radius: 50%;
    border: 1px solid rgba(15, 23, 42, .45);
    background: #f8fafc;
}
.mg-pname { overflow: hidden; text-overflow: ellipsis; max-width: 9.5em; }

.mg-toast {
    position: absolute;
    left: 50%;
    top: 36%;
    transform: translate(-50%, -50%) scale(.96);
    max-width: min(88%, 420px);
    padding: 12px 18px;
    border-radius: 16px;
    background: var(--mg-hud-bg);
    color: var(--mg-hud-text);
    box-shadow: var(--mg-shadow);
    text-align: center;
    font-weight: 800;
    font-size: 1.15rem;
    opacity: 0;
    visibility: hidden;
    transition: opacity .2s, transform .2s, visibility .2s;
}
.mg-toast.is-on { opacity: 1; visibility: visible; transform: translate(-50%, -50%) scale(1); }
.mg-toast small { display: block; font-weight: 500; font-size: .85rem; color: var(--mg-muted); margin-top: 3px; }
.mg-toast.is-ace { color: #b45309; }
body.dark-theme .mg-toast.is-ace { color: #fbbf24; }
.mg-toast.is-bad { color: var(--mg-bad); }

.mg-bottom {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 0 12px;
}
.mg-hint {
    margin: 0;
    min-height: 1.6em;
    max-width: 100%;
    padding: 3px 12px;
    border-radius: 12px;
    background: var(--mg-hud-bg);
    color: var(--mg-hud-text);
    font-size: .88rem;
    text-align: center;
}
.mg-hint:empty { visibility: hidden; }
.mg-power {
    display: flex;
    align-items: center;
    gap: 10px;
    width: min(78%, 360px);
    padding: 6px 12px;
    border-radius: 14px;
    background: var(--mg-hud-bg);
    color: var(--mg-hud-text);
    visibility: hidden;
}
.mg-power.is-on { visibility: visible; }
.mg-power-bar { flex: 1; height: 12px; border-radius: 6px; background: rgba(100, 116, 139, .28); overflow: hidden; }
.mg-power-fill { height: 100%; width: 0; border-radius: 6px; background: linear-gradient(90deg, #22c55e, #eab308 55%, #ef4444); background-size: 100% 100%; }
.mg-power-txt { font-size: .82rem; font-weight: 700; min-width: 6.6em; text-align: right; font-variant-numeric: tabular-nums; }

/* ---- overlays ---- */
.mg-overlay {
    position: absolute;
    inset: 0;
    z-index: 3;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 14px;
    background: var(--mg-overlay);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
    touch-action: pan-y;
    overflow-y: auto;
}
.mg-overlay[hidden] { display: none; }
.mg-card {
    width: 100%;
    max-width: 350px;
    margin: auto 0;
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 16px 14px;
    border-radius: 18px;
    background: var(--mg-card-bg);
    border: 1px solid var(--mg-card-border);
    box-shadow: var(--mg-shadow);
    text-align: center;
    color: var(--text-color);
}
.mg-card-wide { max-width: 420px; }
.mg-card h2 { font-weight: 800; font-size: 1.4rem; margin: 0; }
.mg-muted { margin: 0; color: var(--mg-muted); font-size: .9rem; line-height: 1.45; }

.mg-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 46px;
    padding: 10px 14px;
    border-radius: 12px;
    border: 1px solid var(--mg-card-border);
    background: var(--mg-page-bg);
    color: var(--text-color);
    font-weight: 700;
    font-size: 1rem;
    cursor: pointer;
    touch-action: manipulation;
    transition: border-color .15s, transform .1s;
}
.mg-btn:hover { border-color: var(--mg-accent); }
.mg-btn:active { transform: scale(.98); }
.mg-btn:disabled { opacity: .45; cursor: not-allowed; }
.mg-btn[hidden] { display: none; }
.mg-btn-primary { background: var(--mg-accent); border-color: var(--mg-accent); color: #fff; }
body.dark-theme .mg-btn-primary { color: #052e16; }
.mg-btn-ghost { background: transparent; }
.mg-row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

.mg-players { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; text-align: left; }
.mg-prow {
    display: grid;
    grid-template-columns: 16px 1fr 44px;
    grid-template-areas: "dot name del" ". type del";
    align-items: center;
    column-gap: 8px;
    row-gap: 6px;
    padding: 8px;
    border-radius: 12px;
    border: 1px solid var(--mg-card-border);
    background: var(--mg-page-bg);
}
.mg-prow .mg-dot { grid-area: dot; width: 16px; height: 16px; }
.mg-prow input, .mg-prow select {
    width: 100%;
    min-width: 0;
    min-height: 40px;
    padding: 6px 10px;
    border-radius: 10px;
    border: 1px solid var(--mg-card-border);
    background: var(--mg-card-bg);
    color: var(--text-color);
    font-size: 16px;            /* no iOS zoom on focus */
}
.mg-prow input { grid-area: name; }
.mg-prow select { grid-area: type; }
.mg-prow input:focus, .mg-prow select:focus { outline: 2px solid var(--mg-accent); outline-offset: 0; }
.mg-del {
    grid-area: del;
    width: 44px;
    height: 44px;
    border-radius: 10px;
    border: 1px solid var(--mg-card-border);
    background: transparent;
    color: var(--mg-muted);
    font-size: 1rem;
    cursor: pointer;
    touch-action: manipulation;
}
.mg-del:hover { color: var(--mg-bad); border-color: var(--mg-bad); }
.mg-del[hidden] { display: none; }

.mg-switches { display: flex; justify-content: center; gap: 18px; flex-wrap: wrap; }
.mg-switch { display: inline-flex; align-items: center; gap: 8px; margin: 0; font-size: .92rem; color: var(--mg-muted); cursor: pointer; min-height: 32px; }
.mg-switch input { width: 18px; height: 18px; accent-color: var(--mg-accent); }
.mg-switch[hidden] { display: none; }
.mg-record { margin: 0; font-size: .84rem; color: var(--mg-muted); }
.mg-record[hidden] { display: none; }

/* ---- scorecard ---- */
.mg-table-wrap { max-width: 100%; overflow-x: auto; }
.mg-table { width: 100%; border-collapse: collapse; font-size: .88rem; font-variant-numeric: tabular-nums; }
.mg-table th, .mg-table td { padding: 5px 4px; border-bottom: 1px solid var(--mg-card-border); text-align: center; }
.mg-table thead th { font-weight: 700; vertical-align: bottom; }
.mg-table th.mg-th-name { max-width: 5.6em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mg-table th .mg-dot { width: 11px; height: 11px; margin-right: 3px; vertical-align: -1px; }
.mg-table td.mg-par, .mg-table th.mg-par { color: var(--mg-muted); }
.mg-table tr.is-now td, .mg-table tr.is-now th { background: var(--mg-row-hi); }
.mg-table td.is-under { color: var(--mg-good); font-weight: 700; }
.mg-table td.is-over { color: var(--mg-bad); }
.mg-table td.is-ace { color: #b45309; font-weight: 800; }
body.dark-theme .mg-table td.is-ace { color: #fbbf24; }
.mg-table tfoot td { font-weight: 800; border-bottom: 0; }

.mg-rank { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 6px; text-align: left; }
.mg-rank li { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 12px; background: var(--mg-page-bg); border: 1px solid var(--mg-card-border); }
.mg-rank li.is-first { border-color: var(--mg-accent); }
.mg-rank .mg-place { font-weight: 800; min-width: 1.6em; }
.mg-rank .mg-rname { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mg-rank .mg-rtot { font-weight: 800; font-variant-numeric: tabular-nums; }
.mg-rank .mg-rpar { color: var(--mg-muted); font-size: .85rem; min-width: 2.6em; text-align: right; }

.mg-loading .mg-card { max-width: 280px; }

/* ---- help ---- */
.mg-help-wrap { padding: 22px 0 6px; }
.mg-help { max-width: 760px; margin: 0 auto; padding: 12px 14px; border-radius: 14px; background: var(--mg-card-bg); border: 1px solid var(--mg-card-border); }
.mg-help summary { font-weight: 700; cursor: pointer; min-height: 32px; display: list-item; }
.mg-help summary svg, .mg-help summary i { color: var(--mg-accent); }
.mg-help ul { margin: 10px 0 8px; padding-left: 20px; line-height: 1.6; }
.mg-help kbd { font-size: .8em; }
.mg-help p { margin: 0; color: var(--mg-muted); font-size: .93rem; }
.mg-powered { text-align: center; color: var(--mg-muted); font-size: .85rem; margin: 18px 0 0; }
.mg-powered a { color: var(--mg-accent); }

@media (max-width: 420px) {
    .mg-info { font-size: .82rem; padding: 5px 10px; max-width: calc(100% - 120px); }
    .mg-pname { max-width: 6.5em; }
    .mg-card { padding: 14px 12px; }
    .mg-table { font-size: .82rem; }
}
@media (max-height: 520px) and (orientation: landscape) {
    .mg-col { gap: 6px; }
    .mg-round { width: 40px; height: 40px; font-size: 15px; }
    .mg-toast { top: 42%; }
}
