@import url('https://fonts.googleapis.com/css2?family=Cinzel:wght@400;700;900&family=Courier+Prime:wght@400;700&display=swap');

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  background: #000;
  overflow: hidden;
  font-family: 'Courier Prime', 'Courier New', monospace;
  color: #c8c8c8;
  width: 100vw;
  height: 100vh;
  cursor: none;
}

canvas {
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

.hidden {
  display: none !important;
}

/* =========================================================
   SHARED OVERLAY BASE
   ========================================================= */
#loading-screen,
#title-screen,
#death-screen,
#win-screen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

/* =========================================================
   LOADING SCREEN
   ========================================================= */
#loading-screen {
  background: #000;
}

.load-bg {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse at 50% 60%, rgba(8, 20, 8, .9) 0%, #000 70%),
    radial-gradient(circle at 30% 80%, rgba(20, 5, 5, .4) 0%, transparent 50%),
    radial-gradient(circle at 70% 20%, rgba(5, 15, 5, .3) 0%, transparent 50%);
  animation: bgBreath 6s ease-in-out infinite;
}

@keyframes bgBreath {

  0%,
  100% {
    opacity: .8;
  }

  50% {
    opacity: 1;
  }
}

.load-content {
  position: relative;
  z-index: 2;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.2rem;
  padding: 2rem;
}

.load-title {
  font-family: 'Cinzel', serif;
  font-size: clamp(2rem, 6vw, 4rem);
  font-weight: 900;
  color: #c0c0c0;
  letter-spacing: 10px;
  line-height: 1.25;
  text-shadow:
    0 0 40px rgba(139, 0, 0, .5),
    0 0 80px rgba(139, 0, 0, .25),
    0 2px 4px rgba(0, 0, 0, .9);
  animation: titleFlicker 8s ease-in-out infinite;
}

.load-sub {
  font-size: clamp(.75rem, 1.8vw, 1rem);
  color: #555;
  font-style: italic;
  letter-spacing: 3px;
  animation: fadeInOut 3s ease-in-out infinite;
}

@keyframes fadeInOut {

  0%,
  100% {
    opacity: .4;
  }

  50% {
    opacity: .9;
  }
}

.load-bar-wrap {
  width: min(280px, 60vw);
  height: 3px;
  background: #1a1a1a;
  border-radius: 2px;
  overflow: hidden;
  border: 1px solid #2a2a2a;
}

.load-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #3a0000, #8b0000, #cc4444);
  border-radius: 2px;
  transition: width .3s ease;
  box-shadow: 0 0 8px rgba(139, 0, 0, .6);
}

.load-pct {
  font-size: .7rem;
  color: #444;
  letter-spacing: 2px;
}

/* =========================================================
   TITLE / MENU SCREEN
   ========================================================= */
#title-screen {
  background: radial-gradient(ellipse at 50% 55%, #080f08 0%, #000 72%);
}

.title-bg {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 22% 78%, rgba(10, 28, 10, .5) 0%, transparent 50%),
    radial-gradient(circle at 78% 22%, rgba(10, 20, 10, .35) 0%, transparent 50%),
    radial-gradient(circle at 50% 50%, rgba(0, 0, 0, 0) 0%, rgba(0, 0, 0, .85) 100%);
  animation: fogDrift 22s ease-in-out infinite;
}

@keyframes fogDrift {

  0%,
  100% {
    opacity: .65;
    transform: scale(1);
  }

  50% {
    opacity: 1;
    transform: scale(1.06);
  }
}

.title-content {
  position: relative;
  z-index: 2;
  text-align: center;
  max-width: 580px;
  width: 90%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
  padding: 2rem;
}

.title-glow {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 420px;
  height: 420px;
  background: radial-gradient(circle, rgba(139, 0, 0, .07) 0%, transparent 72%);
  animation: pulseGlow 5s ease-in-out infinite;
  pointer-events: none;
}

@keyframes pulseGlow {

  0%,
  100% {
    opacity: .35;
    transform: translate(-50%, -50%) scale(1);
  }

  50% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1.25);
  }
}

