:root {
  color-scheme: dark;
  --ui-bg: rgba(56, 40, 25, 0.88);
  --ui-border: rgba(206, 172, 114, 0.74);
  --ui-shadow: rgba(23, 13, 6, 0.68);
  --ui-gold: #dfbf7b;
  --ui-parchment: #efe3c8;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  user-select: none;
  cursor: default;
  min-height: 100dvh;
  font-family: "Garamond", "Palatino Linotype", "Book Antiqua", serif;
  background: radial-gradient(circle at top, #39553a 0%, #2e422b 32%, #1d2819 64%, #120f0a 100%);
  color: #f7f2e7;
}

.app {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 0.5rem;
  padding: max(0.5rem, env(safe-area-inset-top)) 0.5rem max(0.5rem, env(safe-area-inset-bottom));
}

.consent-overlay {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: grid;
  place-items: center;
  background: rgba(5, 8, 14, 0.78);
  backdrop-filter: blur(2px);
}

.consent-overlay[hidden] {
  display: none !important;
}

.consent-card {
  width: min(92vw, 560px);
  border: 1px solid var(--ui-border);
  border-radius: 14px;
  background:
    linear-gradient(to bottom, rgba(112, 79, 41, 0.95), rgba(72, 49, 24, 0.96)),
    var(--ui-bg);
  color: var(--ui-parchment);
  box-shadow: 0 14px 36px rgba(0, 0, 0, 0.58);
  padding: 1rem 1.2rem;
  text-align: center;
}

.consent-card h2 {
  margin: 0 0 0.45rem;
}

.consent-card p {
  margin: 0 0 0.95rem;
}

#consent-accept {
  min-width: 180px;
  min-height: 44px;
  border-radius: 10px;
  border: 1px solid rgba(216, 180, 122, 0.84);
  background: linear-gradient(to bottom, rgba(110, 54, 35, 0.95), rgba(72, 32, 18, 0.95));
  color: #f7e7cb;
  font-size: 1.05rem;
  font-family: "Garamond", "Palatino Linotype", serif;
  font-weight: 700;
  letter-spacing: 0.02em;
  cursor: pointer;
}

.game-shell-wrap {
  position: relative;
  display: inline-block;
}

#game-shell {
  --game-scale: 1;
  position: relative;
  width: min(calc(100vw - 1rem), calc((100dvh - 1rem) * 16 / 9));
  aspect-ratio: 16 / 9;
  max-height: min(calc(100dvh - 1rem), 720px);
  max-width: 1280px;
  border: 1px solid rgba(192, 157, 96, 0.72);
  border-radius: 12px;
  overflow: hidden;
  background: #1a1812;
  box-shadow:
    0 20px 40px rgba(0, 0, 0, 0.45),
    0 0 0 2px rgba(86, 58, 28, 0.52) inset;
}

#game-shell-wrap:fullscreen,
#game-shell-wrap:-webkit-full-screen {
  width: 100vw;
  height: 100vh;
  display: grid;
  place-items: center;
  background: #000;
}

#game-shell-wrap:fullscreen #game-shell,
#game-shell-wrap:-webkit-full-screen #game-shell {
  width: min(calc(100vw - 1rem), calc((100vh - 1rem) * 16 / 9));
  height: auto;
  max-width: none;
  max-height: none;
  aspect-ratio: 16 / 9;
}

#toggle-fullscreen {
  position: absolute;
  right: calc(-46px * var(--game-scale, 1));
  bottom: calc(4px * var(--game-scale, 1));
  width: calc(40px * var(--game-scale, 1));
  height: calc(40px * var(--game-scale, 1));
  border-radius: 10px;
  border: 1px solid rgba(216, 180, 122, 0.84);
  background: linear-gradient(to bottom, rgba(110, 54, 35, 0.95), rgba(72, 32, 18, 0.95));
  color: #f7e7cb;
  font-size: calc(24px * var(--game-scale, 1));
  line-height: 1;
  display: grid;
  place-items: center;
  cursor: pointer;
  box-shadow: 0 6px 14px rgba(26, 10, 5, 0.45);
}

body.fullscreen-mode #toggle-fullscreen {
  right: 10px;
  bottom: 10px;
  position: fixed;
  z-index: 100;
}

#game-canvas {
  width: 100%;
  height: 100%;
  display: block;
  image-rendering: pixelated;
}



#dialog-dim {
  position: absolute;
  inset: 0;
  background: linear-gradient(
    to bottom,
    rgba(0, 0, 0, 0.08) 0%,
    rgba(0, 0, 0, 0.26) 42%,
    rgba(0, 0, 0, 0.72) 100%
  );
  z-index: 1;
  pointer-events: none;
}

#dialog-media-row {
  position: absolute;
  left: 50%;
  top: calc(12px * var(--game-scale));
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: calc(14px * var(--game-scale));
  z-index: 2;
  pointer-events: none;
}

