/* === Rain — level-based tap-to-spell game =========================
   Companion to js/games/rain-level.js, hosted on the standalone
   /games/rain page (rain.html). Ported from the designer's prototype
   (share/from designer/rain game) and reskinned to the site palette:
   every colour is a var(--…) token, so it themes light/dark with the
   rest of the site instead of the prototype's fixed neon look.

   Structure: a centred card holds a header (level badge + family +
   controls), a segmented level-progress bar, the target word, the
   falling-kana lane, and three overlays (level picker, level-up,
   all-cleared). Tiles inside .rain2__lane are positioned/moved from JS.
   ==================================================================== */

/* script toggle (hiragana / katakana) — segmented pill above the game */
.rain-scripts {
  display: flex; justify-content: center; gap: 6px;
  margin: 2px auto 14px; padding: 5px;
  width: max-content; max-width: 94vw;
  background: var(--inset); border: 1px solid var(--line); border-radius: 999px;
}
.rain-scripts__btn {
  display: inline-flex; align-items: center; gap: 7px;
  font-family: var(--font-ui); font-size: 14px; font-weight: 600; color: var(--muted);
  padding: 8px 18px; border: none; border-radius: 999px; background: transparent; cursor: pointer;
  transition: background .2s, color .2s;
}
.rain-scripts__btn b { font-family: var(--font-kana-sans); font-size: 16px; font-weight: 700; }
.rain-scripts__btn:hover { color: var(--accent); }
.rain-scripts__btn.is-on { background: var(--accent); color: #fff; }
.rain-scripts__btn.is-on:hover { color: #fff; }

.rain2-host { display: flex; justify-content: center; padding: 4px 0 8px; }

.rain2 {
  position: relative;
  width: min(460px, 94vw);
  height: min(788px, 80vh);
  min-height: 560px;
  display: flex;
  flex-direction: column;
  padding: 18px 18px 20px;
  border-radius: 26px;
  background: var(--card);
  border: 1px solid var(--line-2);
  box-shadow: var(--shadow-card);
  overflow: hidden;
  font-family: var(--font-ui);
  color: var(--ink);
}

/* ambient rain streaks behind the card contents */
.rain2__ambient {
  position: absolute; inset: 0; pointer-events: none; z-index: 0; opacity: 0.5;
}
.rain2__streak {
  position: absolute; top: 0; width: 1px;
  background: linear-gradient(180deg, transparent, var(--accent-line), transparent);
  animation: rain2Streak linear infinite;
}

/* ── header ──────────────────────────────────────────────────── */
.rain2__top {
  position: relative; z-index: 2;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
}
.rain2__level {
  display: flex; align-items: center; gap: 11px;
  background: none; border: none; padding: 0; cursor: pointer;
  font-family: inherit; text-align: left; color: inherit;
}
.rain2__levelbadge {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  width: 52px; height: 52px; border-radius: 16px;
  background: var(--accent); color: #fff;
  box-shadow: 0 8px 22px -8px var(--accent-line);
}
.rain2__levelbadge small { font-size: 9px; font-weight: 700; letter-spacing: .12em; opacity: .8; line-height: 1; }
.rain2__levelbadge b { font-size: 22px; font-weight: 700; line-height: 1; margin-top: 2px; }
.rain2__fam { display: flex; flex-direction: column; gap: 3px; }
.rain2__famname {
  display: flex; align-items: center; gap: 5px;
  font-family: var(--font-kana-sans); font-weight: 700; font-size: 20px;
  color: var(--ink); line-height: 1;
}
.rain2__famname i { font-style: normal; font-size: 11px; color: var(--accent); }
.rain2__famromaji { font-size: 11px; color: var(--faint); letter-spacing: .02em; }

.rain2__actions { display: flex; align-items: center; gap: 8px; }
.rain2__form {
  cursor: pointer; font-family: inherit; font-size: 11px; font-weight: 600; letter-spacing: .03em;
  color: var(--muted); padding: 9px 12px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--inset);
  transition: background .2s, color .2s, border-color .2s;
}
.rain2__form:hover { background: var(--accent-bg); color: var(--accent); border-color: var(--accent-line); }
.rain2__reset {
  cursor: pointer; font-family: inherit; font-size: 15px; color: var(--faint);
  width: 38px; height: 38px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--inset);
  display: flex; align-items: center; justify-content: center;
  transition: background .2s, color .2s;
}
.rain2__reset:hover { background: var(--accent-bg); color: var(--accent); }