.title-text {
  font-family: 'Cinzel', serif;
  font-size: clamp(2rem, 6vw, 4rem);
  font-weight: 900;
  color: #d0d0d0;
  letter-spacing: 8px;
  line-height: 1.2;
  text-shadow:
    0 0 30px rgba(139, 0, 0, .45),
    0 0 65px rgba(139, 0, 0, .2),
    0 2px 4px rgba(0, 0, 0, .9);
  margin-bottom: 1.1rem;
  animation: titleFlicker 8s ease-in-out infinite;
}

@keyframes titleFlicker {

  0%,
  94%,
  100% {
    opacity: 1;
  }

  95% {
    opacity: .8;
  }

  97% {
    opacity: 1;
  }

  99% {
    opacity: .88;
  }
}

.title-sub {
  font-size: clamp(.75rem, 2vw, 1rem);
  color: #5a5a5a;
  font-style: italic;
  margin-bottom: 1.8rem;
  letter-spacing: 2px;
}

.title-separator {
  width: 60px;
  height: 1px;
  background: linear-gradient(90deg, transparent, #3a3a3a, transparent);
  margin: 0 auto 2rem;
}

/* Start button */
.btn-main {
  font-family: 'Cinzel', serif;
  font-size: clamp(.85rem, 2vw, 1.05rem);
  font-weight: 700;
  padding: 14px 44px;
  background: transparent;
  border: 1px solid #383838;
  color: #999;
  cursor: pointer;
  letter-spacing: 4px;
  transition: all .4s ease;
  position: relative;
  overflow: hidden;
  margin-bottom: 2.5rem;
}

.btn-main::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(139, 0, 0, .12), transparent);
  transition: left .55s ease;
}

.btn-main:hover {
  border-color: #8b0000;
  color: #e8e8e8;
  text-shadow: 0 0 18px rgba(139, 0, 0, .6);
  box-shadow: 0 0 22px rgba(139, 0, 0, .18);
}

.btn-main:hover::before {
  left: 100%;
}

/* Controls grid */
.controls-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 6px 16px;
  font-size: .68rem;
  color: #3a3a3a;
  border-top: 1px solid #1a1a1a;
  padding-top: 1.8rem;
  width: 100%;
}

.control-item {
  padding: 3px 0;
}

.key {
  display: inline-block;
  background: rgba(255, 255, 255, .04);
  border: 1px solid #2c2c2c;
  border-radius: 2px;
  padding: 1px 6px;
  font-size: .62rem;
  color: #555;
  margin-right: 5px;
  letter-spacing: 0;
}

/* =========================================================
   GUIDE BUTTON (title screen)
   ========================================================= */
.btn-guide {
  font-family: 'Cinzel', serif;
  font-size: clamp(.72rem, 1.6vw, .88rem);
  font-weight: 700;
  padding: 10px 32px;
  background: transparent;
  border: 1px solid #2a2218;
  color: #6a5a3a;
  cursor: pointer;
  letter-spacing: 3px;
  transition: all .35s ease;
  margin-bottom: 2rem;
}

.btn-guide:hover {
  border-color: #8b6a2a;
  color: #d4b872;
  text-shadow: 0 0 14px rgba(180, 140, 50, .4);
  box-shadow: 0 0 16px rgba(140, 110, 30, .12);
}

/* =========================================================
   GUIDE OVERLAY SCREEN
   ========================================================= */
#guide-screen {
  position: fixed;
  inset: 0;
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: guide-fadein .35s ease both;
}

@keyframes guide-fadein {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

.guide-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, .92);
  backdrop-filter: blur(4px);
}

.guide-scroll {
  position: relative;
  z-index: 1;
  width: min(640px, 92vw);
  max-height: 88vh;
  overflow-y: auto;
  padding: 36px 40px 28px;
  background:
    linear-gradient(180deg, rgba(12, 8, 4, .96) 0%, rgba(6, 4, 2, .98) 100%);
  border: 1px solid rgba(120, 80, 30, .3);
  box-shadow:
    0 0 60px rgba(100, 60, 10, .12),
    inset 0 1px 0 rgba(255, 255, 255, .03);
  scrollbar-width: thin;
  scrollbar-color: #3a2a10 #0a0804;
}

.guide-scroll::-webkit-scrollbar {
  width: 5px;
}

.guide-scroll::-webkit-scrollbar-track {
  background: #0a0804;
}

