/*!
 * MBG Puzzles - game screen styles (mobile first), shared by Codebreaker and Word Puzzle.
 * Layout: one calm screen. A slim top bar (language flag, Help, Settings), the board with
 * the current round's tile rows, and the command deck (status line, input, actions)
 * at the bottom within thumb reach. Everything else opens in a dialog on demand.
 */

@font-face { font-family: 'Unbounded'; font-weight: 700; font-style: normal; font-display: swap;
  src: url('../fonts/Unbounded-Bold.woff2') format('woff2'); }
@font-face { font-family: 'Atkinson Hyperlegible'; font-weight: 400; font-style: normal; font-display: swap;
  src: url('../fonts/AtkinsonHyperlegible-Regular.woff2') format('woff2'); }
@font-face { font-family: 'Atkinson Hyperlegible'; font-weight: 700; font-style: normal; font-display: swap;
  src: url('../fonts/AtkinsonHyperlegible-Bold.woff2') format('woff2'); }
@font-face { font-family: 'Atkinson Hyperlegible Mono'; font-weight: 700; font-style: normal; font-display: swap;
  src: url('../fonts/AtkinsonHyperlegibleMono-Bold.woff2') format('woff2'); }

/* ---------------------------------------------------------------- tokens */
:root {
  --font-display: 'Unbounded', 'Arial Black', 'Segoe UI', system-ui, sans-serif;
  --font-body: 'Atkinson Hyperlegible', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'Atkinson Hyperlegible Mono', ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  --fs: 17px;
  --radius: 12px;
  --tile-gap: 5px;
  --ease: cubic-bezier(.2, .8, .2, 1);

  /* "Porcelain" light palette */
  --bg: #E6EBEF;
  --surface: #F4F7F9;
  --card: #FFFFFF;
  --ink: #15202B;
  --muted: #4E5B68;
  --line: #C6CFD7;
  --accent: #0E5D66;
  --on-accent: #FFFFFF;
  --accent-soft: #D3E7E9;
  --brand: #B4172F;
  --hit: #1E7B4E;
  --on-hit: #FFFFFF;
  --near: #D69512;
  --on-near: #1B1406;
  --miss: #677381;
  --on-miss: #FFFFFF;
  --warn-bg: #FFF2CF;
  --warn-ink: #5A3E00;
  --warn-line: #E6C468;
  --focus: #1565C0;
  --scrim: rgba(10, 16, 22, .55);
  --shadow: 0 10px 30px rgba(15, 25, 35, .18);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0E1419; --surface: #141C23; --card: #1A242D; --ink: #E6ECF1; --muted: #9EABB8; --line: #2C3843;
    --accent: #3DB4A6; --on-accent: #04201C; --accent-soft: #16353A; --brand: #FF6B7E;
    --hit: #238452; --on-hit: #FFFFFF; --near: #E3A82F; --on-near: #1B1406; --miss: #4A5662; --on-miss: #F2F5F7;
    --warn-bg: #3A2E0F; --warn-ink: #F6DB93; --warn-line: #6E5718; --focus: #8CC2FF;
    --scrim: rgba(0, 0, 0, .65); --shadow: 0 10px 30px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0E1419; --surface: #141C23; --card: #1A242D; --ink: #E6ECF1; --muted: #9EABB8; --line: #2C3843;
  --accent: #3DB4A6; --on-accent: #04201C; --accent-soft: #16353A; --brand: #FF6B7E;
  --hit: #238452; --on-hit: #FFFFFF; --near: #E3A82F; --on-near: #1B1406; --miss: #4A5662; --on-miss: #F2F5F7;
  --warn-bg: #3A2E0F; --warn-ink: #F6DB93; --warn-line: #6E5718; --focus: #8CC2FF;
  --scrim: rgba(0, 0, 0, .65); --shadow: 0 10px 30px rgba(0, 0, 0, .5);
  color-scheme: dark;
}

