:root {
  color-scheme: dark;
  --ink: #ecf8f4;
  --muted: #9db9b6;
  --cave: #081316;
  --cave-2: #10282d;
  --panel: rgba(12, 27, 31, 0.86);
  --line: rgba(183, 232, 222, 0.18);
  --teal: #76d7c4;
  --amber: #e0a052;
  --coral: #df6e57;
  --blue: #8fcde3;
  --shadow: 0 22px 70px rgba(0, 0, 0, 0.34);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100svh;
  overflow-x: hidden;
  background:
    linear-gradient(180deg, rgba(8, 19, 22, 0.96), rgba(19, 46, 48, 0.92)),
    var(--cave);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-tap-highlight-color: transparent;
}

body.rift-page {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

button {
  border: 1px solid var(--line);
  background: rgba(118, 215, 196, 0.12);
  color: var(--ink);
  font: inherit;
  font-weight: 850;
  cursor: pointer;
  touch-action: manipulation;
}

button:hover,
button:focus-visible {
  border-color: rgba(118, 215, 196, 0.8);
  background: rgba(118, 215, 196, 0.2);
}

button:focus-visible {
  outline: 3px solid rgba(224, 160, 82, 0.34);
  outline-offset: 3px;
}

a {
  color: inherit;
  text-decoration-thickness: 0.12em;
  text-underline-offset: 0.18em;
}

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  width: min(68rem, 100%);
  margin-inline: auto;
  padding:
    max(1.1rem, env(safe-area-inset-top, 0px))
    max(1.25rem, env(safe-area-inset-right, 0px))
    1.1rem
    max(1.25rem, env(safe-area-inset-left, 0px));
  border-bottom: 1px solid var(--line);
}

.brand-mark {
  display: inline-flex;
  align-items: center;
  gap: 0.65rem;
  color: var(--ink);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.15rem;
  text-decoration: none;
  white-space: nowrap;
}

.brand-mark img {
  width: 2rem;
  height: 2rem;
  object-fit: contain;
}

.site-nav {
  display: flex;
  align-items: center;
  gap: 1rem;
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 700;
}

.site-nav a {
  padding-block: 0.25rem;
  border-bottom: 1px solid transparent;
  text-decoration: none;
}

.site-nav a:hover,
.site-nav a:focus-visible,
.site-nav a[aria-current="page"] {
  color: var(--ink);
  border-bottom-color: var(--amber);
}

.brand-mark:focus-visible,
.site-nav a:focus-visible,
.home-link:focus-visible {
  outline: 3px solid rgba(224, 160, 82, 0.34);
  outline-offset: 3px;
}

h1,
h2,
p,
ol {
  margin: 0;
}

.rift-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(18rem, 23rem);
  gap: 1rem;
  width: 100%;
  max-width: 100vw;
  min-height: 100vh;
  min-height: 100svh;
  overflow-x: hidden;
  padding:
    max(1rem, env(safe-area-inset-top, 0px))
    max(1rem, env(safe-area-inset-right, 0px))
    max(1rem, env(safe-area-inset-bottom, 0px))
    max(1rem, env(safe-area-inset-left, 0px));
}

body.rift-page .rift-shell {
  height: 100%;
  min-height: 0;
}

.rift-play {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 0.85rem;
  min-width: 0;
  min-height: 0;
}

.rift-topbar,
.rift-panel {
  min-width: 0;
  max-width: 100%;
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.rift-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.9rem 1rem;
}

.title-block {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 0.8rem;
}

.rift-brand-mark {
  position: relative;
  display: inline-block;
  width: 2.35rem;
  height: 2.35rem;
  flex: 0 0 auto;
  border: 2px solid var(--amber);
  border-radius: 50%;
  background:
    radial-gradient(circle at 50% 50%, rgba(143, 205, 227, 0.95) 0 22%, transparent 23%),
    radial-gradient(circle at 50% 50%, rgba(118, 215, 196, 0.24) 0 48%, transparent 49%);
}

.rift-brand-mark::before,
.rift-brand-mark::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  border: 1px solid rgba(236, 248, 244, 0.62);
  border-radius: 50%;
  transform: translate(-50%, -50%);
}

.rift-brand-mark::before {
  width: 72%;
  height: 72%;
}

.rift-brand-mark::after {
  width: 112%;
  height: 112%;
}

.home-link {
  display: inline-grid;
  place-items: center;
  width: fit-content;
  min-height: 2.25rem;
  margin-bottom: 0.45rem;
  padding: 0.52rem 0.72rem;
  border: 1px solid rgba(224, 160, 82, 0.7);
  background: rgba(224, 160, 82, 0.18);
  color: #fff4dc;
  font-size: 0.8rem;
  font-weight: 900;
  line-height: 1;
  text-decoration: none;
  touch-action: manipulation;
}

