/* The room in the app: the ghost kanji behind the poem, and the corner
   chrome: back to gallery, the ground toggle, the sound toggle, the season
   nav and the key hint. */

/* ---- the ghost kanji: the season's character behind the poem ----
   larger than the screen and cut by its edges, like a seal bigger than
   the sheet, so it is fainter (--kanji-alpha); its foot fades like thinned
   ink. room.js stacks two layers so one season's kanji dissolves into the
   next */
.glyph-bg {
  position: absolute; inset: 0; z-index: var(--z-behind); pointer-events: none;
  overflow: hidden;
  font-family: var(--font-glyph); font-weight: 500;
  font-size: clamp(420px, max(110vmin, 62vh), 1300px); line-height: 1;
  color: var(--glow); opacity: var(--kanji-alpha);
  -webkit-mask-image: linear-gradient(to bottom, var(--ink-black) 34%, transparent 96%);
  mask-image: linear-gradient(to bottom, var(--ink-black) 34%, transparent 96%);
}
.glyph-layer {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  transform: translateY(calc(-4vh - var(--glyph-lift)));
  opacity: 0; transition: opacity var(--dur-season) var(--ease-breath);
}
.glyph-layer.on { opacity: 1; }
/* boot: the kanji breathes in with the chrome */
body.preboot .glyph-layer { opacity: 0; }

/* back-to-gallery: appears top-centre, under the mode menu, only while reading a poem opened from the gallery */
.back-gallery {
  position: fixed; top: 78px; left: 0; right: 0; z-index: var(--z-chrome-over);
  width: max-content; margin-inline: auto;
  background: none; border: 1px solid var(--ink-soft); border-radius: 40px;
  color: var(--paper-dim); cursor: pointer;
  font-family: var(--font-label); font-weight: 300; font-size: var(--type-1);
  letter-spacing: 0.28em; text-transform: uppercase; padding: 9px 18px;
  transition: color var(--dur-hover) var(--ease-breath), border-color var(--dur-hover) var(--ease-breath), transform var(--dur-hover) var(--ease-breath);
}
.back-gallery:hover { color: var(--paper); border-color: var(--accent); transform: translateY(1px); }
.back-gallery[hidden] { display: none; }

/* ---- ground toggle (void ⇄ slate) · discreet, bottom-left ---- */
.ground-toggle {
  position: fixed; bottom: 30px; left: var(--edge-x); z-index: var(--z-chrome);
  display: flex; align-items: center; gap: 10px;
  background: none; border: none; cursor: pointer; padding: 4px 2px;
  color: var(--paper-dim);
  transition: color var(--dur-state) var(--ease-breath), opacity var(--dur-hush) var(--ease-breath);
}
.ground-toggle:hover { color: var(--paper); }
.ground-toggle:focus-visible { color: var(--accent); border-radius: 40px; }
.ground-toggle .gt-dot {
  width: 13px; height: 13px; border-radius: 50%; flex: none;
  border: 1px solid currentColor;
  /* half-lit disc: the "illuminated" half hints at the ground tone */
  background: linear-gradient(90deg, var(--ink-black) 0 50%, var(--paper-dim) 50% 100%);
  transition: background var(--dur-state) var(--ease-breath);
}
.ground-toggle.amoled .gt-dot { background: linear-gradient(90deg, var(--ink-black) 0 50%, var(--accent) 50% 100%); }
.ground-toggle .gt-label {
  font-family: var(--font-label); font-weight: 300; font-size: var(--type-1);
  letter-spacing: 0.32em; text-transform: uppercase;
}

/* ---- ambient sound toggle ---- */
/* more present than the other chrome: it reads as a real control (faint pill
   + border) and, while off, breathes gently to invite a first tap. Still
   recessive, never louder than the poem */
