/* Glyphs met in the world, spirit popups, speech bubbles, the translate switch */

/* A glyph met in the world, with its meaning underneath.
   The meaning floats below the circle so showing it never moves anything. */
.glyph-with-meaning {
  position: relative;
  color: var(--stone-light);
}

.glyph-with-meaning .glyph-meaning {
  position: absolute;
  top: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  width: 6em;
  field-sizing: content; /* shrinks to the text where the browser supports it */
  min-width: 2em;
  max-width: 8em;
}

.glyph-with-meaning div.glyph-meaning {
  width: max-content;
}

/* Placed in a scene */
/* Inscription popup: the name of the missing picture, and the glyphs on it */
.poi-content {
  position: relative;
}

.inscription-label {
  align-self: flex-start;
  color: var(--stone);
}

/* Glyphs in a row (here and below) are centred on one line, so names and glyphs of
   different sizes line up */
.inscription-words {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 16px;
  row-gap: 44px; /* room for the meanings floating under the glyphs */
  /* room for a meaning below the glyphs, balanced by space above so they sit centred */
  padding: 20px 0 28px;
}

/* Right below the sentence describing it (e.g. the ritual stone) */
.inscription-words.is-close {
  padding-top: 0;
}

/* A step right after the carved glyphs (the ritual stone's "Touch the ground") sits closer to them */
.inscription-words + .poi-step {
  margin-top: -16px;
}

/* Spirit popup: portrait at the bottom left, the conversation on the right from the top.
   Fixed size from the start, so nothing moves as the conversation grows. */
.poi-popup.is-wide {
  width: min(820px, 100%);
  max-width: none;
}

/* Tall enough for three lines of dialogue and the Reply button without scrolling */
.poi-popup.is-wide .poi-content {
  height: min(610px, calc(100vh - 64px));
  flex-direction: row;
  align-items: stretch;
  padding: 24px;
}

.spirit-view {
  display: flex;
  align-items: flex-start;
  gap: 24px;
  width: 100%;
  height: 100%;
}

/* Portrait: a zoomed-in crop of the spirit's full image, no frame,
   fading out softly at the edges where the crop cuts the figure */
.spirit-portrait {
  position: relative;
  align-self: flex-end; /* sits at the bottom of the popup */
  flex-shrink: 0;
  width: 200px;
  height: 240px;
  overflow: hidden;
  -webkit-mask-image: radial-gradient(ellipse 60% 60% at 50% 45%, black 55%, transparent 100%);
  mask-image: radial-gradient(ellipse 60% 60% at 50% 45%, black 55%, transparent 100%);
}

.spirit-portrait img {
  position: absolute;
  top: 50%;
  left: 50%;
  height: auto;
}

/* Mirrored so the spirit looks towards the dialogue */
.spirit-portrait.is-mirrored {
  transform: scaleX(-1);
}

/* The conversation so far: spirit lines on the left, the player's replies on the right */
.dialogue-log {
  flex: 1;
  align-self: stretch;
  display: flex;
  flex-direction: column;
  gap: 36px; /* room for the meanings floating under the glyphs */
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--stone-dark) transparent;
  padding: 18px 30px 40px 18px; /* room for glows, the translate buttons, and a meaning under the last line */
}

/* Speech bubble: the spirit's on the left with its tail bottom left,
   the player's on the right with its tail bottom right */
.dialogue-line {
  position: relative;
  align-self: flex-start;
  max-width: 100%;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 30px 10px 14px;
  background: var(--bubble-spirit);
  border: 1px solid var(--bubble-spirit-border);
  border-radius: 18px;
  box-shadow: 0 5px 12px rgba(0, 0, 0, 0.5);
}

.dialogue-line::after {
  content: "";
  position: absolute;
  bottom: -7px;
  left: 26px;
  width: 12px;
  height: 12px;
  background: inherit;
  border-right: 1px solid var(--bubble-spirit-border);
  border-bottom: 1px solid var(--bubble-spirit-border);
  transform: rotate(45deg);
}

.dialogue-line.is-player {
  align-self: flex-end;
  background: var(--bubble-player);
  border-color: var(--bubble-player-border);
}

.dialogue-line.is-player::after {
  left: auto;
  right: 26px;
  border-color: var(--bubble-player-border);
}


.dialogue-row {
  display: flex;
  flex-wrap: nowrap;
  align-items: flex-start;
  gap: 12px;
}