/* ── progress ────────────────────────────────────────────────── */
.rain2__progress {
  position: relative; z-index: 2;
  display: flex; align-items: center; gap: 10px; margin-top: 16px;
}
.rain2__segs { flex: 1; display: flex; gap: 5px; }
.rain2__seg {
  flex: 1; height: 6px; border-radius: 99px;
  background: var(--line); transition: background .3s;
}
.rain2__seg.is-on { background: var(--accent); }
.rain2__progresslabel { font-size: 11px; font-weight: 600; color: var(--faint); white-space: nowrap; }

/* ── target word ─────────────────────────────────────────────── */
.rain2__target { position: relative; z-index: 2; text-align: center; margin-top: 20px; min-height: 86px; }
.rain2__units {
  display: flex; justify-content: center; align-items: baseline; gap: 3px; flex-wrap: wrap;
  font-family: var(--font-kana-sans);
}
.rain2__unit {
  display: inline-block; font-size: 32px; font-weight: 700; padding: 0 2px;
  color: var(--ink); transition: color .2s, transform .2s, opacity .2s;
}
.rain2__unit.is-done { color: var(--green); opacity: .5; }
.rain2__unit.is-next { color: var(--accent); transform: scale(1.16); }
.rain2__meaning {
  margin: 12px auto 0; max-width: 340px;
  font-size: 13px; line-height: 1.4; color: var(--muted); text-wrap: pretty;
}