/* Skins chosen with "Toggle Background" (FR-UI-011/012). They win over the system theme. */
:root[data-skin="light"] {
  --bg: #E6EBEF; --surface: #F4F7F9; --card: #FFFFFF; --ink: #15202B; --muted: #4E5B68; --line: #C6CFD7;
  --accent: #0E5D66; --on-accent: #FFFFFF; --accent-soft: #D3E7E9; --brand: #B4172F;
  --hit: #1E7B4E; --on-hit: #FFFFFF; --near: #D69512; --on-near: #1B1406; --miss: #677381; --on-miss: #FFFFFF;
  --warn-bg: #FFF2CF; --warn-ink: #5A3E00; --warn-line: #E6C468; --focus: #1565C0;
  --scrim: rgba(10, 16, 22, .55); --shadow: 0 10px 30px rgba(15, 25, 35, .18);
  color-scheme: light;
}
:root[data-skin="dark"] {
  --bg: #0E1419; --surface: #141C23; --card: #1A242D; --ink: #E6ECF1; --muted: #9EABB8; --line: #2C3843;
  --accent: #3DB4A6; --on-accent: #04201C; --accent-soft: #16353A; --brand: #FF6B7E;
  --hit: #238452; --on-hit: #FFFFFF; --near: #E3A82F; --on-near: #1B1406; --miss: #4A5662; --on-miss: #F2F5F7;
  --warn-bg: #3A2E0F; --warn-ink: #F6DB93; --warn-line: #6E5718; --focus: #8CC2FF;
  --scrim: rgba(0, 0, 0, .65); --shadow: 0 10px 30px rgba(0, 0, 0, .5);
  color-scheme: dark;
}
:root[data-skin="adriatic"] {
  --bg: #0A2E3E; --surface: #0E394C; --card: #124459; --ink: #F0F7FA; --muted: #B3CCD7; --line: #2A6680;
  --accent: #7FD3C6; --on-accent: #052A26; --accent-soft: #1A5468; --brand: #FF9AA4;
  --hit: #238452; --on-hit: #FFFFFF; --near: #F0B23F; --on-near: #2A1B00; --miss: #50707F; --on-miss: #FFFFFF;
  --warn-bg: #4A3A12; --warn-ink: #FBE3A6; --warn-line: #8A6C1E; --focus: #FFE08A;
  --scrim: rgba(2, 14, 20, .65); --shadow: 0 10px 30px rgba(0, 0, 0, .45);
  color-scheme: dark;
}
:root[data-skin="meadow"] {
  --bg: #E1ECDB; --surface: #EEF5EA; --card: #FBFDF9; --ink: #142417; --muted: #465A4A; --line: #B8CDB1;
  --accent: #2F558F; --on-accent: #FFFFFF; --accent-soft: #D6E2F2; --brand: #A8192F;
  --hit: #1E7B4E; --on-hit: #FFFFFF; --near: #CC8C0C; --on-near: #1B1406; --miss: #66756A; --on-miss: #FFFFFF;
  --warn-bg: #FFF1C9; --warn-ink: #5A3E00; --warn-line: #E0C164; --focus: #2F558F;
  --scrim: rgba(12, 24, 14, .5); --shadow: 0 10px 30px rgba(20, 36, 23, .16);
  color-scheme: light;
}
:root[data-skin="rose"] {
  --bg: #F4E5E8; --surface: #FAF0F2; --card: #FFFFFF; --ink: #2A1519; --muted: #69474F; --line: #DEC0C7;
  --accent: #8C1D3B; --on-accent: #FFFFFF; --accent-soft: #F2D6DD; --brand: #8C1D3B;
  --hit: #1E7B4E; --on-hit: #FFFFFF; --near: #CC8C0C; --on-near: #1B1406; --miss: #786870; --on-miss: #FFFFFF;
  --warn-bg: #FFF0CC; --warn-ink: #5A3E00; --warn-line: #E2C36A; --focus: #1565C0;
  --scrim: rgba(30, 10, 14, .5); --shadow: 0 10px 30px rgba(42, 21, 25, .16);
  color-scheme: light;
}

/* ------------------------------------------------------------------ base */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: var(--fs);
  line-height: 1.45;
  overflow: hidden;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; }
button:disabled { cursor: not-allowed; }
svg { width: 1.2em; height: 1.2em; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8;
  stroke-linecap: round; stroke-linejoin: round; }
svg .fill { fill: currentColor; stroke: none; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
[hidden] { display: none !important; }

/* ---------------------------------------------------------------- layout */
.app {
  position: fixed;
  top: 0; bottom: 0; left: 0; right: 0;
  margin: 0 auto;
  width: 100%;
  max-width: 760px;
  display: grid;
  grid-template-columns: minmax(0, 1fr);      /* never wider than the screen, whatever the content */
  grid-template-areas: "top" "status" "board" "entry" "actions";
  grid-template-rows: auto auto minmax(0, 1fr) auto auto;
  gap: 10px;
  padding-block: max(10px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-bottom));
  padding-inline: max(16px, env(safe-area-inset-left)) max(16px, env(safe-area-inset-right));
}
.grow { flex: 1; min-width: 4px; }
.topbar { grid-area: top; }
.status { grid-area: status; }
.boardcard { grid-area: board; }
#entryForm { grid-area: entry; }
.actions { grid-area: actions; }

