/* Moară (Nine Men's Morris) — pass-and-play on one phone, or against the phone (js/moara.js).
   Theme-aware like the other tool pages: tokens on :root, redefined under body.dark-theme. */
:root {
    --mr-accent: #b45309;
    --mr-accent-soft: #fdf0dc;
    --mr-page-bg: #faf6ef;
    --mr-card-bg: #ffffff;
    --mr-card-border: #e7e1d6;
    --mr-muted: #6b6457;
    --mr-shadow: 0 10px 30px rgba(90, 60, 20, .10);
    --mr-board: #e9c98f;
    --mr-board-edge: #c99a55;
    --mr-line: #5b3a17;
    --mr-dot: #5b3a17;
    --mr-target: #0f9d58;
    --mr-select: #2563eb;
    --mr-remove: #dc2626;
    --mr-mill: #f59e0b;
    --mr-last: rgba(37, 99, 235, .55);
}

body.dark-theme {
    --mr-accent: #f5b04a;
    --mr-accent-soft: #3a2a14;
    --mr-page-bg: #111827;
    --mr-card-bg: #1f2937;
    --mr-card-border: #374151;
    --mr-muted: #9ca3af;
    --mr-shadow: 0 10px 30px rgba(0, 0, 0, .35);
    --mr-board: #6b4a26;
    --mr-board-edge: #4a3118;
    --mr-line: #f3dcb2;
    --mr-dot: #f3dcb2;
    --mr-target: #34d399;
    --mr-select: #60a5fa;
    --mr-remove: #f87171;
    --mr-mill: #fbbf24;
    --mr-last: rgba(96, 165, 250, .6);
}

/* 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. */
.mr-body, body.mr-body#page-top {
    font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
    background: var(--mr-page-bg);
    color: var(--text-color);
    min-height: 100vh;
    overflow-x: clip;
}
.mr-main { padding-top: 100px; padding-bottom: 40px; }
.mr-game .container, .mr-hero .container { max-width: 560px; }

/* ---- hero ---- */
.mr-hero { text-align: center; padding: 4px 0 10px; }
.mr-hero h1 { font-weight: 800; font-size: clamp(1.7rem, 5vw, 2.3rem); margin-bottom: 4px; }
.mr-lead { margin: 0 auto; color: var(--mr-muted); font-size: 1rem; line-height: 1.5; }

