/* Word games (wordgames.js): Verbum, Lexis, Quattuor.  Uses app.css's tokens (navy, cream, gold, EB Garamond). */

:root {
  --wg-ok: #4f7f4d;           /* right letter, right place */
  --wg-ok-ink: #f4f1e6;
  --wg-near: #c0a06c;         /* in the word, elsewhere */
  --wg-near-ink: #1c2540;
  --wg-no: #6c7284;           /* not in the word */
  --wg-no-ink: #f1eee6;
  --wg-key: #e5ddca;          /* an unused key */
  --wg-key-ink: #1d2333;
  --wg-tile: var(--card);
  --wg-edge: #cfc5ad;
  --wg-y: #e7cf7a; --wg-g: #a9c58f; --wg-b: #8fb2d6; --wg-p: #b79cd3;   /* Quattuor: yellow, green, blue, purple */
  --wg-pick: #192648;
}
:root[data-theme="sepia"] { --wg-key: #e1d4b6; --wg-edge: #cbbb97; }
:root[data-theme="night"] {
  --wg-ok: #4c7a4a; --wg-near: #b79760; --wg-no: #3a4361; --wg-no-ink: #cfd2db; --wg-key: #2c3656; --wg-key-ink: #e8e2d1; --wg-edge: #3a4565;
  --wg-y: #bfa94f; --wg-g: #7e9c68; --wg-b: #5f86ad; --wg-p: #8a72aa; --wg-pick: #e8e2d1;
}
@media (prefers-color-scheme: dark) {
  :root[data-theme="auto"] {
    --wg-ok: #4c7a4a; --wg-near: #b79760; --wg-no: #3a4361; --wg-no-ink: #cfd2db; --wg-key: #2c3656; --wg-key-ink: #e8e2d1; --wg-edge: #3a4565;
    --wg-y: #bfa94f; --wg-g: #7e9c68; --wg-b: #5f86ad; --wg-p: #8a72aa; --wg-pick: #e8e2d1;
  }
}

.wg { max-width: 470px; margin: 0 auto; padding-bottom: 28px; }
.wg-top { display: flex; align-items: center; gap: 10px; margin: 2px 0 6px; }
.wg-top .btn { flex: none; }
.wg-title { flex: 1; text-align: center; min-width: 0; }
.wg-title h1 { font: 600 26px/1.05 var(--text); letter-spacing: .14em; text-transform: uppercase; margin: 0; padding-left: .14em; }
.wg-sub { margin: 3px 0 0; font-size: 13px; color: var(--muted); letter-spacing: .02em; }
.wg-tools { display: flex; gap: 2px; flex: none; }
.wg-tools .ib { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; color: var(--muted); }
.wg-tools .ib:hover { color: var(--ink); background: var(--bg-2); }
.wg-tools .ico { width: 21px; height: 21px; stroke: currentColor; fill: none; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.wg-mode { display: flex; justify-content: center; margin: 8px 0 14px; }
.wg-mode .seg { display: inline-flex; padding: 3px; border-radius: 10px; }
.wg-mode a { display: block; height: 30px; line-height: 30px; padding: 0 16px; border-radius: 8px; font-size: 13.5px; color: var(--muted); text-decoration: none; }
.wg-mode a.on { background: var(--card); color: var(--ink); box-shadow: 0 1px 3px rgba(0, 0, 0, .12); font-weight: 600; }

/* ------------------------------------------------------------ the board */
.wg-board { --tile: min(58px, calc((100vw - 64px) / 5), 8.6vh); display: grid; gap: 6px; justify-content: center; margin: 8px auto 14px; perspective: 800px; }
.wg-row { display: grid; grid-template-columns: repeat(var(--cols, 5), var(--tile)); gap: 6px; }
.wg-row.shake { animation: wg-shake .42s ease; }
.wt { width: var(--tile); height: var(--tile); display: grid; place-items: center; box-sizing: border-box;
  font: 600 calc(var(--tile) * .52)/1 var(--text); text-transform: uppercase; color: var(--ink); background: var(--wg-tile);
  border: 2px solid var(--wg-edge); border-radius: 6px; user-select: none; -webkit-user-select: none; transform-style: preserve-3d; }
.wt.on { border-color: var(--muted); animation: wg-pop .11s ease-out; }
.wt.c, .wt.p, .wt.a { border-color: transparent; }
.wt.c { background: var(--wg-ok); color: var(--wg-ok-ink); }
.wt.p { background: var(--wg-near); color: var(--wg-near-ink); }
.wt.a { background: var(--wg-no); color: var(--wg-no-ink); }
.wt.flip { animation: wg-flip .5s ease both; }
.wt.hop { animation: wg-hop .5s ease both; }
.wt.grc, .wg-grc .wt { font-family: var(--text); }
@keyframes wg-pop { 0% { transform: scale(.92); } 60% { transform: scale(1.07); } 100% { transform: scale(1); } }
@keyframes wg-flip { 0% { transform: rotateX(0); } 50% { transform: rotateX(-90deg); } 100% { transform: rotateX(0); } }
@keyframes wg-hop { 0%, 100% { transform: translateY(0); } 40% { transform: translateY(-9px); } }
@keyframes wg-shake { 0%, 100% { transform: translateX(0); } 18% { transform: translateX(-6px); } 38% { transform: translateX(5px); } 58% { transform: translateX(-4px); } 78% { transform: translateX(3px); } }

/* ------------------------------------------------------------ keyboard */
.wg-kb { display: grid; gap: 6px; margin: 4px -4px 0; user-select: none; -webkit-user-select: none; touch-action: manipulation; }
.wg-kr { display: flex; gap: 5px; justify-content: center; }
.wk { flex: 1 1 0; min-width: 0; max-width: 46px; height: 52px; border-radius: 7px; background: var(--wg-key); color: var(--wg-key-ink);
  font: 600 18px/1 var(--text); text-transform: uppercase; display: grid; place-items: center; transition: background .25s, color .25s, transform .08s; }
.wk:active { transform: scale(.94); }
.wk.wide { flex: 1.65 1 0; max-width: 72px; font: 600 12.5px/1 var(--ui); letter-spacing: .04em; text-transform: uppercase; }
.wk.c { background: var(--wg-ok); color: var(--wg-ok-ink); }
.wk.p { background: var(--wg-near); color: var(--wg-near-ink); }
.wk.a { background: var(--wg-no); color: var(--wg-no-ink); opacity: .75; }
.wg-grc .wk { font-size: 19px; }
@media (max-width: 400px) { .wk { height: 48px; font-size: 17px; } .wg-kr { gap: 4px; } }

/* ------------------------------------------------------------ after the game */
.wg-res { background: var(--card); border-radius: 18px; box-shadow: var(--shadow); padding: 22px 20px 18px; margin-top: 8px; text-align: center; animation: wg-rise .5s ease both; }
@keyframes wg-rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.wg-verdict { font-size: 12.5px; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.wg-word { font: 500 44px/1.1 var(--text); margin: 6px 0 2px; color: var(--ink); }
.wg-def { color: var(--muted); font-size: 15.5px; }
.wg-def i { font-family: var(--text); font-size: 1.05em; }
.wg-ex { margin: 18px 0 4px; padding: 14px 4px 0; border-top: 1px solid var(--line); text-align: left; }
.wg-ex q, .wg-ex p { quotes: none; display: block; margin: 0; font: 400 20px/1.5 var(--text); color: var(--ink); }
.wg-ex mark { background: var(--hl); color: inherit; border-radius: 3px; padding: 0 2px; font-weight: 600; }
.wg-ex footer { margin-top: 8px; font-size: 13.5px; color: var(--muted); }
.wg-ex footer a { color: var(--gold-ink); }
.wg-acts { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin: 18px 0 4px; }
.wg-acts .btn { min-width: 128px; }
.wg-next { margin-top: 14px; font-size: 13.5px; color: var(--muted); }
.wg-next b { font-variant-numeric: tabular-nums; color: var(--ink); letter-spacing: .03em; }

.wg-st { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; margin: 18px 0 10px; border-top: 1px solid var(--line); padding-top: 16px; }
.wg-st div b { display: block; font: 600 26px/1.1 var(--text); font-variant-numeric: tabular-nums; }
.wg-st div span { font-size: 11.5px; color: var(--muted); letter-spacing: .02em; line-height: 1.2; display: block; }
.wg-dist { display: grid; gap: 4px; text-align: left; margin-top: 6px; }
.wg-dist h4 { margin: 0 0 4px; font-size: 12px; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); font-weight: 600; text-align: center; }
.wg-dist div { display: grid; grid-template-columns: 1.1em 1fr; gap: 8px; align-items: center; font-size: 13.5px; font-variant-numeric: tabular-nums; }
.wg-dist i { font-style: normal; color: var(--muted); text-align: right; }
.wg-dist u { text-decoration: none; display: block; min-width: 1.6em; background: var(--wg-no); color: var(--wg-no-ink); padding: 1px 7px; text-align: right; border-radius: 3px; font-size: 12.5px; font-weight: 600; }
.wg-dist u.me { background: var(--wg-ok); color: var(--wg-ok-ink); }
.wg-rules p { margin: 0 0 12px; line-height: 1.5; }
.wg-rules .ex { display: flex; gap: 5px; margin: 6px 0 10px; }
.wg-rules .ex .wt { --tile: 40px; font-size: 21px; animation: none; }

/* ------------------------------------------------------------ Quattuor */
.wq-hint { text-align: center; color: var(--muted); font-size: 14.5px; margin: 4px 0 12px; }
.wq-solved { display: grid; gap: 6px; margin-bottom: 6px; }
.wq-banner { border-radius: 8px; padding: 10px 12px 11px; text-align: center; color: #1c2540; animation: wg-rise .45s ease both; }
.wq-banner.l0 { background: var(--wg-y); } .wq-banner.l1 { background: var(--wg-g); } .wq-banner.l2 { background: var(--wg-b); } .wq-banner.l3 { background: var(--wg-p); }
:root[data-theme="night"] .wq-banner { color: #10172a; }
@media (prefers-color-scheme: dark) { :root[data-theme="auto"] .wq-banner { color: #10172a; } }
.wq-banner b { display: block; font: 700 12.5px/1.25 var(--ui); letter-spacing: .07em; text-transform: uppercase; }
.wq-banner div { font: 400 18px/1.35 var(--text); margin-top: 3px; }
.wq-banner div span { white-space: nowrap; margin: 0 5px; display: inline-block; }
.wq-banner div small { font: 400 12px/1 var(--ui); opacity: .72; margin-left: 4px; }
.wq-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
.wq-t { min-height: 62px; border-radius: 8px; background: var(--bg-2); color: var(--ink); display: grid; place-items: center; text-align: center; padding: 6px 4px;
  font: 500 19px/1.1 var(--text); overflow-wrap: anywhere; hyphens: none; transition: transform .12s, background .15s, color .15s, box-shadow .15s; box-shadow: inset 0 0 0 1.5px var(--line); }
.wq-t[data-n="long"] { font-size: 16px; } .wq-t[data-n="vlong"] { font-size: 14px; letter-spacing: -.005em; }
.wq-t:hover { box-shadow: inset 0 0 0 1.5px var(--gold); }
.wq-t.sel { background: var(--wg-pick); color: var(--bg); box-shadow: none; transform: translateY(-2px); }
.wq-t.bad { animation: wg-shake .42s ease; }
.wq-t.out { animation: wq-out .3s ease both; }
@keyframes wq-out { to { opacity: 0; transform: scale(.9); } }
.wq-bar { display: flex; align-items: center; justify-content: center; gap: 10px; margin: 14px 0 6px; font-size: 14px; color: var(--muted); }
.wq-pips { display: flex; gap: 6px; }
.wq-pips i { width: 11px; height: 11px; border-radius: 50%; background: var(--wg-pick); opacity: .85; transition: opacity .3s, transform .3s; }
.wq-pips i.gone { opacity: .16; transform: scale(.8); }
.wq-btns { display: flex; gap: 10px; justify-content: center; margin-top: 12px; flex-wrap: wrap; }
.wq-btns .btn { min-width: 112px; }
.wg-share-grid { white-space: pre; font-family: var(--ui); }

/* ------------------------------------------------------------ hub cards (the picture-card styles live in app.css) */
.pcard em.wg-done { background: var(--wg-ok); color: var(--wg-ok-ink); }

@media (prefers-reduced-motion: reduce) {
  .wt.flip, .wt.hop, .wt.on, .wg-row.shake, .wg-res, .wq-banner, .wq-t.bad { animation: none !important; }
  .wq-t, .wk, .wq-pips i { transition: none; }
}
@media (max-width: 400px) {
  .wg-title h1 { font-size: 22px; letter-spacing: .1em; }
  .wg-word { font-size: 38px; }
  .wq-t { min-height: 56px; font-size: 17px; }
}

/* phones: the game is the whole screen (it has its own back button), and the board sizes to the height left
   after the title and the keyboard, so board and keys fit together without scrolling */
@media (max-width: 720px) {
  body:has(.wg) .top, body:has(.wg) .tabs { display: none; }
  body:has(.wg) main.page { padding: calc(6px + env(safe-area-inset-top)) 12px calc(8px + env(safe-area-inset-bottom)); }
  .wg { padding-bottom: 0; }
  .wg-mode { margin: 2px 0 6px; }
  .wg-board { --tile: min(58px, calc((100vw - 64px) / 5), calc((100vh - 318px) / 6)); margin: 4px auto 10px; }
  @supports (height: 100dvh) { .wg-board { --tile: min(58px, calc((100vw - 64px) / 5), calc((100dvh - 318px) / 6)); } }
}