/* top bar */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 44px; }
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.mark { display: flex; gap: 3px; flex: none; }
.mt {
  display: inline-grid; place-items: center;
  width: 24px; height: 27px; border-radius: 6px;
  font: 700 13px/1 var(--font-display);
}
.mt.o { background: var(--hit); color: var(--on-hit); }
.mt.q { background: var(--near); color: var(--on-near); }
.mt.x { background: var(--miss); color: var(--on-miss); }
.brandtext { display: none; flex-direction: column; min-width: 0; }
.appname { font: 700 16px/1.15 var(--font-display); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.appby { font-size: 12px; color: var(--muted); letter-spacing: .04em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tools { display: flex; align-items: center; gap: 6px; flex: none; }

/* icon button */
.ib {
  display: inline-grid; place-items: center;
  width: 44px; height: 44px; padding: 0;
  border: 1px solid var(--line); border-radius: 12px;
  background: var(--surface); color: var(--ink);
  transition: background .15s, border-color .15s, transform .1s;
}
.ib svg { width: 21px; height: 21px; }
.ib:active:not(:disabled) { transform: scale(.95); }
.ib:disabled { opacity: .4; }
.ib.font { font: 700 16px/1 var(--font-display); }

/* language: a stack of round flags ("coins") - the language in use in front,
   the other two peeking out behind it; tapping opens the language sheet */
.ib.langbtn { width: 66px; border-radius: 22px; padding: 0; }
.langbtn .coins { position: relative; display: block; width: 50px; height: 28px; }
.langbtn .coin {
  position: absolute; top: 50%; display: block; overflow: hidden; border-radius: 50%;
  background: var(--surface);
  box-shadow: 0 0 0 2px var(--surface), 0 1px 3px rgba(0, 0, 0, .28);
}
.langbtn .coin svg, .lm-flag svg { display: block; width: 100%; height: 100%; stroke: none; }
.langbtn .c0 { left: 0; width: 28px; height: 28px; margin-top: -14px; z-index: 3; }
.langbtn .c1 { left: 20px; width: 22px; height: 22px; margin-top: -11px; z-index: 2; }
.langbtn .c2 { left: 34px; width: 16px; height: 16px; margin-top: -8px; z-index: 1; }
.langbtn.flip .c0 { animation: coin-flip .45s var(--ease); }
@keyframes coin-flip { from { transform: rotateY(90deg) scale(.8); } }
@media (prefers-reduced-motion: reduce) { .langbtn.flip .c0 { animation: none; } }

.langmenu .sheet-head h2 { font-size: 17px; }
.lm-list { display: grid; gap: 10px; }
.lm-opt {
  display: flex; align-items: center; gap: 14px; width: 100%; min-height: 64px; padding: 10px 14px;
  border: 2px solid var(--line); border-radius: 14px; background: var(--surface); color: var(--ink);
  text-align: start; transition: border-color .15s, background .15s, transform .1s;
}
.lm-opt:active { transform: scale(.985); }
.lm-flag {
  flex: none; width: 44px; height: 44px; border-radius: 50%; overflow: hidden;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, .15), 0 2px 4px rgba(0, 0, 0, .18);
}
.lm-text { flex: 1; display: grid; gap: 1px; min-width: 0; }
/* each name keeps its own direction, but sits next to its flag: right in Arabic, left otherwise */
html[dir="rtl"] .lm-text { text-align: right; }
html:not([dir="rtl"]) .lm-text { text-align: left; }
.lm-text strong { font: 700 1.1em/1.2 var(--font-display); }
.lm-text small { color: var(--muted); font-size: .9em; }
.lm-check { flex: none; width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; visibility: hidden; background: var(--accent); color: var(--on-accent, #fff); }
.lm-check svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.lm-opt.on { border-color: var(--accent); background: var(--accent-soft); }
.lm-opt.on .lm-check { visibility: visible; }
@media (hover: hover) {
  .ib:hover:not(:disabled) { background: var(--card); border-color: var(--muted); }
  .lm-opt:hover { border-color: var(--accent); }
}

/* board: earlier tries scroll; the number or word being typed is pinned to the bottom edge,
   right above the input, so a phone keyboard never hides it */
.boardcard {
  display: flex; flex-direction: column; min-height: 0;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  overflow: hidden;
}
.history {
  position: relative; flex: 1 1 auto; min-height: 0;
  overflow-y: auto; overscroll-behavior: contain;
  padding: 14px 12px 8px;
  scroll-padding-bottom: 8px;
  -webkit-overflow-scrolling: touch;
}
.history:focus { outline: none; }
.log { display: flex; flex-direction: column; gap: 9px; }
.log:empty { display: none; }
.boardcard > .preview { flex: none; padding: 9px 12px 12px; border-top: 1px dashed var(--line); background: var(--card); }

/* brand watermark on a fresh board (no instructions, just the name) */
.watermark {
  position: absolute; inset: 0; display: none;
  flex-direction: column; align-items: center; justify-content: center; gap: 12px;
  padding: 16px; text-align: center; pointer-events: none; color: var(--muted);
}
.history.empty .watermark { display: flex; }
.mark.big { gap: 6px; opacity: .9; }
.mark.big .mt { width: 46px; height: 52px; font-size: 24px; border-radius: 11px; }
.wm-name { font: 700 clamp(17px, 5vw, 22px)/1.2 var(--font-display); color: var(--ink); opacity: .85; text-wrap: balance; }
.wm-by { font-size: 13px; letter-spacing: .04em; }
.compact .watermark { display: none !important; }

/* cards */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 14px; }
.legend { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.legend li { display: flex; align-items: center; gap: 10px; }

/* tiles */
.guess { display: grid; grid-template-columns: 1.7em minmax(0, 1fr); align-items: center; gap: 8px; }
.attempt { font: 700 .85em var(--font-mono); color: var(--muted); text-align: end;
  font-variant-numeric: tabular-nums; }
.tiles { display: flex; gap: var(--tile-gap); min-width: 0; perspective: 600px; }
.tile {
  flex: 0 1 3.2rem; min-width: 0;
  aspect-ratio: 1 / 1.12;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  border-radius: 9px;
  background: var(--miss); color: var(--on-miss);
  user-select: none;
}
.tile .ch {
  font: 700 min(calc(var(--fs) * 1.3), calc((100vw - 120px) / var(--len, 5) * .55))/1 var(--font-mono);
}
.tile .mk { font: 700 min(calc(var(--fs) * .72), 3.2vw)/1 var(--font-mono); margin-top: 3px; opacity: .92; }
.tile.o { background: var(--hit); color: var(--on-hit); }
.tile.q { background: var(--near); color: var(--on-near); }
.tile.x { background: var(--miss); color: var(--on-miss); }
.tile.plain { background: var(--accent-soft); color: var(--ink); }
.tile.sm { flex: none; width: 2.1em; aspect-ratio: auto; height: 2.1em; border-radius: 7px; }
.tile.sm .mk { font-size: 1em; margin: 0; }
.tile.anim { animation: flip .34s var(--ease) both; animation-delay: calc(var(--i) * 210ms); }
@keyframes flip { from { transform: rotateX(90deg); opacity: .2; } to { transform: none; opacity: 1; } }
.guess.won .tile .mk { font-family: var(--font-body); }

.preview .tile { background: transparent; color: var(--ink); border: 2px dashed var(--line); }
.preview .tile.filled { border-style: solid; border-color: var(--muted); }
.preview .tile.extra { border-color: var(--warn-line); background: var(--warn-bg); color: var(--warn-ink); }
.preview .tile .mk { visibility: hidden; }
.preview .attempt { opacity: .6; }
.preview.shake .tiles { animation: shake .32s var(--ease); }
@keyframes shake { 20% { transform: translateX(-5px); } 40% { transform: translateX(5px); } 60% { transform: translateX(-3px); } 80% { transform: translateX(3px); } }

/* win & reveal */
.win { display: grid; gap: 6px; }
.win-title { margin: 0; font: 700 clamp(15px, 4.9vw, 24px)/1.15 var(--font-display); color: var(--brand);
  letter-spacing: .01em; text-wrap: balance; overflow-wrap: break-word; }
.hearts { font-size: 1.3em; letter-spacing: .12em; line-height: 1.2; }
.hearts span { display: inline-block; animation: pop .5s var(--ease) both; animation-delay: calc(var(--i) * 70ms); }
@keyframes pop { from { transform: scale(.2); opacity: 0; } 70% { transform: scale(1.25); } to { transform: none; opacity: 1; } }
.win p, .reveal p { margin: 0; }
.luck { font-weight: 700; color: var(--accent); }
.scoreline { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; margin-top: 2px !important; }
.score-label { font-size: .85em; font-weight: 700; color: var(--muted); }
.num { font-family: var(--font-mono); font-weight: 700; font-variant-numeric: tabular-nums; }
.num.big { font-family: var(--font-display); font-size: 1.35em; letter-spacing: .01em; }
.bests { font-size: .86em; color: var(--muted); }
.badge { display: inline-block; padding: 1px 9px; border-radius: 999px; font-size: .78em; font-weight: 700;
  background: var(--accent-soft); color: var(--ink); border: 1px solid var(--accent); }
.reveal { display: grid; gap: 10px; }

/* status line: user / Log in, clock, length */
.status {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px;   /* wraps only for a very long name */
  font-size: min(calc(var(--fs) * .84), 16px); color: var(--muted); font-variant-numeric: tabular-nums;
}
.st { display: inline-flex; align-items: center; gap: 5px; min-width: 0; white-space: nowrap; }
.st svg { width: 17px; height: 17px; }
.pill {
  display: inline-flex; align-items: center; gap: 6px; min-width: 0;
  min-height: 44px; padding: 0 12px;
  border: 1px solid var(--line); border-radius: 999px;
  background: var(--surface); color: var(--ink);
  font-weight: 700; font-size: inherit;
  transition: background .15s, border-color .15s, transform .1s;
}
.pill svg { width: 17px; height: 17px; }
.pill-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pill.user { flex: 0 1 auto; max-width: 100%; }
.pill.len, .st-time { flex: none; }
.status .grow { display: none; }
.pill.len { margin-inline-start: auto; }
.pill.user.is-login { border-color: var(--accent); color: var(--accent); }
.pill.len svg { width: 16px; height: 16px; margin-inline-end: -3px; }
.pill:active { transform: scale(.97); }
@media (hover: hover) { .pill:hover { background: var(--card); border-color: var(--muted); } }

/* entry */
#entryForm { display: grid; gap: 6px; margin: 0; }
.field { position: relative; }
#guess {
  width: 100%; min-height: 52px;
  padding-block: 0; padding-inline: 14px 3.6em;
  border: 2px solid var(--line); border-radius: var(--radius);
  background: var(--card); color: var(--ink);
  font: 700 calc(var(--fs) * 1.2) var(--font-mono); letter-spacing: .1em;
  -webkit-appearance: none; appearance: none;
  text-overflow: ellipsis;
}
#guess::placeholder { color: var(--muted); opacity: .8; letter-spacing: .01em; font-family: var(--font-body);
  font-weight: 400; font-size: min(calc(var(--fs) * .95), 18px); }
#guess:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
#guess:focus-visible { outline: 3px solid var(--focus); outline-offset: 1px; }
.mode-play #guess { text-transform: uppercase; }
.mode-play #guess::placeholder { text-transform: none; }
.counter { position: absolute; inset-inline-end: 14px; top: 50%; transform: translateY(-50%);
  font: 700 .85em var(--font-mono); color: var(--muted); font-variant-numeric: tabular-nums; pointer-events: none; }
.counter.ok { color: var(--hit); }
.counter.over { color: var(--brand); }
.hint {
  margin: 0; padding: 0 4px;
  font-size: min(calc(var(--fs) * .84), 16px); font-weight: 700; color: var(--warn-ink);
  display: flex; gap: 6px; align-items: baseline;
}
.hint::before { content: '!'; flex: none; display: inline-grid; place-items: center;
  width: 1.25em; height: 1.25em; border-radius: 50%; transform: translateY(.15em);
  background: var(--warn-ink); color: var(--bg); font-size: .8em; }

/* the input with the hint button right next to it */
.entryrow { display: flex; gap: 8px; align-items: stretch; }
.entryrow .field { flex: 1 1 auto; min-width: 0; }
.hintbtn {
  position: relative; flex: none; width: 52px; min-height: 52px; padding: 0;
  display: grid; place-items: center;
  border: 2px solid var(--line); border-radius: var(--radius); background: var(--card); color: var(--ink);
  cursor: pointer; transition: border-color .15s, box-shadow .15s;
}
.hintbtn svg { width: 26px; height: 26px; }
.hintbtn:disabled { opacity: .45; cursor: default; }
.hintbtn.used-up { opacity: .6; }
.hintbtn.nudge { border-color: var(--near); box-shadow: 0 0 0 3px color-mix(in srgb, var(--near) 30%, transparent); color: var(--near); }
.hintbtn.wiggle { animation: hint-wiggle .75s var(--ease) both; }
@keyframes hint-wiggle {
  0%, 100% { transform: none; }
  12% { transform: rotate(-14deg) scale(1.1); }
  28% { transform: rotate(12deg) scale(1.1); }
  44% { transform: rotate(-9deg) scale(1.06); }
  60% { transform: rotate(6deg) scale(1.03); }
  78% { transform: rotate(-3deg); }
}
.hb-badge {
  position: absolute; top: -7px; inset-inline-end: -7px; min-width: 20px; height: 20px; padding: 0 5px;
  border-radius: 10px; font: 700 12px/20px var(--font-body); text-align: center;
  background: var(--accent); color: var(--on-accent); box-shadow: 0 0 0 2px var(--bg);
}
.hb-badge.empty { background: var(--miss); color: var(--on-miss); }

/* hint credits: the sheet (⚙ › Hint credits) and the reward line on a win */
.creditsheet .cr { display: grid; gap: 8px; }
.cr-total { display: flex; align-items: center; gap: 12px; font-size: 1.05em; }
.cr-total strong { font: 700 1.5em/1.1 var(--font-display); }
.cr-bulb { font-size: 2em; line-height: 1; }
.cr-lines { margin: 0; padding-inline-start: 1.2em; display: grid; gap: 4px; }
.cr-packs { display: grid; gap: 8px; }
.cr-pack { justify-content: flex-start; }
.creditsheet h3 { margin: 10px 0 0; font-size: 1em; }
.creditsheet p { margin: 0; }
.card.win .reward { font-weight: 700; color: var(--accent); }
.card.win .reward.muted { font-weight: 400; color: var(--muted); }
.dlg.creditask .dlg-body p { margin: 0 0 10px; }
@media (hover: hover) { .hintbtn:hover:not(:disabled) { border-color: var(--accent); } }
.compact .hintbtn { width: 46px; min-height: 44px; }

/* hints on the board: the letters or digits shown so far, in their places */
.tile.h { background: var(--card); color: var(--accent); box-shadow: inset 0 0 0 2px var(--accent); }
.tile.h.new { animation: flip .34s var(--ease) both; }
.tile.blank { background: transparent; box-shadow: inset 0 0 0 2px var(--line); }
.hintrow .attempt { font-family: var(--font-body); }
.preview .tile.ghost { border-style: dashed; border-color: var(--accent); }
.preview .tile.ghost .ch { color: var(--accent); opacity: .55; }
.card.win .hintnote { color: var(--muted); font-size: .92em; }
.lasttry .hintrow .tile.blank { box-shadow: inset 0 0 0 1.5px var(--line); }

/* the latest try, right above the input: still in view when a phone keyboard is open.
   Phones and tablets only - on a computer the whole board is always in view. */
.app:not(.touch-ui) .lasttry { display: none !important; }
.lasttry {
  display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: center; gap: 10px;
  padding: 6px 10px; border: 1px solid var(--line); border-radius: 12px; background: var(--card);
}
.lt-label { font: 700 .8em/1.15 var(--font-body); color: var(--muted); max-width: 4.6em; overflow-wrap: anywhere; }
.lasttry .guess { grid-template-columns: minmax(0, 1fr); gap: 0; }
.lasttry .attempt { display: none; }
.lasttry .tiles { gap: max(3px, calc(var(--tile-gap) * .7)); }
.lasttry .tile { flex: 0 1 2.6rem; aspect-ratio: 1 / 1.02; border-radius: 7px; }
.lasttry .tile .ch { font-size: min(calc(var(--fs) * 1.08), calc((100vw - 150px) / var(--len, 5) * .52)); }
.lasttry .tile .mk { font-size: min(calc(var(--fs) * .6), 2.8vw); margin-top: 1px; }
.compact .lasttry { padding: 4px 8px; gap: 8px; }
.compact .lasttry .tile { flex-basis: 2.3rem; }
/* with the keyboard open the input itself shows what is being typed, so the board keeps its
   room for the earlier tries */
.app.kb-open .boardcard > .preview { display: none; }

/* actions: Reveal / New Game lower left, Quit + Submit on the right (FR-UI-004/005) */
.actions { display: flex; align-items: center; gap: 8px; }
.btn {
  min-height: 48px; padding: 0 18px; border-radius: var(--radius);
  border: 2px solid transparent; font-weight: 700; font-size: calc(var(--fs) * .95);
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; text-align: center; line-height: 1.15;
  transition: transform .1s, background .15s, border-color .15s, opacity .15s;
}
.btn:active:not(:disabled) { transform: scale(.97); }
.btn:disabled { opacity: .45; }
.btn.submit { background: var(--accent); color: var(--on-accent); }
.btn.submit, .btn.quit { white-space: nowrap; }   /* keeps "Ok-Provo" on one line */
.btn.quit { background: transparent; border-color: var(--line); color: var(--ink); }
.btn.reveal { background: transparent; border-color: var(--line); border-style: dashed; color: var(--ink); }
.btn.reveal.is-new { background: var(--ink); color: var(--bg); border-style: solid; border-color: var(--ink); }
.btn.ghost { background: transparent; border-color: var(--line); color: var(--ink); }
.btn.small { min-height: 40px; padding: 0 14px; }
@media (hover: hover) {
  .btn.submit:hover:not(:disabled) { filter: brightness(1.08); }
  .btn.quit:hover, .btn.ghost:hover, .btn.reveal:not(.is-new):hover:not(:disabled) { border-color: var(--muted); }
}
.linkbtn {
  justify-self: start; min-height: 44px; padding: 0 2px; border: 0; background: none;
  color: var(--accent); font-weight: 700; text-decoration: underline; text-underline-offset: 3px;
}

/* toast */
.toast {
  position: fixed; left: 50%; top: calc(max(10px, env(safe-area-inset-top)) + 60px); transform: translateX(-50%);
  max-width: calc(100vw - 32px); padding: 9px 16px; border-radius: 999px;
  background: var(--ink); color: var(--bg); font-weight: 700; font-size: 14px; box-shadow: var(--shadow);
  text-align: center; z-index: 40; animation: toast-in .2s var(--ease);
}
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, -8px); } }

