:root {
  --bg: #07050b;
  --panel: rgba(11, 8, 17, 0.8);
  --line: rgba(255, 180, 94, 0.16);
  --ink: #efe7da;
  --dim: #a89f92;
  --amber: #ffb45e;
  --cyan: #6ee7ff;
  --red: #ff5d5d;
  --violet: #b18cff;
  --green: #8fe3b0;
  --serif: "Cormorant Garamond", "Iowan Old Style", Georgia, serif;
  --ui: Rajdhani, system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--ui);
  font-size: 16px;
  -webkit-tap-highlight-color: transparent;
}

#scene {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  display: block;
  cursor: pointer;
}

#cam {
  position: fixed;
  left: -9999px;
  width: 4px;
  height: 4px;
}

#cam-overlay {
  position: fixed;
  left: 14px;
  bottom: 14px;
  width: 176px;
  height: 132px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.5);
  display: none;
  z-index: 5;
}

#cam-overlay.live {
  display: block;
}

button,
input {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

#topbar {
  position: fixed;
  top: 10px;
  left: 16px;
  right: 16px;
  display: flex;
  align-items: center;
  gap: 18px;
  pointer-events: none;
  z-index: 3;
}

#topbar > * {
  pointer-events: auto;
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.brand span {
  font-family: var(--serif);
  font-weight: 700;
  font-size: 26px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.brand i {
  font-style: normal;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--dim);
}

#room-title {
  font-family: var(--serif);
  font-style: italic;
  font-size: 20px;
  color: var(--amber);
  flex: 1;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.8);
}

.pills {
  display: flex;
  gap: 8px;
  align-items: center;
}

body:has(#title:not([hidden])) #side,
body:has(#title:not([hidden])) #cam-overlay {
  visibility: hidden;
}

.pill {
  white-space: nowrap;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.04em;
  padding: 5px 11px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--dim);
}

button.pill[aria-pressed="true"] {
  color: var(--cyan);
  border-color: rgba(110, 231, 255, 0.5);
}

.pill.online {
  color: var(--green);
}

.pill.offline {
  color: var(--amber);
}

#side {
  position: fixed;
  top: 52px;
  right: 12px;
  bottom: 12px;
  width: 348px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow-y: auto;
  scrollbar-width: thin;
  z-index: 2;
}

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  backdrop-filter: blur(10px);
}

.stat {
  display: grid;
  grid-template-columns: 78px 1fr;
  align-items: center;
  gap: 6px 10px;
  margin-bottom: 8px;
}

.stat label,
.stat .second {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--dim);
}

.stat .second {
  grid-column: 1;
}

.bar {
  position: relative;
  height: 20px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.06);
  overflow: hidden;
}

