/* =====================================================================
   playendgames+ – styles (style.css)
   index.html loads this file
   with "?v=" + the version, so a new version is always fetched fresh.
   ===================================================================== */
/* =====================================================================
   0. INTER FONT
   The only typeface, served from the fonts/ folder (see fonts/README.md),
   one file per weight. A browser only downloads the weights a screen uses.
   "?v=4.0" is Inter's version: change it only if the font files change.
   ===================================================================== */
@font-face{font-family:Inter;font-style:normal;font-weight:300;font-display:swap;src:url(fonts/inter-300.woff?v=4.0) format("woff")}  /* light: logo "play", try number */
@font-face{font-family:Inter;font-style:normal;font-weight:400;font-display:swap;src:url(fonts/inter-400.woff?v=4.0) format("woff")}  /* regular: body text */
@font-face{font-family:Inter;font-style:normal;font-weight:500;font-display:swap;src:url(fonts/inter-500.woff?v=4.0) format("woff")}
@font-face{font-family:Inter;font-style:normal;font-weight:600;font-display:swap;src:url(fonts/inter-600.woff?v=4.0) format("woff")}
@font-face{font-family:Inter;font-style:normal;font-weight:700;font-display:swap;src:url(fonts/inter-700.woff?v=4.0) format("woff")}
@font-face{font-family:Inter;font-style:normal;font-weight:800;font-display:swap;src:url(fonts/inter-800.woff?v=4.0) format("woff")}  /* extrabold: logo "endgames" */

/* =====================================================================
   1. THEME COLOURS
   All colours live in CSS variables so light and dark mode only need
   to swap values here. --accent is the dark blue brand colour.
   ===================================================================== */
:root{
  --bg:#E6EAEE;        /* page background */
  --panel:#F5F7F9;     /* cards, buttons, info panel */
  --ink:#1B2733;       /* main text */
  --muted:#5A6B7B;     /* secondary text and labels */
  --line:#C3CCD5;      /* borders */
  --light:#DCE3EA;     /* light board squares (slate blue) */
  --dark:#6F8CA8;      /* dark board squares (slate blue) */
  --accent:#24507A;    /* dark blue brand accent */
  --onaccent:#fff;     /* text on top of the accent colour */
  --err:#B3261E;       /* error message text */
  --last:rgba(232,196,60,.55);  /* highlight for the last move / hint / best move */
  --lastb:rgba(240,222,120,.32); /* highlight for Black's last move (pale yellow) */
  --sel:rgba(240,180,41,.85);   /* highlight for the selected piece */
  --pre:rgba(214,96,64,.45);    /* highlight for a premove (coral) */
  --check:rgba(200,50,50,.75);  /* red glow behind a king in check */
  --dot:rgba(27,39,51,.38);     /* legal-move dots and capture rings */
  --sq:min(11.5vw,64px);        /* size of one board square */
  color-scheme:light;
  /* keep content clear of the iPhone notch and home bar */
  box-sizing:border-box;
  padding-top:env(safe-area-inset-top,0px);
  padding-bottom:env(safe-area-inset-bottom,0px);
}

/* Dark mode follows the device setting, unless data-theme="light" is forced */
@media (prefers-color-scheme:dark){
  :root:not([data-theme="light"]){
    --bg:#11181F;--panel:#18222C;--ink:#E6EBF0;--muted:#97A6B5;--line:#2B3947;
    --light:#8CA3B9;--dark:#3D5870;--accent:#7FA8D6;--onaccent:#0B1419;--err:#FF8A80;
    --last:rgba(232,196,60,.45);--lastb:rgba(240,222,120,.24);--dot:rgba(10,16,22,.45);color-scheme:dark;
  }
}
/* Dark mode can also be forced with <html data-theme="dark"> */
:root[data-theme="dark"]{
  --bg:#11181F;--panel:#18222C;--ink:#E6EBF0;--muted:#97A6B5;--line:#2B3947;
  --light:#8CA3B9;--dark:#3D5870;--accent:#7FA8D6;--onaccent:#0B1419;--err:#FF8A80;
  --last:rgba(232,196,60,.45);--lastb:rgba(240,222,120,.24);--dot:rgba(10,16,22,.45);color-scheme:dark;
}

/* Board colour choices (Options > Board colours), set as <html data-board="…">.
   Slate blue is the default above; each option sets light and dark mode squares.
   Saved in this browser as "pe-board". */
