/* Boggle — English Room Games */
:root {
  --bg: #1d2452;
  --bg-2: #252d63;
  --ink: #fff8e7;
  --muted: #b9c0ea;
  --muted-2: #8790c4;
  --line: rgba(255, 255, 255, .14);
  --gold: #ffc93c;
  --gold-dark: #c99a1c;
  --green: #3bb273;
  --red: #ef6461;
  --cube: #f6dfa8;
  --cube-edge: #c9a45c;
  --tray: #2f8fd8;
  --tray-dark: #1b64a3;
  --display: 'Fredoka', 'Nunito', sans-serif;
  --body: 'Nunito', sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: var(--body);
  color: var(--ink);
  background-color: var(--bg);
  background-image:
    linear-gradient(45deg, rgba(255,255,255,.03) 25%, transparent 25%, transparent 75%, rgba(255,255,255,.03) 75%),
    linear-gradient(45deg, rgba(255,255,255,.03) 25%, transparent 25%, transparent 75%, rgba(255,255,255,.03) 75%);
  background-size: 64px 64px;
  background-position: 0 0, 32px 32px;
  min-height: 100dvh;
}
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 14px; padding-top: calc(8px + env(safe-area-inset-top, 0px));
  border-bottom: 1px solid var(--line); background: rgba(20, 26, 64, .8);
  position: sticky; top: 0; z-index: 40;
}
.brand { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.brand h1 { margin: 0; font: 700 26px var(--display); }
.brand .site { font-size: 11.5px; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; color: var(--muted-2); text-decoration: none; white-space: nowrap; }
.brand .site:hover { color: var(--gold); }
.spacer { flex: 1; }
.iconbtn {
  width: 38px; height: 38px; flex-shrink: 0; display: grid; place-items: center;
  border: 1px solid var(--line); border-radius: 10px; background: rgba(255,255,255,.05);
  color: var(--muted); cursor: pointer; text-decoration: none;
}
.iconbtn:hover { color: var(--ink); border-color: var(--gold); }
.iconbtn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.iconbtn[aria-pressed="false"] .wave { display: none; }
.pill-stat {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line);
  background: rgba(0,0,0,.2); font: 600 1.15rem var(--display); white-space: nowrap;
}
.pill-stat svg { width: 19px; height: 19px; fill: none; stroke: var(--gold); stroke-width: 2; stroke-linecap: round; }
.pill-stat.score { color: var(--gold); }
.timer.low { color: #fff; background: var(--red); border-color: transparent; animation: throb 1s infinite; }
.timer.low svg { stroke: #fff; }
@keyframes throb { 50% { transform: scale(1.06); } }

/* ---------- layout ---------- */
.layout {
  display: grid; grid-template-columns: auto minmax(280px, 380px);
  gap: 24px; justify-content: center; align-items: start;
  padding: 16px 16px 30px; max-width: 1100px; margin: 0 auto;
}
.play { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.board-info { margin: 0; color: var(--muted); font-weight: 700; font-size: .95rem; text-align: center; }
.board-info b { color: var(--gold); }

.wordbar {
  min-height: 58px; min-width: 260px; max-width: 100%;
  display: flex; align-items: center; justify-content: center;
  padding: 4px 22px; border-radius: 16px;
  background: rgba(0,0,0,.22); border: 2px solid var(--line);
  transition: border-color .15s, background .15s;
}
.wordbar .current { font: 700 2rem var(--display); letter-spacing: .12em; text-transform: uppercase; white-space: nowrap; }
.wordbar.good { border-color: var(--green); background: rgba(59, 178, 115, .2); }
.wordbar.bad { border-color: var(--red); background: rgba(239, 100, 97, .18); animation: shake .4s; }
.wordbar.off .current { color: var(--red); }
@keyframes shake { 20%, 60% { transform: translateX(-7px); } 40%, 80% { transform: translateX(7px); } }

/* the tray and letter cubes */
.tray {
  --n: 4;
  --tile: max(44px, min(92px, calc((100vw - 64px) / var(--n)), calc((100dvh - 330px) / var(--n))));
  position: relative;
  padding: 14px; border-radius: 22px;
  background: linear-gradient(160deg, var(--tray), var(--tray-dark));
  box-shadow: inset 0 3px 0 rgba(255,255,255,.2), inset 0 -6px 0 rgba(0,0,0,.25), 0 16px 34px rgba(0,0,0,.4);
  touch-action: none; user-select: none; -webkit-user-select: none;
}
.grid {
  display: grid;
  grid-template-columns: repeat(var(--n), var(--tile));
  grid-template-rows: repeat(var(--n), var(--tile));
  gap: calc(var(--tile) * .1);
  transition: transform .4s cubic-bezier(.5, -0.2, .4, 1.2);
}
.grid.spin { transform: rotate(90deg); }
.grid.nospin { transition: none; }
.tile {
  position: relative;
  display: flex; align-items: center; justify-content: center;
  border-radius: 18%;
  background: linear-gradient(160deg, #fdf0cf, var(--cube));
  box-shadow: inset 0 calc(var(--tile) * -.07) 0 var(--cube-edge), 0 4px 8px rgba(0,0,0,.3);
  color: var(--bg);
  font: 700 calc(var(--tile) * .5) var(--display);
  cursor: pointer;
  transition: transform .1s, background .12s;
}
.tile span { display: block; transition: transform .4s; }
.tile .qu { font-size: .78em; }
.tile.sel { background: linear-gradient(160deg, #ffe08a, var(--gold)); box-shadow: inset 0 calc(var(--tile) * -.07) 0 var(--gold-dark), 0 0 0 3px rgba(255,255,255,.5); transform: scale(.94); }
.tile.last { box-shadow: inset 0 calc(var(--tile) * -.07) 0 var(--gold-dark), 0 0 0 4px #fff; }
.tile.ok { background: linear-gradient(160deg, #7fe0aa, var(--green)); color: #fff; box-shadow: inset 0 calc(var(--tile) * -.07) 0 #22844f; }
.tile.no { background: linear-gradient(160deg, #ffa3a0, var(--red)); color: #fff; box-shadow: inset 0 calc(var(--tile) * -.07) 0 #b23a37; }
.tile.show { background: linear-gradient(160deg, #c3b2ff, #8a63d2); color: #fff; box-shadow: inset 0 calc(var(--tile) * -.07) 0 #6340a8; }
.tile.blank span { opacity: 0; }
.tray.locked .tile { cursor: default; }
.trail { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; overflow: visible; }
.trail polyline { fill: none; stroke: rgba(255, 255, 255, .75); stroke-width: 7; stroke-linecap: round; stroke-linejoin: round; }
.trail.show polyline { stroke: rgba(255, 255, 255, .9); }
.tray.shuffle .tile { animation: roll .5s ease-out both; }
@keyframes roll { 0% { transform: rotate(-200deg) scale(.3); opacity: 0; } 100% { transform: none; opacity: 1; } }

.controls { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.tip { margin: 0; color: var(--muted-2); font-size: .9rem; text-align: center; }

/* buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line); background: rgba(255,255,255,.07);
  border-radius: 12px; padding: 10px 16px; font-weight: 800; font-size: 1rem; cursor: pointer; min-height: 44px;
}
.btn:hover { background: rgba(255,255,255,.13); }
.btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.btn.primary { background: var(--gold); color: var(--bg); border-color: transparent; box-shadow: 0 4px 0 var(--gold-dark); font-family: var(--display); font-weight: 600; font-size: 1.1rem; }
.btn.primary:hover { background: #ffd35e; }
.btn.primary:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--gold-dark); }
.btn.wide { width: 100%; margin-top: 8px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.linkbtn { background: none; border: 0; color: var(--gold); font-weight: 800; cursor: pointer; padding: 4px; }
.linkbtn:hover { text-decoration: underline; }
.linkbtn.center { display: block; margin: 12px auto 0; }

/* ---------- side panel ---------- */
.side { display: flex; flex-direction: column; gap: 14px; }
.panel { background: rgba(255,255,255,.05); border: 1px solid var(--line); border-radius: 20px; padding: 16px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.panel h2 { margin: 0; font: 600 1.3rem var(--display); }
.panel h2 .count { display: inline-block; min-width: 30px; text-align: center; margin-left: 6px; padding: 1px 8px; border-radius: 999px; background: var(--gold); color: var(--bg); font-size: 1rem; }
.panel h3 { margin: 16px 0 8px; font: 600 1.1rem var(--display); color: var(--gold); }
.chips { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; max-height: 46vh; overflow: auto; }
.chips li {
  display: inline-flex; align-items: baseline; gap: 5px;
  padding: 5px 11px; border-radius: 999px; background: rgba(0,0,0,.22); border: 1px solid var(--line);
  font-weight: 800; text-transform: uppercase; letter-spacing: .04em; font-size: .95rem;
}
.chips li sup { font-size: .72rem; color: var(--gold); }
.chips li.new { animation: popin .35s ease-out; border-color: var(--green); }
.chips li.long { background: rgba(59, 178, 115, .22); }
@keyframes popin { from { transform: scale(.4); opacity: 0; } }
.results .chips li { cursor: pointer; }
.results .chips li:hover, .results .chips li.on { border-color: #c3b2ff; background: rgba(138, 99, 210, .35); }
#res-missed li { color: var(--muted); }
.empty, .hint { color: var(--muted-2); margin: 4px 0 0; font-size: .92rem; }
.results h2 { font-size: 1.7rem; }
.res-stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin-top: 10px; }
.res-stats div { background: rgba(0,0,0,.2); border-radius: 12px; padding: 10px; text-align: center; }
.res-stats b { display: block; font: 700 1.6rem var(--display); color: var(--gold); text-transform: uppercase; word-break: break-all; }
.res-stats span { color: var(--muted); font-size: .85rem; font-weight: 700; }
.res-stats .newbest { grid-column: 1 / -1; background: rgba(59, 178, 115, .25); font-weight: 800; }
.res-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 16px; }

/* ---------- toasts ---------- */
.toasts { position: fixed; top: 72px; left: 50%; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: none; width: max-content; max-width: 92vw; }
.toast { background: var(--ink); color: var(--bg); font-weight: 800; font-size: 1.05rem; padding: 10px 18px; border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.35); animation: toastIn .15s ease-out; transition: opacity .3s; text-align: center; }
.toast.good { background: var(--green); color: #fff; font: 700 1.25rem var(--display); }
.toast.big { background: var(--gold); font: 700 1.5rem var(--display); }
@keyframes toastIn { from { transform: translateY(-8px); opacity: 0; } }

/* ---------- overlays ---------- */
.overlay { position: fixed; inset: 0; z-index: 100; background: rgba(10, 14, 40, .75); backdrop-filter: blur(4px); display: flex; align-items: center; justify-content: center; padding: 14px; }
.card { position: relative; width: min(500px, 100%); max-height: calc(100dvh - 28px); overflow: auto; background: var(--bg-2); border: 1px solid var(--line); border-radius: 20px; padding: 22px; box-shadow: 0 30px 70px rgba(0,0,0,.5); }
.card h2 { margin: 0 0 6px; font: 700 2rem var(--display); }
.card h3 { margin: 18px 0 8px; font: 600 1.15rem var(--display); color: var(--gold); }
.card p { line-height: 1.5; margin: 0 0 10px; }
.card .big { font-size: 1.1rem; }
.kicker { font: 600 .8rem var(--display); letter-spacing: .12em; text-transform: uppercase; color: var(--gold); }
.kicker a { color: inherit; text-decoration: none; }
.close { position: absolute; top: 10px; right: 12px; width: 36px; height: 36px; border: 0; border-radius: 50%; background: rgba(255,255,255,.08); font-size: 1.6rem; line-height: 1; cursor: pointer; color: var(--muted); }
.field { margin-bottom: 14px; }
.label { display: block; font: 600 .8rem var(--display); letter-spacing: .08em; text-transform: uppercase; color: var(--muted); margin-bottom: 6px; }
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; background: rgba(0,0,0,.25); padding: 4px; border-radius: 12px; border: 1px solid var(--line); }
.seg.four { grid-template-columns: repeat(4, 1fr); }
.seg button { border: 0; background: transparent; border-radius: 9px; padding: 9px 6px; font-weight: 800; cursor: pointer; color: var(--muted); }
.seg button small { font-weight: 700; opacity: .8; }
.seg button[aria-pressed="true"] { background: var(--gold); color: var(--bg); }
.numrow { margin-top: 8px; display: flex; gap: 10px; align-items: center; }
.numrow input { width: 110px; font: 700 1.3rem var(--display); text-align: center; color: var(--ink); background: rgba(0,0,0,.3); border: 2px solid var(--line); border-radius: 12px; padding: 6px; }
.numrow input:focus { outline: none; border-color: var(--gold); }
.note { color: var(--muted); font-size: .88rem; line-height: 1.35; }
.steps { padding-left: 20px; line-height: 1.55; margin: 6px 0; }
.steps li { margin-bottom: 4px; }
.points { border-collapse: separate; border-spacing: 4px; margin-bottom: 8px; }
.points th { text-align: left; color: var(--muted); padding-right: 6px; font-size: .9rem; }
.points td { background: rgba(0,0,0,.25); border-radius: 8px; padding: 5px 10px; text-align: center; font-weight: 800; }
.points tr:last-child td { color: var(--gold); }
.help-demo { display: flex; gap: 14px; align-items: center; margin: 8px 0 6px; }
.help-demo p { margin: 0; }
.demo-grid { display: grid; grid-template-columns: repeat(3, 36px); gap: 4px; padding: 6px; background: var(--tray); border-radius: 10px; flex-shrink: 0; }
.demo-grid .t { height: 36px; display: grid; place-items: center; border-radius: 7px; background: var(--cube); color: var(--bg); font: 700 1.1rem var(--display); }
.demo-grid .t.on { background: var(--gold); }

/* ---------- smaller screens ---------- */
@media (max-width: 860px) {
  .layout { grid-template-columns: minmax(0, 1fr); gap: 14px; padding: 10px 10px 30px; }
  .tray { --tile: max(40px, min(84px, calc((100vw - 56px) / var(--n)), calc((100dvh - 300px) / var(--n)))); }
  .chips { max-height: none; }
}
@media (max-width: 480px) {
  .brand .site { display: none; }
  .brand h1 { font-size: 21px; }
  .topbar { gap: 6px; padding-inline: 8px; }
  .iconbtn { width: 33px; height: 33px; }
  .pill-stat { padding: 5px 9px; font-size: 1rem; }
  .pill-stat svg { width: 16px; height: 16px; }
  .wordbar { min-height: 50px; }
  .wordbar .current { font-size: 1.6rem; }
  .tray { padding: 10px; border-radius: 18px; }
  .card { padding: 18px 16px; }
  .seg.four button { font-size: .88rem; padding: 9px 2px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}
