@import url('https://fonts.googleapis.com/css2?family=Caveat:wght@400;700&family=Patrick+Hand&family=Playfair+Display:wght@700;900&display=swap');

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

:root {
  --font-sketch: 'Caveat', cursive;
  --font-hand: 'Patrick Hand', cursive;
  --font-death: 'Playfair Display', serif;
  --paper-bg: #f5f0e8;
  --paper-line: #c8d8e8;
  --ink-color: #2c2c2c;
  --ink-light: #666;
  --ink-muted: #5b5650;
  --red-accent: #c0392b;
  --green-accent: #27ae60;
  --paper-card: rgba(255, 250, 240, 0.88);
  --focus-ring: rgba(39, 174, 96, 0.28);
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: var(--font-sketch);
  background-color: var(--paper-bg);
}

#game-canvas {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
}

#ui-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 10;
  pointer-events: none;
}

#ui-overlay > * {
  pointer-events: auto;
}

/* Stock Picker / Menu */
#menu-screen {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  background: var(--paper-bg);
  background-image:
    linear-gradient(90deg, transparent 0, transparent 72px, rgba(192, 57, 43, 0.2) 73px, transparent 75px),
    linear-gradient(var(--paper-line) 1px, transparent 1px);
  background-size: 100% 32px;
  background-position: 0 -1px;
  overflow-y: auto;
  padding: 1.5rem 1rem 4rem;
}

.start-panel {
  display: grid;
  place-items: center;
  width: min(520px, 92vw);
  margin: 0 auto 1rem;
  text-align: center;
}

.brand-mark {
  width: 104px;
  height: 104px;
  object-fit: contain;
  margin-bottom: -0.35rem;
  filter: drop-shadow(0 8px 0 rgba(44, 44, 44, 0.12));
}

.seo-content {
  width: min(860px, 92vw);
  margin: 2rem auto 0;
  padding: 1.5rem;
  font-family: var(--font-hand);
  color: var(--ink-color);
  background: rgba(255, 250, 240, 0.62);
  border: 2px dashed rgba(44, 44, 44, 0.24);
  border-radius: 8px;
  text-align: left;
}

.seo-content h2 {
  font-family: var(--font-sketch);
  font-size: 2rem;
  margin: 1.25rem 0 0.5rem;
}

.seo-content h2:first-child {
  margin-top: 0;
}

.seo-content h3 {
  font-size: 1.25rem;
  margin-top: 1rem;
}

.seo-content p,
.seo-content li {
  font-size: 1.05rem;
  line-height: 1.55;
}

.seo-content ol {
  padding-left: 1.4rem;
}

.seo-content a {
  color: var(--red-accent);
  font-weight: 700;
  text-decoration-thickness: 2px;
}

.seo-anchor-nav {
  padding-bottom: 1rem;
  margin-bottom: 1rem;
  border-bottom: 2px dashed rgba(44, 44, 44, 0.18);
}

.seo-anchor-nav h2 {
  font-size: 1.45rem;
}

.seo-anchor-nav nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.6rem;
}

.seo-anchor-nav a {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0.2rem 0.65rem;
  color: var(--ink-color);
  background: rgba(39, 174, 96, 0.1);
  border: 2px solid rgba(44, 44, 44, 0.28);
  border-radius: 999px;
  text-decoration: none;
}

.seo-anchor-nav a:hover,
.seo-anchor-nav a:focus-visible {
  background: rgba(39, 174, 96, 0.18);
  border-color: rgba(44, 44, 44, 0.5);
}

.noscript-message {
  position: fixed;
  z-index: 50;
  inset: 1rem;
  display: grid;
  place-items: center;
  padding: 2rem;
  background: #f5f0e8;
  color: #2c2c2c;
  font: 1.25rem system-ui, sans-serif;
  text-align: center;
}

#menu-screen h1 {
  font-family: var(--font-sketch);
  font-size: 3.8rem;
  color: var(--ink-color);
  margin-bottom: 0.2rem;
  text-align: center;
  line-height: 0.95;
}

#menu-screen .subtitle {
  font-family: var(--font-hand);
  font-size: 1.25rem;
  color: var(--ink-muted);
  max-width: 36rem;
  margin: 0;
}

.stock-picker {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  width: min(92vw, 520px);
  padding: 1rem;
  background: var(--paper-card);
  border: 2px solid rgba(44, 44, 44, 0.78);
  border-radius: 8px;
  box-shadow: 0 8px 0 rgba(44, 44, 44, 0.1);
}