.dialogue-words {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 16px;
  row-gap: 44px;
}

/* The last two glyphs of a question, kept on the same line (see appendWords) */
.keep-together {
  display: inline-flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: inherit;
}

/* A meaning being written sits on its own background, over the bubble (or the lamp's Press button) */
.dialogue-line .glyph-with-meaning input.glyph-meaning,
.lamp-glyph .glyph-with-meaning input.glyph-meaning {
  z-index: 2;
  background: var(--forest-darkest);
  border-radius: 4px;
}

/* Translate button: the arrows, overlapping the bubble's right side */
.translate-button {
  position: absolute;
  top: 50%;
  right: -12px;
  width: 24px;
  height: 24px;
  padding: 5px;
  transform: translateY(-50%);
  background: var(--forest-darkest);
  border: 1px solid var(--stone-dark);
  border-radius: 50%;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.6);
  cursor: pointer;
  transition: transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

/* The arrows image, recoloured with filters (the original is dark grey):
   pale stone normally, sunlight gold on hover or while the meanings are shown.
   (Filters, not a mask, so it also shows when index.html is opened straight from the folder.) */
.translate-icon {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: brightness(0) invert(86%) sepia(14%) saturate(320%) hue-rotate(8deg);
  transition: filter 0.2s ease, transform 0.3s ease;
}

.translate-button:hover,
.translate-button:focus-visible {
  transform: translateY(-50%) scale(1.15);
  border-color: var(--sunlight);
  box-shadow: 0 5px 12px rgba(0, 0, 0, 0.7), 0 0 10px rgba(217, 182, 92, 0.35);
  outline: none;
}

.translate-button:hover .translate-icon,
.translate-button:focus-visible .translate-icon,
.translate-button.is-active .translate-icon {
  filter: brightness(0) invert(76%) sepia(45%) saturate(620%) hue-rotate(5deg) brightness(95%);
}

.translate-button:active {
  transform: translateY(-50%) scale(0.9);
  transition-duration: 0.08s;
}

/* While the meanings are shown: gold, and the arrows turn over */
.translate-button.is-active {
  border-color: var(--sunlight);
}

.translate-button.is-active .translate-icon {
  transform: rotate(180deg);
}

/* Glyph ↔ meaning: each item flips over like a card, word by word */
.dialogue-item {
  display: inline-flex;
  align-items: center;
}

/* A glyph flipping to its meaning, or a whole sentence flipping to its phrase */
.dialogue-item.is-flipping,
.dialogue-words.is-flipping,
.inscription-words.is-flipping {
  animation: item-flip 0.32s ease-in-out;
}

/* A whole sentence in place of its glyphs, once all are confirmed (see the phrase bank) */
.translation-phrase {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 84px;
  padding: 0 8px;
  font-family: var(--font-main);
  font-size: 1.5rem;
  font-style: italic;
  line-height: 1.2;
  text-align: center;
  color: var(--stone-light);
}

/* In place of the glyphs, it fills the space they took (the bubble keeps its size) */
.is-whole > .translation-phrase {
  flex: 1 1 100%;
  align-self: stretch;
  min-height: 0;
}

.dialogue-line.is-player .translation-phrase {
  color: var(--sunlight);
}

/* Glyphs written somewhere (inscription, wall) with the translate switch on their right */
.translatable-line {
  position: relative;
  padding-right: 46px; /* room between the glyphs and the switch */
}

.translatable-line .translate-button {
  right: 0;
}

@keyframes item-flip {
  0% { transform: perspective(300px) rotateY(0deg); opacity: 1; }
  50% { transform: perspective(300px) rotateY(90deg); opacity: 0.3; }
  100% { transform: perspective(300px) rotateY(0deg); opacity: 1; }
}

/* A meaning in place of its glyph: same height as the circle, so the bubble keeps its size */
.translation-word {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 84px;
  height: 84px;
  padding: 0 6px;
  font-family: var(--font-handwriting);
  font-size: 1.6rem;
  line-height: 1;
  color: var(--stone-light);
  white-space: nowrap;
}

.translation-word.is-confirmed {
  font-family: var(--font-main);
  font-size: 1.3rem;
}

.dialogue-line.is-player .translation-word {
  color: var(--sunlight);
}

.translation-word.is-unknown {
  color: var(--stone);
}
