/* =============================================================================
   minesweeper.css — the Minesweeper page's own sheet (labs 561)

   One file for both editions. Everything is a var(): the house tokens that
   assets/css/site.css defines and dark.css redefines, and nineteen tokens of
   this page's own (the eight digit inks, the grounds of a covered and an open
   square, the marks of a hint), which are defined ONCE for paper and ONCE for
   the dark edition at the top of this file and nowhere else. A literal colour
   below those two blocks is a bug.

   Class names are prefixed msw-. site.css owns the short names (.band,
   .console, .btn, .seg__b, .field, .lbl, .hint) and this sheet only places
   them.

   COLOUR IS NEVER THE ONLY SIGNAL. A digit is a numeral before it is a colour
   (and "Plain digits" drops the colours altogether); a covered square is
   raised and an open one is flat; a flag, a mine, a wrong flag and the mine
   that ended the game are four different drawings; a hint's safe square
   carries a tick and its mine a dot, and the numbers it rests on a ring.

   PHONES: the board is never wider than the screen. One that fits at 30 px a
   square or more is shown whole; a wider one keeps squares of 34 px and pans
   inside its own box (.msw-scroll), and the reader can grow them to 56. Every
   control outside the board is at least 44 px tall.
   ========================================================================== */

.msw {
    --msw-n1: #1D4ED8; --msw-n2: #15803D; --msw-n3: #B91C1C; --msw-n4: #6D28D9;
    --msw-n5: #9A3412; --msw-n6: #0F766E; --msw-n7: #1E262B; --msw-n8: #57534E;
    --msw-cover: #DDE2E6; --msw-cover-hi: #F4F6F7; --msw-cover-lo: #AEB7BE; --msw-cover-hover: #D0D7DC;
    --msw-open: #FFFFFF; --msw-grid: #C9D0D5;
    --msw-safe: #15803D; --msw-mine: #B91C1C; --msw-why: #C2410C;
    --msw-boom: #FDE2E2; --msw-flagpole: #1E262B;
    --msw-cell: 34px;
}
html[data-dark] .msw {
    --msw-n1: #93C5FD; --msw-n2: #4ADE80; --msw-n3: #F87171; --msw-n4: #C4B5FD;
    --msw-n5: #FDBA74; --msw-n6: #5EEAD4; --msw-n7: #FFFFFF; --msw-n8: #B8B2AC;
    --msw-cover: #2B3540; --msw-cover-hi: #3C4856; --msw-cover-lo: #161C23; --msw-cover-hover: #354150;
    --msw-open: #0C1116; --msw-grid: #2A323B;
    --msw-safe: #4ADE80; --msw-mine: #F87171; --msw-why: #F97316;
    --msw-boom: #4A1D1D; --msw-flagpole: #FFFFFF;
}

/* ------------------------------------------------------------------ the hero */
.msw-fact {
    margin: 2.2rem 0 0; padding-top: 1.1rem;
    border-top: 1px solid var(--line);
    max-width: 46rem;
    font-size: .84rem; line-height: 1.6; color: var(--ink-55);
}
/* the headline wraps where the words fall, in lines of like length: no word left alone on a line */
.msw-h1 { text-wrap: balance; }

/* --------------------------------------------------------------- the console */
.msw .console__head { flex-wrap: wrap; gap: .6rem 1rem; }
.msw-meters { display: flex; align-items: center; gap: 1.1rem; margin: 0 0 0 auto; font-variant-numeric: tabular-nums; }
.msw-meter { display: inline-flex; align-items: center; gap: .4rem; margin: 0; font-weight: 700; font-size: 1rem; color: var(--ink); }
.msw-meter svg { flex: 0 0 auto; }
.msw-meter small { font-weight: 600; font-size: .68rem; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-55); }
/* Flag mode, in words beside the board's title (a dashed pill with the flag), and on the board's own box below */
.msw-modetag { display: inline-flex; align-items: center; gap: .35rem; margin: 0; padding: .14rem .6rem; border: 1px dashed var(--msw-mine); border-radius: 999px; font-size: .68rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--ink); }
.msw-modetag[hidden] { display: none; }
.msw-modetag svg { flex: 0 0 auto; color: var(--msw-mine); }