#dialog-media-row[hidden] {
  display: none !important;
}

#dialog-video {
  display: none;
  width: calc(576px * var(--game-scale));
  height: calc(576px * var(--game-scale));
  border-radius: calc(12px * var(--game-scale));
  border: 1px solid rgba(198, 166, 113, 0.75);
  background: rgba(29, 21, 12, 0.84);
  object-fit: cover;
  image-rendering: auto;
  box-shadow:
    0 18px 32px rgba(0, 0, 0, 0.55),
    0 0 24px rgba(236, 197, 123, 0.24),
    0 0 0 2px rgba(104, 72, 36, 0.52) inset;
}

#dialog-video:not([hidden]) {
  display: block;
}

#dialog-media-row.special-video-layout #dialog-video {
  width: calc(1024px * var(--game-scale));
  height: calc(576px * var(--game-scale));
}

#dialog-side-controls {
  width: calc(270px * var(--game-scale));
  min-height: calc(576px * var(--game-scale));
  display: flex;
  flex-direction: column;
  gap: calc(10px * var(--game-scale));
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

#dialog-media-row.special-video-layout #dialog-side-controls {
  width: calc(224px * var(--game-scale));
  min-height: calc(576px * var(--game-scale));
  transform: translateX(calc(38px * var(--game-scale)));
  justify-content: space-between;
  padding: calc(18px * var(--game-scale)) 0;
}

#dialog-media-row.dialog-active #dialog-side-controls {
  pointer-events: auto;
}

#dialog-box {
  cursor: default;
  pointer-events: none;
  position: absolute;
  left: calc(72px * var(--game-scale));
  right: calc(72px * var(--game-scale));
  bottom: calc(16px * var(--game-scale));
  min-height: calc(122px * var(--game-scale));
  background:
    linear-gradient(to bottom, rgba(112, 79, 41, 0.92), rgba(72, 49, 24, 0.94)),
    var(--ui-bg);
  border: 1px solid var(--ui-border);
  border-radius: calc(12px * var(--game-scale));
  padding: calc(14px * var(--game-scale)) calc(72px * var(--game-scale)) calc(14px * var(--game-scale)) calc(20px * var(--game-scale));
  font-size: calc(26px * var(--game-scale));
  line-height: 1.35;
  z-index: 3;
  letter-spacing: 0.01em;
  color: var(--ui-parchment);
  box-shadow:
    0 10px 20px var(--ui-shadow),
    0 0 0 1px rgba(58, 37, 18, 0.8) inset;
}

#dialog-reply-options {
  display: grid;
  width: 100%;
  grid-template-columns: minmax(0, 1fr);
  gap: calc(8px * var(--game-scale));
}

#dialog-reply-options[hidden] {
  display: none !important;
}

.dialog-reply-option {
  border: 1px solid rgba(210, 174, 117, 0.8);
  border-radius: calc(10px * var(--game-scale));
  background: linear-gradient(to bottom, rgba(123, 88, 47, 0.96), rgba(92, 62, 31, 0.96));
  color: #f7edd7;
  font: inherit;
  font-family: "Garamond", "Palatino Linotype", serif;
  font-size: calc(28px * var(--game-scale));
  line-height: 1.2;
  min-height: calc(56px * var(--game-scale));
  padding: calc(12px * var(--game-scale)) calc(18px * var(--game-scale));
  cursor: pointer;
  text-align: center;
  box-shadow: 0 6px 14px rgba(20, 11, 4, 0.42);
}

.dialog-reply-option:hover,
.dialog-reply-option:focus-visible {
  border-color: rgba(236, 201, 132, 0.98);
  background: linear-gradient(to bottom, rgba(146, 105, 57, 0.98), rgba(106, 74, 37, 0.98));
  color: #fff6de;
}



#dialog-continue[hidden] {
  display: none !important;
}

#dialog-continue {
  width: calc(96px * var(--game-scale));
  height: calc(96px * var(--game-scale));
  border-radius: 999px;
  border: 1px solid rgba(230, 198, 133, 0.85);
  background: radial-gradient(circle at 32% 26%, rgba(235, 208, 151, 0.96), rgba(163, 117, 55, 0.96));
  color: #3f230f;
  font-size: calc(56px * var(--game-scale));
  display: grid;
  place-items: center;
  cursor: pointer;
  animation: continueJab 680ms ease-in-out infinite;
  box-shadow:
    0 8px 18px rgba(30, 15, 6, 0.54),
    0 0 18px rgba(246, 217, 139, 0.38);
}

#dialog-end[hidden] {
  display: none !important;
}

#dialog-end {
  min-width: calc(220px * var(--game-scale));
  min-height: calc(56px * var(--game-scale));
  border-radius: calc(10px * var(--game-scale));
  border: 1px solid rgba(216, 180, 122, 0.84);
  background: linear-gradient(to bottom, rgba(110, 54, 35, 0.95), rgba(72, 32, 18, 0.95));
  color: #f7e7cb;
  font-size: calc(24px * var(--game-scale));
  font-weight: 700;
  cursor: pointer;
  font-family: "Garamond", "Palatino Linotype", serif;
  letter-spacing: 0.02em;
  box-shadow: 0 6px 14px rgba(26, 10, 5, 0.45);
}