/* dialogs */
.dlg {
  border: none; padding: 0; border-radius: 18px;
  background: var(--card); color: var(--ink);
  width: min(440px, calc(100vw - 32px)); max-height: calc(100dvh - 48px);
  box-shadow: var(--shadow);
}
.dlg::backdrop { background: var(--scrim); }
.dlg[open] { animation: dlg-in .22s var(--ease); }
@keyframes dlg-in { from { opacity: 0; transform: translateY(12px); } }
.dlg-body { padding: 20px; display: grid; gap: 12px; margin: 0; }
.dlg h2 { margin: 0; font: 700 18px/1.25 var(--font-display); text-wrap: balance; overflow-wrap: anywhere; }
.dlg p { margin: 0; }
.dlg .muted { color: var(--muted); }
.dlg-actions { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 8px; margin: 0; }
.fieldlabel { font-size: .85em; font-weight: 700; color: var(--muted); margin-bottom: -6px; }
.textfield {
  width: 100%; min-height: 48px; padding: 0 12px;
  border: 2px solid var(--line); border-radius: var(--radius);
  background: var(--surface); color: var(--ink); font-weight: 700;
}
.textfield:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.textfield:focus-visible { outline: 3px solid var(--focus); outline-offset: 1px; }
#dlgLogin .hint { padding: 0; }
.saved { display: grid; gap: 8px; }
.saved-list { display: grid; gap: 6px; max-height: min(38vh, 240px); overflow-y: auto; overscroll-behavior: contain; }
.saved-user {
  display: flex; align-items: center; gap: 10px; width: 100%; min-height: 48px; padding: 0 14px;
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); color: var(--ink);
  font-weight: 700; text-align: start;
}
.saved-user svg { width: 18px; height: 18px; color: var(--accent); }
.saved-user .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.saved-user .sc { color: var(--muted); font-variant-numeric: tabular-nums; }
.saved-user:active { transform: scale(.98); }
@media (hover: hover) { .saved-user:hover { border-color: var(--accent); background: var(--card); } }