.ticker-label {
  align-self: flex-start;
  font-family: var(--font-hand);
  font-size: 1.05rem;
  color: var(--ink-color);
  font-weight: 700;
}

.search-container {
  position: relative;
  width: 100%;
}

#ticker-search {
  width: 100%;
  min-height: 56px;
  padding: 12px 16px;
  font-family: var(--font-hand);
  font-size: 1.2rem;
  border: 3px solid var(--ink-color);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  outline: none;
  color: var(--ink-color);
}

#ticker-search::placeholder {
  color: #706a62;
}

#ticker-search:focus {
  border-color: var(--green-accent);
  box-shadow: 0 0 0 4px var(--focus-ring);
}

#autocomplete-list {
  position: static;
  width: 100%;
  background: #fffaf0;
  border: 3px solid var(--ink-color);
  border-radius: 8px;
  margin-top: 0.35rem;
  max-height: 240px;
  overflow-y: auto;
  display: none;
  z-index: 100;
  box-shadow: 0 10px 0 rgba(44, 44, 44, 0.12);
}

#autocomplete-list.visible {
  display: block;
}

.autocomplete-item {
  min-height: 44px;
  padding: 9px 16px;
  cursor: pointer;
  font-family: var(--font-hand);
  font-size: 1rem;
  color: var(--ink-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.autocomplete-item:hover,
.autocomplete-item.selected {
  background: var(--paper-line);
}

.autocomplete-item .symbol {
  font-weight: bold;
}

.autocomplete-item .name {
  color: var(--ink-light);
  font-size: 0.9rem;
  text-align: right;
  flex: 1;
  margin-left: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.timeframe-selector {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
}

.timeframe-btn {
  min-width: 52px;
  min-height: 44px;
  padding: 8px 16px;
  font-family: var(--font-hand);
  font-size: 1rem;
  border: 2px solid var(--ink-color);
  border-radius: 6px;
  background: transparent;
  color: var(--ink-color);
  cursor: pointer;
  transition: transform 0.2s, background-color 0.2s, color 0.2s;
}

.timeframe-btn:hover {
  background: var(--ink-color);
  color: var(--paper-bg);
}

.timeframe-btn.active {
  background: var(--ink-color);
  color: var(--paper-bg);
}

.timeframe-btn:focus-visible,
#ride-btn:focus-visible,
.quick-rides a:focus-visible {
  outline: 3px solid var(--green-accent);
  outline-offset: 3px;
}

#ride-btn {
  min-height: 64px;
  padding: 14px 48px;
  font-family: var(--font-sketch);
  font-size: 1.8rem;
  font-weight: 700;
  border: 3px solid var(--ink-color);
  border-radius: 10px;
  background: transparent;
  color: var(--ink-color);
  cursor: pointer;
  transition: transform 0.2s, background-color 0.2s, color 0.2s, opacity 0.2s;
  margin-top: 0.15rem;
}

#ride-btn:hover:not(:disabled) {
  background: var(--ink-color);
  color: var(--paper-bg);
  transform: scale(1.05);
}

#ride-btn:disabled {
  opacity: 0.42;
  cursor: not-allowed;
  background: rgba(44, 44, 44, 0.04);
}

#selected-ticker-display {
  font-family: var(--font-hand);
  font-size: 1rem;
  color: var(--ink-light);
  min-height: 1.2em;
  text-align: center;
}

.quick-rides {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.45rem;
  width: 100%;
}

.quick-rides a {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.25rem 0.7rem;
  font-family: var(--font-hand);
  color: var(--ink-color);
  background: rgba(39, 174, 96, 0.12);
  border: 2px solid rgba(44, 44, 44, 0.66);
  border-radius: 999px;
  text-decoration: none;
}

.quick-rides a:hover {
  background: rgba(39, 174, 96, 0.22);
}

.control-hint {
  font-family: var(--font-hand);
  color: var(--ink-muted);
  font-size: 1rem;
  text-align: center;
}

/* Loading Screen */
#loading-screen {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--paper-bg);
  background-image:
    linear-gradient(var(--paper-line) 1px, transparent 1px);
  background-size: 100% 32px;
}

#loading-screen.visible {
  display: flex;
}

#loading-screen .loading-text {
  font-family: var(--font-sketch);
  font-size: 2rem;
  color: var(--ink-color);
  margin-bottom: 1rem;
}

.loading-line {
  width: 200px;
  height: 4px;
  background: var(--paper-line);
  border-radius: 2px;
  overflow: hidden;
}