@keyframes continueJab {
  0%, 100% { transform: translateX(0); }
  50% { transform: translateX(calc(8px * var(--game-scale))); }
}

#audio-toggles {
  position: absolute;
  right: calc(18px * var(--game-scale));
  top: calc(18px * var(--game-scale));
  display: flex;
  gap: calc(10px * var(--game-scale));
  z-index: 4;
}

#inventory-hud {
  position: absolute;
  left: calc(18px * var(--game-scale));
  top: calc(18px * var(--game-scale));
  z-index: 4;
  display: flex;
  align-items: center;
  gap: calc(10px * var(--game-scale));
  padding: calc(8px * var(--game-scale)) calc(12px * var(--game-scale));
  border: 1px solid var(--ui-border);
  border-radius: calc(10px * var(--game-scale));
  background: rgba(10, 14, 22, 0.82);
}

#inventory-hud[hidden] {
  display: none !important;
}

#inventory-item-icon {
  width: calc(18px * var(--game-scale));
  height: calc(32px * var(--game-scale));
  object-fit: contain;
  image-rendering: auto;
}

#inventory-item-count {
  font-size: calc(14px * var(--game-scale));
  font-weight: 700;
  letter-spacing: 0.02em;
  color: #f3f8ff;
}

.audio-toggle {
  width: calc(44px * var(--game-scale));
  height: calc(44px * var(--game-scale));
  border-radius: 10px;
  border: 1px solid var(--ui-border);
  background: rgba(18, 22, 30, 0.8);
  color: #fff;
  font-size: calc(20px * var(--game-scale));
  display: grid;
  place-items: center;
  cursor: pointer;
}

.audio-toggle.muted {
  opacity: 0.45;
  filter: grayscale(1);
}

#rotate-hint {
  display: none;
  text-align: center;
  padding: 0.5rem;
  border: 1px solid var(--ui-border);
  background: rgba(0, 0, 0, 0.45);
  border-radius: 10px;
}

.touch-controls {
  display: grid;
  place-items: center;
  gap: 0.45rem;
  user-select: none;
  touch-action: manipulation;
}

.middle-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.45rem;
}

.touch-controls button {
  min-width: 3.2rem;
  min-height: 3.2rem;
  border-radius: 999px;
  border: 1px solid var(--ui-border);
  background: var(--ui-bg);
  color: #fff;
  font-size: 1.1rem;
}

@media (hover: hover) and (pointer: fine) {
  .touch-controls {
    opacity: 0.7;
  }
}


@keyframes dialogPopIn {
  0% { transform: scale(0.94); opacity: 0.5; }
  100% { transform: scale(1); opacity: 1; }
}

.dialog-pop-in {
  animation: dialogPopIn 160ms ease-out;
}

@keyframes dialogScaleIn {
  0% { transform: scale(0.86); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

@keyframes dialogScaleOut {
  0% { transform: scale(1); opacity: 1; }
  100% { transform: scale(0.86); opacity: 0; }
}

@keyframes dialogScaleInRow {
  0% { transform: translateX(-50%) scale(0.86); opacity: 0; }
  100% { transform: translateX(-50%) scale(1); opacity: 1; }
}

@keyframes dialogScaleOutRow {
  0% { transform: translateX(-50%) scale(1); opacity: 1; }
  100% { transform: translateX(-50%) scale(0.86); opacity: 0; }
}

.dialog-scale-in {
  animation: dialogScaleIn 180ms ease-out;
}

.dialog-scale-out {
  animation: dialogScaleOut 180ms ease-in forwards;
}

.dialog-scale-in-row {
  animation: dialogScaleInRow 180ms ease-out;
}

.dialog-scale-out-row {
  animation: dialogScaleOutRow 180ms ease-in forwards;
}


@media (orientation: portrait) and (max-width: 900px) {
  #rotate-hint {
    display: block !important;
  }
}

#dialog-box.dialog-player {
  background: linear-gradient(to bottom, rgba(243, 231, 201, 0.95), rgba(219, 198, 154, 0.94));
  color: #3b2a16;
  border-color: rgba(109, 82, 46, 0.62);
}

.magic-flash-overlay {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: rgba(255, 255, 255, 0);
  z-index: 9999;
}

.magic-flash-overlay.active {
  animation: magicFlash 220ms ease-out;
}

@keyframes magicFlash {
  0% { background: rgba(255, 255, 255, 0); }
  30% { background: rgba(255, 255, 255, 0.92); }
  100% { background: rgba(255, 255, 255, 0); }
}

.magic-video-invert {
  filter: invert(1) hue-rotate(180deg);
}
