/* ========== RESET & BASE ========== */
*, *::before, *::after {
  margin: 0; padding: 0; box-sizing: border-box;
}

:root {
  --parchment: #f4e8c1;
  --parchment-dark: #d4c49a;
  --ink: #2c1810;
  --ink-light: #5a3e2b;
  --river-deep: #1a3a4a;
  --river-mid: #2a5a6a;
  --river-light: #3a8a9a;
  --gold: #c4972a;
  --gold-light: #e8c45a;
  --danger: #8b2500;
  --danger-light: #c44a20;
  --grass-left: #3a5a2a;
  --grass-right: #2a4a1a;
  --twilight: #1a1a2e;
  --font-display: 'Cinzel Decorative', serif;
  --font-body: 'Crimson Pro', serif;
  --font-mono: 'JetBrains Mono', monospace;
}

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

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

.hidden { display: none !important; }

/* ========== INTRO ========== */
#intro-overlay {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  z-index: 100;
  background: radial-gradient(ellipse at 50% 80%, #1a2a3a 0%, #0a0a1a 70%);
  display: flex;
  align-items: center;
  justify-content: center;
  animation: introFadeIn 1.5s ease-out;
}

@keyframes introFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.intro-content {
  text-align: center;
  position: relative;
  z-index: 2;
  animation: introSlideUp 1.8s ease-out 0.3s both;
}

@keyframes introSlideUp {
  from { opacity: 0; transform: translateY(60px); }
  to { opacity: 1; transform: translateY(0); }
}

.intro-lantern {
  width: 12px; height: 12px;
  background: var(--gold-light);
  border-radius: 50%;
  margin: 0 auto 30px;
  box-shadow: 0 0 40px 15px rgba(232, 196, 90, 0.3),
              0 0 80px 30px rgba(196, 151, 42, 0.15);
  animation: lanternPulse 3s ease-in-out infinite;
}

@keyframes lanternPulse {
  0%, 100% { box-shadow: 0 0 40px 15px rgba(232, 196, 90, 0.3), 0 0 80px 30px rgba(196, 151, 42, 0.15); }
  50% { box-shadow: 0 0 60px 20px rgba(232, 196, 90, 0.4), 0 0 100px 40px rgba(196, 151, 42, 0.2); }
}

.intro-title {
  font-family: var(--font-display);
  font-size: clamp(2rem, 6vw, 4.5rem);
  font-weight: 900;
  color: var(--parchment);
  letter-spacing: 0.08em;
  text-shadow: 0 0 30px rgba(244, 232, 193, 0.2);
  line-height: 1.2;
}

.intro-subtitle {
  font-family: var(--font-body);
  font-size: clamp(0.9rem, 2vw, 1.4rem);
  font-weight: 300;
  font-style: italic;
  color: var(--parchment-dark);
  margin-top: 10px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
}

.intro-line {
  width: 60px; height: 1px;
  background: linear-gradient(90deg, transparent, var(--gold), transparent);
  margin: 30px auto;
  animation: lineExpand 2s ease-out 1.5s both;
}

@keyframes lineExpand {
  from { width: 0; opacity: 0; }
  to { width: 60px; opacity: 1; }
}

.intro-mist {
  position: absolute;
  bottom: 0; left: -10%;
  width: 120%; height: 30%;
  background: linear-gradient(to top, rgba(26, 42, 58, 0.8), transparent);
  animation: mistDrift 8s ease-in-out infinite;
  z-index: 1;
  pointer-events: none;
}

.mist-2 {
  animation-delay: -4s;
  animation-duration: 12s;
  opacity: 0.5;
  height: 40%;
}

@keyframes mistDrift {
  0%, 100% { transform: translateX(0); }
  50% { transform: translateX(3%); }
}

/* ========== BUTTONS ========== */
.btn-parchment {
  font-family: var(--font-display);
  font-size: clamp(0.8rem, 1.5vw, 1rem);
  font-weight: 700;
  color: var(--ink);
  background: linear-gradient(135deg, var(--parchment) 0%, var(--parchment-dark) 100%);
  border: 2px solid var(--gold);
  padding: 14px 36px;
  cursor: pointer;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  position: relative;
  overflow: hidden;
  transition: all 0.3s ease;
  animation: btnAppear 1s ease-out 2.5s both;
}