.guide-scroll::-webkit-scrollbar-thumb {
  background: #3a2a10;
  border-radius: 3px;
}

/* Close button */
.guide-close {
  position: absolute;
  top: 12px;
  right: 14px;
  background: none;
  border: 1px solid rgba(100, 60, 30, .35);
  color: #6a5a3a;
  font-size: 1rem;
  width: 30px;
  height: 30px;
  cursor: pointer;
  transition: all .25s;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.guide-close:hover {
  border-color: #c8a050;
  color: #f0d080;
  box-shadow: 0 0 10px rgba(200, 160, 80, .15);
}

/* Header */
.guide-header {
  font-family: 'Cinzel', serif;
  font-size: clamp(1.2rem, 3vw, 1.7rem);
  font-weight: 900;
  color: #c8a050;
  letter-spacing: 4px;
  text-align: center;
  text-shadow: 0 0 20px rgba(200, 160, 80, .35);
  margin-bottom: 6px;
}

.guide-flavor {
  text-align: center;
  font-size: .78rem;
  color: #4a4030;
  font-style: italic;
  letter-spacing: 1px;
  margin-bottom: 28px;
}

/* Sections */
.guide-section {
  margin-bottom: 26px;
  padding-bottom: 22px;
  border-bottom: 1px solid rgba(100, 70, 30, .15);
}

.guide-section:last-of-type {
  border-bottom: none;
  margin-bottom: 10px;
}

.guide-section-title {
  font-family: 'Cinzel', serif;
  font-size: .95rem;
  font-weight: 700;
  color: #a08040;
  letter-spacing: 3px;
  margin-bottom: 12px;
  text-shadow: 0 0 12px rgba(160, 128, 64, .2);
}

.guide-section p {
  font-size: .82rem;
  color: #8a8070;
  line-height: 1.6;
  margin-bottom: 10px;
}

/* Lists */
.guide-list {
  list-style: none;
  padding: 0;
}

.guide-list li {
  font-size: .8rem;
  color: #7a7060;
  line-height: 1.65;
  padding: 5px 0 5px 18px;
  position: relative;
}

.guide-list li::before {
  content: '▸';
  position: absolute;
  left: 0;
  color: #5a4a2a;
}

.guide-list li strong {
  color: #b0a080;
}

.guide-list li em {
  color: #8b4040;
}

/* Highlight chips */
.guide-hl {
  display: inline-block;
  padding: 0 5px;
  border-radius: 2px;
  font-size: .75rem;
  font-weight: 700;
  letter-spacing: .05em;
}

.guide-hl.exit {
  background: rgba(80, 180, 80, .12);
  color: #5cbb5c;
  border: 1px solid rgba(80, 180, 80, .2);
}

.guide-hl.hp {
  background: rgba(200, 50, 50, .12);
  color: #cc5555;
  border: 1px solid rgba(200, 50, 50, .2);
}

.guide-hl.sanity {
  background: rgba(120, 80, 200, .12);
  color: #a070d0;
  border: 1px solid rgba(120, 80, 200, .2);
}

.guide-hl.wood {
  background: rgba(160, 120, 50, .12);
  color: #c8a040;
  border: 1px solid rgba(160, 120, 50, .2);
}

.guide-hl.tool {
  background: rgba(100, 160, 200, .12);
  color: #70b0d0;
  border: 1px solid rgba(100, 160, 200, .2);
}

/* Controls rows */
.guide-controls {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.guide-key-row {
  font-size: .8rem;
  color: #7a7060;
  display: flex;
  align-items: center;
  gap: 12px;
}

.guide-key {
  display: inline-block;
  min-width: 70px;
  text-align: center;
  background: rgba(255, 255, 255, .04);
  border: 1px solid #2c2418;
  border-radius: 3px;
  padding: 3px 8px;
  font-size: .72rem;
  color: #8a7a5a;
  letter-spacing: .08em;
  font-family: 'Courier Prime', monospace;
}

/* Monster grid */
.guide-warn {
  font-size: .78rem;
  color: #6a4040 !important;
  font-style: italic;
  margin-bottom: 14px !important;
}

.guide-monster-grid {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.guide-monster {
  display: flex;
  gap: 14px;
  align-items: flex-start;
  padding: 12px 14px;
  background: rgba(255, 255, 255, .015);
  border: 1px solid rgba(80, 40, 40, .2);
  border-left: 3px solid rgba(139, 0, 0, .4);
  transition: border-color .3s, background .3s;
}

.guide-monster:hover {
  border-color: rgba(139, 0, 0, .5);
  background: rgba(139, 0, 0, .04);
}

.guide-monster-icon {
  font-size: 1.5rem;
  line-height: 1;
  flex-shrink: 0;
}

.guide-monster strong {
  display: block;
  font-size: .82rem;
  color: #b08060;
  letter-spacing: .1em;
  margin-bottom: 4px;
}

.guide-monster p {
  font-size: .76rem;
  color: #6a6050;
  line-height: 1.55;
  margin: 0;
}

/* Footer */
.guide-footer {
  text-align: center;
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid rgba(100, 70, 30, .15);
}

.guide-footer p {
  font-size: .72rem;
  color: #3a3020;
  font-style: italic;
  letter-spacing: 1px;
}

/* =========================================================
   DEATH SCREEN
   ========================================================= */
#death-screen {
  background: rgba(0, 0, 0, .92);
  gap: 12px;
  font-family: 'Courier Prime', monospace;
}

#death-screen h2 {
  font-family: 'Cinzel', serif;
  font-size: clamp(1.4rem, 4vw, 2.4rem);
  color: #8b0000;
  letter-spacing: 5px;
  text-shadow: 0 0 40px rgba(139, 0, 0, .7), 0 0 80px rgba(139, 0, 0, .35);
  animation: deathPulse 3s ease-in-out infinite;
}

@keyframes deathPulse {

  0%,
  100% {
    text-shadow: 0 0 40px rgba(139, 0, 0, .6);
  }

  50% {
    text-shadow: 0 0 70px rgba(139, 0, 0, .9), 0 0 110px rgba(139, 0, 0, .4);
  }
}

/* =========================================================
   WIN SCREEN
   ========================================================= */
#win-screen {
  background: rgba(0, 0, 0, .92);
  gap: 12px;
  font-family: 'Courier Prime', monospace;
}