:root[data-board="teal-b"]{--light:#E2EDEE;--dark:#4E8C93}   /* deeper teal (build 17) */
:root[data-board="green"]{--light:#E4ECEA;--dark:#6E9E9C}    /* green-grey (build 15) */
:root[data-board="teal-a"]{--light:#DCEAEC;--dark:#5E9CA2}   /* soft teal (builds 16–18) */
:root[data-board="grey"]{--light:#FFFFFF;--dark:#A3A8AD}     /* cool grey on white */
/* classic brown wood, as on most online boards */
:root[data-board="brown"]{--light:#F0D9B5;--dark:#B58863}
:root[data-board="news"]{--light:#FFFFFF;--dark:#FFFFFF;--hatch:#3A3F44}   /* newspaper diagram: white, hatched dark squares */
@media (prefers-color-scheme:dark){
  :root[data-board="teal-b"]:not([data-theme="light"]){--light:#A9C8CA;--dark:#356A70}
  :root[data-board="green"]:not([data-theme="light"]){--light:#9DB8B5;--dark:#3F6766}
  :root[data-board="teal-a"]:not([data-theme="light"]){--light:#A2C3C6;--dark:#3E7378}
  :root[data-board="grey"]:not([data-theme="light"]){--light:#C4C8CC;--dark:#6A7076}
  :root[data-board="brown"]:not([data-theme="light"]){--light:#D9C3A1;--dark:#9A7252}
  :root[data-board="news"]:not([data-theme="light"]){--light:#C4C8CC;--dark:#C4C8CC;--hatch:#2A2E32}
}
:root[data-theme="dark"][data-board="teal-b"]{--light:#A9C8CA;--dark:#356A70}
:root[data-theme="dark"][data-board="green"]{--light:#9DB8B5;--dark:#3F6766}
:root[data-theme="dark"][data-board="teal-a"]{--light:#A2C3C6;--dark:#3E7378}
:root[data-theme="dark"][data-board="grey"]{--light:#C4C8CC;--dark:#6A7076}
:root[data-theme="dark"][data-board="brown"]{--light:#D9C3A1;--dark:#9A7252}
:root[data-theme="dark"][data-board="news"]{--light:#C4C8CC;--dark:#C4C8CC;--hatch:#2A2E32}
/* Newspaper: fine diagonal lines on the dark squares, dark coordinates on every square */
:root[data-board="news"] .sq.d{background-image:repeating-linear-gradient(135deg,var(--hatch) 0 1px,transparent 1px 4px)}
:root[data-board="news"] .sq .co{color:var(--hatch)}
:root[data-board="news"] #board{outline:2px solid var(--hatch);outline-offset:0}

/* =====================================================================
   2. PAGE BASICS AND LAYOUT
   ===================================================================== */
html{scroll-padding-top:env(safe-area-inset-top,0px)}
/* While screens flip: a shade darker than the page behind the turning page (so its edge shows),
   page fills the screen and turns about its centre */
html.flipping{background:color-mix(in srgb,var(--bg) 85%,#000);overflow:hidden}
html.flipping body{min-height:100vh;transform-origin:50% 50vh;backface-visibility:hidden}
*{box-sizing:border-box}
body{margin:0;background:var(--bg);color:var(--ink);font:16px/1.45 Inter,system-ui,-apple-system,"Segoe UI",sans-serif}

/* Main area: board column, then setup panel (side by side on wide screens) */
/* The board column is centred on every screen size (the old two-column layout for wide
   screens left room for a setup panel that now lives in Settings, so the board sat left of centre) */
.wrap{max-width:980px;margin:0 auto;padding:20px 14px 40px;display:grid;gap:22px;justify-content:center}
.board-col{display:grid;gap:10px;justify-items:start}

/* Keyboard focus ring, in the accent colour */
.sq:focus-visible,button:focus-visible,select:focus-visible,textarea:focus-visible,input:focus-visible{outline:3px solid var(--accent);outline-offset:-3px}

/* =====================================================================
   3. LOGO  ("play" light, "endgames" bold, "+" dark blue)
   ===================================================================== */
.logo{font:300 min(54px,11vw)/1 Inter,system-ui,-apple-system,"Segoe UI",sans-serif;letter-spacing:-.03em;color:var(--muted);white-space:nowrap;margin-bottom:12px}
.logo .lg-b{font-weight:800;color:var(--ink)}
.logo .lg-c{font-weight:800;color:var(--accent)}
.lg-tag{font:500 .8rem/1 Inter,system-ui,-apple-system,"Segoe UI",sans-serif;letter-spacing:.18em;color:var(--muted);margin-bottom:34px}

/* =====================================================================
   4. INFO PANEL  (above the board)
   Row of four stats: Moves, Accuracy, Evaluation, Time;
   then the move-rating tally and the scrolling move list.
   ===================================================================== */
.info{width:calc(var(--sq)*8);display:grid;gap:6px;padding:10px 12px;border:1px solid var(--line);border-radius:10px;background:var(--panel)}
.irow{display:grid;grid-template-columns:repeat(4,minmax(0,1fr));align-items:center;gap:4px;text-align:center;padding:6px 0}
.irow .lb{font:600 .85rem/1 Inter,system-ui,-apple-system,"Segoe UI",sans-serif;color:var(--muted);letter-spacing:0}

/* Each stat: small label on top, big number underneath (all four numbers in the same ink colour) */
.wc,#acc,.ev,#clock{display:flex;flex-direction:column;align-items:center;gap:4px;white-space:nowrap}
.wc,#clock{color:var(--ink);font:600 1.1rem/1 Inter,system-ui,sans-serif;font-variant-numeric:tabular-nums}
#clock{letter-spacing:.02em}
#clock[data-low] #clk{color:var(--err)}   /* Last 30 seconds of the countdown */
#clock[data-paused] #clk{opacity:.4}      /* Clock paused (Black thinking, Oops box, Restart question): figure dimmed, red too */
#wcn,#clk,#acc .vv,#evn{font:700 1.6rem/1 Inter,system-ui,sans-serif;font-variant-numeric:tabular-nums;color:var(--ink)}

/* Rating pills: Best, Excellent, Good, Inaccuracy, Mistake, Blunder */
.rt{display:inline-block;padding:3px 10px;border-radius:999px;color:#fff;font:700 .8rem/1.4 Inter,system-ui,-apple-system,"Segoe UI",sans-serif}
.rt.best{background:#178A6A;--c:#178A6A}
.rt.exc{background:#3A9A3A;--c:#3A9A3A}
.rt.good{background:#5B7C99;--c:#5B7C99}
.rt.inacc{background:#A67C00;--c:#A67C00}
.rt.mist{background:#C8621A;--c:#C8621A}
.rt.blun{background:#C03A36;--c:#C03A36}

/* Tally: 3 x 2 grid of pills counting this game's ratings */
#tally{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:6px;width:100%}
#tally .rt{min-width:0;text-align:center;padding:3px 4px;font-size:.75rem;white-space:nowrap}
#tally .rt.zero{opacity:.35}                    /* faded when the count is 0 */
#tally .rt.pop{animation:tpop .45s ease-out}   /* brief "pop" when a count goes up */
@keyframes tpop{
  0%{transform:scale(1);filter:brightness(1);box-shadow:0 0 0 0 var(--c)}
  35%{transform:scale(1.18);filter:brightness(1.25);box-shadow:0 0 0 5px color-mix(in srgb,var(--c) 35%,transparent)}
  100%{transform:scale(1);filter:brightness(1);box-shadow:0 0 0 0 transparent}
}
@media (prefers-reduced-motion:reduce){#tally .rt.pop{animation:none}}

/* Status line under the panel ("Your move", "Thinking…", hints) */
/* Move-rating squares under the status line: 🟩 🟨 🟥, wrapping onto a new line when long */
#mrow{width:calc(var(--sq)*8);min-height:1.4em;font-size:1.05rem;line-height:1.4;letter-spacing:1px;word-break:break-all}
#status{width:calc(var(--sq)*8);text-align:left;color:var(--muted);font-size:.9rem;font-weight:600;min-height:1.3em}

/* "Oh no…" box: covers the info panel at the top, same size, when your move turns
   a winning position into a draw or a loss. Takeback button (Restart once none are left). */
.info{position:relative}
#slip,#rsc{position:absolute;top:-1px;left:-1px;right:-1px;min-height:calc(100% + 2px);z-index:3;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:6px;padding:8px 12px;border:2px solid var(--accent);border-radius:10px;background:var(--panel);text-align:center;animation:slipin .25s ease-out}
#slip[hidden],#rsc[hidden]{display:none}
#slip .sl-h,#rsc .sl-h{margin:0;text-wrap:balance;font:700 1.25rem/1.25 Inter,system-ui,-apple-system,"Segoe UI",sans-serif;letter-spacing:-.01em;color:var(--ink)}
#slip .sl-h svg{display:inline-block;vertical-align:-4px;margin-right:4px;color:var(--accent)}
#slip .sl-s,#rsc .sl-s{margin:-2px 0 2px;text-wrap:balance;font:500 1rem/1.3 Inter,system-ui,-apple-system,"Segoe UI",sans-serif;color:var(--ink)}
#slip .sl-row,#rsc .sl-row{display:flex;gap:8px;width:100%;justify-content:center}
#slip .st-btn,#rsc .st-btn{width:auto;flex:1 1 0;max-width:200px;height:42px;margin:0;padding:0 12px;font-size:.95rem;display:inline-flex;align-items:center;justify-content:center;gap:6px;white-space:nowrap}
#endbox #slip,#endbox #rsc{display:none}   /* never on the result screen */
@keyframes slipin{from{opacity:0;transform:scale(.97)}to{opacity:1;transform:none}}
@media (prefers-reduced-motion:reduce){#slip{animation:none}}

/* =====================================================================
   5. BOARD
   An 8 x 8 grid of buttons, one per square. Pieces are SVG images.
   ===================================================================== */
.bw{display:flex;flex-direction:column;gap:8px}
#board{display:grid;grid-template-columns:repeat(8,var(--sq));grid-template-rows:repeat(8,var(--sq));border-radius:3px;overflow:hidden;touch-action:manipulation}

/* A square */
.sq{position:relative;width:var(--sq);height:var(--sq);border:0;margin:0;padding:0;cursor:pointer;line-height:1;display:flex;align-items:center;justify-content:center;color:inherit}
.sq.l{background:var(--light)}
.sq.d{background:var(--dark)}

/* Highlights drawn underneath the piece */
.sq.last::before,.sq.lastb::before,.sq.sel::before,.sq.chk::before{content:"";position:absolute;inset:0}
.sq.last::before{background:var(--last)}   /* White's last move, hint, or White's best move */
.sq.lastb::before{background:var(--lastb)} /* Black's last move */
.sq.sel::before{background:var(--sel)}     /* selected piece */
.sq.pre::before,.sq.presel::before{content:"";position:absolute;inset:0;background:var(--pre)}   /* premove (set, or piece picked for one) */
.sq.chk::before{background:radial-gradient(circle,var(--check),transparent 75%)}  /* king in check */

/* Pieces: Lichess "cburnett" SVG images (defined in the script), filling the square */
.sq .pc{position:relative;z-index:1;display:block;width:100%;height:100%;pointer-events:none;user-select:none;-webkit-user-drag:none}

/* Legal-move markers: dot on an empty square, ring on a capture */
.sq.dot::after{content:"";position:absolute;width:30%;height:30%;border-radius:50%;background:var(--dot);z-index:2}
.sq.cap::after{content:"";position:absolute;inset:6%;border-radius:50%;border:4px solid var(--dot);z-index:2}

/* Rank numbers (right edge) and file letters (bottom edge) */
.co{display:block;position:absolute;font:700 11px/1 Inter,system-ui,sans-serif;z-index:2;pointer-events:none}
.co.r{top:3px;right:4px}
.co.f{bottom:3px;left:4px}
.sq.l .co{color:color-mix(in srgb,var(--dark) 55%,#000)}
.sq.d .co{color:color-mix(in srgb,var(--light) 75%,#fff)}

/* =====================================================================
   6. TOP BAR AND ICON BUTTONS
   Restart and Home above the info panel; the square icon button style (.gear)
   used for every corner button.
   ===================================================================== */
/* Top bar above the info panel: Home on the right, dark blue outline like the start screen's account button */
.topbar{width:calc(var(--sq)*8);display:flex;justify-content:space-between}   /* Restart on the left, Home on the right */
.topbar .gear{border-color:var(--accent);color:var(--accent)}
.topbar .tb-r{display:flex;gap:8px}   /* favourite heart and Home together on the right (v3.6) */
.gear.fav[hidden]{display:none}   /* no heart for positions without a code */
.gear.fav.on svg{fill:currentColor}   /* filled heart: a favourite */
.topbar{position:relative}
.favmsg{position:absolute;right:0;top:calc(100% + 6px);z-index:20;max-width:90%;margin:0;padding:8px 12px;border:1px solid var(--line);border-radius:10px;background:var(--panel);color:var(--ink);font-size:.85rem;box-shadow:0 4px 14px rgba(0,0,0,.12)}
.favmsg[hidden]{display:none}
.pk .nm .fh{color:var(--accent);margin-right:4px}   /* heart before a favourite's name in Choose endgame */
.gear{flex:none;display:grid;place-items:center;width:40px;height:40px;padding:0;border-radius:10px;border:1px solid var(--line);background:var(--panel);color:var(--ink);cursor:pointer}
.gear:disabled{opacity:.4;cursor:default}
#rs{position:relative}
/* small blue badge: tries so far, on the Restart button */
.ub{position:absolute;top:-5px;right:-5px;min-width:17px;height:17px;padding:0 4px;border-radius:9px;background:var(--accent);color:var(--onaccent);font:700 11px/17px Inter,system-ui,sans-serif;text-align:center;pointer-events:none}

/* "See result" button, shown after the game ends and the result screen is closed */
.seeres{justify-self:start;font:inherit;font-weight:600;padding:8px 20px;border:1.5px solid var(--accent);border-radius:999px;background:var(--panel);color:var(--accent);cursor:pointer}

/* =====================================================================
   7. SETUP PANEL AND FORM CONTROLS
   FEN box, examples, side, strength, current FEN.
   Shown on the Settings screen, opened from the start screen.
   ===================================================================== */
/* The panel sits inside the Settings screen (see section 8) */
.panel{background:var(--panel);border:1px solid var(--line);border-radius:10px;padding:14px;display:grid;gap:12px}
.row{display:flex;flex-wrap:wrap;gap:8px}
.opts{display:grid;grid-template-columns:repeat(auto-fit,minmax(130px,1fr));gap:10px}
label{display:grid;gap:4px;font-size:.9rem;color:var(--muted)}
textarea,select,input{font:inherit;color:var(--ink);background:var(--bg);border:1px solid var(--line);border-radius:8px;padding:8px 10px;width:100%}
button.btn{font:inherit;font-weight:600;padding:9px 14px;border-radius:8px;border:1px solid var(--line);background:var(--panel);color:var(--ink);cursor:pointer}
button.btn.go{background:var(--accent);border-color:var(--accent);color:var(--onaccent)}  /* main action, e.g. "Load position" */

/* =====================================================================
   8. FULL-SCREEN OVERLAYS  (start screen and end-of-game screen)
   ===================================================================== */
#start,#end,#about,#settings,#howto{position:fixed;inset:0;justify-content:center;align-items:flex-start;padding:max(calc(env(safe-area-inset-top,0px) + 88px),18vh) 24px max(24px,env(safe-area-inset-bottom,0px));overflow:auto;background:var(--bg);color:var(--ink);text-align:center}

/* Pill buttons used on both screens */
.st-btn{width:min(230px,100%);height:48px;border-radius:999px;font:600 1.05rem/1 Inter,system-ui,-apple-system,"Segoe UI",sans-serif;cursor:pointer}
.st-play{border:1.5px solid var(--accent);background:var(--accent);color:var(--onaccent)}   /* filled, blue: the main action */
.st-alt{margin-top:12px;border:1.5px solid var(--ink);background:transparent;color:var(--ink)}  /* outline */
.st-share{margin-top:2px;padding:8px;border:0;background:none;color:var(--accent);font:600 1rem/1 Inter,system-ui,sans-serif;text-decoration:underline;text-underline-offset:3px;cursor:pointer}  /* text link */

/* --- Start screen: logo, streak message, Play / Choose a position, date and puzzle number --- */
#start{z-index:60;display:flex}
#start.gone{display:none}
#start .st-in{width:min(420px,100%);display:flex;flex-direction:column;align-items:center}
/* Account button (placeholder until user accounts exist): top-right corner, dark blue outline */
#start .acct{position:fixed;top:calc(env(safe-area-inset-top,0px) + 14px);right:calc(env(safe-area-inset-right,0px) + 14px);z-index:1;border-color:var(--accent);color:var(--accent)}
/* The big streak sentence is gone; a small streak line sits under the position instead */
#st-streak{margin-top:2px;font-size:.95rem;color:var(--muted)}
#st-streak.due{color:var(--ink);font-weight:700}   /* not played yet today: a gentle nudge */
#start .st-meta{margin-top:34px;line-height:1.5}
#st-date{font-weight:600}
#st-by{color:var(--muted)}   /* "Set up by Rob", under the position's description (v3.8) */
/* The start-screen description is hidden on screen but kept for search engines and screen readers */
.sr-only{position:absolute;width:1px;height:1px;margin:-1px;padding:0;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap;border:0}
#st-no{color:var(--muted)}
#start .st-about{margin-top:18px;font-size:.9rem}   /* "About" link under the description */
h1.logo{margin-top:0}                                 /* h1 keeps the logo's size and spacing */
#start .st-desc{max-width:320px;margin:26px auto 0;font-size:.85rem;line-height:1.45;color:var(--muted)}   /* plain description */

/* --- End-of-game screen: result, reason, info panel (moved in by script), streak, buttons --- */
#end{z-index:50;display:none}
#end.show{display:flex}
#end .ab-x{position:fixed;top:calc(env(safe-area-inset-top,0px) + 14px);right:calc(env(safe-area-inset-right,0px) + 14px);z-index:1}   /* Home, top-right */
#end .end-fav{position:fixed;z-index:1;display:flex}   /* the favourites heart, just left of Home (v3.7); placed with the corner buttons below */
#end .end-fav .favmsg{width:max-content;max-width:min(320px,80vw)}   /* its message, under the heart */
#end .card{width:min(420px,100%);display:flex;flex-direction:column;align-items:center}
#end .lg-tag{margin-bottom:16px}
#end h2{margin:0 0 8px;font:800 2.4rem/1.1 Inter,system-ui,sans-serif;letter-spacing:-.03em}         /* "Win 3rd try" / "Draw 1st try" */
#end h2 .try{font-weight:300}                   /* try number in the light weight, as "play" in the logo */
#end #endd{margin:0 0 14px;color:var(--ink);font:400 1.3rem/1.3 Inter,system-ui,sans-serif}          /* "Checkmate" etc. */
#end #endbox{width:100%;margin-bottom:14px}
#endbox .info{width:100%}
#endbox .ev{display:none}                              /* evaluation repeats the result, so hidden here */
#endbox .irow{grid-template-columns:repeat(3,minmax(0,1fr))}
/* +rating: overall game score, first row of the result box. Result screen only. */
/* Label and number on one line, in the same styles as the Accuracy label and figure */
.plus{display:none;justify-content:center;align-items:baseline;gap:8px;width:100%;padding:6px 0;white-space:nowrap}
.plus .lb{font:700 1.6rem/1 Inter,system-ui,sans-serif;color:var(--ink)}   /* "+rating" in the same font as the score */
.plus .pl{color:var(--accent);font-weight:800}
#plusn{font:700 1.6rem/1 Inter,system-ui,sans-serif;font-variant-numeric:tabular-nums;color:var(--ink)}
#endbox .plus{display:flex}
/* "Today's best 92" under +rating on the result screen (from the 2nd try at today's position) */
.dbest{display:none}
#endbox .dbest:not([hidden]){display:block;margin:-4px 0 2px;text-align:center;font-size:.9rem;font-weight:600;color:var(--muted)}
#end #ends{display:none}  /* time line: used by Share, not shown */
#end #ende{margin:0;color:var(--ink);font:400 1.3rem/1.3 Inter,system-ui,sans-serif}               /* streak line */
#end #ende b{font-weight:800}
#end .row{width:100%;flex-direction:column;align-items:center;justify-content:center;gap:8px;margin-top:16px}
#end .st-btn{height:44px}
#end #endagain{margin-top:0}
#endshare{display:inline-flex;align-items:center;justify-content:center;gap:10px}   /* "Share" then the icon */
#end .st-watch{margin-top:10px;font-size:.9rem}   /* "Watch solution" text link, styled like "About" on the start screen */
#end .st-watch[hidden]{display:none}

/* --- About screen: version, credits, collapsible licence texts --- */
#about{z-index:70;display:none}                 /* sits above every other screen */
#about.show{display:flex}
#about .ab-x{position:fixed;top:calc(env(safe-area-inset-top,0px) + 14px);right:calc(env(safe-area-inset-right,0px) + 14px);z-index:1}   /* top-right close button */
#about .card{width:min(420px,100%);display:flex;flex-direction:column;align-items:center}
#about .lg-tag{margin-bottom:16px}
#about h2{margin:0 0 8px;font:800 2.4rem/1.1 Inter,system-ui,sans-serif;letter-spacing:-.03em}
#about h3{align-self:stretch;margin:22px 0 8px;font:600 .8rem/1 Inter,system-ui,sans-serif;letter-spacing:.14em;text-transform:uppercase;color:var(--muted);text-align:left}
.ab-lead{margin:0 0 8px;font:400 1.1rem/1.4 Inter,system-ui,sans-serif}
.ab-ver{margin:0;color:var(--muted);font-size:.9rem;font-variant-numeric:tabular-nums}
/* Credits list: label on the left, detail underneath */
.ab-cred{align-self:stretch;margin:0;display:grid;gap:8px;text-align:left}
.ab-cred div{padding:10px 12px;border:1px solid var(--line);border-radius:10px;background:var(--panel)}
.ab-cred dt{font-weight:600;font-size:.95rem}
.ab-cred dd{margin:2px 0 0;color:var(--muted);font-size:.9rem}
/* Licence texts: tap a heading to expand */
.ab-lic{align-self:stretch;margin-bottom:8px;border:1px solid var(--line);border-radius:10px;background:var(--panel);text-align:left}
.ab-lic summary{padding:10px 12px;font-weight:600;font-size:.95rem;cursor:pointer}
.ab-lic summary::marker{color:var(--accent)}
.ab-lic pre{margin:0;padding:0 12px 12px;white-space:pre-wrap;font:400 .72rem/1.45 Inter,system-ui,sans-serif;color:var(--muted)}
#about .row{width:100%;flex-direction:column;align-items:center;margin-top:16px}
#about .st-btn{height:44px}

/* --- How to play screen: same layout as About. Opened from the "?" button on the
   start screen and the link on About; opens by itself on the first visit ("pe-howto") --- */
#howto{z-index:72;display:none}                 /* above About, so the link on About opens on top */
#howto.show{display:flex}
#howto .ab-x{position:fixed;top:calc(env(safe-area-inset-top,0px) + 14px);right:calc(env(safe-area-inset-right,0px) + 14px);z-index:1}
#howto .card{width:min(420px,100%);display:flex;flex-direction:column;align-items:center}
#howto .lg-tag{margin-bottom:16px}
#howto h2{margin:0 0 8px;font:800 2.4rem/1.1 Inter,system-ui,sans-serif;letter-spacing:-.03em}
#howto .ab-cred{margin-top:8px}
#howto .row{width:100%;flex-direction:column;align-items:center;margin-top:16px}
#howto .st-btn{height:44px}
/* "?" button: top-left of the start screen, opposite the account button */
#start .help{position:fixed;top:calc(env(safe-area-inset-top,0px) + 14px);left:calc(env(safe-area-inset-left,0px) + 14px);z-index:1;border-color:var(--accent);color:var(--accent)}
#about .ab-how{margin:2px 0 0;font-size:.9rem}   /* "New here? How to play" link on About */
#about .ab-priv{margin-top:14px;font-size:.9rem}   /* "Privacy policy" link at the bottom of About (privacy.html) */

/* --- Settings screen: same layout as About, holding the setup panel --- */
#settings{z-index:65;display:none}              /* above the start screen, below About */
#settings.show{display:flex}
#settings .ab-x{position:fixed;top:calc(env(safe-area-inset-top,0px) + 14px);right:calc(env(safe-area-inset-right,0px) + 14px);z-index:1}
#settings .card{width:min(420px,100%);display:flex;flex-direction:column;align-items:center}
#settings .lg-tag{margin-bottom:16px}
#settings h2{margin:0 0 8px;font:800 2.4rem/1.1 Inter,system-ui,sans-serif;letter-spacing:-.03em}
/* Account box (js/account.js): above the settings, same panel style */
#settings .acct-box{width:100%;margin-bottom:12px;text-align:left}
#settings .acct-box h3{margin:0;font:700 1rem/1.2 Inter,system-ui,sans-serif;color:var(--ink)}
#settings .acct-box form,#acct-out,#acct-sent,#acct-in{display:grid;gap:10px}
#settings .acct-box [hidden]{display:none}
.acct-p{margin:0;font-size:.9rem;line-height:1.4;color:var(--ink)}
.acct-small{color:var(--muted);font-size:.85rem}
.acct-p b{overflow-wrap:anywhere}
.acct-link{color:var(--accent);font-weight:600;text-underline-offset:3px}
#acct-msg:empty{display:none}
#acct-msg.bad{color:var(--err);font-weight:600}
#settings .acct-box button.btn{width:100%}
#settings .acct-box button:disabled{opacity:.6;cursor:default}
/* First name (v3.4): greeting, the "What should we call you?" form and the "Change name" link */
.acct-hi{font-weight:700;font-size:1rem}
.acct-lb{background:none;border:0;padding:0;font:inherit;font-weight:600;text-decoration:underline;cursor:pointer}
#st-hello{font-weight:700;color:var(--accent)}
#settings .panel{width:100%;text-align:left}
/* Settings: one setting per line */
#settings .opts{grid-template-columns:1fr;gap:12px}
#settings > .card > .row{width:100%;flex-direction:column;align-items:center;margin-top:16px}
#settings .st-btn{height:44px}

/* --- Position picker: a small board for each example position (from "Choose a position") --- */
#pick{position:fixed;inset:0;z-index:65;display:none;justify-content:center;align-items:flex-start;padding:max(calc(env(safe-area-inset-top,0px) + 72px),12vh) 18px max(24px,env(safe-area-inset-bottom,0px));overflow:auto;background:var(--bg);color:var(--ink);text-align:center}
#pick.show{display:flex}
#pick .ab-x{position:fixed;top:calc(env(safe-area-inset-top,0px) + 14px);right:calc(env(safe-area-inset-right,0px) + 14px);z-index:1}
#pick .card{width:min(520px,100%);display:flex;flex-direction:column;align-items:center}
#pick h2{margin:0 0 6px;font:800 2.2rem/1.1 Inter,system-ui,sans-serif;letter-spacing:-.03em}
#pick .pk-sub{margin:0 0 18px;color:var(--muted);font-size:.9rem}
#pick-grid{width:100%;display:grid;grid-template-columns:repeat(auto-fill,minmax(140px,1fr));gap:14px}
.pk{display:flex;flex-direction:column;gap:6px;padding:8px;border:1px solid var(--line);border-radius:12px;background:var(--panel);color:var(--ink);font:inherit;cursor:pointer;text-align:left}
.pk:hover{border-color:var(--accent)}
.pk .mb{display:grid;grid-template-columns:repeat(8,1fr);aspect-ratio:1;width:100%;border-radius:4px;overflow:hidden}
.pk .mb i{position:relative;display:block}
.pk .mb i.l{background:var(--light)} .pk .mb i.d{background:var(--dark)}
.pk .mb img{position:absolute;inset:0;width:100%;height:100%}
.pk .nm{font-weight:700;font-size:.9rem;line-height:1.25;display:-webkit-box;-webkit-box-orient:vertical;-webkit-line-clamp:2;line-clamp:2;overflow:hidden;overflow-wrap:anywhere}   /* never more than two lines (v3.8) */
.pk .nm .pe{display:inline-grid;place-items:center;width:22px;height:22px;margin:-3px 0 -6px 2px;border-radius:6px;color:var(--accent);vertical-align:middle;cursor:pointer}   /* edit pencil after the name: positions you set up */
.pk .nm .pe:hover,.pk .nm .pe:focus-visible{background:var(--line);outline:none}
.pk .tm.by{color:var(--accent);font-weight:600}   /* "Set up by you" */
.pk.editing{cursor:default}
.pk.editing input{width:100%;box-sizing:border-box;padding:6px 8px;border:1px solid var(--accent);border-radius:8px;background:var(--bg);color:var(--ink);font:600 .9rem/1.25 Inter,system-ui,sans-serif}
.pk.editing input:focus{outline:none;box-shadow:0 0 0 2px color-mix(in srgb,var(--accent) 25%,transparent)}
.pk.editing .pe-row{display:flex;gap:6px}
.pk.editing .pe-row button{flex:1;height:32px;border-radius:8px;border:1px solid var(--line);background:var(--panel);color:var(--ink);font:600 .8rem Inter,system-ui,sans-serif;cursor:pointer}
.pk.editing .pe-row .pe-save{background:var(--accent);border-color:var(--accent);color:#fff}
.pk.editing .pe-err{margin:0;font-size:.75rem;color:var(--muted)}
.pk .tm{font-size:.78rem;color:var(--muted)}
.pk.own{align-items:center;justify-content:center;min-height:120px;border-style:dashed;text-align:center}

/* --- Board editor: tap a piece in the tray, then tap squares --- */
#edit{position:fixed;inset:0;z-index:66;display:none;justify-content:center;align-items:flex-start;padding:max(calc(env(safe-area-inset-top,0px) + 64px),9vh) 14px max(24px,env(safe-area-inset-bottom,0px));overflow:auto;background:var(--bg);color:var(--ink);text-align:center}
#edit.show{display:flex}
#edit .ab-x{position:fixed;top:calc(env(safe-area-inset-top,0px) + 14px);right:calc(env(safe-area-inset-right,0px) + 14px);z-index:1}
/* On short screens the board and tray shrink so the Play button stays on screen */
#edit .card{width:min(420px,100%,calc((100vh - 260px) / 1.3));width:min(420px,100%,calc((100svh - 260px) / 1.3));display:flex;flex-direction:column;align-items:center;gap:12px}
#edit h2{margin:0;font:800 2rem/1.1 Inter,system-ui,sans-serif;letter-spacing:-.03em}
#ed-board{display:grid;grid-template-columns:repeat(8,1fr);width:100%;aspect-ratio:1;border-radius:3px;overflow:hidden;touch-action:manipulation}
#ed-board button{position:relative;border:0;margin:0;padding:0;cursor:pointer}
#ed-board button.l{background:var(--light)} #ed-board button.d{background:var(--dark)}
#ed-board img{position:absolute;inset:0;width:100%;height:100%;pointer-events:none}
#ed-board .co{color:inherit}
#ed-board button.l .co{color:color-mix(in srgb,var(--dark) 55%,#000)} #ed-board button.d .co{color:color-mix(in srgb,var(--light) 75%,#fff)}
.ed-tray{display:grid;grid-template-columns:repeat(7,1fr);gap:6px;width:100%}
.ed-tray button{aspect-ratio:1;border:1px solid var(--line);border-radius:10px;background:var(--panel);padding:2px;cursor:pointer;display:grid;place-items:center;color:var(--ink)}
.ed-tray button img{width:100%;height:100%}
.ed-tray button[aria-pressed="true"]{border:2px solid var(--accent);background:color-mix(in srgb,var(--accent) 14%,var(--panel))}
.ed-row{display:flex;flex-wrap:wrap;gap:8px;justify-content:center;width:100%}
.ed-row select{width:auto}
#edit .ed-sub{margin:-6px 0 0;color:var(--muted);font-size:.9rem}
#edit .ed-note{margin:0;max-width:340px;color:var(--muted);font-size:.8rem;line-height:1.4}   /* positions may become daily ones (v3.8) */
.ed-tray button.ed-clear{font:600 .72rem/1 Inter,system-ui,sans-serif}
#ed-msg{min-height:1.3em;margin:0;font-size:.9rem;font-weight:600;color:var(--muted)}
#ed-msg.bad{color:var(--err)}
#ed-fen{font-size:.8rem}
/* Paste a FEN straight onto the editor board */
.ed-lbl{width:100%;margin:4px 0 -2px;text-align:left;font-size:.85rem;color:var(--muted)}
#edit .st-btn{height:44px}

/* Corner buttons line up with the game screen's Restart and Home buttons on every screen:
   the same distance from the top, and at the edges of a board-wide strip in the middle of the
   screen (instead of the far corners of a laptop or iPad screen). On a phone this is about where
   they were before. */
#start .acct,#start .help,#end .ab-x,#about .ab-x,#settings .ab-x,#pick .ab-x,#edit .ab-x,#howto .ab-x{top:calc(env(safe-area-inset-top,0px) + 20px)}
#start .acct,#end .ab-x,#about .ab-x,#settings .ab-x,#pick .ab-x,#edit .ab-x,#howto .ab-x{right:calc(50% - var(--sq) * 4)}
#start .help{left:calc(50% - var(--sq) * 4)}
#end .end-fav{top:calc(env(safe-area-inset-top,0px) + 20px);right:calc(50% - var(--sq) * 4 + 48px)}   /* heart: Home's width (40px) and an 8px gap to the left of Home */