.msw-pick { display: grid; gap: .7rem; min-width: 0; }
.msw-level .seg__b { min-height: 44px; }
.msw-level .seg__b small { display: block; margin: 0; font-size: .68rem; }
.msw-custom { display: flex; flex-wrap: wrap; align-items: flex-end; gap: .6rem; min-width: 0; }
.msw-custom[hidden], .msw-veil[hidden], .msw-sayacts[hidden] { display: none; }
.msw-custom label { display: grid; gap: .2rem; font-size: .7rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-55); }
.msw-custom .field { width: 5.6rem; min-height: 44px; font-variant-numeric: tabular-nums; }
.msw-custom .btn { min-height: 44px; }
.msw-custom .hint { flex: 1 1 100%; margin: 0; }

.msw-bar { display: flex; flex-wrap: wrap; align-items: center; gap: .6rem .9rem; min-width: 0; }
.msw-bar .btn, .msw-bar .seg__b { min-height: 44px; }
.msw-bar .btn[aria-pressed="true"] { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.msw-bar .btn svg, .msw-mode .seg__b svg { flex: 0 0 auto; vertical-align: -3px; margin-right: .3rem; }
.msw-mode { display: inline-flex; gap: .3rem; }
.msw-mode .seg__b { min-width: 4.6rem; text-align: center; }
.msw-zoom { display: inline-flex; align-items: center; gap: .3rem; margin-left: auto; }
.msw-zoom .btn { min-width: 44px; padding-left: .5rem; padding-right: .5rem; justify-content: center; font-size: 1rem; line-height: 1; }
.msw-zoom span { font-size: .72rem; color: var(--ink-55); min-width: 3.2rem; text-align: center; font-variant-numeric: tabular-nums; }
.msw-opt { display: inline-flex; align-items: center; gap: .5rem; min-height: 44px; font-size: .86rem; color: var(--ink-77); cursor: pointer; }
.msw-opt input { width: 20px; height: 20px; accent-color: var(--accent); }
@media (max-width: 30rem) {
    .msw .console__body { padding: .85rem .7rem 1rem; }
    /* the board's box runs to the console's own edges, so nine squares fit a 360 px screen */
    .msw-stage { margin-left: -.7rem; margin-right: -.7rem; }
    .msw-stage .msw-scroll { border-left: 0; border-right: 0; border-radius: 0; }
    .msw-zoom { margin-left: 0; }
    .msw-level .seg__b { flex: 1 1 calc(50% - .4rem); text-align: center; }
}

/* ------------------------------------------------------------------ the board
   .msw-scroll is the box the board pans in. touch-action: one finger pans it
   (and, at its end, the page: the vertical overscroll is not held), two
   fingers are this page's own pinch, which changes the size of a square. The
   browser's double-tap zoom is off site-wide (micro.css) and is not relied on. */
.msw-stage { position: relative; min-width: 0; }
.msw-scroll {
    max-width: 100%; max-height: min(82vh, 60rem);
    overflow: auto; overscroll-behavior-x: contain;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-x pan-y;
    border: 1px solid var(--line); border-radius: 12px;
    background: var(--tint);
    scrollbar-width: thin;
}
/* Flag mode is drawn on the box the squares are in: a dashed edge all round (a shape, not only a colour), there
   wherever the board is on screen, however far the Open | Flag switch has scrolled away */
.msw--flagmode .msw-scroll { outline: 2px dashed var(--msw-mine); outline-offset: -2px; }
.msw-scroll:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.msw-board {
    display: grid; grid-template-columns: repeat(var(--msw-w, 9), var(--msw-cell));
    grid-auto-rows: var(--msw-cell);
    gap: 1px; padding: 1px;
    width: max-content; margin: 0 auto;
    background: var(--msw-grid);
    -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
}
.msw-row { display: contents; }
.msw-c {
    -webkit-appearance: none; appearance: none;
    position: relative; display: grid; place-items: center;
    width: var(--msw-cell); height: var(--msw-cell); margin: 0; padding: 0;
    border: 0; border-radius: 0;
    background: var(--msw-cover);
    box-shadow: inset 2px 2px 0 var(--msw-cover-hi), inset -2px -2px 0 var(--msw-cover-lo);
    color: var(--ink); font: inherit; font-weight: 800; line-height: 1;
    font-size: calc(var(--msw-cell) * .56); font-variant-numeric: tabular-nums;
    cursor: pointer; -webkit-tap-highlight-color: transparent;
    touch-action: pan-x pan-y;
}
.msw-c:hover { background: var(--msw-cover-hover); }
.msw-c:focus { outline: none; }
.msw-c:focus-visible { outline: 3px solid var(--accent); outline-offset: -3px; z-index: 2; }
.msw-c svg { width: 62%; height: 62%; display: block; pointer-events: none; }
.msw-c.is-open { background: var(--msw-open); box-shadow: none; cursor: default; }
.msw-c.is-open.n1 { color: var(--msw-n1); } .msw-c.is-open.n2 { color: var(--msw-n2); }
.msw-c.is-open.n3 { color: var(--msw-n3); } .msw-c.is-open.n4 { color: var(--msw-n4); }
.msw-c.is-open.n5 { color: var(--msw-n5); } .msw-c.is-open.n6 { color: var(--msw-n6); }
.msw-c.is-open.n7 { color: var(--msw-n7); } .msw-c.is-open.n8 { color: var(--msw-n8); }
.msw-c.is-open[data-n] { cursor: pointer; }
.msw--plain .msw-c.is-open { color: var(--ink); }
.msw--plain .msw-c { box-shadow: inset 0 0 0 2px var(--ink-77); }
.msw--plain .msw-c.is-open { box-shadow: none; }

.msw-c .msw-i-pole { stroke: var(--msw-flagpole); }
.msw-c .msw-i-flag { fill: var(--msw-mine); }
.msw-c .msw-i-mine { fill: var(--ink); stroke: var(--ink); }
.msw-c .msw-i-glint { fill: var(--msw-open); }
.msw-c .msw-i-cross { stroke: var(--msw-mine); }
.msw-c.is-mine { background: var(--msw-open); box-shadow: none; cursor: default; }
.msw-c.is-boom { background: var(--msw-boom); box-shadow: inset 0 0 0 3px var(--msw-mine); }
.msw-c.is-wrong { cursor: default; }
/* the daily board's first square: a ring and a dot, until it is opened */
.msw-c.is-start::after {
    content: ''; position: absolute; inset: 22%; border-radius: 50%;
    border: 3px solid var(--msw-why); background: radial-gradient(circle, var(--msw-why) 0 28%, transparent 32%);
}
@media (prefers-reduced-motion: no-preference) { .msw-c.is-start::after { animation: msw-pulse 1.6s var(--ease) infinite; } }
@keyframes msw-pulse { 50% { transform: scale(.78); opacity: .7; } }

/* the hint's marks: the numbers it rests on, the mines it takes as found, what it concludes */
.msw-c.is-why { box-shadow: inset 0 0 0 3px var(--msw-why); z-index: 1; }
.msw-c.is-why::before { content: ''; position: absolute; left: 18%; right: 18%; bottom: 9%; height: 3px; border-radius: 2px; background: var(--msw-why); }
.msw-c.is-known { box-shadow: inset 2px 2px 0 var(--msw-cover-hi), inset -2px -2px 0 var(--msw-cover-lo), inset 0 0 0 3px var(--msw-why); }
.msw-c.is-hsafe { box-shadow: inset 0 0 0 3px var(--msw-safe); }
.msw-c.is-hsafe::after { content: '\2713'; position: absolute; inset: 0; display: grid; place-items: center; color: var(--msw-safe); font-size: calc(var(--msw-cell) * .6); font-weight: 800; }
.msw-c.is-hmine { box-shadow: inset 0 0 0 3px var(--msw-mine); outline: 2px dashed var(--msw-mine); outline-offset: -7px; }
.msw-c.is-hmine:not(.is-flag)::after { content: ''; position: absolute; width: 30%; height: 30%; border-radius: 50%; background: var(--msw-mine); }

.msw-veil {
    position: absolute; inset: 0; z-index: 3; display: grid; place-items: center; text-align: center;
    padding: 1.2rem; border-radius: 12px;
    background: var(--paper); border: 1px solid var(--line);
}
.msw-veil p { margin: 0; max-width: 30rem; color: var(--ink-77); }

/* ------------------------------------------------------------------- the say */
.msw-say {
    min-height: 4.6rem; padding: .85rem 1rem;
    border: 1px solid var(--line); border-left: 3px solid var(--accent); border-radius: 10px;
    background: var(--paper);
    font-size: .93rem; line-height: 1.55; color: var(--ink-77);
}
.msw-say p { margin: 0; }
.msw-say p + p { margin-top: .45rem; }
.msw-say b { color: var(--ink); }
.msw-say--won { border-left-color: var(--free); }
.msw-say--lost { border-left-color: var(--taken); }
.msw-say__rule { display: inline-block; margin-right: .5rem; padding: .08rem .5rem; border: 1px solid var(--line); border-radius: 999px; font-size: .68rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--ink); }
.msw-sayacts { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .7rem; }
.msw-sayacts .btn { min-height: 44px; }
.msw-keys { margin: 0; }
.msw-legend { display: flex; flex-wrap: wrap; gap: .4rem 1.1rem; margin: 0; padding: 0; list-style: none; font-size: .8rem; color: var(--ink-77); }
.msw-legend li { display: inline-flex; align-items: center; gap: .45rem; }
.msw-legend .msw-c { --msw-cell: 26px; cursor: default; flex: 0 0 auto; }

