/* The nerd layer: the chat box (js/chat.js), the combat log
   (js/views/ticker.js), the footer HUD and tips (js/hud.js), the
   keybindings sheet (js/keys.js), the achievement toast, /dance and the
   secret's party (js/fx/party.js), number tick-ups (js/fx/tick.js), and the
   small freshen touches: a light sweeping over cards on hover and items
   glowing in their quality's colour. A genre homage: original shapes only.
   Motion lives under prefers-reduced-motion: no-preference. */

/* --- the chat box ------------------------------------------------------------- */

.chat {
  position: fixed;
  left: max(1rem, env(safe-area-inset-left));
  bottom: max(1rem, env(safe-area-inset-bottom));
  z-index: 40;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.45rem;
  width: min(30rem, calc(100vw - 2rem));
  pointer-events: none;
}

.chat-launcher,
.chat-box {
  pointer-events: auto;
}

.chat-log {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.12rem;
  width: 100%;
  max-height: 13.5rem;
  margin: 0;
  padding: 0;
  overflow: hidden;
  list-style: none;
  pointer-events: none;
}

.chat-open .chat-log {
  overflow-y: auto;
  padding: 0.5rem 0.6rem;
  border-radius: var(--radius-sm);
  background: rgba(6, 4, 10, 0.94);
  box-shadow: 0 0 0 1px rgba(212, 175, 55, 0.25), 0 12px 30px rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(6px);
  pointer-events: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--gold-dim) transparent;
}

.chat-open .chat-log:empty {
  display: none;
}

.chat-line {
  max-width: 100%;
  padding: 0.08rem 0.45rem;
  border-radius: 4px;
  background: rgba(6, 4, 10, 0.92);
  box-shadow: 0 0 0 1px rgba(212, 175, 55, 0.14), 0 4px 12px rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(4px);
  font-size: var(--fs-small);
  line-height: 1.4;
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.9);
  overflow-wrap: anywhere;
}

.chat-open .chat-line {
  background: transparent;
  box-shadow: none;
  backdrop-filter: none;
}

/* A line fades a while after it is said, unless the box is open. */
.chat-old {
  animation: chat-fade 11s linear forwards;
}

.chat-open .chat-old {
  animation: none;
}

@keyframes chat-fade {
  0%,
  82% {
    opacity: 1;
  }

  100% {
    opacity: 0;
    visibility: hidden;
  }
}

.chat-system {
  color: var(--text-tip-yellow);
}

.chat-roll {
  color: var(--text-tip-yellow);
}

.chat-say {
  color: var(--text-strong);
}

.chat-error {
  color: var(--text-bad);
}

.chat-help {
  color: var(--text-muted);
}

.chat-loot {
  color: var(--text-ok);
}

.chat-achievement {
  color: var(--text-tip-orange);
}

.chat-name {
  font-weight: 700;
  color: var(--class-text);
}

.chat-name:hover {
  text-decoration: underline;
}

.chat-item {
  font-weight: 700;
  color: var(--quality-color);
}

.chat-cmd {
  font-family: var(--font-mono);
  color: var(--text-tip-cyan);
}

.chat-you {
  font-weight: 700;
  color: var(--text-strong);
}

.chat-achieve {
  font-weight: 700;
  color: var(--text-tip-yellow);
}

.chat-box {
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.3rem 0.6rem;
  border: 1px solid var(--gold);
  border-radius: var(--radius-sm);
  background: rgba(6, 4, 10, 0.94);
  box-shadow: 0 0 0 1px var(--ink-line), 0 0 22px rgba(212, 175, 55, 0.22), 0 12px 30px rgba(0, 0, 0, 0.55);
}

.chat-box:focus-within {
  box-shadow: 0 0 0 1px var(--ink-line), 0 0 0 3px rgba(247, 231, 172, 0.35), 0 0 26px rgba(212, 175, 55, 0.3);
}

.chat-prompt {
  flex: none;
  font-family: var(--font-display);
  font-size: var(--fs-small);
  font-weight: 800;
  letter-spacing: 0.06em;
  color: var(--text-gold);
}

.chat-input {
  flex: 1;
  min-width: 0;
  padding: 0.4rem 0.1rem;
  border: 0;
  background: transparent;
  font-family: inherit;
  font-size: var(--fs-text);
  color: var(--text-strong);
  caret-color: var(--gold-bright);
}

.chat-input:focus {
  outline: none;
}

.chat-input::placeholder {
  color: var(--text-faint);
}

.chat-suggest {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(100% + 0.35rem);
  max-height: 16rem;
  margin: 0;
  padding: 0.3rem;
  overflow-y: auto;
  list-style: none;
  border: 1px solid var(--panel-line-strong);
  border-radius: var(--radius-sm);
  background: rgba(14, 11, 19, 0.98);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.6);
}