.home-link:hover,
.home-link:focus-visible {
  border-color: rgba(118, 215, 196, 0.82);
  background: rgba(118, 215, 196, 0.18);
  color: var(--ink);
}

h1 {
  overflow-wrap: anywhere;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1.7rem, 3.4vw, 3.65rem);
  line-height: 0.94;
  letter-spacing: 0;
}

#zone-name {
  margin-top: 0.35rem;
  color: var(--teal);
  font-size: 0.76rem;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

.hud-strip {
  display: grid;
  grid-template-columns: auto auto auto minmax(11rem, 1fr);
  align-items: center;
  min-width: 0;
  gap: 0.75rem;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 900;
  white-space: nowrap;
}

#completion,
.progression {
  min-width: 0;
}

.progression {
  color: var(--ink);
  line-height: 1.2;
  white-space: normal;
}

.hearts,
.upgrades {
  display: flex;
  align-items: center;
  min-width: 0;
  flex-wrap: wrap;
  gap: 0.32rem;
}

.heart,
.upgrade {
  display: inline-grid;
  place-items: center;
  width: 1.7rem;
  height: 1.7rem;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: rgba(236, 248, 244, 0.08);
  color: rgba(236, 248, 244, 0.34);
  font-size: 0.95rem;
  line-height: 1;
}

.heart::before {
  content: "";
  width: 0.78rem;
  height: 0.78rem;
  background: currentColor;
  clip-path: polygon(50% 92%, 8% 48%, 8% 22%, 28% 8%, 50% 24%, 72% 8%, 92% 22%, 92% 48%);
}

.heart.is-full {
  border-color: rgba(223, 110, 87, 0.76);
  background: rgba(223, 110, 87, 0.18);
  color: #ff9d8c;
}

.upgrade::before {
  content: "";
  display: block;
  width: 0.9rem;
  height: 0.9rem;
  border: 0.14rem solid currentColor;
}

.upgrade[data-ability="resonance"]::before {
  border-radius: 50%;
  box-shadow: inset 0 0 0 0.18rem rgba(8, 19, 22, 0.9);
}

.upgrade[data-ability="grip"]::before {
  width: 1rem;
  height: 0.72rem;
  border-top: 0;
  border-right: 0;
  border-radius: 0 0 0.45rem 0.45rem;
  transform: rotate(-14deg);
}

.upgrade[data-ability="softstep"]::before {
  height: 0.58rem;
  border-radius: 50%;
}

.upgrade[data-ability="lens"]::before {
  border-radius: 50%;
  box-shadow: 0 0 0 0.22rem rgba(143, 205, 227, 0.18);
}

.upgrade.is-unlocked {
  border-color: rgba(224, 160, 82, 0.84);
  background: rgba(224, 160, 82, 0.18);
  color: #ffd27f;
}

.stage {
  position: relative;
  width: 100%;
  min-width: 0;
  max-width: 100%;
  min-height: 22rem;
  overflow: hidden;
  border: 1px solid rgba(183, 232, 222, 0.24);
  background: #0c2025;
  box-shadow: inset 0 0 0 1px rgba(236, 248, 244, 0.08), var(--shadow);
}

canvas {
  position: relative;
  z-index: 0;
  display: block;
  width: 100%;
  max-width: 100%;
  height: 100%;
  min-height: 0;
  touch-action: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-user-drag: none;
  -webkit-user-select: none;
}

.context-prompt {
  position: absolute;
  left: 50%;
  bottom: max(1rem, env(safe-area-inset-bottom, 0px));
  z-index: 3;
  min-width: 7rem;
  padding: 0.55rem 0.8rem;
  border: 1px solid rgba(224, 160, 82, 0.7);
  background: rgba(8, 19, 22, 0.84);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.28);
  color: var(--amber);
  font-size: 0.86rem;
  font-weight: 950;
  text-align: center;
  transform: translateX(-50%);
  backdrop-filter: blur(12px);
}

.touch-controls {
  --touch-size: 3.45rem;
  position: absolute;
  right: 0.85rem;
  bottom: max(0.85rem, env(safe-area-inset-bottom, 0px));
  left: 0.85rem;
  z-index: 4;
  display: none;
  align-items: end;
  justify-content: space-between;
  gap: 1rem;
  pointer-events: none;
  touch-action: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
}

.touch-group {
  position: relative;
  z-index: 1;
  pointer-events: auto;
}

.move-pad {
  display: grid;
  grid-template-columns: repeat(3, var(--touch-size));
  grid-template-rows: repeat(2, var(--touch-size));
  gap: 0.38rem;
}

.move-pad [data-rift-control="left"] {
  grid-column: 1;
  grid-row: 2;
}