/* ---- mode switch ---- */
.mr-modes { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; padding: 5px; margin: 6px 0 12px; border-radius: 16px; background: var(--mr-card-bg); border: 1px solid var(--mr-card-border); }
.mr-mode { min-height: 46px; padding: 6px 8px; border: 0; border-radius: 12px; background: transparent; color: inherit; font-weight: 700; font-size: .88rem; line-height: 1.2; cursor: pointer; touch-action: manipulation; display: flex; align-items: center; justify-content: center; gap: 7px; text-align: center; }
.mr-mode[aria-pressed="true"] { background: var(--mr-accent); color: #fff; }
body.dark-theme .mr-mode[aria-pressed="true"] { color: #1f1300; }
.mr-mode:focus-visible { outline: 2px solid var(--mr-accent); outline-offset: 2px; }

/* ---- turn banner ---- */
.mr-turn { display: flex; align-items: center; gap: 14px; padding: 12px 16px; margin-bottom: 12px; border-radius: 18px; background: var(--mr-card-bg); border: 1px solid var(--mr-card-border); box-shadow: var(--mr-shadow); }
.mr-turn-text { min-width: 0; }
.mr-turn-title { font-weight: 800; font-size: clamp(1.35rem, 6vw, 1.75rem); line-height: 1.15; }
.mr-turn-hint { color: var(--mr-muted); font-size: 1rem; font-weight: 600; margin-top: 2px; }
.mr-turn.is-remove { border-color: var(--mr-remove); background: color-mix(in srgb, var(--mr-remove) 10%, var(--mr-card-bg)); }
.mr-turn.is-remove .mr-turn-hint { color: var(--mr-remove); }
.mr-turn.is-over { border-color: var(--mr-mill); }

.mr-disc { display: inline-block; width: 22px; height: 22px; border-radius: 50%; flex: none; box-shadow: 0 2px 4px rgba(0, 0, 0, .3); }
.mr-disc-w { background: radial-gradient(circle at 38% 32%, #fff 0%, #f1ede4 55%, #bfb6a3 100%); }
.mr-disc-b { background: radial-gradient(circle at 38% 32%, #6b6f78 0%, #2a2d33 45%, #08090b 100%); }
body.dark-theme .mr-disc-b { box-shadow: 0 0 0 1px rgba(255, 255, 255, .25), 0 2px 4px rgba(0, 0, 0, .3); }
.mr-turn-disc { width: 42px; height: 42px; }

/* ---- board ---- */
.mr-board-wrap { max-width: 520px; margin: 0 auto 12px; }
.mr-board { display: block; width: 100%; height: auto; user-select: none; -webkit-user-select: none; -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
.mr-board-bg { fill: var(--mr-board); stroke: var(--mr-board-edge); stroke-width: 10; }
.mr-lines line, .mr-lines rect { stroke: var(--mr-line); stroke-width: 7; fill: none; stroke-linecap: round; }
.mr-dots circle { fill: var(--mr-dot); }
.mr-mill-layer line { stroke: var(--mr-mill); stroke-width: 22; stroke-linecap: round; opacity: .85; animation: mr-mill-in .45s ease-out; }
@keyframes mr-mill-in { from { opacity: 0; stroke-width: 4; } to { opacity: .85; stroke-width: 22; } }

.mr-piece { transform-box: fill-box; transform-origin: center; }
.mr-piece circle.mr-face-w { fill: url(#mr-grad-w); stroke: #9a917e; stroke-width: 2; }
.mr-piece circle.mr-face-b { fill: url(#mr-grad-b); stroke: #000; stroke-width: 2; }
body.dark-theme .mr-piece circle.mr-face-b { stroke: #8a8f99; }
.mr-piece circle.mr-shine { fill: none; stroke: rgba(255, 255, 255, .35); stroke-width: 3; }
.mr-piece.is-new { animation: mr-pop .28s ease-out; }
@keyframes mr-pop { from { transform: scale(.3); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.mr-piece.is-gone { animation: mr-gone .35s ease-in forwards; pointer-events: none; }
@keyframes mr-gone { to { transform: scale(.2); opacity: 0; } }
.mr-piece.in-mill circle.mr-ring-mill { fill: none; stroke: var(--mr-mill); stroke-width: 6; }

.mr-marks .mr-ring { fill: none; stroke-width: 6; }
.mr-marks .mr-ring.is-selectable { stroke: var(--mr-select); stroke-dasharray: 10 8; animation: mr-spin 3s linear infinite; transform-box: fill-box; transform-origin: center; opacity: .9; }
.mr-marks .mr-ring.is-selected { stroke: var(--mr-select); stroke-width: 9; }
.mr-marks .mr-ring.is-removable { stroke: var(--mr-remove); stroke-width: 7; animation: mr-pulse 1s ease-in-out infinite; transform-box: fill-box; transform-origin: center; }
.mr-marks .mr-ring.is-last { stroke: var(--mr-last); stroke-width: 5; stroke-dasharray: 4 7; }
.mr-marks .mr-target { fill: var(--mr-target); opacity: .85; animation: mr-pulse 1.1s ease-in-out infinite; transform-box: fill-box; transform-origin: center; }
@keyframes mr-spin { to { transform: rotate(360deg); } }
@keyframes mr-pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.15); } }

.mr-hits circle { fill: transparent; cursor: pointer; }
.mr-hits circle:focus { outline: none; }
.mr-hits circle:focus-visible { stroke: var(--mr-accent); stroke-width: 4; }
.mr-board.is-busy .mr-hits circle { cursor: wait; }

/* ---- players ---- */
.mr-players { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
.mr-player { min-width: 0; padding: 10px 12px; border-radius: 16px; background: var(--mr-card-bg); border: 2px solid var(--mr-card-border); transition: border-color .2s, box-shadow .2s; }
.mr-player.is-active { border-color: var(--mr-accent); box-shadow: var(--mr-shadow); }
.mr-player-head { display: flex; align-items: center; gap: 8px; }
.mr-player-name { font-weight: 800; font-size: 1rem; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.mr-player-stats .mr-player-score { color: var(--mr-accent); white-space: nowrap; }
.mr-player-stats .mr-player-score b { color: var(--mr-accent); }
.mr-stock { display: flex; flex-wrap: wrap; gap: 3px; min-height: 14px; margin: 8px 0 6px; }
.mr-stock .mr-disc { width: 13px; height: 13px; box-shadow: 0 1px 2px rgba(0, 0, 0, .3); }
.mr-player-stats { display: flex; flex-wrap: wrap; gap: 2px 12px; color: var(--mr-muted); font-size: .88rem; }
.mr-player-stats b { color: var(--text-color); font-size: 1.05rem; }

/* ---- actions ---- */
.mr-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.mr-btn { min-height: 48px; padding: 8px 12px; border: 1px solid var(--mr-card-border); border-radius: 14px; background: var(--mr-card-bg); color: inherit; font-weight: 700; font-size: .95rem; cursor: pointer; touch-action: manipulation; display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.mr-btn:hover:not(:disabled) { border-color: var(--mr-accent); }
.mr-btn:disabled { opacity: .45; cursor: not-allowed; }
.mr-btn:focus-visible { outline: 2px solid var(--mr-accent); outline-offset: 2px; }
.mr-btn-primary { background: var(--mr-accent); border-color: var(--mr-accent); color: #fff; }
body.dark-theme .mr-btn-primary { color: #1f1300; }
.mr-score-reset { text-align: center; margin: 8px 0 0; }
.mr-link { border: 0; background: none; padding: 6px 8px; color: var(--mr-muted); font-size: .85rem; text-decoration: underline; cursor: pointer; }

.mr-help { margin-top: 14px; padding: 12px 16px; border-radius: 14px; background: var(--mr-card-bg); border: 1px solid var(--mr-card-border); }
.mr-help summary { cursor: pointer; font-weight: 700; }
.mr-help ol { margin: 10px 0 0; padding-left: 20px; color: var(--mr-muted); line-height: 1.55; }
.mr-help li { margin-bottom: 4px; }
.mr-help strong { color: var(--text-color); }
.mr-help p { color: var(--mr-muted); margin: 10px 0 0; line-height: 1.55; }
.mr-powered { text-align: center; color: var(--mr-muted); font-size: .85rem; margin: 26px 0 0; }

/* ---- win overlay ---- */
.mr-overlay { position: fixed; inset: 0; z-index: 2000; display: grid; place-items: center; padding: 16px; background: rgba(0, 0, 0, .45); animation: mr-fade .25s ease-out; }
.mr-overlay[hidden] { display: none; }
@keyframes mr-fade { from { opacity: 0; } }
.mr-win { width: 100%; max-width: 340px; padding: 22px 18px 18px; border-radius: 22px; background: var(--mr-card-bg); color: var(--text-color); text-align: center; box-shadow: 0 20px 50px rgba(0, 0, 0, .35); animation: mr-rise .3s ease-out; }
@keyframes mr-rise { from { transform: translateY(20px) scale(.96); opacity: 0; } }
.mr-win-icon { font-size: 34px; color: var(--mr-mill); }
.mr-win-disc { width: 40px; height: 40px; margin: 6px auto 4px; display: block; }
.mr-win h2 { font-weight: 800; font-size: 1.5rem; margin: 4px 0 6px; }
.mr-win-reason { color: var(--mr-muted); margin: 0 0 6px; }
.mr-win-score { font-weight: 700; margin: 0 0 14px; }
.mr-win-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

@media (max-width: 400px) {
    .mr-mode { font-size: .8rem; gap: 5px; }
    .mr-turn { padding: 10px 12px; gap: 10px; }
    .mr-turn-disc { width: 34px; height: 34px; }
    .mr-player { padding: 8px 10px; }
    .mr-btn { font-size: .88rem; padding: 8px; }
}

@media (prefers-reduced-motion: reduce) {
    .mr-marks .mr-ring, .mr-marks .mr-target, .mr-piece, .mr-mill-layer line { animation: none !important; }
}