#win-screen h2 {
  font-family: 'Cinzel', serif;
  font-size: clamp(1.4rem, 4vw, 2.4rem);
  color: #4aaa4a;
  letter-spacing: 5px;
  text-shadow: 0 0 40px rgba(80, 160, 80, .5);
}

/* Shared overlay text */
.overlay-msg {
  font-size: .95rem;
  color: #777;
  font-style: italic;
}

.overlay-stats {
  font-size: .8rem;
  color: #484848;
}

.overlay-btn {
  padding: 10px 36px;
  background: transparent;
  border: 1px solid #444;
  color: #888;
  font-family: 'Courier Prime', monospace;
  font-size: .88rem;
  cursor: pointer;
  letter-spacing: 3px;
  transition: border-color .25s, color .25s;
  margin-top: 8px;
}

.overlay-btn:hover {
  border-color: #999;
  color: #eee;
}

/* =========================================================
   AUTH SCREEN
   ========================================================= */
#auth-screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  background: #000;
}

.auth-bg {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse at 50% 40%, rgba(40, 8, 8, .85) 0%, #000 70%);
  animation: title-fog 12s ease-in-out infinite alternate;
}

.auth-panel {
  position: relative;
  z-index: 1;
  width: 360px;
  padding: 36px 36px 28px;
  background: rgba(6, 4, 4, .88);
  border: 1px solid rgba(120, 40, 40, .35);
  box-shadow:
    0 0 40px rgba(120, 0, 0, .18),
    inset 0 1px 0 rgba(255, 255, 255, .04);
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0;
  animation: auth-fadein .6s ease both;
}