.move-pad [data-rift-control="jump"] {
  grid-column: 2;
  grid-row: 1;
}

.move-pad [data-rift-control="right"] {
  grid-column: 3;
  grid-row: 2;
}

.move-pad [data-rift-control="drop"] {
  grid-column: 2;
  grid-row: 2;
}

.action-pad {
  display: flex;
  align-items: end;
  gap: 0.45rem;
}

.touch-button {
  position: relative;
  z-index: 1;
  display: inline-grid;
  place-items: center;
  width: var(--touch-size);
  height: var(--touch-size);
  min-height: var(--touch-size);
  padding: 0;
  border-color: rgba(236, 248, 244, 0.44);
  border-radius: 50%;
  background: rgba(8, 19, 22, 0.72);
  box-shadow: 0 0.8rem 1.8rem rgba(0, 0, 0, 0.28);
  color: var(--ink);
  pointer-events: auto;
  touch-action: none;
  user-select: none;
  backdrop-filter: blur(12px);
  -webkit-touch-callout: none;
  -webkit-user-select: none;
}

.touch-button span {
  position: relative;
  display: inline-grid;
  place-items: center;
  width: 1.3rem;
  height: 1.3rem;
}

.touch-button.is-pressed {
  transform: translateY(2px) scale(0.96);
}

.touch-button span::before {
  content: "";
  display: block;
  width: 0.72rem;
  height: 0.72rem;
  border-top: 0.18rem solid currentColor;
  border-left: 0.18rem solid currentColor;
}

[data-rift-control="left"] span::before {
  transform: rotate(-45deg);
}

[data-rift-control="right"] span::before {
  transform: rotate(135deg);
}

[data-rift-control="jump"] span::before {
  transform: rotate(45deg);
}

[data-rift-control="drop"] span::before {
  transform: rotate(225deg);
}

.touch-button.action {
  border-color: rgba(224, 160, 82, 0.66);
  background: rgba(224, 160, 82, 0.24);
}

.touch-button.scan {
  border-color: rgba(118, 215, 196, 0.66);
  background: rgba(118, 215, 196, 0.2);
}

.touch-button.action span::before {
  width: 1.25rem;
  height: 1.25rem;
  border: 0.18rem solid currentColor;
  border-radius: 50%;
  transform: none;
}

.touch-button.pulse span::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 2.05rem;
  height: 2.05rem;
  border: 0.12rem solid rgba(236, 248, 244, 0.8);
  border-radius: 50%;
  transform: translate(-50%, -50%);
}

.touch-button.scan span::before {
  border-radius: 0.35rem 50% 50% 50%;
  transform: rotate(45deg);
}

.win-banner {
  position: absolute;
  inset: auto 1rem 1rem 1rem;
  z-index: 5;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.35rem 1rem;
  align-items: center;
  padding: 0.9rem;
  border: 1px solid rgba(255, 210, 127, 0.62);
  background: rgba(8, 19, 22, 0.92);
  box-shadow: var(--shadow);
}

.win-banner[hidden] {
  display: none;
}

.win-banner strong {
  color: #ffd27f;
  font-size: 1.04rem;
}

.win-banner span {
  color: var(--muted);
  font-size: 0.9rem;
}

.win-banner button {
  grid-row: 1 / span 2;
  grid-column: 2;
  min-height: 2.6rem;
  padding: 0 0.9rem;
}

.rift-panel {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  gap: 1rem;
  min-height: 0;
  padding: 1rem;
}

.room-card,
.map-card,
.notes-card {
  min-width: 0;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--line);
}

.notes-card {
  min-height: 0;
  overflow: auto;
  padding-bottom: 0;
  border-bottom: 0;
}

.notes-card summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  list-style: none;
  min-height: 2.45rem;
  color: var(--teal);
  font-size: 0.82rem;
  font-weight: 950;
  letter-spacing: 0;
  text-transform: uppercase;
  cursor: pointer;
}

.notes-card summary::-webkit-details-marker {
  display: none;
}

.notes-card summary::marker {
  content: "";
}

.notes-card summary::after {
  content: "+";
  display: inline-grid;
  place-items: center;
  width: 1.45rem;
  height: 1.45rem;
  border: 1px solid rgba(118, 215, 196, 0.36);
  border-radius: 50%;
  color: var(--ink);
  line-height: 1;
}

.notes-card[open] summary {
  margin-bottom: 0.75rem;
}

.notes-card[open] summary::after {
  content: "-";
}

.report-card {
  position: sticky;
  bottom: 0;
  z-index: 3;
  padding-top: 0.2rem;
  background: var(--panel);
}