.loading-line-fill {
  width: 0%;
  height: 100%;
  background: var(--ink-color);
  border-radius: 2px;
  transition: width 0.3s;
}

/* HUD */
#hud {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  padding: 16px 24px;
  display: none;
  justify-content: space-between;
  align-items: flex-start;
  font-family: var(--font-hand);
  color: var(--ink-color);
  pointer-events: none;
}

#hud.visible {
  display: flex;
}

.hud-left {
  font-size: 1.3rem;
}

.hud-left .ticker-name {
  font-weight: bold;
  font-size: 1.5rem;
}

.hud-center {
  text-align: center;
  font-size: 1rem;
  color: var(--ink-light);
}

.hud-center .speed-level {
  font-size: 1.1rem;
  font-weight: bold;
  color: var(--ink-color);
  transition: color 0.3s;
}

.hud-center .speed-level.fast {
  color: var(--red-accent);
}

.hud-right {
  text-align: right;
  font-size: 1.2rem;
}

.hud-right .price {
  font-size: 1.5rem;
  font-weight: bold;
}

.hud-right .price.up { color: var(--green-accent); }
.hud-right .price.down { color: var(--red-accent); }

#jump-hint {
  position: absolute;
  bottom: 60px;
  left: 50%;
  transform: translateX(-50%);
  font-family: var(--font-hand);
  font-size: 1.3rem;
  color: var(--ink-light);
  opacity: 1;
  transition: opacity 1s;
  pointer-events: none;
}

#jump-hint.hidden {
  opacity: 0;
}

/* Death Screen — Resident Evil bloody */
@keyframes blood-drip {
  0% { transform: scaleY(0); opacity: 0; }
  30% { transform: scaleY(1); opacity: 0.9; }
  100% { transform: scaleY(1); opacity: 0.6; }
}

@keyframes blood-vignette-pulse {
  0%, 100% { opacity: 0.7; }
  50% { opacity: 1; }
}

@keyframes title-glitch {
  0%, 88%, 100% { transform: scale(1) skew(0deg); filter: blur(0); }
  89% { transform: scale(1.03) skew(-3deg); filter: blur(1px); }
  91% { transform: scale(0.97) skew(2deg); filter: blur(2px); }
  93% { transform: scale(1.02) skew(-1deg); filter: blur(0); }
  95% { transform: scale(0.99) skew(1deg); filter: blur(1px); }
}

@keyframes splatter-in {
  0% { transform: scale(0); opacity: 0; }
  50% { transform: scale(1.3); opacity: 0.8; }
  100% { transform: scale(1); opacity: 0.6; }
}

@keyframes blood-pool-spread {
  0% { transform: scaleX(0); opacity: 0; }
  60% { transform: scaleX(1); opacity: 0.7; }
  100% { transform: scaleX(1); opacity: 0.5; }
}

#death-screen {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0);
  z-index: 20;
  overflow: hidden;
}

#death-screen.visible {
  display: flex;
  animation: death-fade-in 2s ease-out forwards;
}

@keyframes death-fade-in {
  0% { background: rgba(100, 0, 0, 0); }
  15% { background: rgba(120, 0, 0, 0.4); }
  40% { background: rgba(60, 0, 0, 0.7); }
  100% { background: rgba(8, 0, 0, 0.94); }
}

/* Heavy blood vignette overlay */
#death-screen::before {
  content: '';
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse at center, transparent 20%, rgba(100, 0, 0, 0.4) 60%, rgba(60, 0, 0, 0.8) 100%);
  opacity: 0;
  pointer-events: none;
}

#death-screen.visible::before {
  animation: blood-vignette-pulse 3s ease-in-out 0.8s infinite;
}