/* ----------------------------------------------------------------- the times */
.msw-times { display: grid; grid-template-columns: repeat(auto-fit, minmax(13.5rem, 1fr)); gap: .9rem; margin-top: 1.4rem; }
.msw-tcard { min-width: 0; padding: 1rem 1.1rem 1.05rem; border: 1px solid var(--line); border-radius: 12px; background: var(--paper); display: grid; gap: .35rem; align-content: start; }
.msw-tcard h3 { margin: 0; font-size: 1rem; color: var(--ink); }
.msw-tcard h3 small { font-weight: 600; font-size: .72rem; color: var(--ink-55); margin-left: .4rem; }
.msw-tcard p { margin: 0; font-size: .86rem; line-height: 1.5; color: var(--ink-77); }
.msw-tcard__best { font-size: 1.5rem !important; font-weight: 800; color: var(--ink) !important; font-variant-numeric: tabular-nums; }
.msw-tcard .btn { justify-self: start; min-height: 44px; margin-top: .3rem; }
.msw-rec { display: flex; flex-wrap: wrap; align-items: center; gap: .7rem 1.2rem; margin-top: 1.2rem; }
.msw-rec p { margin: 0; font-size: .86rem; color: var(--ink-77); }
.msw-rec .btn { min-height: 44px; }