/* ── lane ────────────────────────────────────────────────────── */
.rain2__lane {
  position: relative; z-index: 1; flex: 1; margin-top: 14px;
  border-radius: 18px; overflow: hidden;
  background: var(--subtle-bg); border: 1px solid var(--line);
}
.rain2__lanefield { position: absolute; inset: 0; }
.rain2__floor {
  position: absolute; left: 10px; right: 10px; bottom: 0; height: 2px;
  background: linear-gradient(90deg, transparent, var(--accent-line), transparent);
}
.rain2__tile {
  position: absolute; top: 0; left: 0;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-kana-sans); font-weight: 700;
  color: var(--ink); border-radius: 14px;
  background: var(--inset); border: 1px solid var(--line);
  box-shadow: 0 4px 12px -6px rgba(0,0,0,0.25);
  cursor: pointer; user-select: none; -webkit-user-select: none;
  will-change: transform;
}
.rain2__tile.is-correct {
  background: var(--green); color: #fff; border-color: transparent;
  animation: rain2Glow .5s ease-out; pointer-events: none;
}
.rain2__tile.is-wrong { background: var(--red); color: #fff; border-color: transparent; }

/* word-complete flash */
.rain2__flash {
  position: absolute; inset: 0; z-index: 5; pointer-events: none;
  display: flex; align-items: center; justify-content: center;
}
.rain2__flashinner { display: flex; flex-direction: column; align-items: center; gap: 6px; animation: rain2Flash .9s ease-out forwards; }
.rain2__flashcheck {
  width: 66px; height: 66px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 32px; color: #fff; background: var(--green);
  box-shadow: 0 12px 34px -8px var(--green);
}
.rain2__flashword { font-size: 13px; font-weight: 600; color: var(--green); letter-spacing: .04em; }

/* ── foot ────────────────────────────────────────────────────── */
.rain2__foot {
  position: relative; z-index: 2;
  display: flex; align-items: center; justify-content: space-between;
  margin-top: 14px; padding: 0 2px;
}
.rain2__hint { font-size: 11px; color: var(--faint); }
.rain2__score { font-size: 11px; color: var(--muted); font-weight: 600; }

/* ── overlays ────────────────────────────────────────────────── */
.rain2__overlay {
  position: absolute; inset: 0; z-index: 20;
  display: flex; flex-direction: column;
  padding: 22px 20px 20px;
  background: color-mix(in srgb, var(--card) 94%, transparent);
  backdrop-filter: blur(4px);
}
.rain2__overlay[hidden] { display: none; }

/* level picker */
.rain2__picker { z-index: 30; }
.rain2__pickerhead { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 6px; }
.rain2__pickertitle { display: flex; flex-direction: column; gap: 3px; }
.rain2__pickertitle b { font-size: 11px; font-weight: 700; letter-spacing: .24em; color: var(--accent); }
.rain2__pickertitle span { font-size: 12px; color: var(--muted); }
.rain2__x {
  cursor: pointer; font-family: inherit; font-size: 16px; color: var(--muted);
  width: 36px; height: 36px; border-radius: 11px;
  border: 1px solid var(--line); background: var(--inset);
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.rain2__x:hover { background: var(--accent-bg); color: var(--accent); }
.rain2__levelgrid {
  flex: 1; overflow-y: auto; margin-top: 12px;
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 9px;
  align-content: start; padding-right: 2px;
}
.rain2__lv {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 5px;
  min-height: 60px; padding: 9px 4px; border-radius: 14px; cursor: pointer;
  font-family: inherit; text-align: center; transition: transform .12s;
  color: var(--muted); border: 1px solid var(--line); background: var(--inset);
}
.rain2__lv:hover { transform: translateY(-1px); }
.rain2__lv small { font-size: 10px; font-weight: 700; letter-spacing: .08em; opacity: .7; }
.rain2__lv b { font-family: var(--font-kana-sans); font-size: 17px; font-weight: 700; line-height: 1.15; letter-spacing: .02em; }
.rain2__lv.is-reached { color: var(--ink); border-color: var(--accent-line); background: var(--accent-bg); }
.rain2__lv.is-current { color: #fff; border-color: transparent; background: var(--accent); box-shadow: 0 8px 20px -8px var(--accent-line); }

/* level-up + all-cleared + start share the centred layout */
.rain2__levelup, .rain2__cleared, .rain2__start {
  align-items: center; justify-content: center; gap: 16px; text-align: center; padding: 30px;
}

/* start screen */
.rain2__starticon { font-size: 52px; animation: rain2Pop .5s ease-out both; }
.rain2__startsub {
  font-size: 14px; line-height: 1.5; color: var(--muted);
  max-width: 300px; text-wrap: pretty; animation: rain2Rise .5s ease-out .1s both;
}
.rain2__start .rain2__cta { font-size: 16px; padding: 15px 40px; margin-top: 4px; }
.rain2__lueyebrow { font-size: 12px; font-weight: 700; letter-spacing: .32em; color: var(--accent); animation: rain2Rise .5s ease-out both; }
.rain2__lunum { font-family: var(--font-ui); font-size: 64px; font-weight: 700; color: var(--ink); line-height: 1; margin-top: 6px; animation: rain2Rise .5s ease-out both; }
.rain2__lusub { font-size: 13px; color: var(--muted); animation: rain2Rise .5s ease-out .1s both; }
.rain2__lucard {
  display: flex; flex-direction: column; align-items: center; gap: 12px;
  padding: 22px 26px; border-radius: 22px;
  background: var(--accent-bg); border: 1px solid var(--accent-line);
  animation: rain2Pop .5s ease-out .18s both;
}
.rain2__lufam { font-family: var(--font-kana-sans); font-size: 24px; font-weight: 700; color: var(--accent); }
.rain2__luchars { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; max-width: 320px; }
.rain2__luchar { display: flex; flex-direction: column; align-items: center; gap: 3px; }
.rain2__luchar b { font-family: var(--font-kana-sans); font-size: 32px; font-weight: 700; color: var(--ink); }
.rain2__luchar span { font-size: 11px; color: var(--faint); }
.rain2__cta {
  cursor: pointer; font-family: inherit; font-size: 14px; font-weight: 600; color: #fff;
  padding: 14px 32px; border-radius: 14px; border: none; background: var(--accent);
  box-shadow: 0 12px 30px -10px var(--accent-line); animation: rain2Rise .5s ease-out .28s both;
}
.rain2__cta:hover { filter: brightness(1.06); }
.rain2__cta--ghost { background: var(--inset); color: var(--muted); border: 1px solid var(--line); box-shadow: none; }
.rain2__cta--ghost:hover { background: var(--accent-bg); color: var(--accent); filter: none; }

.rain2__clearedicon { font-size: 56px; animation: rain2Pop .6s ease-out both; }
.rain2__clearedbig { font-family: var(--font-ui); font-size: 26px; font-weight: 700; color: var(--ink); margin-top: 8px; }
.rain2__clearedtext { font-size: 13px; line-height: 1.5; color: var(--muted); max-width: 300px; text-wrap: pretty; animation: rain2Rise .5s ease-out .2s both; }
.rain2__clearedbtns { display: flex; gap: 10px; animation: rain2Rise .5s ease-out .3s both; }

/* ── keyframes ───────────────────────────────────────────────── */
@keyframes rain2Pop { 0%{transform:scale(.6);opacity:0} 60%{transform:scale(1.06)} 100%{transform:scale(1);opacity:1} }
@keyframes rain2Rise { from{transform:translateY(18px);opacity:0} to{transform:translateY(0);opacity:1} }
@keyframes rain2Glow { 0%,100%{box-shadow:0 0 0 0 var(--accent-bg)} 50%{box-shadow:0 0 26px 4px var(--accent-line)} }
@keyframes rain2Streak { from{transform:translateY(-120%)} to{transform:translateY(120%)} }
@keyframes rain2Flash { 0%{opacity:0;transform:scale(.9)} 20%{opacity:1;transform:scale(1)} 80%{opacity:1} 100%{opacity:0;transform:scale(1.04)} }