.sheet { display: none; flex-direction: column; width: min(560px, calc(100vw - 32px)); }
.sheet[open] { display: flex; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 18px 10px; }
.sheet-head form { margin: 0; }
.sheet-scroll { overflow-y: auto; padding: 0 18px 20px; overscroll-behavior: contain; }

@media (max-width: 719px) {
  .sheet {
    margin: auto 0 0; width: 100%; max-width: 100%;
    border-radius: 20px 20px 0 0;
    padding-bottom: env(safe-area-inset-bottom);
    max-height: 88dvh;
  }
  .sheet[open] { animation: sheet-in .26s var(--ease); }
  @keyframes sheet-in { from { transform: translateY(40px); opacity: 0; } }
}

/* settings */
/* a column whose rows never shrink, so a taller row (a hint text, a choice) is never cut off */
.settings { display: flex; flex-direction: column; gap: 8px; }
.settings > * { flex: none; }
.srow {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  min-height: 56px; padding: 6px 12px 6px 14px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--surface);
}
.srow-btn { width: 100%; text-align: start; color: var(--ink); font-weight: 700; }
.srow-label { display: flex; align-items: center; gap: 8px; font-weight: 700; min-width: 0; }
.srow-label small { display: block; font-weight: 400; color: var(--muted); font-size: .85em; }
.srow.opt .srow-label { display: block; }
.srow-value { color: var(--muted); font-weight: 700; white-space: nowrap; }
.srow-value::after { content: ' ›'; }
.srow.opt input { width: 24px; height: 24px; margin: 0; accent-color: var(--accent); flex: none; }
.stepper { display: inline-flex; align-items: center; gap: 8px; }
.stepper-val { min-width: 3.4em; text-align: center; font-weight: 700; font-variant-numeric: tabular-nums; }
.switch {
  position: relative; flex: none; width: 52px; height: 32px; padding: 0;
  border: 0; border-radius: 999px; background: var(--miss);
  transition: background .18s;
}
.switch .knob {
  position: absolute; top: 4px; left: 4px; width: 24px; height: 24px; border-radius: 50%;
  background: #FFFFFF; box-shadow: 0 1px 3px rgba(0, 0, 0, .3); transition: transform .18s var(--ease);
}
.switch[aria-checked="true"] { background: var(--accent); }
.switch[aria-checked="true"] .knob { transform: translateX(20px); }
@media (hover: hover) { .srow-btn:hover { border-color: var(--muted); } }