@keyframes btnAppear {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

.btn-parchment:hover {
  background: linear-gradient(135deg, #fff 0%, var(--parchment) 100%);
  box-shadow: 0 0 20px rgba(196, 151, 42, 0.3);
  transform: translateY(-2px);
}

.btn-parchment:active {
  transform: translateY(0);
}

.btn-parchment:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.btn-secondary {
  background: transparent;
  color: var(--parchment);
  border-color: var(--parchment-dark);
}

.btn-secondary:hover {
  background: rgba(244, 232, 193, 0.1);
  color: var(--parchment);
}

.btn-small {
  font-family: var(--font-body);
  font-size: 0.85rem;
  color: var(--parchment-dark);
  background: rgba(26, 26, 46, 0.7);
  border: 1px solid rgba(244, 232, 193, 0.15);
  padding: 8px 16px;
  cursor: pointer;
  transition: all 0.2s;
  backdrop-filter: blur(4px);
}

.btn-small:hover {
  background: rgba(244, 232, 193, 0.1);
  color: var(--parchment);
  border-color: var(--gold);
}

/* ========== LEVEL SELECT ========== */
#level-select {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(10, 10, 26, 0.85);
  backdrop-filter: blur(8px);
}

.level-select-inner {
  text-align: center;
  animation: fadeSlideUp 0.8s ease-out;
}

@keyframes fadeSlideUp {
  from { opacity: 0; transform: translateY(40px); }
  to { opacity: 1; transform: translateY(0); }
}

.screen-title {
  font-family: var(--font-display);
  font-size: clamp(1.5rem, 4vw, 2.5rem);
  font-weight: 700;
  margin-bottom: 40px;
  letter-spacing: 0.06em;
  text-shadow: 0 0 20px rgba(244, 232, 193, 0.15);
}

.level-cards {
  display: flex;
  gap: 24px;
  flex-wrap: wrap;
  justify-content: center;
}

.level-card {
  width: 240px;
  padding: 32px 24px;
  background: linear-gradient(160deg, rgba(44, 24, 16, 0.9), rgba(26, 26, 46, 0.9));
  border: 1px solid rgba(196, 151, 42, 0.25);
  cursor: pointer;
  transition: all 0.4s ease;
  position: relative;
  overflow: hidden;
}

.level-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0;
  width: 100%;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--gold), transparent);
  opacity: 0;
  transition: opacity 0.3s;
}

.level-card:hover {
  transform: translateY(-8px);
  border-color: var(--gold);
  box-shadow: 0 12px 40px rgba(196, 151, 42, 0.15);
}

.level-card:hover::before {
  opacity: 1;
}

.level-number {
  font-family: var(--font-display);
  font-size: 2.5rem;
  font-weight: 900;
  color: var(--gold);
  margin-bottom: 12px;
}

.level-name {
  font-family: var(--font-display);
  font-size: 0.95rem;
  font-weight: 400;
  margin-bottom: 12px;
  letter-spacing: 0.04em;
}

.level-desc {
  font-family: var(--font-body);
  font-size: 0.8rem;
  font-weight: 300;
  color: var(--parchment-dark);
  line-height: 1.5;
}

/* ========== GAME HUD ========== */
#game-hud {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  z-index: 10;
  pointer-events: none;
}

#game-hud > * {
  pointer-events: auto;
}

#game-hud > .hud-side {
  pointer-events: auto;
}

.hud-top {
  position: absolute;
  top: 0; left: 0; right: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  background: linear-gradient(to bottom, rgba(10, 10, 26, 0.7), transparent);
}

.hud-level-name {
  font-family: var(--font-display);
  font-size: 1.1rem;
  letter-spacing: 0.08em;
}

.hud-moves {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: var(--gold-light);
  letter-spacing: 0.05em;
}

.hud-bottom {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 20px 24px;
  background: linear-gradient(to top, rgba(10, 10, 26, 0.7), transparent);
}

