/* Five Letters: how it looks.
   Phone first. The page is exactly one screen tall: header, grid, keyboard.
   The grid shrinks to fit whatever height is left, so nothing scrolls. */

:root {
  --bg: #121316;
  --text: #f2f2f2;
  --muted: #9a9ca3;
  --line: #3a3c42;
  --key: #7c7f87;
  --green: #4c9a52;
  --yellow: #c3a332;
  --grey: #3a3c42;
  --header: 52px;
  --keyboard: 196px;   /* the keyboard's height; the grid gets what is left */
}

/* High contrast: orange and blue are easy to tell apart for most
   colour-blind eyes. Tiles also get a shape, so colour is not the only clue. */
body.contrast {
  --green: #f2751f;
  --yellow: #4aa3e8;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

body {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;           /* the real visible height on phones */
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

button { font: inherit; color: inherit; }

/* ---- header ---- */

header {
  height: var(--header);
  flex: none;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0 max(8px, (100% - 520px) / 2);   /* on a wide screen, keep the buttons near the game */
  padding-top: env(safe-area-inset-top);
  border-bottom: 1px solid var(--line);
}

h1 {
  flex: 1;
  margin: 0;
  font-size: 22px;
  letter-spacing: 0.04em;
  text-align: center;
}

.icon {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 8px;
  background: none;
  cursor: pointer;
}
.icon:hover { background: #ffffff14; }
/* the help button sits alone on the left; this keeps the title centred */
#btn-help { margin-right: 44px; }

#debug {
  margin: 0;
  padding: 4px 8px;
  font-size: 12px;
  color: var(--muted);
  text-align: center;
}

/* ---- grid ---- */

main {
  flex: 1;
  min-height: 0;
  position: relative;
  display: grid;
  place-items: center;
  padding: 8px;
}

/* main is a "container", so the grid can size itself to the space main has.
   One tile is the smallest of: 62px, a fifth of the width, a sixth of the height.
   (cqw and cqh are 1% of the container's width and height.) */
main { container-type: size; }

#grid {
  --gap: 5px;
  --tile: min(62px,
              (100cqw - 16px) / 5 - var(--gap),
              (100cqh - 16px) / 6 - var(--gap));
  display: grid;
  gap: var(--gap);
}

.row {
  display: grid;
  grid-template-columns: repeat(5, var(--tile));
  gap: var(--gap);
}

.tile {
  width: var(--tile);
  height: var(--tile);
  display: grid;
  place-items: center;
  position: relative;
  border: 2px solid var(--line);
  font-size: calc(var(--tile) * 0.55);
  font-weight: 700;
  text-transform: uppercase;
  user-select: none;
}
.tile.filled { border-color: var(--key); }
.tile.filled:not(.green):not(.yellow):not(.grey) { animation: pop 0.1s; }

.tile.green, .tile.yellow, .tile.grey { border-color: transparent; color: #fff; }
.tile.green { background: var(--green); }
.tile.yellow { background: var(--yellow); }
.tile.grey { background: var(--grey); }

/* Shapes for high contrast: a bar along the bottom for "right place",
   a dot in the corner for "wrong place". */
body.contrast .tile.green::after,
body.contrast .tile.yellow::after {
  content: "";
  position: absolute;
  background: #fff;
}
body.contrast .tile.green::after { left: 18%; right: 18%; bottom: 8%; height: 9%; border-radius: 2px; }
body.contrast .tile.yellow::after { top: 8%; right: 8%; width: 18%; height: 18%; border-radius: 50%; }

.tile.flip { animation: flip 0.5s ease-in-out; }   /* 0.5s matches FLIP_TIME in game.js */
.tile.bounce { animation: bounce 0.5s ease; }
.row.shake { animation: shake 0.4s; }

@keyframes pop { 50% { transform: scale(1.1); } }
@keyframes flip { 50% { transform: rotateX(90deg); } }
@keyframes bounce { 40% { transform: translateY(-30%); } 70% { transform: translateY(4%); } }
@keyframes shake {
  20%, 60% { transform: translateX(-6px); }
  40%, 80% { transform: translateX(6px); }
}

@media (prefers-reduced-motion: reduce) {
  .tile.flip, .tile.bounce, .row.shake, .tile.filled { animation: none !important; }
}

/* ---- message ---- */

/* fixed and on top, so "Copied" shows over the stats panel too */
#toast {
  position: fixed;
  top: calc(var(--header) + 12px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 20;
  width: max-content;
  max-width: calc(100% - 32px);
  padding: 10px 16px;
  border-radius: 6px;
  background: var(--text);
  color: var(--bg);
  font-weight: 700;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}
#toast.show { opacity: 1; }

/* ---- keyboard ---- */

#keyboard {
  height: var(--keyboard);
  flex: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  max-width: 500px;
  margin: 0 auto;
  padding: 0 6px 8px;
  padding-bottom: calc(8px + env(safe-area-inset-bottom));
  user-select: none;
}

.key-row {
  flex: 1;
  display: flex;
  gap: 5px;
}
/* the middle row has 9 keys: half a key of space at each end */
.key-row:nth-child(2)::before,
.key-row:nth-child(2)::after { content: ""; flex: 0.5; }

.key {
  flex: 1;
  min-width: 0;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 5px;
  background: var(--key);
  font-size: 18px;
  font-weight: 700;
  text-transform: uppercase;
  cursor: pointer;
  touch-action: manipulation;   /* no double-tap zoom while typing fast */
}
.key.wide { flex: 1.5; font-size: 13px; }
.key:active { filter: brightness(1.2); }
.key.green { background: var(--green); }
.key.yellow { background: var(--yellow); }
.key.grey { background: var(--grey); color: #c8c9cd; }

/* ---- panels ---- */

.panel {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 16px;
  background: #000000aa;
  overflow-y: auto;
}
.panel[hidden] { display: none; }

.card {
  position: relative;
  width: 100%;
  max-width: 420px;
  padding: 20px;
  border-radius: 10px;
  background: #1d1f24;
  border: 1px solid var(--line);
}
.card h2 { margin: 0 0 12px; font-size: 20px; }
.card h3 { margin: 18px 0 8px; font-size: 15px; }
.card p { margin: 0 0 10px; line-height: 1.4; }

.close {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 44px;
  height: 44px;
  border: 0;
  background: none;
  font-size: 28px;
  line-height: 1;
  cursor: pointer;
}

.example { display: flex; gap: 4px; margin: 4px 0 6px; --tile: 36px; }

.numbers {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  text-align: center;
}
.numbers b { display: block; font-size: 30px; }
.numbers span { font-size: 12px; color: var(--muted); }

.bar-row { display: flex; align-items: center; gap: 6px; margin: 4px 0; font-size: 14px; }
.bar-row > span:first-child { width: 12px; }
.bar {
  padding: 2px 6px;
  background: var(--grey);
  text-align: right;
  font-weight: 700;
}
.bar.today { background: var(--green); }

#end {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}
#end[hidden] { display: none; }
.next { flex: 1; text-align: center; }
.next span { display: block; font-size: 13px; color: var(--muted); }
.next b { font-size: 26px; font-variant-numeric: tabular-nums; }

.share {
  flex: 1;
  min-height: 52px;
  border: 0;
  border-radius: 8px;
  background: var(--green);
  color: #fff;
  font-size: 18px;
  font-weight: 700;
  cursor: pointer;
}

.option {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
}
.option > span { flex: 1; }
.option small { display: block; margin-top: 2px; color: var(--muted); }
.option input { width: 24px; height: 24px; accent-color: var(--green); }
.option input:disabled { opacity: 0.5; }

:focus-visible { outline: 2px solid #7fb8ff; outline-offset: 2px; }