/* help */
#helpBody h3 { margin: 18px 0 6px; font: 700 14px/1.3 var(--font-display); letter-spacing: .02em; }
#helpBody h3:first-child { margin-top: 4px; }
#helpBody p { margin: 0 0 8px; max-width: 65ch; }
#helpBody code { font-family: var(--font-mono); background: var(--surface); border: 1px solid var(--line);
  border-radius: 6px; padding: 0 5px; }
#helpBody .example { color: var(--muted); }
.tablewrap { overflow-x: auto; margin: 6px 0 10px; }
.tablewrap table { border-collapse: collapse; width: 100%; font-size: .9em; font-variant-numeric: tabular-nums; }
.tablewrap th, .tablewrap td { text-align: start; padding: 6px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.tablewrap th { color: var(--muted); font-size: .85em; }
.about p { color: var(--muted); font-size: .9em; }

/* length wheel (FR-UI-014A) */
.wheel-wrap { position: relative; height: 240px; margin: 4px 18px 12px; }
.wheel-band {
  position: absolute; left: 0; right: 0; top: 96px; height: 48px;
  border-radius: 12px; background: var(--accent-soft); border: 1px solid var(--accent);
  pointer-events: none;
}
.wheel {
  position: relative; height: 100%; overflow-y: scroll;
  scroll-snap-type: y mandatory; overscroll-behavior: contain;
  scrollbar-width: none; -webkit-overflow-scrolling: touch;
  perspective: 700px;
  -webkit-mask-image: linear-gradient(transparent, #000 30%, #000 70%, transparent);
  mask-image: linear-gradient(transparent, #000 30%, #000 70%, transparent);
}
.wheel::-webkit-scrollbar { display: none; }
.wheel:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 12px; }
.wheel-pad { height: 96px; }
.wheel-item {
  height: 48px; scroll-snap-align: center;
  display: flex; align-items: center; justify-content: center;
  font: 700 20px/1 var(--font-display); color: var(--ink);
  transform-origin: 50% 50%;
  cursor: pointer; user-select: none;
}
.wheel-item[aria-selected="true"] { color: var(--accent); }
#dlgWheel { width: min(380px, calc(100vw - 32px)); }
@media (max-width: 719px) { #dlgWheel { width: 100%; } }   /* a full-width bottom sheet on phones */
#dlgWheel .dlg-actions { padding: 0 18px 18px; }

/* goodbye */
.goodbye {
  position: fixed; inset: 0; z-index: 50;
  display: grid; place-items: center;
  background: var(--bg); color: var(--ink);
  padding: 24px max(16px, env(safe-area-inset-right)) 24px max(16px, env(safe-area-inset-left));
  text-align: center;
}
.gb-inner { display: grid; gap: 14px; justify-items: center; max-width: 30rem; }
.gb-mark { display: flex; gap: 8px; }
.gb-mark .mt { width: 56px; height: 64px; font-size: 28px; border-radius: 12px; animation: flip .5s var(--ease) both; }
.gb-mark .mt:nth-child(2) { animation-delay: .12s; }
.gb-mark .mt:nth-child(3) { animation-delay: .24s; }
.goodbye h2 { margin: 6px 0 0; font: 700 clamp(22px, 6vw, 32px)/1.15 var(--font-display); text-wrap: balance; }
.goodbye p { margin: 0; }
.gb-sign { font-weight: 700; color: var(--brand); }
.gb-close { color: var(--muted); font-size: .9em; }

.noscript { position: fixed; inset: 0; display: grid; place-items: center; padding: 24px; background: var(--bg); text-align: center; }

/* ------------------------------------------------- phones (narrow screens) */
/* The board text grows with A+ to the full size; controls stop growing earlier so they always fit. */
@media (max-width: 420px) {
  .btn { font-size: min(calc(var(--fs) * .95), 19px); }
  #guess { font-size: min(calc(var(--fs) * 1.2), 24px); }
  .pill { padding: 0 10px; gap: 5px; }
}
@media (max-width: 359px) {
  .tools { gap: 5px; }
  .actions { gap: 6px; }
  .btn { padding: 0 12px; }
  .status { gap: 6px; }
  .pill { padding: 0 9px; }
}

/* ----------------------------------------------------- wider screens */
@media (min-width: 560px) {
  .brandtext { display: flex; }
}
@media (min-width: 720px) {
  .app { gap: 12px; padding-block: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-bottom)); }
  .mt { width: 28px; height: 31px; font-size: 15px; }
  .appname { font-size: 18px; }
  .appby { font-size: 13px; }
  .history { padding: 18px 16px; }
  .btn { padding: 0 22px; }
}

/* short screens (phone in landscape, or the on-screen keyboard is open) */
.app.compact { gap: 6px; grid-template-rows: auto auto minmax(48px, 1fr) auto auto;
  padding-block: max(6px, env(safe-area-inset-top)) max(6px, env(safe-area-inset-bottom));
  overflow-y: auto; overscroll-behavior: contain; }   /* last resort on tiny screens with very large text */
.compact .topbar { min-height: 40px; }
.compact .ib { width: 40px; height: 40px; }
.compact .history { padding: 8px 10px 4px; }
.compact .boardcard > .preview { padding: 6px 10px 8px; }
.compact .preview .tile { flex-basis: 2.6rem; }
.compact .preview .tile .ch { font-size: min(calc(var(--fs) * 1.15), calc((100vw - 120px) / var(--len, 5) * .5)); }
.compact #entryForm { gap: 3px; }
.compact #guess { min-height: 44px; font-size: min(calc(var(--fs) * 1.2), 22px); }
.compact .btn { min-height: 44px; font-size: min(calc(var(--fs) * .95), 18px); }
.compact .pill { min-height: 40px; }
.compact .status, .compact .hint { font-size: min(calc(var(--fs) * .84), 15px); }

/* phone keyboard open: the top bar steps aside while typing */
.app.kb-open { grid-template-areas: "status" "board" "entry" "actions";
  grid-template-rows: auto minmax(40px, 1fr) auto auto; }
.app.kb-open .topbar { display: none; }
/* inside another app's frame on a phone, while typing: latest try and input at the top, because
   such a frame is often not shrunk for the keyboard (see kb-top in ui.js) */
.app.kb-top { grid-template-areas: "status" "entry" "board" "actions";
  grid-template-rows: auto auto minmax(0, 1fr) auto; }
.app.kb-top .topbar { display: none; }
.app.kb-top .boardcard > .preview { display: none; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-delay: 0s !important; transition: none !important; scroll-behavior: auto !important; }
}