/* ---------------------------------------------------------------- the method */
.msw-cols { display: grid; gap: 0 3rem; margin-top: 1.4rem; }
@media (min-width: 62rem) { .msw-cols { grid-template-columns: 1fr 1fr; } }
.msw-cols > div { min-width: 0; }
.msw-h3 { margin: 1.5rem 0 .5rem; font-size: 1.02rem; color: var(--ink); }
.msw-cols p, .msw-limit { margin: 0 0 .8rem; font-size: .93rem; line-height: 1.65; color: var(--ink-77); max-width: 44rem; }
.msw-rules { margin: 0 0 .8rem; padding: 0; list-style: none; display: grid; gap: .55rem; max-width: 44rem; }
.msw-rules li { padding: .6rem .8rem; border: 1px solid var(--line); border-radius: 10px; background: var(--paper); font-size: .9rem; line-height: 1.55; color: var(--ink-77); }
.msw-rules b { color: var(--ink); }
.msw-proof { margin-top: 1.6rem; }
.msw-run { margin: 0 0 .9rem; font-size: .93rem; line-height: 1.65; color: var(--ink-77); max-width: 62rem; }
.msw-run b { color: var(--ink); }
.msw-cap { margin: 1.1rem 0 .4rem; font-size: .72rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-55); }
.msw-tabwrap { overflow-x: auto; max-width: 100%; border: 1px solid var(--line); border-radius: 10px; background: var(--paper); }
.msw-tabwrap:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.msw-tab { width: 100%; border-collapse: collapse; font-size: .84rem; font-variant-numeric: tabular-nums; }
.msw-tab th, .msw-tab td { padding: .5rem .7rem; text-align: left; border-bottom: 1px solid var(--line-soft); white-space: nowrap; color: var(--ink-77); }
.msw-tab thead th { font-size: .68rem; letter-spacing: .06em; text-transform: uppercase; color: var(--ink-55); white-space: normal; vertical-align: bottom; }
.msw-tab tbody th { color: var(--ink); font-weight: 700; }
.msw-tab tr:last-child th, .msw-tab tr:last-child td { border-bottom: 0; }
.msw-tab .msw-num { text-align: right; }
