/*
 * Kanji rich back-face styles — extracted so the Challenge Box can render
 * kanji items with the same visual as the standalone Kanji game without
 * pulling in the entire kanji/css/style.css (which carries game-page tile
 * sizing rules that would override goi/bunpou tile dimensions in the box).
 *
 * Every rule here is scoped to `.flipped-overlay …` (the body-level overlay)
 * or to one of the kanji-specific overlay element ids/classes
 * (`.kanji-examples-trigger`, `.kanji-examples-overlay`, `.radical-overlay`).
 * None of these touch goi/bunpou tile chrome.
 *
 * Keep this file in sync with the same blocks in kanji/css/style.css. A
 * future cleanup can dedupe by having kanji/css/style.css @import this file.
 */

/* ------------------------------------------------------------
 * Kanji `.flipped` neutralizers — the legacy `.domino.flipped {
 * transform: scale(2.2) }` rule from goi/css/style.css would scale
 * the kanji wrapper 2.2x, blowing the contents past the overlay box.
 * Kanji uses the body-level overlay as its modal, so the wrapper
 * itself must not scale or get the legacy ::after ring. The in-grid
 * tile (a closed tile carrying `.flipped` only as a JS state marker)
 * also stays a normal closed kanji tile — its back face is hidden by
 * the rule below.
 *
 * Lives here (not in kanji/css/style.css) so the Challenge Box, which
 * does NOT load kanji/css/style.css, gets the same neutralization.
 * ------------------------------------------------------------ */
.domino.domino-kanji.flipped {
  transform: none !important;
  -webkit-transform: none !important;
  z-index: auto !important;
  box-shadow:
    0 3px 0 var(--tile-edge),
    0 6px 16px rgba(0, 0, 0, 0.5);
}
.grid-container > .domino.domino-kanji.flipped:nth-child(3n+1),
.grid-container > .domino.domino-kanji.flipped:nth-child(3n+2),
.grid-container > .domino.domino-kanji.flipped:nth-child(3n+3),
.grid-container > .domino.domino-kanji.flipped:nth-child(4n+1),
.grid-container > .domino.domino-kanji.flipped:nth-child(4n+4) {
  transform: none !important;
}
.domino.domino-kanji.flipped::after { display: none !important; }
.grid-container .domino.domino-kanji.flipped .domino-face-back {
  display: none !important;
}

/* ------------------------------------------------------------
 * Back-face wrapper inside the body-level overlay (kanji only)
 * ------------------------------------------------------------ */
:is(.flipped-overlay, .tile-panel-inner, .tile-overlay-card) .domino.domino-kanji .domino-face-back {
  background: var(--canvas-elev);
  border-radius: 14px;
  padding: 1.4rem 1.2rem;
  gap: 0.5rem;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
}

/* ------------------------------------------------------------
 * Top header — three stacked rows (kun / on / meaning) + brass double-rule
 * ------------------------------------------------------------ */
:is(.flipped-overlay, .tile-panel-inner, .tile-overlay-card) .kanji-readings-top {
  min-height: 33%;
  flex: 0 0 auto;
  margin: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 0.35rem;
}
:is(.flipped-overlay, .tile-panel-inner, .tile-overlay-card) .reading-line {
  text-align: center;
  font-family: var(--font-jp);
  line-height: 1.15;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding: 0 0.4rem;
}
/* Reading chips — multiple on/kun (on = blue --read-on, kun = coral --read-kun).
   Filled = primary; outlined = secondary; brass ring = the linking headword's
   reading. Each chip carries data-audio → tap to hear (NihonAudio delegate). */