.bar i {
  position: absolute;
  inset: 0 auto 0 0;
  background: linear-gradient(90deg, #b3312b, #e0493f);
  transition: width 0.35s ease;
}

.bar b {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 600;
}

.pips {
  display: flex;
  gap: 6px;
  min-height: 16px;
}

.pips span {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid var(--amber);
  transition: background 0.2s;
}

.pips span.on {
  background: var(--amber);
  box-shadow: 0 0 10px rgba(255, 180, 94, 0.7);
}

.pips.insight span {
  border-color: var(--cyan);
  transform: rotate(45deg);
  border-radius: 3px;
  width: 13px;
  height: 13px;
}

.pips.insight span.on {
  background: var(--cyan);
  box-shadow: 0 0 10px rgba(110, 231, 255, 0.7);
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.chip {
  font-family: var(--mono);
  font-size: 10px;
  padding: 3px 8px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--dim);
}

.enemy {
  padding: 8px 0;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}

.enemy:first-child {
  border-top: 0;
  padding-top: 0;
}

.enemy .row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.enemy .name {
  font-weight: 700;
  font-size: 17px;
  flex: 1;
}

.enemy .hp {
  font-family: var(--mono);
  font-size: 11px;
  color: #ff9a92;
}

.enemy .eye {
  font-family: var(--mono);
  font-size: 11px;
  padding: 3px 9px;
  border-radius: 6px;
  border: 1px solid rgba(110, 231, 255, 0.4);
  background: rgba(110, 231, 255, 0.08);
  color: var(--cyan);
}

.enemy .eye:disabled {
  opacity: 0.35;
  cursor: default;
}

.enemy .odds {
  display: flex;
  height: 9px;
  border-radius: 5px;
  overflow: hidden;
  margin: 6px 0 4px;
  background: rgba(255, 255, 255, 0.06);
}

.enemy .odds i {
  display: block;
  animation: shimmer 2.4s ease-in-out infinite;
}

.enemy .odds.locked i {
  animation: none;
}

.enemy .legend {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
  font-family: var(--mono);
  font-size: 10px;
  color: var(--dim);
}

.enemy .legend b {
  font-weight: 600;
}

.enemy .note {
  font-family: var(--serif);
  font-style: italic;
  font-size: 14px;
  color: var(--dim);
  margin-top: 3px;
}

@keyframes shimmer {
  0%,
  100% {
    opacity: 0.55;
  }
  50% {
    opacity: 1;
  }
}

.actions {
  display: grid;
  grid-template-columns: 1fr 1fr 1.3fr;
  gap: 8px;
  padding: 10px;
}

.actions button,
.declare button,
.overlay button,
#replay-bar button {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.05);
  border-radius: 9px;
  padding: 8px 10px;
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 0.03em;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition:
    background 0.15s,
    border-color 0.15s,
    transform 0.1s;
}

.actions button:hover:not(:disabled),
.declare button:hover:not(:disabled),
.overlay button:hover:not(:disabled) {
  background: rgba(255, 180, 94, 0.14);
  border-color: rgba(255, 180, 94, 0.5);
}

button:active:not(:disabled) {
  transform: scale(0.97);
}

button:disabled {
  opacity: 0.4;
  cursor: default;
}

button:focus-visible,
input:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 2px;
}

kbd {
  font-family: var(--mono);
  font-size: 10px;
  padding: 1px 5px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--dim);
}

button.primary {
  background: linear-gradient(
    180deg,
    rgba(255, 180, 94, 0.28),
    rgba(255, 180, 94, 0.12)
  );
  border-color: rgba(255, 180, 94, 0.55);
}

button.primary.pulse {
  animation: glow 1.4s ease-in-out infinite;
}

@keyframes glow {
  0%,
  100% {
    box-shadow: 0 0 0 rgba(255, 180, 94, 0);
  }
  50% {
    box-shadow: 0 0 16px rgba(255, 180, 94, 0.6);
  }
}

.declare form {
  display: flex;
  gap: 8px;
}

.declare input,
.seed input {
  flex: 1;
  min-width: 0;
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 8px 11px;
  font-size: 15px;
}

#declare-hint {
  margin: 8px 0 0;
  font-family: var(--serif);
  font-style: italic;
  font-size: 15px;
  color: var(--dim);
  line-height: 1.25;
}

#preview {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

#preview .q {
  font-family: var(--serif);
  font-style: italic;
  font-size: 18px;
  margin: 0 0 6px;
}

#preview .meta {
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--dim);
  margin: 0 0 8px;
  line-height: 1.5;
}

.prob {
  position: relative;
  display: flex;
  height: 26px;
  border-radius: 8px;
  overflow: hidden;
  margin: 6px 0 8px;
  border: 1px solid rgba(255, 255, 255, 0.12);
}

.prob .yes,
.prob .no {
  display: grid;
  place-items: center;
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 600;
  color: #06060a;
  transition:
    opacity 0.4s,
    flex-basis 0.5s;
}