.chat-option {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.8rem;
  padding: 0.3rem 0.5rem;
  border-radius: 5px;
  font-size: var(--fs-small);
  cursor: pointer;
}

.chat-option[aria-selected="true"],
.chat-option:hover {
  background: var(--tint-gold);
  box-shadow: inset 2px 0 0 var(--gold);
}

.chat-option-label {
  flex: none;
  font-family: var(--font-mono);
  font-weight: 700;
  color: var(--text-tip-cyan);
}

.chat-option-player {
  font-family: var(--font-body);
  color: var(--class-text);
}

.chat-option-hint {
  min-width: 0;
  overflow: hidden;
  text-align: right;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-faint);
}

.chat-launcher {
  display: inline-grid;
  place-items: center;
  width: 2.5rem;
  height: 2.5rem;
  padding: 0;
  border: 2px solid rgba(212, 175, 55, 0.45);
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, rgba(255, 255, 255, 0.08), rgba(10, 8, 14, 0.94));
  color: var(--text-muted);
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
  transition: color var(--t-fast), border-color var(--t-fast), box-shadow var(--t-fast);
}

.chat-launcher:hover {
  color: var(--text-gold-bright);
  border-color: var(--gold);
  box-shadow: 0 0 16px rgba(212, 175, 55, 0.3), 0 6px 16px rgba(0, 0, 0, 0.5);
}

.chat-launcher[aria-expanded="true"] {
  color: var(--text-gold-bright);
  border-color: var(--gold);
}

.chat-launcher .icon {
  width: 1.35rem;
  height: 1.35rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* --- the combat log --------------------------------------------------------------- */

.combat-log {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  min-height: 2.6rem;
  padding: 0.3rem 0.4rem 0.3rem 0.45rem;
  border: 1px solid var(--panel-line);
  border-radius: 999px;
  background: linear-gradient(90deg, rgba(14, 11, 19, 0.94), rgba(22, 18, 29, 0.86));
  box-shadow: inset 0 1px 0 rgba(255, 235, 180, 0.07), 0 10px 24px -14px rgba(0, 0, 0, 0.8);
  font-size: var(--fs-small);
}

.clog-tag {
  flex: none;
  padding: 0.12rem 0.65rem;
  border: 1px solid var(--panel-line-strong);
  border-radius: 999px;
  background: rgba(212, 175, 55, 0.12);
  font-family: var(--font-display);
  font-size: var(--fs-label);
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-gold);
}

.clog-paused .clog-tag {
  border-style: dashed;
}

.clog-list {
  position: relative;
  flex: 1;
  min-width: 0;
  height: 1.7rem;
  margin: 0;
  padding: 0;
  overflow: hidden;
  list-style: none;
}

.clog-line {
  position: absolute;
  inset: 0;
  overflow: hidden;
  line-height: 1.7rem;
  white-space: nowrap;
  text-overflow: ellipsis;
  color: var(--text-muted);
  opacity: 0;
  visibility: hidden;
}

.clog-on {
  opacity: 1;
  visibility: visible;
}

.clog-time {
  margin-right: 0.1rem;
  font-family: var(--font-mono);
  font-size: var(--fs-label);
  color: var(--text-faint);
}

.clog-name {
  font-weight: 700;
  color: var(--class-text);
}

.clog-item {
  font-weight: 700;
  color: var(--quality-color);
}

.clog-button {
  flex: none;
  display: grid;
  place-items: center;
  width: 1.95rem;
  height: 1.95rem;
  padding: 0;
  border: 1px solid var(--panel-line);
  border-radius: 50%;
  background: transparent;
  color: var(--text-faint);
  cursor: pointer;
}

.clog-button:hover {
  border-color: var(--gold);
  color: var(--text-gold-bright);
}

.clog-button .icon {
  width: 1rem;
  height: 1rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

@media (max-width: 560px) {
  .clog-tag {
    display: none;
  }

  .combat-log {
    padding-left: 0.8rem;
  }
}

/* --- loading tips and the footer HUD ------------------------------------------------- */

.loading-tip {
  max-width: var(--page-max);
  margin: 0.6rem auto 0;
  padding: 0 var(--gutter);
  text-align: center;
  font-size: var(--fs-note);
  font-style: italic;
  color: var(--text-muted);
}

.loading-tip-label {
  font-family: var(--font-display);
  font-size: var(--fs-label);
  font-style: normal;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-gold);
}

.hud {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.35rem;
  margin: 0 0 0.9rem;
  padding: 0;
  list-style: none;
}

.hud:empty {
  display: none;
}

