:root {
  --bg-deep: #071223;
  --bg-mid: #102544;
  --bg-soft: #17345c;
  --gold: #f3c977;
  --gold-soft: rgba(243, 201, 119, 0.26);
  --book-height: min(74vh, 860px);
  --page-ratio: 0.7033;
  --shadow-strong: 0 40px 80px rgba(0, 0, 0, 0.42);
  --shadow-soft: 0 14px 30px rgba(0, 0, 0, 0.24);
  --transition-slow: 800ms cubic-bezier(0.22, 0.7, 0.18, 1);
}

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

html, body {
  min-height: 100%;
  font-family: 'Montserrat', sans-serif;
  background: linear-gradient(rgba(7, 18, 35, 0.6), rgba(7, 18, 35, 0.8)), url('../bg.png') no-repeat center center fixed;
  background-size: cover;
  color: #fff8e7;
  overflow: hidden;
}

h1, h2, h3, .game-title, .player-name, .quest-title {
  font-family: 'Montserrat', sans-serif;
  font-weight: 700;
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.9);
  z-index: 1000;
  display: grid;
  place-items: center;
  transition: opacity 0.5s;
}

.overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.overlay-content {
  text-align: center;
}

.game-title {
  font-size: 3rem;
  color: var(--gold);
  margin-bottom: 10px;
}

.game-subtitle {
  font-size: 1.2rem;
  margin-bottom: 30px;
  color: #aaa;
}

.btn-start {
  padding: 15px 30px;
  font-size: 1.2rem;
  background: transparent;
  color: var(--gold);
  border: 2px solid var(--gold);
  cursor: pointer;
  border-radius: 5px;
  font-family: 'Montserrat', sans-serif;
  font-weight: 700;
  transition: 0.3s;
}

.btn-start:hover {
  background: var(--gold);
  color: #000;
}

.app {
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-height: 100vh;
  padding: 20px;
  position: relative;
  z-index: 1;
}

.game-header {
  display: flex;
  justify-content: center;
}

.status-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: min(1180px, 100%);
  padding: 10px 20px;
  background: rgba(16, 37, 68, 0.88);
  border: 1px solid rgba(243, 201, 119, 0.22);
  border-radius: 10px;
}

.player-info {
  display: flex;
  align-items: center;
  gap: 15px;
}

.avatar {
  font-size: 2rem;
}

.hp-bar {
  width: 150px;
  height: 10px;
  background: #333;
  border-radius: 5px;
  overflow: hidden;
  margin-top: 5px;
}

.hp-fill {
  width: 100%;
  height: 100%;
  background: #e74c3c;
}

.quest-title {
  font-size: 1.2rem;
  color: var(--gold);
}

.stage {
  width: min(1280px, 100%);
  margin: 0 auto;
  display: grid;
  place-items: center;
  position: relative;
  perspective: 2200px;
}

.book {
  position: relative;
  height: var(--book-height);
  width: calc(var(--book-height) * var(--page-ratio));
  transform-style: preserve-3d;
  filter: drop-shadow(0 18px 35px rgba(0, 0, 0, 0.28));
  transform: translateX(50%);
}

.sheet {
  position: absolute;
  inset: 0;
  transform-origin: left center;
  transform-style: preserve-3d;
  transition: transform var(--transition-slow), z-index 0s linear 400ms;
  cursor: pointer;
  border-radius: 12px 20px 20px 12px;
}

.sheet.flipped {
  transform: rotateY(-180deg);
}

.face {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  overflow: hidden;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  background: #fdf5e6;
  box-shadow: inset 2px 0 10px rgba(0, 0, 0, 0.1);
}

.face.front {
  transform: rotateY(0deg);
}

.face.back {
  transform: rotateY(180deg);
  border-radius: 20px 12px 12px 20px;
  box-shadow: inset -2px 0 10px rgba(0, 0, 0, 0.1);
}

.face img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.face::before {
  content: "";
  position: absolute;
  top: 0; bottom: 0;
  width: 30px;
  mix-blend-mode: multiply;
  pointer-events: none;
}
.face.front::before { left: 0; background: linear-gradient(to right, rgba(0,0,0,0.25), transparent); }
.face.back::before { right: 0; background: linear-gradient(to left, rgba(0,0,0,0.25), transparent); }

.hud-bottom {
  display: flex;
  justify-content: center;
}

.controls-wrapper {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: min(1180px, 100%);
  padding: 15px 20px;
  background: rgba(16, 37, 68, 0.88);
  border: 1px solid rgba(243, 201, 119, 0.22);
  border-radius: 10px;
  gap: 20px;
}

.btn-group { display: flex; gap: 10px; }

.game-btn {
  background: rgba(0,0,0,0.5);
  border: 1px solid var(--gold);
  color: var(--gold);
  padding: 10px 20px;
  cursor: pointer;
  border-radius: 5px;
  font-family: inherit;
  transition: 0.2s;
}

.game-btn:hover:not(:disabled) {
  background: var(--gold);
  color: #000;
}
.game-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.game-btn.tiny { padding: 10px 15px; }

.exp-container {
  flex: 1;
  text-align: center;
  max-width: 400px;
}

.exp-label {
  font-size: 0.8rem;
  color: #aaa;
  margin-bottom: 5px;
}

.exp-bar-wrapper {
  display: flex;
  align-items: center;
  position: relative;
}

.game-slider {
  width: 100%;
  accent-color: var(--gold);
  cursor: pointer;
}

.page-counter {
  font-size: 0.9rem;
  margin-top: 5px;
}

.end-text {
  display: flex; height: 100%; width: 100%;
  align-items: center; justify-content: center;
  color: #333; font-size: 1.5rem; text-align: center;
  background: #f5ebd1; padding: 20px;
}

@media (max-width: 900px) {
  .book { transform: translateX(0); }
  .controls-wrapper { flex-direction: column; gap: 15px; }
  .btn-group { width: 100%; justify-content: space-between; }
  .game-btn { flex: 1; }
  .exp-container { max-width: 100%; width: 100%; }
}