:is(.flipped-overlay, .tile-panel-inner, .tile-overlay-card) .reading-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.3rem;
  padding: 0 0.3rem;
}
:is(.flipped-overlay, .tile-panel-inner, .tile-overlay-card) .reading-tag {
  font-family: var(--font-ui, sans-serif);
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  opacity: 0.85;
  margin-right: 0.1rem;
}
:is(.flipped-overlay, .tile-panel-inner, .tile-overlay-card) .reading-tag-on { color: var(--read-on); }
:is(.flipped-overlay, .tile-panel-inner, .tile-overlay-card) .reading-tag-kun { color: var(--read-kun); }
:is(.flipped-overlay, .tile-panel-inner, .tile-overlay-card) .reading-chip {
  font-family: var(--font-jp);
  font-size: 1.3rem;
  font-weight: 500;
  line-height: 1.1;
  padding: 0.1rem 0.55rem;
  border-radius: 999px;
  border: 1px solid transparent;
  background: transparent;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
:is(.flipped-overlay, .tile-panel-inner, .tile-overlay-card) .on-chip { color: var(--read-on); border-color: var(--read-on); }
:is(.flipped-overlay, .tile-panel-inner, .tile-overlay-card) .kun-chip { color: var(--read-kun); border-color: var(--read-kun); }
/* Primary chip filled: text = canvas so it contrasts in BOTH light + dark
   (reading colors are tuned against --canvas-elev in each mode). */
:is(.flipped-overlay, .tile-panel-inner, .tile-overlay-card) .reading-chip.is-primary.on-chip { background: var(--read-on); color: var(--canvas-elev); }
:is(.flipped-overlay, .tile-panel-inner, .tile-overlay-card) .reading-chip.is-primary.kun-chip { background: var(--read-kun); color: var(--canvas-elev); }
:is(.flipped-overlay, .tile-panel-inner, .tile-overlay-card) .reading-chip.is-context { outline: 2px solid var(--brass); outline-offset: 1px; }
:is(.flipped-overlay, .tile-panel-inner, .tile-overlay-card) .reading-chip.reading-more {
  font-family: var(--font-ui, sans-serif);
  font-size: 0.95rem;
  font-weight: 600;
  opacity: 0.85;
  border-style: dashed;
}
:is(.flipped-overlay, .tile-panel-inner, .tile-overlay-card) .reading-line.reading-meaning {
  color: var(--text);
  font-size: 1.45rem;
  font-weight: 400;
  margin-top: 0.15rem;
  line-height: 1.25;
  white-space: normal;
}
:is(.flipped-overlay, .tile-panel-inner, .tile-overlay-card) .reading-divider {
  border: 0;
  border-top: 4px double var(--brass);
  margin: 0.6rem 0 0.5rem;
  height: 0;
  opacity: 0.9;
}

/* ------------------------------------------------------------
 * Glyph row — kanji on the left, radical chips stacked on the right
 * ------------------------------------------------------------ */
:is(.flipped-overlay, .tile-panel-inner, .tile-overlay-card) .kanji-glyph-row {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 0.7rem;
  padding: 0.2rem 0.4rem 0.2rem 0.8rem;
  flex: 1 1 auto;
  min-height: 0;
}
:is(.flipped-overlay, .tile-panel-inner, .tile-overlay-card) .kanji-svg-wrapper {
  flex: 0 0 auto;
  width: 58%;
  max-width: 220px;
  aspect-ratio: 1 / 1;
  margin: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}
:is(.flipped-overlay, .tile-panel-inner, .tile-overlay-card) .kanji-svg-wrapper > svg {
  width: 100%;
  height: 100%;
}
:is(.flipped-overlay, .tile-panel-inner, .tile-overlay-card) .kanji-svg-wrapper > svg path {
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}
:is(.flipped-overlay, .tile-panel-inner, .tile-overlay-card) .kanji-svg-wrapper [id*="StrokeNumbers"] { display: none; }

/* Stroke-order play button */
:is(.flipped-overlay, .tile-panel-inner, .tile-overlay-card) .stroke-play-btn {
  position: absolute;
  top: -2px;
  right: -2px;
  width: 36px;
  height: 36px;
  padding: 8px;
  border: 1px solid var(--rule);
  border-radius: 50%;
  background: rgba(20, 23, 33, 0.7);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
  color: var(--brass);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s ease, background 0.15s ease, transform 0.18s ease;
  -webkit-tap-highlight-color: transparent;
  z-index: 2;
}
:is(.flipped-overlay, .tile-panel-inner, .tile-overlay-card) .stroke-play-btn:hover {
  color: var(--read-label);
  background: rgba(20, 23, 33, 0.9);
}
:is(.flipped-overlay, .tile-panel-inner, .tile-overlay-card) .stroke-play-btn:active { transform: scale(0.92); }
:is(.flipped-overlay, .tile-panel-inner, .tile-overlay-card) .stroke-play-btn svg {
  width: 100%;
  height: 100%;
  display: block;
}
:is(.flipped-overlay, .tile-panel-inner, .tile-overlay-card) .stroke-play-btn[hidden] { display: none; }
:is(.flipped-overlay, .tile-panel-inner, .tile-overlay-card) .stroke-play-btn.is-animating { color: var(--vermilion); }
/* LIGHT MODE — the dark navy disc reads as a black blob on the porcelain card.
   Flip it to a light bone disc with a VERMILION play glyph (the app's primary
   accent, matching the kanji glyph) + a vermilion-tinted ring. Hardcoded (not
   var(--vermilion)) so it stays vermilion even when study mode rebinds the token. */
:root[data-theme="light"] :is(.flipped-overlay, .tile-panel-inner, .tile-overlay-card) .stroke-play-btn {
  background: #fffaf0;
  border-color: rgba(194, 64, 47, 0.45);
  color: #c2402f;
  box-shadow: 0 1px 3px rgba(60, 50, 30, 0.22);
}
:root[data-theme="light"] :is(.flipped-overlay, .tile-panel-inner, .tile-overlay-card) .stroke-play-btn:hover {
  background: #ffffff;
  color: #a3302a;
}

/* ------------------------------------------------------------
 * Radical chips — column of tappable radicals to the right of the glyph
 * ------------------------------------------------------------ */
:is(.flipped-overlay, .tile-panel-inner, .tile-overlay-card) .kanji-radicals-row {
  display: flex;
  flex-direction: column;
  flex-wrap: nowrap;
  align-items: stretch;
  justify-content: center;
  gap: 0.4rem;
  margin: 0;
  flex: 1 1 auto;
  min-width: 0;
}
:is(.flipped-overlay, .tile-panel-inner, .tile-overlay-card) .kanji-radicals-row .radical-chip {
  width: 100%;
  justify-content: flex-start;
}
:is(.flipped-overlay, .tile-panel-inner, .tile-overlay-card) .radical-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.3rem 0.65rem;
  background: rgba(232, 220, 196, 0.06);
  border: 1px solid var(--rule);
  border-radius: 100px;
  font-family: var(--font-en);
  font-size: 0.78rem;
  color: var(--text-soft);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
}
:is(.flipped-overlay, .tile-panel-inner, .tile-overlay-card) .radical-chip:hover {
  background: rgba(232, 220, 196, 0.12);
  border-color: rgba(232, 220, 196, 0.3);
}
:is(.flipped-overlay, .tile-panel-inner, .tile-overlay-card) .radical-chip:active { transform: scale(0.96); }
:is(.flipped-overlay, .tile-panel-inner, .tile-overlay-card) .radical-chip .chip-glyph {
  font-family: var(--font-jp);
  font-size: 1.15rem;
  line-height: 1;
  font-weight: 600;
  color: var(--chip-color, var(--bone));
}
:is(.flipped-overlay, .tile-panel-inner, .tile-overlay-card) .radical-chip .chip-meaning {
  letter-spacing: 0.02em;
}

