/* Shared look of every game: colours, top bar, buttons, message line, rules guide, dialogs.
   A game page links this file, then adds its own table and pieces. */
:root {
  --gold: #FFC83D; --accent: #0B6B5D; --text: #1B2422;
  /* Each game has its own felt: a game page may set these three. */
  --felt-top: #1A6A5F; --felt: #0F4F47; --shade: 6,28,25;
  --face: #FFFDF6; --ink: #14171A; --red: #C4122F; --back: #1F4470;
  --ui: "Lexend", "Segoe UI", system-ui, sans-serif;
  --title: "Lexend", "Segoe UI", system-ui, sans-serif;
}
/* The font, kept on the site so it works offline. Lexend was drawn to make reading easier: wide letters
   and open spacing. It is used for the text and the titles. */
@font-face { font-family: "Lexend"; font-weight: 400 800; font-display: swap; src: url("../fonts/lexend.woff2") format("woff2"); }
* { box-sizing: border-box; }
/* Read by a screen reader, not shown. */
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
html, body { margin: 0; height: 100%; }
body {
  display: grid; grid-template-rows: auto auto minmax(0, 1fr) auto; grid-template-columns: minmax(0, 1fr); /* never wider than the window */
  background: radial-gradient(120% 100% at 50% 0%, var(--felt-top), var(--felt) 70%) var(--felt); color: #fff;
  font-family: var(--ui);
  overflow: hidden; user-select: none; -webkit-user-select: none; touch-action: none;
}

/* Top bar: a light, flat surface with the buttons */
#bar { display: flex; align-items: center; gap: 12px; padding: 8px 18px; background: #F6F8F7; color: var(--text);
  border-bottom: 1px solid rgba(0,0,0,.14); box-shadow: 0 2px 14px rgba(0,0,0,.22); position: relative; z-index: 10; }
#home { display: inline-flex; align-items: center; gap: 6px; min-height: 54px; padding: 8px 18px 8px 10px; border-radius: 15px;
  font: 600 21px var(--ui); color: #fff; text-decoration: none; background: #26302D; }
#home:hover { background: #3A4542; }
#home:focus-visible { outline: 4px solid #1B2422; outline-offset: 3px; }
#home svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
#title { display: flex; align-items: center; gap: 10px; font: 700 28px var(--title); letter-spacing: -.01em;
  margin-right: 10px; padding-left: 16px; border-left: 2px solid #D5DCD9; }
/* Groups in the bar: going back on the left, playing in the middle, the game on the right. The free room is
   split in two around the play buttons. */
#bar .spacer { display: none; }
#title + *, #bar .spacer + * { margin-left: auto; }
/* Each label in one line. A button has up to three labels: <span class="long">…</span><span class="short">…</span>
   <span class="tiny">…</span>. Kit measures the bar and takes the longest labels that fit (see fitBar). */