.hud-seg {
  display: inline-flex;
  align-items: baseline;
  gap: 0.45rem;
  padding: 0.22rem 0.7rem;
  border: 1px solid var(--panel-line);
  border-radius: 5px;
  background: linear-gradient(180deg, rgba(36, 29, 46, 0.92), rgba(10, 8, 14, 0.96));
  box-shadow: inset 0 1px 0 rgba(255, 235, 180, 0.08), 0 2px 6px rgba(0, 0, 0, 0.4);
  font-family: var(--font-mono);
  font-size: var(--fs-label);
  cursor: help;
}

.hud-seg:hover {
  border-color: var(--panel-line-strong);
}

.hud-label {
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-faint);
}

.hud-value {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--text-strong);
}

.hud-good .hud-value {
  color: var(--text-ok);
}

.hud-meh .hud-value {
  color: var(--text-warn);
}

.hud-bad .hud-value {
  color: var(--text-bad);
}

.footer-tip {
  max-width: 48rem;
  margin: 0 auto 0.8rem;
  font-size: var(--fs-note);
  color: var(--text-muted);
}

.footer-tip-label {
  margin-right: 0.2rem;
  font-family: var(--font-display);
  font-size: var(--fs-label);
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-gold);
}

.footer-tip-text {
  font-style: italic;
}

/* --- the keybindings sheet -------------------------------------------------------------- */

.keys-dialog {
  width: min(54rem, calc(100vw - 2rem));
}

.keys-body {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1.2rem 2rem;
}

.keys-head {
  margin-bottom: 0.3rem;
  font-size: var(--fs-text);
  color: var(--text-gold-bright);
}

.keys-group {
  margin: 0.75rem 0 0.35rem;
  font-family: var(--font-display);
  font-size: var(--fs-label);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-gold);
}

.keys-list {
  display: grid;
  grid-template-columns: 7.2rem minmax(0, 1fr);
  align-items: center;
  gap: 0.35rem 0.8rem;
  margin: 0;
}

.keys-cmds {
  grid-template-columns: max-content minmax(0, 1fr);
}

.keys-keys {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  margin: 0;
}

.keys-kbd {
  display: inline-grid;
  place-items: center;
  min-width: 1.95rem;
  height: 1.95rem;
  padding: 0 0.45rem;
  border: 1px solid rgba(212, 175, 55, 0.45);
  border-bottom-width: 3px;
  border-radius: 5px;
  background: linear-gradient(180deg, #2a2233, #120e18);
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.6);
  font-family: var(--font-mono);
  font-size: var(--fs-small);
  font-weight: 700;
  color: var(--text-strong);
}

.keys-then {
  font-size: var(--fs-label);
  font-style: italic;
  color: var(--text-faint);
}

.keys-what {
  margin: 0;
  font-size: var(--fs-small);
  color: var(--text-muted);
}

.keys-cmd {
  margin: 0;
  font-family: var(--font-mono);
  font-size: var(--fs-small);
  font-weight: 700;
  white-space: nowrap;
  color: var(--text-tip-cyan);
}

.keys-note {
  margin-bottom: 0.6rem;
  font-size: var(--fs-small);
  font-style: italic;
  color: var(--text-faint);
}

.keys-secret {
  margin-top: 0.9rem;
  font-size: var(--fs-small);
  font-style: italic;
  color: var(--text-faint);
}

@media (max-width: 760px) {
  .keys-body {
    grid-template-columns: minmax(0, 1fr);
  }

  .keys-cmd {
    white-space: normal;
  }
}

/* --- the achievement toast ---------------------------------------------------------------- */