/* ------------------------------------------------------------
 * Mnemonic — italic body text under the glyph
 * ------------------------------------------------------------ */
:is(.flipped-overlay, .tile-panel-inner, .tile-overlay-card) .kanji-mnemonic {
  margin: 0.6rem 0.4rem 0.5rem;
  padding: 0.65rem 0.85rem;
  background: rgba(201, 164, 100, 0.07);
  border-left: 3px solid var(--brass);
  border-radius: 0 8px 8px 0;
  font-family: var(--font-en);
  font-style: italic;
  font-size: 0.92rem;
  line-height: 1.45;
  color: var(--text);
  text-align: left;
}
:is(.flipped-overlay, .tile-panel-inner, .tile-overlay-card) .kanji-mnemonic strong {
  color: var(--brass);
  font-style: normal;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}
:is(.flipped-overlay, .tile-panel-inner, .tile-overlay-card) .kanji-mnemonic .mnemonic-placeholder {
  color: var(--text-soft);
  font-size: 0.88rem;
}

/* ------------------------------------------------------------
 * Compound-examples trigger button
 * ------------------------------------------------------------ */
:is(.flipped-overlay, .tile-panel-inner, .tile-overlay-card) .kanji-examples-trigger-row {
  display: flex;
  justify-content: center;
  margin: 0.4rem 0 0.2rem;
}
.kanji-examples-trigger {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.42rem 1rem;
  background: rgba(232, 220, 196, 0.06);
  border: 1px solid var(--rule);
  border-radius: 100px;
  font-family: var(--font-en);
  font-size: 0.86rem;
  color: var(--brass);
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}
.kanji-examples-trigger:hover {
  background: rgba(201, 164, 100, 0.12);
  border-color: rgba(201, 164, 100, 0.4);
  color: var(--read-label);
}
.kanji-examples-trigger .trigger-jp {
  font-family: var(--font-jp);
  font-size: 1rem;
  font-weight: 600;
}
.kanji-examples-trigger .trigger-en { letter-spacing: 0.04em; }