.prob .yes {
  background: linear-gradient(90deg, #3fb7d1, var(--cyan));
}

.prob .no {
  background: linear-gradient(90deg, var(--violet), #7e5bd6);
}

.prob.superposed .yes,
.prob.superposed .no {
  animation: shimmer 1.6s ease-in-out infinite;
}

.prob.settled .lost {
  opacity: 0.22;
}

.prob .marker {
  position: absolute;
  top: -2px;
  bottom: -2px;
  width: 3px;
  background: #fff;
  box-shadow: 0 0 10px #fff;
}

#preview .buttons {
  display: flex;
  gap: 8px;
}

#preview .buttons button {
  flex: 1;
}

#preview .result {
  font-family: var(--serif);
  font-size: 19px;
  font-weight: 700;
}

.log {
  flex: 1;
  min-height: 120px;
  overflow-y: auto;
  font-family: var(--serif);
  font-size: 16px;
  line-height: 1.3;
  scrollbar-width: thin;
}

.log p {
  margin: 0 0 5px;
  color: var(--dim);
}

.log p.plain {
  color: var(--ink);
}

.log p.good {
  color: var(--green);
}

.log p.bad {
  color: #ff9a92;
}

.log p.magic {
  color: var(--cyan);
  font-style: italic;
}

.log p.fate {
  color: var(--amber);
  font-style: italic;
  font-size: 17px;
}

.overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  background: radial-gradient(
    ellipse at center,
    rgba(5, 3, 9, 0.62),
    rgba(5, 3, 9, 0.9)
  );
  overflow-y: auto;
  padding: 24px;
}

.overlay[hidden],
#roomcard[hidden],
#replay-bar[hidden],
#preview[hidden] {
  display: none;
}

.title-inner {
  max-width: 640px;
  text-align: center;
}

.kicker {
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.16em;
  color: var(--dim);
  text-transform: uppercase;
  margin: 0;
}

.kicker span {
  color: var(--cyan);
}

h1 {
  position: relative;
  margin: 8px 0 4px;
  font-family: var(--serif);
  font-weight: 700;
  font-size: clamp(54px, 11vw, 116px);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  line-height: 1;
}

h1 .ghost {
  position: absolute;
  inset: 0;
  opacity: 0.55;
  mix-blend-mode: screen;
}

h1 .g1 {
  color: var(--cyan);
  animation: drift1 5s ease-in-out infinite;
}

h1 .g2 {
  color: var(--amber);
  animation: drift2 5s ease-in-out infinite;
}

h1 .real {
  position: relative;
  color: var(--ink);
}

@keyframes drift1 {
  0%,
  100% {
    transform: translate(-3px, 0);
  }
  50% {
    transform: translate(3px, 1px);
  }
}

@keyframes drift2 {
  0%,
  100% {
    transform: translate(3px, 0);
  }
  50% {
    transform: translate(-3px, -1px);
  }
}

.tagline {
  font-family: var(--serif);
  font-style: italic;
  font-size: clamp(20px, 3vw, 28px);
  color: var(--amber);
  margin: 0 0 26px;
}

.title-actions {
  display: flex;
  gap: 16px;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 26px;
}

.big {
  font-size: 20px !important;
  padding: 13px 34px !important;
  font-family: var(--serif);
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.seed {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--dim);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.seed input {
  width: 130px;
  flex: none;
}

.how {
  display: grid;
  gap: 10px;
  text-align: left;
  font-size: 16px;
  color: var(--dim);
  line-height: 1.3;
}

.how b {
  color: var(--ink);
}

.how em {
  color: var(--cyan);
  font-style: normal;
}

.shelf {
  margin-top: 22px;
  font-family: var(--serif);
  font-size: 18px;
  color: var(--dim);
}

.shelf .have {
  color: var(--amber);
}

.record {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--dim);
  margin: 10px 0 0;
}

#boon .panel,
#ending .panel {
  max-width: 760px;
  width: 100%;
  text-align: center;
}

#boon h2,
#ending h2 {
  font-family: var(--serif);
  font-size: clamp(28px, 5vw, 44px);
  margin: 0 0 6px;
  letter-spacing: 0.06em;
}