.sound-toggle {
  position: fixed; top: 90px; left: var(--edge-x); z-index: var(--z-chrome);
  display: flex; align-items: center; gap: 12px;
  cursor: pointer; padding: 9px 16px 9px 13px;
  color: var(--paper);
  background: color-mix(in srgb, var(--accent) 7%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 28%, var(--ink-soft));
  border-radius: 40px;
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
  transition: color var(--dur-state) var(--ease-breath), border-color var(--dur-state) var(--ease-breath),
              background var(--dur-state) var(--ease-breath), opacity var(--dur-hush) var(--ease-breath),
              transform var(--dur-state) var(--ease-breath);
}
.sound-toggle[hidden] { display: none; }
.sound-toggle:hover {
  color: var(--accent);
  border-color: color-mix(in srgb, var(--accent) 55%, transparent);
  background: color-mix(in srgb, var(--accent) 13%, transparent);
}
.sound-toggle:focus-visible { border-color: var(--accent); }
.sound-toggle .sound-label {
  font-family: var(--font-label); font-weight: 400; font-size: var(--type-1);
  letter-spacing: 0.32em; text-transform: uppercase;
  transition: color var(--dur-state) var(--ease-breath);
}
/* three little wave bars, the "speaker / wave" glyph */
.sound-glyph {
  display: inline-flex; align-items: center; gap: 3px; height: 16px;
}
.sound-glyph .wave {
  width: 2.5px; border-radius: 2px; background: currentColor; transform-origin: center;
  opacity: 0.7; transition: height var(--dur-hover) var(--ease-breath), opacity var(--dur-hover) var(--ease-breath), background var(--dur-state) var(--ease-breath);
}
.sound-glyph .w1 { height: 6px; }
.sound-glyph .w2 { height: 13px; }
.sound-glyph .w3 { height: 8px; }
/* on: accent-tinted, the bars breathe (below, motion permitting) */
.sound-toggle.on {
  color: var(--accent);
  border-color: color-mix(in srgb, var(--accent) 50%, transparent);
  background: color-mix(in srgb, var(--accent) 12%, transparent);
}
.sound-toggle.on .sound-glyph .wave { opacity: 1; background: var(--accent); }

/* ---- season nav (read + gallery) ---- */
/* each kanji sits in a 44px target; right: 31px keeps the glyphs' centre
   line on the edge's rhythm. Inactive ink is --paper-faint, not an opacity
   over --paper-dim, so it stays at AA on both grounds */
.seasons {
  position: fixed; right: 31px; top: 50%; transform: translateY(-50%); z-index: var(--z-chrome);
  display: flex; flex-direction: column; gap: 10px; align-items: center;
}
.seasons button {
  display: flex; align-items: center; justify-content: center;
  min-width: 44px; min-height: 44px; border-radius: 50%;
  background: none; border: none; cursor: pointer;
  font-family: var(--font-glyph); font-size: 25px; line-height: 1;
  color: var(--paper-faint);
  writing-mode: vertical-rl; letter-spacing: 0.1em; padding: 3px;
  transition: color 0.7s var(--ease-breath), transform 0.7s var(--ease-breath);
}
/* compose has its own season picker */
body[data-mode="compose"] .seasons { display: none; }
.seasons button:hover { color: var(--paper-dim); }
.seasons button:focus-visible { color: var(--paper); }
.seasons button.active {
  color: var(--accent); transform: scale(1.16);
  text-shadow: 0 0 14px color-mix(in srgb, var(--glow) 35%, transparent);
}

.hint {
  position: fixed; bottom: 34px; right: 40px; z-index: var(--z-chrome);
  font-family: var(--font-label); font-size: var(--type-1); font-weight: 300;
  letter-spacing: 0.24em; color: var(--paper-faint); text-transform: uppercase;
}
/* the key hint speaks of read mode only */
body:not([data-mode="read"]) .hint { opacity: 0; }

/* tablets, large phones: the right-side season nav keeps clear of the poem
   column; keyboard hints are for keyboards (here they met the controls) */
@media (max-width: 820px) {
  .seasons { right: 9px; gap: 6px; }
  .seasons button { font-size: 22px; }
  .hint { display: none; }
}

/* phones: one quiet top row, 間 · sound · ground on the left, the season
   row on the right */