/* ------------------------------------------------------------
 * Compound-examples overlay (body-level, sits above the kanji popup)
 * ------------------------------------------------------------ */
.kanji-examples-overlay {
  position: fixed;
  inset: 0;
  z-index: 1200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: rgba(20, 23, 33, 0.93);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  animation: kanji-examples-fade-in 0.18s ease-out;
}
.kanji-examples-overlay[hidden] { display: none !important; }
@keyframes kanji-examples-fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}
.kanji-examples-overlay .examples-card {
  width: min(94vw, 480px);
  max-height: min(82vh, 600px);
  overflow: auto;
  background: var(--canvas-elev);
  border: 1px solid var(--rule);
  border-radius: 14px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.6);
  padding: 1.2rem 1rem 1.1rem;
  cursor: pointer;
}
.kanji-examples-overlay .examples-header {
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
  padding-bottom: 0.7rem;
  margin-bottom: 0.6rem;
  border-bottom: 1px solid var(--rule);
}
.kanji-examples-overlay .examples-title-jp {
  font-family: var(--font-jp);
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--brass);
}
.kanji-examples-overlay .examples-title-en {
  flex: 1 1 auto;
  font-family: var(--font-en);
  font-size: 0.92rem;
  color: var(--text-soft);
  font-style: italic;
}
.kanji-examples-overlay .examples-title-en strong {
  color: var(--text);
  font-style: normal;
  font-weight: 700;
  font-family: var(--font-jp);
  font-size: 1.1rem;
}
.kanji-examples-overlay .examples-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}
.kanji-examples-overlay .example-row {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.55rem 0.7rem;
  background: rgba(232, 220, 196, 0.04);
  border-left: 2px solid var(--brass);
  border-radius: 0 6px 6px 0;
  min-height: 2.3rem;
}
.kanji-examples-overlay .example-jp {
  flex: 0 0 auto;
  font-family: var(--font-jp);
  font-size: 1.85rem;
  font-weight: 600;
  color: var(--text);
  line-height: 1.05;
  white-space: nowrap;
}
.kanji-examples-overlay .example-jp ruby { ruby-position: over; }
.kanji-examples-overlay .example-jp rt {
  font-size: 0.5em;
  color: var(--brass);
  font-weight: 500;
  letter-spacing: -0.05em;
}
.kanji-examples-overlay .example-jp .example-target-kanji {
  color: var(--vermilion);
}
.kanji-examples-overlay .example-en {
  flex: 1 1 auto;
  font-family: var(--font-en);
  font-size: 0.92rem;
  color: var(--text-soft);
  font-style: italic;
  line-height: 1.3;
  min-width: 0;
  overflow-wrap: anywhere;
}
.kanji-examples-overlay .audio-btn { flex: 0 0 auto; }

/* ------------------------------------------------------------
 * Compound-jump trigger — small forward-tap wrapping the Japanese
 * ruby of each compound row. Tap → opens the Goi flipped overlay
 * (#goi-from-kanji-overlay) with full Goi card content. The English
 * meaning span and the audio button are NOT inside the trigger, so
 * everything outside the ruby remains a "tap to close popup" target.
 * ------------------------------------------------------------ */
.kanji-examples-overlay .compound-jump-trigger {
  display: inline-flex;
  align-items: center;
  flex: 0 0 auto;
  text-decoration: none;
  color: inherit;
  border-bottom: 1px dashed rgba(201, 164, 100, 0.55);
  padding: 0.05rem 0.05rem 0.1rem;
  border-radius: 2px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.12s ease, border-color 0.12s ease;
}
.kanji-examples-overlay .compound-jump-trigger:hover,
.kanji-examples-overlay .compound-jump-trigger:focus-visible {
  background: rgba(201, 164, 100, 0.10);
  border-bottom-color: var(--brass);
  outline: none;
}
.kanji-examples-overlay .compound-jump-trigger:active {
  background: rgba(201, 164, 100, 0.18);
}
/* The trigger replaces the .example-jp span as the leftmost row
 * element, so it inherits the same flex-shrink behavior. */