#bar > * { white-space: nowrap; }
#bar .short, #bar .tiny { display: none; }
#bar.fit-short .long { display: none; } #bar.fit-short .short { display: inline; }
#bar.fit-tiny { gap: 8px; } #bar.fit-tiny .long, #bar.fit-tiny .short { display: none; } #bar.fit-tiny .tiny { display: inline; }
#bar.fit-tiny #title { margin-right: 4px; padding-left: 12px; }
#bar.fit-bare #title { display: none; }
#title svg { width: 28px; height: 28px; fill: var(--accent); }
button {
  min-height: 54px; padding: 6px 20px; border-radius: 15px; cursor: pointer; /* padding + 2px border = the old 8px 22px */
  display: inline-flex; align-items: center; gap: 10px;
  font: 600 21px var(--ui); background: #fff; color: var(--text);
  /* A raised white key with a dark edge, so it reads as something to press on the pale bar. */
  border: 2px solid #9AA6A1; box-shadow: 0 3px 0 #9AA6A1;
  transition: background-color .12s;
}
button svg { width: 26px; height: 26px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
button:hover { background: #E8EEEB; }
button:active { background: #D5DCD9; box-shadow: none; transform: translateY(3px); }
button:focus-visible { outline: 4px solid #1B2422; outline-offset: 3px; box-shadow: 0 0 0 3px #fff; }
/* Nothing to do yet: flat, pale and dashed, so it does not look like a key to press. */
button:disabled, button:disabled:hover { background: transparent; color: #8C9692; border: 2px dashed #C9D1CE; box-shadow: none; transform: none; cursor: default; }
button.primary { background: var(--gold); color: #1F1A00; border-color: #C9951A; box-shadow: 0 3px 0 #C9951A; }
button.primary:hover { background: #FFD666; }
button.primary:active { background: #F2BB2E; }
/* A yellow button with nothing to do yet looks idle too, so yellow always means "press me". */
button.primary:disabled, button.primary:disabled:hover { background: transparent; color: #8C9692; border: 2px dashed #C9D1CE; box-shadow: none; transform: none; }
/* Win count: a chip at the left of the bottom bar. */
#wins { flex: none; height: 46px; padding: 0 18px; display: flex; align-items: center; gap: 10px;
  background: #fff; color: var(--text); font: 600 21px var(--ui); white-space: nowrap;
  border-radius: 15px; box-shadow: 0 2px 10px rgba(0,0,0,.25); }
#wins:empty { display: none; }
#wins::before { content: ""; width: 26px; height: 26px; background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%231B2422' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M7 4h10v5a5 5 0 0 1-10 0z'/%3E%3Cpath d='M7 6H4v1a3 3 0 0 0 3 3M17 6h3v1a3 3 0 0 1-3 3M12 14v4M8.5 20h7'/%3E%3C/svg%3E") center / contain no-repeat; }
@media (max-width: 960px) {
  #bar { overflow-x: auto; }
  #bar > * { flex-shrink: 0; white-space: nowrap; }
  #home, #newBtn { order: -1; }
}
/* The level, under the name of the game: as large as every other text, lighter and grey. */
#title .name { display: flex; flex-direction: column; line-height: 1.05; }
#title #level { font: 500 20px/1.1 var(--ui); color: #4E5A57; letter-spacing: 0; }
/* A phone: the bar takes two rows. "Jeux" and "Nouvelle partie" on top, the three game buttons under
   them, sharing the width; a label that does not fit takes two lines. The name of the game goes. */
@media (max-width: 700px) {
  #bar { flex-wrap: wrap; overflow: visible; gap: 8px; padding: 8px 10px; }
  #bar > * { flex-shrink: 1; }
  #title, #bar .spacer { display: none; }
  #bar::after { content: ""; order: 0; flex-basis: 100%; height: 0; margin-top: -8px; }
  #newBtn { flex: 1; }
  #bar button, #home { min-height: 46px; }
  #bar .long, #bar .short { display: none; } #bar .tiny { display: inline; }
  #undoBtn, #hintBtn, #helpBtn { order: 1; flex: 1 1 0; min-width: 0; padding: 4px 8px; gap: 6px; justify-content: center;
    font-size: 20px; line-height: 1.05; white-space: normal; text-align: left; }
  #undoBtn svg, #hintBtn svg, #helpBtn svg { width: 22px; height: 22px; }
}
button.game { --accent: #0B6B5D; background: var(--accent); color: #fff; --edge: color-mix(in srgb, var(--accent), #000 40%); border-color: var(--edge); box-shadow: 0 3px 0 var(--edge); }
button.game:hover { background: #0E7D6D; }
button.game:active { background: #095A4E; }

/* Message line: under the top bar, where his eyes already are, centred with room above and under it.
   Dark bold text on a warm cream band with a gold edge. A new text flashes once (see Kit.say). */
#say { display: flex; justify-content: center; padding: clamp(16px, 4vh - 8px, 32px) clamp(10px, 1.4vw, 18px) clamp(12px, 8vh - 40px, 40px); }
#msg {
  flex: 0 1 auto; min-width: 0; height: 52px; padding: 2px 24px 2px 16px; box-sizing: border-box;
  display: flex; align-items: center; gap: 12px;
  background: #FFF4D6; color: var(--text); font: 700 23px/1.2 var(--ui);
  border: 2px solid #E9C46A; border-radius: 16px; box-shadow: 0 4px 14px rgba(0,0,0,.3);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
#msg:empty { visibility: hidden; }
/* A text too long for one line: two lines, a little smaller, in the same height, so the board never moves
   (see Kit.say). Only a phone lets the band grow. */
#msg.long { white-space: normal; font-size: 20px; line-height: 22px; height: auto; min-height: 52px; }
#msg.flash { animation: flash 1s; }
@keyframes flash { 25% { background: #FFD666; } }
@media (prefers-reduced-motion: reduce) { #msg.flash { animation: none; } }
/* Bottom bar, always at the foot of the window: who made the games and the counts on the left, the size
   buttons on the right. Kit adds the credit. */
#rail { grid-row: 4; /* its own row, also while the table is hidden */ display: flex; align-items: center; gap: 10px; padding: 7px clamp(14px, 2vw, 28px); margin-top: clamp(0px, 4vh - 28px, 24px);
  background: rgba(0,0,0,.18); border-top: 1px solid rgba(255,255,255,.08); }
#rail .zoom { margin-left: auto; }
.credit { flex: none; min-height: 44px; padding: 4px 18px 4px 4px; display: inline-flex; align-items: center; gap: 10px; border-radius: 999px;
  background: rgba(255,255,255,.08); border: 1px solid rgba(255,255,255,.2); color: rgba(255,255,255,.78);
  font: 500 20px var(--ui); text-decoration: none; white-space: nowrap; transition: background-color .12s; }
.credit b { color: #fff; font-weight: 700; }
.credit img { width: 34px; height: 34px; flex: none; border-radius: 50%; box-shadow: 0 0 0 2px var(--gold, #FFC83D); }
.credit:hover { background: rgba(255,255,255,.16); }
.credit:focus-visible { outline: 4px solid #fff; outline-offset: 3px; }
/* A page 1340 px wide or less (lib/zoom.js sets the class): the counts and the size buttons need the room. */
html.narrow .credit { display: none; }
/* A phone has no size buttons and no credit: the bar goes when it has no count to show. */
@media (max-width: 699px) {
  .credit { display: none; }
  #rail:not(:has(> :not(:empty, .zoom, .credit))) { display: none; }
}
/* A short page (lib/zoom.js sets the class): the gaps close up, so the board keeps its size. */
html.short #say { padding-block: 8px; }
html.short #rail { margin-top: 0; }
#msg::before { content: ""; flex: none; width: 28px; height: 28px; background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%230B6B5D' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M21 12a8.5 8.5 0 0 1-12.6 7.4L3.5 20.5l1.2-4.6A8.5 8.5 0 1 1 21 12z'/%3E%3C/svg%3E") center / contain no-repeat; }

/* Rules guide */
#help, #over { position: fixed; inset: 0; background: rgba(var(--shade),.6); display: none; align-items: center; justify-content: center; z-index: 5000; }
#help.on, #over.on { display: flex; }
#helpBox, #box { background: #fff; color: var(--text); border-radius: 24px; box-shadow: 0 30px 90px rgba(0,0,0,.45); }
#helpBox { width: min(840px, calc(94vw / var(--z, 1))); height: min(560px, calc(94vh / var(--z, 1))); display: flex; flex-direction: column; }
#helpBox .head { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 16px 24px 12px 32px; border-bottom: 1px solid #D5DCD9; }
#helpBox h2 { margin: 0; font: 700 32px var(--ui); letter-spacing: -.01em; }
#helpClose { flex: none; }
#helpText { flex: 1; overflow-y: auto; overscroll-behavior: contain; touch-action: pan-y; padding: 14px 32px;
  font: 400 22px/1.32 var(--ui); color: #26302D; }
#helpText:focus-visible { outline: 3px solid var(--text); outline-offset: -4px; }
#helpText h3 { margin: 0 0 8px; font: 700 28px/1.15 var(--ui); color: var(--accent); }
#helpText p { margin: 0 0 10px; }
#helpText ol, #helpText ul { margin: 0 0 10px; padding-left: 1.4em; }
#helpText li + li { margin-top: 4px; }
#helpText .page { display: none; }
#helpText .page.on { display: block; }
#helpText .page > :last-child { margin-bottom: 0; }
.guide-panel { margin: 12px 0; padding: 12px 16px; border: 1px solid #D5DCD9; border-radius: 14px; background: #F2F5F3; }
.guide-example { margin: 0; display: flex; align-items: center; flex-wrap: wrap; gap: 10px 20px; }
.guide-example figcaption { flex: 1 1 220px; }
.guide-art { display: flex; align-items: center; justify-content: center; gap: 12px; }
#helpText .guide-key { list-style: none; padding-left: 0; }
.guide-key li { display: flex; align-items: center; gap: 12px; }
.guide-arrow { font-size: 1.5em; font-weight: 700; line-height: 1; }
#helpBox .end { padding: 12px 32px 18px; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 12px;
  border-top: 1px solid #D5DCD9; }
#helpBox .end button, #overBtns button { min-height: 58px; padding: 8px 28px; justify-content: center; }
#helpPrev { justify-self: start; }
#helpNext { justify-self: end; }
#helpBox .end button[hidden] { visibility: hidden; display: block; }
#helpPage { font: 600 20px var(--ui); color: #55605C; white-space: nowrap; }
html.short #helpText { font-size: 20px; }
html.low #helpBox .head { padding-block: 10px; }
html.low #helpBox .end { padding-block: 8px 12px; }
/* A phone: the rules and the dialogs take the width, with smaller margins. */
@media (max-width: 700px) {
  #helpBox { height: min(720px, 94vh); }
  #helpBox .head, #helpText, #helpBox .end { padding-inline: 16px; }
  #helpBox h2, #helpText h3 { font-size: 24px; }
  #helpText { font-size: 20px; }
  #helpClose, #helpBox .end button { font-size: 18px; padding: 6px 10px; }
  #helpBox .end { gap: 6px 8px; grid-template-columns: 1fr 1fr; }
  #helpPage { grid-area: 1 / 1 / 2 / -1; justify-self: center; font-size: 18px; }
  .guide-panel { padding: 10px; }
  .guide-example { justify-content: center; }
  .guide-example figcaption { flex-basis: 185px; }
  #box { padding: 28px 20px; }
  #overBtns button { padding-inline: 12px; }
}

/* Dialog */
#over.soft { background: rgba(var(--shade),.3); }
#box { padding: 40px 48px 40px; text-align: center; max-width: min(680px, calc(92vw / var(--z, 1))); }
#box h2 { margin: 0 0 10px; font: 700 32px var(--ui); letter-spacing: -.01em; }
#box p { margin: 0 0 28px; font: 400 22px/1.4 var(--ui); color: #3A4542; }
#box p:empty { display: none; }
/* The choices: one wide button each, under each other, the yellow one first. A row of three wraps
   into two rows of different widths, and a column reads in order from the top. */
#overBtns { display: flex; flex-direction: column; align-items: stretch; gap: 12px; width: min(420px, 100%); margin: 6px auto 0; }
/* The levels: what the level means goes under its name. */
#box.levels { width: min(560px, calc(92vw / var(--z, 1))); }
#box.levels #overBtns { width: auto; }
#box.levels #overBtns button { min-height: 64px; }
/* After two choices or more, the way out ("Retour aux jeux", "Continuer la partie") stands a little apart. */
#overBtns button:not(.choice):nth-child(n+3):last-child { margin-top: 10px; }
#overBtns button.choice { flex-direction: column; gap: 2px; padding-block: 8px; font-size: 24px; font-weight: 700; }
#overBtns button.choice::after { content: attr(data-note); font: 500 20px var(--ui); color: #4E5A57; }
#overBtns button.choice.primary::after { color: #3D3000; }
/* "La partie en cours sera effacée": said plainly, in bold. */
#box p.warn { font-weight: 700; color: #8A1C1C; }
/* A low page, 600 px high or less (lib/zoom.js sets the class): the dialog closes up, and a level's
   meaning goes beside its name. */
html.low #box { padding: 22px 32px 24px; }
html.low #box p { margin-bottom: 14px; }
html.low #overBtns { gap: 10px; }
html.low #box.levels #overBtns button { min-height: 54px; }
html.low #overBtns button.choice { flex-direction: row; gap: 14px; padding-block: 4px; }
/* The win: a yellow badge with a check mark grows in once. */
#over.soft #box::before {
  content: ""; display: block; width: 84px; height: 84px; margin: 0 auto 18px; border-radius: 50%;
  background: var(--gold) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%231F1A00' stroke-width='2.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 12.5l4.5 4.5L19 7.5'/%3E%3C/svg%3E") center / 48px no-repeat; animation: pop .45s cubic-bezier(.2,1.4,.4,1) both;
}
@keyframes pop { from { transform: scale(.3); opacity: 0; } }

.shake { animation: sh .3s; }
@keyframes sh { 25% { translate: -8px 0; } 75% { translate: 8px 0; } }

@media (prefers-reduced-motion: reduce) {
  .shake, #over.soft #box::before { animation: none; }
}