.report-button {
  width: 100%;
  min-height: 3rem;
  border-color: rgba(224, 160, 82, 0.62);
  background:
    linear-gradient(135deg, rgba(224, 160, 82, 0.28), rgba(118, 215, 196, 0.14)),
    rgba(8, 19, 22, 0.72);
  color: #fff4dc;
}

dialog {
  width: min(34rem, calc(100vw - 2rem));
  padding: 0;
  border: 1px solid rgba(183, 232, 222, 0.28);
  background: rgba(8, 19, 22, 0.96);
  color: var(--ink);
  box-shadow: var(--shadow);
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.64);
  backdrop-filter: blur(5px);
}

.report-form {
  display: grid;
  gap: 0.85rem;
  padding: 1rem;
}

.dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 2.25rem;
  height: 2.25rem;
  padding: 0;
  border-radius: 50%;
}

.field {
  display: grid;
  gap: 0.35rem;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 900;
}

.field textarea,
.field input {
  width: 100%;
  border: 1px solid var(--line);
  background: rgba(236, 248, 244, 0.08);
  color: var(--ink);
  font: inherit;
}

.field textarea {
  min-height: 5.2rem;
  resize: vertical;
}

.field input {
  min-height: 2.45rem;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 800;
}

#report-output {
  display: block;
  min-height: 3.8rem;
  max-height: 3.8rem;
  overflow: auto;
  color: var(--teal);
  font-size: 0.9rem;
  font-weight: 850;
  line-height: 1.35;
}

.button-row {
  display: flex;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 0.6rem;
}

.button-row button {
  min-height: 2.55rem;
  padding: 0 0.85rem;
}

.report-actions {
  display: grid;
  grid-template-columns: minmax(7rem, 1fr) minmax(9rem, 1fr);
  align-items: stretch;
  min-height: 2.55rem;
}

.report-actions button {
  width: 100%;
  min-width: 0;
}

.report-actions #submit-report:disabled {
  border-color: var(--line);
  background: rgba(236, 248, 244, 0.08);
  color: rgba(236, 248, 244, 0.48);
  cursor: not-allowed;
}

h2 {
  color: var(--ink);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.6rem;
  line-height: 1;
  letter-spacing: 0;
}

#room-note {
  margin-top: 0.55rem;
  color: var(--muted);
  font-size: 0.96rem;
  line-height: 1.45;
}

.rift-map {
  display: grid;
  grid-template-columns: repeat(15, 1.06rem);
  grid-template-rows: repeat(2, 1.06rem);
  gap: 0.28rem;
  align-items: center;
  width: max-content;
  max-width: 100%;
  overflow: auto;
  padding: 0.1rem;
}

.map-cell {
  display: block;
  width: 1.06rem;
  height: 1.06rem;
  border: 1px solid rgba(236, 248, 244, 0.13);
  background: rgba(236, 248, 244, 0.05);
}

.map-cell.is-seen {
  border-color: rgba(118, 215, 196, 0.58);
  background: rgba(118, 215, 196, 0.22);
}

.map-cell.is-current {
  border-color: #ffd27f;
  background: #ffd27f;
  box-shadow: 0 0 0 3px rgba(255, 210, 127, 0.18);
}

#rift-notes {
  display: grid;
  gap: 0.65rem;
  padding: 0;
  list-style: none;
}

#rift-notes li {
  padding-left: 0.75rem;
  border-left: 3px solid rgba(118, 215, 196, 0.48);
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.35;
}

@media (hover: none), (pointer: coarse), (max-width: 780px) {
  .touch-controls {
    display: flex;
  }
}

@media (max-width: 900px) {
  .site-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .site-nav {
    flex-wrap: wrap;
    gap: 0.65rem 1rem;
  }

  .rift-shell {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto;
    gap: 0.75rem;
    min-height: auto;
    padding: 0.75rem;
  }

  .rift-topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .hud-strip {
    width: 100%;
    grid-template-columns: auto auto auto minmax(0, 1fr);
  }

  .stage {
    aspect-ratio: 16 / 9;
    min-height: 18rem;
  }

  .rift-panel {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto;
    max-height: 32svh;
    overflow: auto;
  }
}

@media (max-width: 560px) {
  .rift-shell {
    padding: 0.5rem;
  }

  .rift-topbar,
  .rift-panel {
    padding: 0.75rem;
  }

  h1 {
    font-size: 1.7rem;
  }

  .hud-strip {
    grid-template-columns: 1fr;
    gap: 0.45rem;
    white-space: normal;
  }

  .stage {
    min-height: 17rem;
  }

  .touch-controls {
    --touch-size: 3.05rem;
    right: 0.45rem;
    left: 0.45rem;
  }

  .context-prompt {
    bottom: 6.8rem;
  }

  .win-banner {
    grid-template-columns: 1fr;
  }

  .win-banner button {
    grid-column: 1;
    grid-row: auto;
  }
}
