/* ==========================================================================
   Word Attack — styles. Theme tokens and shared components come from
   shared/style.css.

   The field is a well, MAX rows tall, with the pile of word tiles sitting
   at its bottom and a dashed line at the top: the overflow. It glows sun,
   then tomato, as the pile nears the line. The text box sits right under it,
   so with a phone's keyboard up the field is still in view.
   ========================================================================== */

.wa {
  --row: 28px; /* one word tile, with its gap */
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr); /* never wider than the screen, whatever is inside */
  gap: .6rem;
  max-width: 30rem;
  margin-inline: auto;
  padding-block: .5rem 2rem;
}
@media (max-height: 700px) { .wa { --row: 24px; } }

.wa-title { font-size: clamp(1.6rem, 7vw, 2.2rem); text-align: center; }
.wa-sub { font-size: 1.2rem; text-align: center; }
.wa-note { font-size: 1.02rem; font-weight: 700; text-align: center; }
.wa-center { text-align: center; font-weight: 700; }
.wa-center-btn { justify-self: center; }
.wa-result { font-size: 1.5rem; font-weight: 900; text-align: center; }
.wa-best { font-weight: 800; text-align: center; color: var(--muted); }
.wa-best.wa-center { font-size: 1.2rem; color: var(--olive); }
:root[data-theme="dark"] .wa-best.wa-center { color: #b7cc6a; }
.wa-top { display: flex; align-items: center; gap: .6rem; }
.wa-top__end { margin-inline-start: auto; }
.wa-clock { margin-inline-start: auto; font-size: 1.3rem; font-variant-numeric: tabular-nums; }
.wa-clock + .wa-top__end { margin-inline-start: 0; }

/* ---------- Menu ---------- */

.wa-menu { display: grid; gap: .5rem; }
.wa-tagline { font-size: 1.08rem; font-weight: 700; text-align: center; }
.wa-langs { display: grid; gap: .35rem; }
.wa-art { --row: 30px; display: flex; flex-direction: column-reverse; align-items: center; gap: 4px; padding: .6rem 0 .2rem; list-style: none; }
.wa-art .wa-word:nth-child(2) { translate: 22px 0; }
.wa-art .wa-word:nth-child(3) { translate: -18px 0; }
.wa-art .wa-word:nth-child(4) { translate: 8px 0; rotate: -4deg; }
.howto { max-width: 30rem; margin: 1.5rem auto 0; padding: .25rem 1rem; }
.howto summary { min-height: var(--tap); display: flex; align-items: center; font-weight: 800; cursor: pointer; }
.howto ol { display: grid; gap: .5rem; padding: 0 0 1rem; padding-inline-start: 1.4rem; list-style: decimal; }
.host--small .host__teta { width: 76px; }
.host--small .bubble { padding: .65rem .9rem; font-weight: 700; }
.choices { display: grid; gap: .5rem; }
.choices--row { grid-auto-flow: column; grid-auto-columns: 1fr; }
.choice { position: relative; display: block; cursor: pointer; }
.choice input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.choice span { display: flex; align-items: center; justify-content: center; min-height: 44px; padding: .3rem .7rem; font-weight: 800; text-align: center; background: var(--surface); border: 3px solid var(--line); border-radius: 14px 16px 13px 17px; }
.choice input:checked + span { background: var(--sun); color: var(--ink); box-shadow: 0 3px 0 var(--line); }
.choice input:focus-visible + span { outline: 3px solid var(--focus); outline-offset: 2px; }

/* ---------- The field ---------- */

.wa-play { display: grid; gap: .5rem; }
.wa-field {
  position: relative;
  height: calc(var(--max) * var(--row) + 26px);
  overflow: hidden;
  background:
    repeating-linear-gradient(transparent 0 calc(var(--row) - 1px), color-mix(in srgb, var(--line) 6%, transparent) calc(var(--row) - 1px) var(--row)),
    var(--surface);
  border: 3px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 5px 0 var(--line);
  cursor: text;
  transition: border-color .3s, box-shadow .3s;
}
/* The overflow line, at the top. */
.wa-field__line { position: absolute; inset: 10px 10px auto; border-top: 2.5px dashed color-mix(in srgb, var(--tomato) 55%, transparent); }
.wa-field[data-level="warn"] { border-color: #d89b00; }
.wa-field[data-level="danger"] { border-color: var(--tomato); animation: wa-danger .9s ease-in-out infinite; }
@keyframes wa-danger { 50% { box-shadow: 0 5px 0 var(--line), 0 0 0 6px color-mix(in srgb, var(--tomato) 30%, transparent); } }

.wa-pile { position: absolute; inset: auto 8px 8px; display: flex; flex-direction: column-reverse; align-items: center; gap: 3px; padding: 0; list-style: none; }

/* A word tile. */
.wa-word {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  height: calc(var(--row) - 3px);
  max-width: 100%;
  padding: 0 .75rem;
  font-size: calc(var(--row) * .56);
  font-weight: 800;
  line-height: 1;
  letter-spacing: .02em;
  white-space: nowrap;
  color: var(--text);
  background: var(--surface-2);
  border: 2.5px solid var(--line);
  border-radius: 9px 10px 8px 11px;
  box-shadow: 0 2px 0 var(--line);
  transition: transform .12s, border-color .12s, background-color .12s;
}
.wa-pile .wa-word { translate: calc(var(--x, 0%) * .9) 0; rotate: var(--r, 0deg); }
.wa-word__icon { font-size: .9em; }
.wa-word mark { color: var(--olive); background: none; }
:root[data-theme="dark"] .wa-word mark { color: #b7cc6a; }
.wa-word.is-typing { border-color: var(--sun); background: color-mix(in srgb, var(--sun) 22%, var(--surface-2)); transform: scale(1.06); z-index: 1; }
.wa-word--bomb { background: color-mix(in srgb, var(--tomato) 20%, var(--surface-2)); }
.wa-word--scramble { border-style: dashed; background: color-mix(in srgb, var(--sea) 22%, var(--surface-2)); letter-spacing: .14em; }
.wa-word--mirror { background: color-mix(in srgb, #8c6bd6 24%, var(--surface-2)); }
.wa-word--mirror .wa-word__text { display: inline-block; transform: scaleX(-1); }
.wa-word--emoji { padding-inline: .6rem; font-size: calc(var(--row) * .7); background: color-mix(in srgb, var(--sun) 18%, var(--surface-2)); }
.wa-word.is-attack { border-color: var(--tomato); box-shadow: 0 2px 0 var(--tomato); }
.wa-word__from { position: absolute; inset-inline-start: calc(100% + 4px); top: 50%; translate: 0 -50%; max-width: 5rem; overflow: hidden; font-size: .62rem; font-weight: 800; letter-spacing: 0; text-overflow: ellipsis; color: var(--tomato); }
.wa-word.is-new { animation: wa-drop .28s cubic-bezier(.3, 1.4, .5, 1); }
.wa-word.is-attack.is-new { animation: wa-hit .45s cubic-bezier(.3, 1.4, .5, 1); }
@keyframes wa-drop { from { opacity: 0; translate: 0 -40px; } }
@keyframes wa-hit { 0% { opacity: 0; scale: 1.8; } 60% { opacity: 1; scale: .9; } }

/* A cleared word bursts. */
.wa-ghost { position: fixed; z-index: 20; margin: 0; pointer-events: none; animation: wa-burst .16s ease-out forwards; }
/* Quick, and up and away, so the word behind it shows at once. */
@keyframes wa-burst { from { opacity: .7; } to { opacity: 0; translate: 0 -14px; scale: 1.08; } }

/* A word fired at someone. */
.wa-shot { position: fixed; z-index: 21; font-size: 1.5rem; pointer-events: none; }

/* A word over the field: Go!, a streak, a hit. */
.wa-flash {
  position: absolute;
  z-index: 3;
  top: 22px;
  left: 50%;
  translate: -50% 0;
  padding: .2rem .8rem;
  font-weight: 900;
  white-space: nowrap;
  color: var(--ink);
  background: var(--sun);
  border: 2.5px solid var(--line);
  border-radius: 999px;
  opacity: 0;
  scale: .8;
  transition: opacity .15s, scale .2s cubic-bezier(.3, 1.6, .5, 1);
  pointer-events: none;
}
.wa-flash.is-on { opacity: 1; scale: 1; }
.wa-flash.is-good { background: #b7d36a; }
.wa-flash.is-bad { color: #fff; background: var(--tomato); }

/* No keyboard yet (opened from a link, or a room starting): a tap to bring it up. */
.wa-cover { position: absolute; z-index: 4; inset: auto 0 0; padding: .6rem; font: inherit; font-weight: 900; color: #fff; background: color-mix(in srgb, var(--sea) 92%, transparent); border: 0; cursor: pointer; }
.wa-out { position: absolute; z-index: 5; inset: 40% 1rem auto; padding: .6rem; font-size: 1.3rem; font-weight: 900; text-align: center; color: #fff; background: var(--tomato); border: 3px solid var(--line); border-radius: 14px; }

/* The text box. */
.wa-typebar { display: flex; }
.wa-input {
  flex: 1;
  width: 100%;
  min-width: 0;
  min-height: 52px;
  padding: .5rem 1rem;
  font: inherit;
  font-size: 1.3rem; /* 16px or more: phones do not zoom in */
  font-weight: 800;
  color: var(--text);
  background: var(--surface);
  border: 3px solid var(--line);
  border-radius: 14px 16px 13px 17px;
  box-shadow: 0 4px 0 var(--line);
}
.wa-input:focus { outline: none; border-color: var(--sea); }
:root[data-theme="dark"] .wa-input:focus { border-color: #7cc8ea; }
.wa-input:disabled { opacity: .5; }
.wa-input.is-wrong { animation: wa-shake .3s; }
@keyframes wa-shake { 25%, 75% { translate: -5px 0; } 50% { translate: 5px 0; } }

/* ---------- The others, along the top ---------- */

.wa-rivals { display: flex; gap: .35rem; overflow-x: auto; padding: 0 0 .1rem; list-style: none; scrollbar-width: none; }
.wa-rival { display: flex; align-items: center; gap: .3rem; flex: none; padding: .2rem .35rem .2rem .5rem; background: var(--surface); border: 2px solid var(--line); border-radius: 999px; transition: opacity .3s; }
.wa-rival__face { font-size: 1.1rem; line-height: 1; }
.wa-rival__name { max-width: 4.5rem; overflow: hidden; font-size: .8rem; font-weight: 800; text-overflow: ellipsis; white-space: nowrap; }
/* How full their pile is. */
.wa-rival__meter { position: relative; width: 8px; height: 22px; overflow: hidden; background: var(--surface-2); border: 1.5px solid var(--line); border-radius: 3px; }
.wa-rival__meter i { position: absolute; inset: auto 0 0; height: 0; background: var(--olive); transition: height .25s; }
.wa-rival.is-danger .wa-rival__meter i { background: var(--tomato); }
.wa-rival.is-out { opacity: .4; text-decoration: line-through; }

/* ---------- The end ---------- */

.wa-standings { display: grid; gap: .35rem; padding: 0; list-style: none; }
.wa-standing { display: grid; grid-template-columns: 1.6rem auto minmax(0, 1fr) auto; align-items: center; gap: .5rem; padding: .4rem .7rem; background: var(--surface); border: 2px solid var(--line); border-radius: 14px; }
.wa-standing.is-you { background: var(--surface-2); border-width: 3px; }
.wa-standing__place { font-size: 1.1rem; text-align: center; }
.wa-standing bdi { overflow: hidden; font-weight: 800; text-overflow: ellipsis; white-space: nowrap; }
.wa-standing small { font-weight: 700; color: var(--muted); }

@media (prefers-reduced-motion: reduce) {
  .wa-word.is-new, .wa-ghost, .wa-field[data-level="danger"], .wa-input.is-wrong { animation: none; }
  .wa-ghost { display: none; }
}