.achieve {
  position: fixed;
  top: 4.4rem;
  left: 50%;
  z-index: 60;
  display: flex;
  align-items: center;
  gap: 0.85rem;
  width: max-content;
  max-width: calc(100vw - 2rem);
  padding: 0.7rem 1.2rem 0.7rem 0.75rem;
  translate: -50% 0;
  border: 2px solid var(--gold);
  border-radius: 12px;
  background:
    radial-gradient(120% 140% at 0% 0%, rgba(212, 175, 55, 0.26), transparent 60%),
    linear-gradient(180deg, #2a2133, #0e0b13);
  box-shadow: 0 0 0 1px var(--ink-line), 0 0 34px rgba(212, 175, 55, 0.35), 0 18px 40px rgba(0, 0, 0, 0.6);
}

.achieve-out {
  opacity: 0;
  translate: -50% -0.8rem;
  transition: opacity 0.5s ease, translate 0.5s ease;
}

.achieve-badge {
  flex: none;
  display: grid;
  place-items: center;
  width: 3rem;
  height: 3rem;
  border: 2px solid var(--gold-bright);
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #5a4410, #1a1206);
  box-shadow: 0 0 16px rgba(212, 175, 55, 0.5);
}

.achieve-badge svg {
  width: 1.8rem;
  height: 1.8rem;
  fill: none;
  stroke: var(--gold-bright);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.achieve-words {
  display: flex;
  flex-direction: column;
  min-width: 0;
  line-height: 1.25;
}

.achieve-kicker {
  font-family: var(--font-display);
  font-size: var(--fs-label);
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-gold);
}

.achieve-title {
  font-family: var(--font-display);
  font-size: var(--fs-name);
  font-weight: 900;
  color: var(--text-strong);
}

.achieve-sub {
  font-family: var(--font-mono);
  font-size: var(--fs-small);
  color: var(--text-muted);
}

/* --- freshen: number tick-ups ----------------------------------------------------------- */

.ribbon-value.tick-run {
  text-shadow: 0 0 14px rgba(247, 231, 172, 0.8);
}

/* --- freshen: items glow in their quality's colour when pointed at ---------------------- */

.slot:hover .slot-name,
.slot:focus-visible .slot-name,
a.ah-name:hover,
a.mk-name:hover,
a.vault-item:hover,
a.doll-row-name:hover,
a.ledger-best-name:hover,
.clog-item,
.chat-item {
  text-shadow: 0 0 10px color-mix(in srgb, var(--quality-color) 65%, transparent), 0 1px 1px rgba(0, 0, 0, 0.9);
}

/* --- motion: the hover glint, the combat log, the tips, the toast, /dance, the party ------- */

@media (prefers-reduced-motion: no-preference) {
  .clog-anim {
    animation: clog-in 420ms cubic-bezier(0.22, 1, 0.36, 1);
  }

  .tip-in {
    animation: tip-in 600ms ease-out;
  }

  .achieve {
    animation: achieve-in 560ms cubic-bezier(0.2, 1.4, 0.4, 1);
  }

  .podium-dance .podium-fig > .fig {
    transform-origin: 50% 100%;
    animation: fig-dance 0.6s ease-in-out 6;
  }

  .podium-dance .podium-1 .podium-fig > .fig {
    animation-delay: 0.08s;
  }

  .podium-dance .podium-3 .podium-fig > .fig {
    animation-delay: 0.16s;
  }

  .nerd-party .fig {
    animation: fig-jump 0.5s cubic-bezier(0.3, 1.5, 0.5, 1) 8 alternate;
  }

  .nerd-party .panel {
    box-shadow: 0 0 0 1px rgba(247, 231, 172, 0.35), 0 0 40px rgba(212, 175, 55, 0.18), 0 22px 44px -22px rgba(0, 0, 0, 0.85);
    transition: box-shadow 0.4s ease;
  }
}

/* A light sweeping across a card under the pointer (fine pointers only). */
@media (prefers-reduced-motion: no-preference) and (hover: hover) {
  .ribbon-tile,
  .tales-counter,
  .tale,
  .ov-tile,
  .stat,
  .mk-card,
  .record,
  .pf-skill {
    position: relative;
  }

  .ribbon-tile::after,
  .tales-counter::after,
  .tale::after,
  .ov-tile::after,
  .stat::after,
  .mk-card::after,
  .record::after,
  .pf-skill::after {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: inherit;
    pointer-events: none;
    background: linear-gradient(110deg, transparent 38%, rgba(255, 240, 200, 0.08) 46%, rgba(255, 240, 200, 0.15) 50%, rgba(255, 240, 200, 0.08) 54%, transparent 62%) no-repeat;
    background-position: 130% 0;
    background-size: 260% 100%;
    opacity: 0;
    transition: background-position 0.95s ease, opacity 0.3s ease;
  }

  .ribbon-tile:hover::after,
  .tales-counter:hover::after,
  .tale:hover::after,
  .ov-tile:hover::after,
  .stat:hover::after,
  .mk-card:hover::after,
  .record:hover::after,
  .pf-skill:hover::after {
    opacity: 1;
    background-position: -30% 0;
  }
}

@keyframes clog-in {
  from {
    opacity: 0;
    translate: 0 70%;
  }

  to {
    opacity: 1;
    translate: 0 0;
  }
}

@keyframes tip-in {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

@keyframes achieve-in {
  from {
    opacity: 0;
    translate: -50% -1.4rem;
    scale: 0.92;
  }

  to {
    opacity: 1;
    translate: -50% 0;
    scale: 1;
  }
}

@keyframes fig-dance {
  0%,
  100% {
    translate: 0 0;
    rotate: 0deg;
  }

  25% {
    translate: 0 -9%;
    rotate: -9deg;
  }

  50% {
    translate: 0 0;
    rotate: 0deg;
  }

  75% {
    translate: 0 -9%;
    rotate: 9deg;
  }
}

@keyframes fig-jump {
  from {
    translate: 0 0;
  }

  to {
    translate: 0 -14%;
  }
}