.hud-rules {
  position: absolute;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  font-family: var(--font-body);
  font-size: 0.8rem;
  font-style: italic;
  color: var(--parchment-dark);
  text-align: center;
  max-width: 500px;
  line-height: 1.5;
  opacity: 0.7;
  pointer-events: none;
}

.btn-sail {
  animation: none;
  padding: 14px 48px;
  font-size: 1rem;
}

.hud-side {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  pointer-events: none;
}

.hud-side.left-bank { left: 16px; }
.hud-side.right-bank { right: 16px; }

.hud-passenger-tag {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  padding: 8px 14px;
  background: rgba(10, 10, 26, 0.7);
  border: 1px solid rgba(244, 232, 193, 0.15);
  color: var(--parchment-dark);
  white-space: nowrap;
  backdrop-filter: blur(4px);
  cursor: pointer;
  transition: all 0.2s ease;
  user-select: none;
}

.hud-passenger-tag:hover {
  background: rgba(196, 151, 42, 0.2);
  border-color: var(--gold);
  color: var(--parchment);
  transform: translateX(4px);
}

.right-bank .hud-passenger-tag:hover {
  transform: translateX(-4px);
}

.hud-passenger-tag:active {
  background: rgba(196, 151, 42, 0.35);
}

.hud-passenger-tag.disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.hud-passenger-tag.disabled:hover {
  background: rgba(10, 10, 26, 0.7);
  border-color: rgba(244, 232, 193, 0.15);
  color: var(--parchment-dark);
  transform: none;
}

.hud-passenger-tag.on-boat {
  border-color: var(--gold);
  color: var(--gold-light);
  background: rgba(196, 151, 42, 0.15);
}

/* ========== OVERLAYS ========== */
.overlay {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(10, 10, 26, 0.9);
  backdrop-filter: blur(10px);
  animation: overlayIn 0.5s ease-out;
}

@keyframes overlayIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.overlay-content {
  text-align: center;
  position: relative;
  padding: 48px;
  animation: contentPop 0.6s ease-out 0.2s both;
}

@keyframes contentPop {
  from { opacity: 0; transform: scale(0.9) translateY(20px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.overlay-title {
  font-family: var(--font-display);
  font-size: clamp(1.8rem, 5vw, 3rem);
  font-weight: 900;
  margin-bottom: 16px;
  letter-spacing: 0.06em;
}

.win-content .overlay-title {
  color: var(--gold-light);
  text-shadow: 0 0 40px rgba(232, 196, 90, 0.3);
}

.lose-title {
  color: var(--danger-light);
  text-shadow: 0 0 40px rgba(196, 37, 0, 0.3);
}

.overlay-text {
  font-family: var(--font-body);
  font-size: 1.1rem;
  font-weight: 300;
  color: var(--parchment-dark);
  margin-bottom: 32px;
  line-height: 1.6;
}

.overlay-buttons {
  display: flex;
  gap: 16px;
  justify-content: center;
}

.overlay-buttons .btn-parchment {
  animation: none;
}

.win-glow, .lose-glow {
  position: absolute;
  top: -100px; left: 50%;
  transform: translateX(-50%);
  width: 200px; height: 200px;
  border-radius: 50%;
  pointer-events: none;
}

.win-glow {
  background: radial-gradient(circle, rgba(232, 196, 90, 0.15), transparent);
}

.lose-glow {
  background: radial-gradient(circle, rgba(196, 37, 0, 0.15), transparent);
}

/* ========== 3D CLICK INDICATORS ========== */
.click-hint {
  position: fixed;
  bottom: 100px;
  left: 50%;
  transform: translateX(-50%);
  font-family: var(--font-body);
  font-size: 0.85rem;
  color: var(--parchment-dark);
  opacity: 0;
  z-index: 11;
  pointer-events: none;
  transition: opacity 0.5s;
}

.click-hint.show { opacity: 0.7; }

/* ========== RESPONSIVE ========== */
@media (max-width: 768px) {
  .level-cards { flex-direction: column; align-items: center; }
  .level-card { width: 80vw; max-width: 300px; }
  .hud-side { display: none; }
  .hud-bottom { flex-wrap: wrap; }
}