@keyframes auth-fadein {
  from {
    opacity: 0;
    transform: translateY(18px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Logo area */
.auth-logo {
  text-align: center;
  margin-bottom: 22px;
}

.auth-title {
  font-family: 'Cinzel', serif;
  font-size: 1.5rem;
  font-weight: 900;
  letter-spacing: .18em;
  line-height: 1.2;
  color: #c8a060;
  text-shadow: 0 0 18px rgba(200, 80, 20, .5);
  animation: title-flicker 6s ease-in-out infinite;
}

.auth-sub {
  margin-top: 6px;
  font-size: .72rem;
  color: #555;
  letter-spacing: .1em;
}

/* Tabs */
.auth-tabs {
  display: flex;
  gap: 2px;
  margin-bottom: 20px;
  border-bottom: 1px solid rgba(100, 40, 40, .4);
}

.auth-tab {
  flex: 1;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 8px 0;
  margin-bottom: -1px;
  font-family: 'Courier Prime', monospace;
  font-size: .78rem;
  letter-spacing: .15em;
  color: #555;
  cursor: pointer;
  transition: color .2s, border-color .2s;
}

.auth-tab.active {
  color: #c8a060;
  border-bottom-color: #8b2020;
}

.auth-tab:hover:not(.active) {
  color: #888;
}

/* Form */
.auth-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.auth-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.auth-field label {
  font-size: .68rem;
  letter-spacing: .14em;
  color: #666;
}

.auth-field input {
  background: rgba(255, 255, 255, .04);
  border: 1px solid rgba(100, 60, 60, .45);
  color: #c8b8a0;
  font-family: 'Courier Prime', monospace;
  font-size: .88rem;
  padding: 9px 12px;
  outline: none;
  transition: border-color .2s, box-shadow .2s;
  cursor: text;
}

.auth-field input::placeholder {
  color: #3a3028;
}

.auth-field input:focus {
  border-color: rgba(180, 60, 60, .7);
  box-shadow: 0 0 12px rgba(160, 30, 30, .25);
}

/* Error message */
.auth-error {
  min-height: 14px;
  font-size: .72rem;
  color: #cc3030;
  letter-spacing: .05em;
  text-align: center;
  animation: none;
}

.auth-error.shake {
  animation: auth-shake .35s ease;
}

@keyframes auth-shake {

  0%,
  100% {
    transform: translateX(0);
  }

  20% {
    transform: translateX(-6px);
  }

  40% {
    transform: translateX(6px);
  }

  60% {
    transform: translateX(-4px);
  }

  80% {
    transform: translateX(4px);
  }
}

/* Main button */
.auth-btn-main {
  margin-top: 4px;
  padding: 11px;
  background: rgba(100, 20, 20, .55);
  border: 1px solid rgba(160, 40, 40, .6);
  color: #d8b080;
  font-family: 'Courier Prime', monospace;
  font-size: .82rem;
  letter-spacing: .18em;
  cursor: pointer;
  transition: background .2s, border-color .2s, color .2s;
}

.auth-btn-main:hover {
  background: rgba(140, 30, 30, .7);
  border-color: rgba(200, 60, 60, .7);
  color: #f0c890;
}

/* Divider */
.auth-divider {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 16px 0 10px;
  color: #333;
  font-size: .7rem;
  letter-spacing: .1em;
}

.auth-divider::before,
.auth-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: rgba(100, 40, 40, .3);
}

/* Guest button */
.auth-btn-guest {
  padding: 9px;
  background: none;
  border: 1px solid rgba(80, 60, 40, .4);
  color: #555;
  font-family: 'Courier Prime', monospace;
  font-size: .78rem;
  letter-spacing: .15em;
  cursor: pointer;
  transition: border-color .2s, color .2s;
}

.auth-btn-guest:hover {
  border-color: #666;
  color: #888;
}

/* Note */
.auth-note {
  margin-top: 10px;
  text-align: center;
  font-size: .65rem;
  color: #333;
  letter-spacing: .08em;
}

/* ── Title screen user bar ─────────────────────────────────── */
.title-user-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
  font-size: .72rem;
  color: #555;
  letter-spacing: .08em;
  justify-content: center;
}

.title-user-bar span {
  color: #6a5030;
}

.title-logout-btn {
  background: none;
  border: 1px solid rgba(80, 40, 40, .4);
  color: #5a3030;
  font-family: 'Courier Prime', monospace;
  font-size: .65rem;
  letter-spacing: .12em;
  padding: 3px 8px;
  cursor: pointer;
  transition: border-color .2s, color .2s;
}

.title-logout-btn:hover {
  border-color: #8b2020;
  color: #cc4040;
}