/* Word Puzzle: everyday words / all dictionary words */
.srow-pool { flex-wrap: wrap; padding-block: 10px; }
.srow-pool .srow-label { flex: 1 1 12rem; flex-direction: column; align-items: flex-start; gap: 2px; }
.seg { display: inline-flex; flex: none; padding: 3px; gap: 3px; border-radius: 12px; background: var(--card); border: 1px solid var(--line); }
.seg-btn { min-height: 40px; padding: 0 12px; border: 0; border-radius: 9px; background: transparent; color: var(--ink); font-weight: 700; }
.seg-btn.on { background: var(--accent); color: var(--on-accent); }

/* Word Puzzle: the level (Normal / Expert) in the length sheet, and the invitation on a win */
.wheel-level { display: grid; gap: 6px; padding: 4px 18px 6px; justify-items: start; }
.wheel-level .wl-title { font-weight: 700; }
.wheel-level p { margin: 0; font-size: .9em; }
.card.win .tryexpert { color: var(--muted); }

/* ------------------------------------------------- Arabic: right to left
   The page turns with dir="rtl" (set from MBG.AppText.RTL); the rules above use start/end.
   Numbers, the number tiles of Codebreaker, the switches and the flag coins stay left to right.
   Letter spacing would break the joined Arabic letters, so it is off. */
[dir="rtl"] .switch, [dir="rtl"] .langbtn, [dir="rtl"] .num { direction: ltr; }
[dir="rtl"] .mark, [dir="rtl"] .gb-mark, [dir="rtl"] .gc-tiles, [dir="rtl"] .promo-mark { direction: ltr; }
[dir="rtl"] #tilesWord { direction: rtl; }
[dir="rtl"] .numbers .tiles { direction: ltr; }
[dir="rtl"] .numbers .field { direction: ltr; }
[dir="rtl"] #lblWhatsApp { direction: ltr; unicode-bidi: isolate; }   /* the phone number keeps its order */
[dir="rtl"] .brand.homebtn .back, [dir="rtl"] .gc-play svg, [dir="rtl"] .worldcard > svg { transform: scaleX(-1); }
:lang(ar) * { letter-spacing: normal !important; }
:lang(ar) { --font-body: system-ui, 'Noto Sans Arabic', 'Noto Naskh Arabic', Tahoma, 'Segoe UI', Roboto, sans-serif;
  --font-display: system-ui, 'Noto Kufi Arabic', 'Noto Sans Arabic', Tahoma, 'Segoe UI', sans-serif; }