.kanji-examples-overlay .compound-jump-trigger .example-jp {
  flex: 0 0 auto;
}

/* ------------------------------------------------------------
 * Goi-from-kanji overlay — quaternary popup opened when the user
 * taps a compound's Japanese writing in #kanji-examples-overlay.
 * Stacks above the examples popup (z-index 1300 > 1200). Provides
 * its own dim+blur backdrop. The Goi card inside is `.domino-goi
 * .flipped` rendered by NihonGoiBackFace — styled by the shared
 * css/goi-back-face.css. The card centers itself via position:fixed
 * (defined in goi-back-face.css), so this overlay is just a backdrop
 * + click target for "tap anywhere to return to examples popup".
 * ------------------------------------------------------------ */
.goi-from-kanji-overlay {
  position: fixed;
  inset: 0;
  z-index: 1300;
  background: rgba(20, 23, 33, 0.93);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  cursor: pointer;
  animation: goi-from-kanji-fade-in 0.18s ease-out;
}
.goi-from-kanji-overlay[hidden] { display: none !important; }
@keyframes goi-from-kanji-fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}
/* Bump the inner card's z-index above this overlay's backdrop so it
 * receives clicks normally. position:fixed already comes from
 * goi-back-face.css; we only need to bump z-index here. */
.goi-from-kanji-overlay .domino.domino-goi.flipped {
  z-index: 1301;
}

/* The .goi-jump-overlay rule (cross-pillar Goi-jump backdrop) lives in
 * css/goi-back-face.css so it travels with every page that already
 * loads Goi card rendering. */

/* ------------------------------------------------------------
 * Radical-detail overlay (body-level, opens when a chip is tapped)
 * ------------------------------------------------------------ */
.radical-overlay {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(86vw, 360px);
  max-height: min(78vh, 520px);
  z-index: 1100;
  background: var(--canvas-elev);
  border-radius: 14px;
  border: 1px solid var(--rule);
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.6);
  padding: 1.4rem 1.2rem;
  cursor: pointer;
  overflow: auto;
  will-change: auto;
  backface-visibility: visible;
  -webkit-backface-visibility: visible;
  transform-style: flat;
  -webkit-transform-style: flat;
}
.radical-overlay[hidden] { display: none !important; }

.radical-overlay .radical-glyph {
  display: block;
  text-align: center;
  font-family: var(--font-jp);
  font-size: 4rem;
  line-height: 1;
  font-weight: 600;
  color: var(--chip-color, var(--bone));
  margin: 0 0 0.4rem;
}
.radical-overlay .radical-meaning {
  text-align: center;
  font-family: var(--font-en);
  font-size: 0.78rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-soft);
  margin: 0 0 1.1rem;
}
.radical-overlay .radical-section-label {
  text-align: center;
  font-family: var(--font-en);
  font-size: 0.7rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-faint);
  margin: 0 0 0.7rem;
  padding-top: 0.7rem;
  border-top: 1px solid var(--rule);
}
.radical-overlay .radical-empty {
  text-align: center;
  font-family: var(--font-en);
  font-style: italic;
  font-size: 0.85rem;
  color: var(--text-soft);
  margin: 0 0 0.4rem;
}
.radical-overlay .radical-examples {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.4rem;
}
.radical-overlay .example-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.15rem;
  padding: 0.5rem 0.3rem;
  background: linear-gradient(155deg, var(--bone-bright) 0%, var(--bone) 50%, var(--bone-shadow) 100%);
  border-radius: 8px;
  box-shadow:
    inset -1px -1px 2px rgba(74, 69, 51, 0.25),
    inset 1px 1px 2px rgba(255, 255, 255, 0.4);
}
.radical-overlay .example-tile .example-kanji {
  font-family: var(--font-jp);
  font-size: 1.4rem;
  line-height: 1;
  font-weight: 700;
  color: #1a1d2c; /* always dark ink on the ivory bone tile (was --canvas, which flips light in light mode) */
}
.radical-overlay .example-tile .example-meaning {
  font-family: var(--font-en);
  font-size: 0.62rem;
  color: #1a1d2c; /* always dark ink on the ivory bone tile (was --canvas, which flips light in light mode) */
  opacity: 0.75;
  text-align: center;
  line-height: 1.15;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