/* Blood drip streaks — lots of them, varying thickness and length */
#death-screen::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background:
    linear-gradient(180deg, rgba(139, 0, 0, 0.9) 0%, rgba(80, 0, 0, 0.3) 70%, transparent 100%) no-repeat 5% 0 / 4px 55%,
    linear-gradient(180deg, rgba(160, 0, 0, 0.8) 0%, transparent 80%) no-repeat 12% 0 / 2px 70%,
    linear-gradient(180deg, rgba(139, 0, 0, 1) 0%, rgba(90, 0, 0, 0.4) 60%, transparent 100%) no-repeat 18% 0 / 5px 45%,
    linear-gradient(180deg, rgba(120, 0, 0, 0.7) 0%, transparent 75%) no-repeat 27% 0 / 3px 65%,
    linear-gradient(180deg, rgba(160, 0, 0, 0.9) 0%, rgba(100, 0, 0, 0.5) 50%, transparent 100%) no-repeat 33% 0 / 6px 40%,
    linear-gradient(180deg, rgba(139, 0, 0, 0.6) 0%, transparent 85%) no-repeat 41% 0 / 2px 75%,
    linear-gradient(180deg, rgba(150, 0, 0, 1) 0%, rgba(80, 0, 0, 0.3) 65%, transparent 100%) no-repeat 48% 0 / 4px 50%,
    linear-gradient(180deg, rgba(130, 0, 0, 0.8) 0%, transparent 70%) no-repeat 55% 0 / 3px 60%,
    linear-gradient(180deg, rgba(160, 10, 0, 0.9) 0%, rgba(90, 0, 0, 0.4) 55%, transparent 100%) no-repeat 63% 0 / 5px 42%,
    linear-gradient(180deg, rgba(139, 0, 0, 0.7) 0%, transparent 80%) no-repeat 70% 0 / 2px 72%,
    linear-gradient(180deg, rgba(150, 0, 0, 0.85) 0%, rgba(80, 0, 0, 0.3) 60%, transparent 100%) no-repeat 78% 0 / 4px 48%,
    linear-gradient(180deg, rgba(120, 0, 0, 0.6) 0%, transparent 75%) no-repeat 85% 0 / 3px 58%,
    linear-gradient(180deg, rgba(160, 0, 0, 0.95) 0%, rgba(100, 0, 0, 0.5) 50%, transparent 100%) no-repeat 92% 0 / 5px 38%,
    linear-gradient(180deg, rgba(139, 0, 0, 0.7) 0%, transparent 65%) no-repeat 97% 0 / 2px 52%;
  transform-origin: top;
  transform: scaleY(0);
  opacity: 0;
  pointer-events: none;
}

#death-screen.visible::after {
  animation: blood-drip 2.5s ease-out 0.2s forwards;
}

/* Blood splatter blobs */
.blood-splatter {
  position: absolute;
  border-radius: 50%;
  pointer-events: none;
  z-index: 0;
  opacity: 0;
  transform: scale(0);
}

.blood-splatter {
  width: 300px;
  height: 280px;
  top: 15%;
  right: 8%;
  background: radial-gradient(ellipse at 40% 45%, rgba(120, 0, 0, 0.7) 0%, rgba(80, 0, 0, 0.3) 50%, transparent 70%);
}

.blood-splatter.s2 {
  width: 220px;
  height: 200px;
  top: 55%;
  left: 5%;
  background: radial-gradient(ellipse at 55% 50%, rgba(100, 0, 0, 0.6) 0%, rgba(70, 0, 0, 0.2) 55%, transparent 70%);
}

.blood-splatter.s3 {
  width: 180px;
  height: 160px;
  bottom: 10%;
  right: 20%;
  background: radial-gradient(ellipse at 45% 55%, rgba(130, 0, 0, 0.5) 0%, rgba(80, 0, 0, 0.2) 50%, transparent 70%);
}

#death-screen.visible .blood-splatter {
  animation: splatter-in 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) 0.4s forwards;
}

#death-screen.visible .blood-splatter.s2 {
  animation: splatter-in 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) 0.7s forwards;
}

#death-screen.visible .blood-splatter.s3 {
  animation: splatter-in 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) 1s forwards;
}

#death-screen .death-title {
  font-family: var(--font-death);
  font-size: 3.5rem;
  font-weight: 900;
  color: #dd1100;
  text-transform: uppercase;
  letter-spacing: 6px;
  text-align: center;
  opacity: 0;
  transform: scale(0.3);
  padding: 0 20px;
  text-shadow:
    0 0 10px rgba(255, 0, 0, 0.9),
    0 0 30px rgba(200, 0, 0, 0.7),
    0 0 60px rgba(150, 0, 0, 0.5),
    0 0 120px rgba(100, 0, 0, 0.4),
    0 4px 8px rgba(0, 0, 0, 0.95);
  position: relative;
  z-index: 1;
}

#death-screen.visible .death-title {
  animation: death-title-in 1.2s cubic-bezier(0.16, 1, 0.3, 1) 0.6s forwards,
             title-glitch 4s ease-in-out 3s infinite;
}