@media (max-width: 640px) {
  /* sound becomes its three bars in a circle; the aria-label still names it */
  .sound-toggle { top: 14px; left: 64px; width: 40px; height: 40px; padding: 0; justify-content: center; }
  .sound-toggle .sound-label { display: none; }
  /* the ground disc joins the row (it stays bottom-left on larger screens,
     where it has room); it rests in compose and gallery */
  .ground-toggle { bottom: auto; top: 12px; left: 108px; width: 44px; height: 44px; padding: 0; justify-content: center; }
  .ground-toggle .gt-label { display: none; }
  body[data-mode="compose"] .ground-toggle,
  body[data-mode="gallery"] .ground-toggle { display: none; }

  .seasons {
    top: 22px; right: 18px; left: auto; transform: none;
    flex-direction: row; gap: 18px;
  }
  .seasons button {
    writing-mode: horizontal-tb; font-size: 20px; padding: 4px 2px;
    min-width: 28px; min-height: 0; text-align: center;
  }

  .back-gallery { top: 110px; }
}

@media (max-width: 380px) {
  .sound-toggle { left: 56px; }
  .ground-toggle { left: 98px; }
  .seasons { right: 14px; gap: 12px; }
  .seasons button { font-size: 18px; }
}

/* short viewports: the vertical season nav stays, tighter */
@media (max-height: 560px) {
  .seasons { gap: 4px; }
}

/* landscape phones: season row top-right, sound and ground in a column
   under the brand */
@media (max-height: 480px) and (max-width: 900px) {
  .seasons {
    top: 14px; right: 16px; left: auto; transform: none;
    flex-direction: row; gap: 12px;
  }
  .seasons button { writing-mode: horizontal-tb; font-size: 18px; min-width: 0; min-height: 0; }
  .sound-toggle { top: 60px; left: 14px; width: 40px; height: 40px; padding: 0; justify-content: center; }
  .sound-toggle .sound-label { display: none; }
  .ground-toggle { bottom: auto; top: 104px; left: 12px; width: 44px; height: 44px; padding: 0; justify-content: center; }
  .ground-toggle .gt-label { display: none; }
  body[data-mode="compose"] .ground-toggle,
  body[data-mode="gallery"] .ground-toggle { display: none; }
  .back-gallery { top: 56px; left: auto; right: 16px; margin: 0; }
  .hint { display: none; }
}

/* the one motion exception (identity.md 8): while sound is off, the
   control breathes to invite a first tap; it rests on hover and while the
   page is hushed. When on, the bars breathe. The ghost kanji breathes
   too, slower than anything else on the page */
@media (prefers-reduced-motion: no-preference) {
  .glyph-ink { animation: glyphBreath 18s ease-in-out infinite alternate; }
  @keyframes glyphBreath {
    from { opacity: 1; }
    to   { opacity: 0.7; }
  }
  .sound-toggle:not(.on) { animation: sndInvite 4.4s var(--ease-breath) infinite; }
  .sound-toggle:not(.on):hover { animation: none; }
  body.hushed .sound-toggle:not(.on) { animation: none; }
  .sound-toggle.on .sound-glyph .w1 { animation: sndWave 2.6s var(--ease-breath) infinite; }
  .sound-toggle.on .sound-glyph .w2 { animation: sndWave 2.6s var(--ease-breath) 0.3s infinite; }
  .sound-toggle.on .sound-glyph .w3 { animation: sndWave 2.6s var(--ease-breath) 0.6s infinite; }
  @keyframes sndInvite {
    0%, 100% { border-color: color-mix(in srgb, var(--accent) 24%, var(--ink-soft)); }
    50%      { border-color: color-mix(in srgb, var(--accent) 60%, transparent); }
  }
  @keyframes sndWave {
    0%, 100% { transform: scaleY(0.55); }
    50%      { transform: scaleY(1); }
  }
}

/* nothing slides: the back pill stays put under the pointer; the kanji
   changes season in a short plain fade */
@media (prefers-reduced-motion: reduce) {
  .back-gallery:hover { transform: none; }
  .glyph-layer { transition: opacity 0.5s linear; }
}