#boon p.sub,
#ending p.sub {
  font-family: var(--serif);
  font-style: italic;
  font-size: 19px;
  color: var(--dim);
  margin: 0 0 20px;
}

.cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
}

.cards button {
  flex-direction: column;
  align-items: flex-start !important;
  text-align: left;
  padding: 18px !important;
  min-height: 150px;
  gap: 8px !important;
  justify-content: flex-start !important;
}

.cards .glyph {
  font-size: 30px;
  color: var(--amber);
}

.cards .bname {
  font-family: var(--serif);
  font-size: 24px;
}

.cards .btext {
  font-weight: 500;
  color: var(--dim);
  font-size: 15px;
  line-height: 1.25;
}

.cards kbd {
  align-self: flex-end;
  margin-top: auto;
}

.epitaph {
  font-family: var(--serif);
  font-style: italic;
  font-size: clamp(22px, 3.4vw, 32px);
  line-height: 1.25;
  color: var(--ink);
  margin: 4px auto 18px;
  max-width: 600px;
}

.grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin: 16px 0;
}

.grid div {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 6px;
}

.grid b {
  display: block;
  font-size: 26px;
}

.grid span {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--dim);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.unlock {
  border: 1px solid rgba(255, 180, 94, 0.5);
  background: rgba(255, 180, 94, 0.08);
  border-radius: 12px;
  padding: 12px 16px;
  margin: 14px 0;
  font-family: var(--serif);
  font-size: 19px;
}

.unlock b {
  color: var(--amber);
}

.end-buttons {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 16px;
}

#roomcard {
  position: fixed;
  inset: 0;
  z-index: 8;
  display: grid;
  place-items: center;
  pointer-events: none;
  text-align: center;
  font-family: var(--serif);
}

#roomcard .n {
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.3em;
  color: var(--cyan);
  text-transform: uppercase;
}

#roomcard .t {
  font-size: clamp(34px, 6vw, 64px);
  font-weight: 700;
  font-style: italic;
  letter-spacing: 0.04em;
  text-shadow: 0 4px 40px #000;
}

#toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%) translateY(20px);
  opacity: 0;
  pointer-events: none;
  z-index: 20;
  padding: 10px 18px;
  border-radius: 999px;
  background: rgba(10, 8, 16, 0.94);
  border: 1px solid var(--line);
  font-family: var(--serif);
  font-style: italic;
  font-size: 18px;
  transition:
    opacity 0.25s,
    transform 0.25s;
  max-width: 90vw;
  text-align: center;
}

#toast.show {
  opacity: 1;
  transform: translateX(-50%);
}

#replay-bar {
  position: fixed;
  top: 52px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 9;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid rgba(110, 231, 255, 0.5);
  font-family: var(--mono);
  font-size: 12px;
  color: var(--cyan);
}

@media (max-width: 860px) {
  #topbar {
    top: 6px;
    left: 10px;
    right: 10px;
    gap: 8px;
  }

  .brand i,
  #room-title {
    display: none;
  }

  .brand {
    flex: 1;
  }

  .brand span {
    font-size: 18px;
    letter-spacing: 0.1em;
  }

  .pills {
    gap: 5px;
  }

  #side {
    top: 50%;
    left: 8px;
    right: 8px;
    bottom: 8px;
    width: auto;
  }

  .actions {
    grid-template-columns: 1fr 1fr 1.3fr;
  }

  .cards {
    grid-template-columns: 1fr;
  }

  .cards button {
    min-height: 0;
  }

  #cam-overlay {
    bottom: auto;
    top: 44px;
    left: 8px;
    width: 120px;
    height: 90px;
  }

  .pill {
    padding: 4px 8px;
    font-size: 10px;
  }
}

@media (prefers-reduced-motion: reduce) {
  h1 .ghost,
  .prob.superposed .yes,
  .prob.superposed .no,
  .enemy .odds i,
  button.primary.pulse {
    animation: none;
  }
}