@keyframes death-title-in {
  0% { opacity: 0; transform: scale(0.3); filter: blur(10px) brightness(3); }
  50% { opacity: 1; transform: scale(1.15); filter: blur(0) brightness(1.5); }
  75% { transform: scale(0.95); filter: blur(0) brightness(1); }
  100% { opacity: 1; transform: scale(1); filter: blur(0) brightness(1); }
}

.death-stats {
  margin-top: 2rem;
  text-align: center;
  font-family: var(--font-hand);
  font-size: 1.1rem;
  color: #aa8888;
  opacity: 0;
  transition: opacity 1.2s ease-out;
  transition-delay: 2.2s;
  line-height: 1.8;
  position: relative;
  z-index: 1;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.6);
}

#death-screen.visible .death-stats {
  opacity: 1;
}

.death-buttons {
  margin-top: 2rem;
  display: flex;
  gap: 16px;
  opacity: 0;
  transition: opacity 1s ease-out;
  transition-delay: 3s;
  position: relative;
  z-index: 1;
}

#death-screen.visible .death-buttons {
  opacity: 1;
}

.death-btn {
  padding: 12px 32px;
  font-family: var(--font-sketch);
  font-size: 1.4rem;
  font-weight: 700;
  border: 2px solid #664444;
  border-radius: 4px;
  background: rgba(40, 0, 0, 0.6);
  color: #aa8888;
  cursor: pointer;
  transition: all 0.2s;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}

.death-btn:hover {
  background: rgba(100, 10, 10, 0.7);
  color: #ddc;
  border-color: #993333;
}

.death-btn.primary {
  border-color: #992211;
  color: #cc3322;
}

.death-btn.primary:hover {
  background: rgba(150, 20, 10, 0.8);
  color: white;
  box-shadow: 0 0 20px rgba(200, 0, 0, 0.4);
}

/* Pause overlay */
#pause-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.5);
  z-index: 15;
}

#pause-overlay.visible {
  display: flex;
}

#pause-overlay .pause-text {
  font-family: var(--font-sketch);
  font-size: 3rem;
  color: white;
}

/* Error message */
.error-message {
  font-family: var(--font-hand);
  color: var(--red-accent);
  font-size: 1rem;
  min-height: 1.4em;
  text-align: center;
}

/* Toast notification */
.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  padding: 10px 24px;
  background: var(--ink-color);
  color: var(--paper-bg);
  font-family: var(--font-hand);
  font-size: 1rem;
  border-radius: 6px;
  z-index: 100;
  transition: transform 0.3s;
}

.toast.visible {
  transform: translateX(-50%) translateY(0);
}

/* Responsive */
@media (max-width: 768px) {
  #menu-screen {
    padding: 1rem 1rem 3rem;
    background-image:
      linear-gradient(90deg, transparent 0, transparent 26px, rgba(192, 57, 43, 0.2) 27px, transparent 29px),
      linear-gradient(var(--paper-line) 1px, transparent 1px);
  }

  .start-panel {
    margin-bottom: 0.8rem;
  }

  .brand-mark {
    width: 82px;
    height: 82px;
  }

  #menu-screen h1 {
    font-size: 2.65rem;
  }

  #menu-screen .subtitle {
    font-size: 1.05rem;
    line-height: 1.3;
    max-width: 20rem;
  }

  .stock-picker {
    width: 100%;
    max-width: 380px;
    padding: 0.9rem;
    gap: 0.65rem;
  }

  #autocomplete-list {
    width: 100%;
    max-height: 176px;
    border: 2px solid var(--ink-color);
    box-shadow: none;
  }

  .autocomplete-item {
    min-height: 46px;
  }

  .timeframe-btn {
    min-width: 50px;
    min-height: 44px;
    padding: 7px 12px;
    font-size: 0.9rem;
  }

  #ride-btn {
    min-height: 58px;
    padding: 10px 38px;
    font-size: 1.55rem;
  }

  .seo-content {
    width: 100%;
    margin-top: 1.5rem;
    padding: 1rem;
  }

  .seo-content h2 {
    font-size: 1.65rem;
    line-height: 1.12;
  }

  .seo-content p,
  .seo-content li {
    font-size: 1rem;
    line-height: 1.48;
  }

  #death-screen .death-title {
    font-size: 2.2rem;
    letter-spacing: 3px;
  }

  .death-stats {
    font-size: 0.95rem;
  }

  .hud-left, .hud-right {
    font-size: 1rem;
  }

  .hud-left .ticker-name,
  .hud-right .price {
    font-size: 1.2rem;
  }
}
