/* === SANDAN GAMES - Bali: Fragmen Kenangan === */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;600;700&family=Noto+Sans+Bali&display=swap');

* { margin:0; padding:0; box-sizing:border-box; -webkit-tap-highlight-color: transparent; }
body { 
  font-family: 'Inter', sans-serif; 
  background: #0a0a0f; 
  color: #e0d5c8;
  overflow: hidden;
  height: 100vh;
  height: 100dvh;
  width: 100vw;
  width: 100dvw;
  padding: env(safe-area-inset-top, 0px) 0 env(safe-area-inset-bottom, 0px) 0;
}

/* === TAP-TO-START OVERLAY === */
#tap-overlay {
  position: fixed;
  inset: 0;
  background: radial-gradient(ellipse at center, #1a1a2e 0%, #0a0a0f 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  cursor: pointer;
  animation: tapFadeIn 1.5s ease-out;
}

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

.tap-content {
  text-align: center;
  animation: tapPulse 2s ease-in-out infinite;
  padding: 1.5rem;
}

@keyframes tapPulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.02); opacity: 0.9; }
}

.tap-title {
  font-size: clamp(1.8rem, 6vw, 3.5rem);
  font-weight: 700;
  color: #f0e6d0;
  letter-spacing: 0.15em;
  text-shadow: 0 0 30px rgba(255,200,100,0.3);
}

.tap-sub {
  font-size: clamp(0.85rem, 3vw, 1.5rem);
  color: #c4a882;
  letter-spacing: 0.3em;
  margin-top: 0.5em;
  font-style: italic;
}

.tap-hint {
  margin-top: clamp(1.5rem, 5vh, 3rem);
  font-size: clamp(0.7rem, 2vw, 0.9rem);
  color: #a08060;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  animation: tapBlink 1.5s ease-in-out infinite;
}

#audio-status {
  margin-top: 0.75rem;
  font-size: clamp(0.6rem, 1.5vw, 0.8rem);
  color: #6a9080;
}

@keyframes tapBlink {
  0%, 100% { opacity: 0.4; }
  50% { opacity: 1; }
}

#app {
  width: 100%;
  height: 100vh;
  height: 100dvh;
  position: relative;
}

.screen { display: none; width:100%; height:100%; }
.screen.active { display: flex; }

/* === TITLE SCREEN === */
#title-screen {
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
  background: linear-gradient(180deg, #0a0a0f 0%, #1a1520 50%, #0d0a12 100%);
}
.title-bg {
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at 50% 30%, rgba(200,160,100,0.05) 0%, transparent 60%);
}
.title-content { text-align: center; z-index: 1; padding: 0 1rem; }
.title-main {
  font-family: 'Noto Sans Bali', serif;
  font-size: clamp(2.5rem, 7vw, 5rem);
  color: #d4a853;
  letter-spacing: 0.3em;
  text-shadow: 0 0 30px rgba(212,168,83,0.3);
  margin-bottom: 0.2em;
  word-break: break-word;
}
.title-sub {
  font-size: clamp(1rem, 3vw, 1.8rem);
  color: #a09080;
  letter-spacing: 0.2em;
  margin-bottom: 1.5em;
}
.title-tagline {
  font-size: clamp(0.75rem, 1.8vw, 0.95rem);
  color: #6a6050;
  font-style: italic;
  margin-bottom: clamp(1.5em, 4vh, 4em);
  max-width: min(280px, 80vw);
  padding: 0 1rem;
}
.title-buttons { display: flex; flex-direction: column; gap: 1em; align-items: center; width: 100%; }

.btn-primary, .btn-secondary {
  padding: 0.8em 2em;
  border: none;
  border-radius: 6px;
  font-family: 'Inter', sans-serif;
  font-size: clamp(0.85rem, 2.2vw, 1.05rem);
  cursor: pointer;
  transition: all 0.3s;
  width: min(280px, 85vw);
  min-height: 48px;
  touch-action: manipulation;
}
.btn-primary {
  background: linear-gradient(135deg, #d4a853, #b8923a);
  color: #0a0a0f; font-weight: 600;
}
.btn-primary:hover { transform: translateY(-2px); box-shadow: 0 4px 20px rgba(212,168,83,0.3); }
.btn-primary:active { transform: translateY(0); }
.btn-secondary {
  background: transparent; color: #8a7a6a; border: 1px solid #3a3028;
}
.btn-secondary:hover { color: #d4a853; border-color: #d4a853; }

/* === GAME SCREEN === */
#game-screen {
  flex-direction: column;
  background: #0d0a12;
}

/* Top Bar */
#top-bar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.5em clamp(0.5em, 2vw, 1em);
  background: #12101a; border-bottom: 1px solid #1e1828;
  min-height: 40px; gap: 0.4em; flex-shrink: 0;
}
#chapter-indicator { font-size: clamp(0.65rem, 1.8vw, 0.85rem); color: #c8a050; font-weight: 600; white-space: nowrap; }
#alignment-bar {
  display: flex; align-items: center; gap: 0.3em;
}
#align-label { font-size: clamp(0.5rem, 1.4vw, 0.65rem); color: #6a9080; text-transform: uppercase; letter-spacing: 0.1em; }
#align-label:last-child { color: #906a6a; }
#align-track {
  width: clamp(40px, 8vw, 70px);
  height: 4px; background: #1e1828; border-radius: 2px; overflow: hidden;
}
#align-fill {
  height: 100%; width: 50%; background: linear-gradient(90deg, #6a9080, #907a50, #906a6a);
  border-radius: 2px; transition: width 0.5s ease;
}

#top-right-group {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
}

.sound-btn {
  background: rgba(0,0,0,0.4);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 6px;
  padding: 4px 8px;
  font-size: clamp(0.85rem, 2.2vw, 1.1rem);
  cursor: pointer;
  color: #e0d5c8;
  transition: all 0.2s;
  line-height: 1;
  min-height: 36px;
  min-width: 36px;
  touch-action: manipulation;
}

.sound-btn:hover {
  background: rgba(255,255,255,0.15);
  border-color: rgba(255,200,100,0.5);
}

#fragment-count {
  font-size: clamp(0.6rem, 1.5vw, 0.75rem);
  color: #7ab0d0;
  white-space: nowrap;
}

/* Scene */
#scene-area {
  position: relative;
  flex: 1;
  overflow: hidden;
  min-height: 40px;
}
#scene-image {
  position: absolute; inset: 0;
}
#scene-bg {
  width: 100%; height: 100%; object-fit: cover; opacity: 0.92;
  image-rendering: auto;
}
#scene-overlay {
  position: absolute; inset: 0;
  background: linear-gradient(0deg, rgba(10,10,15,0.7) 0%, rgba(10,10,15,0.1) 50%, rgba(10,10,15,0.3) 100%);
}
#npc-portrait {
  position: absolute;
  top: clamp(4px, 1.5vh, 16px);
  left: clamp(4px, 1.5vw, 16px);
  display: flex; align-items: center; gap: 4px;
  z-index: 10;
}
#npc-img {
  width: clamp(26px, 5vw, 48px);
  height: clamp(26px, 5vw, 48px);
  border-radius: 6px;
  border: 1px solid rgba(212,168,83,0.4);
  object-fit: cover;
  background: rgba(10,10,15,0.6);
  flex-shrink: 0;
}
#npc-name {
  font-size: clamp(0.5rem, 1.4vw, 0.85rem);
  color: #d4a853; font-weight: 600;
  text-shadow: 0 1px 3px rgba(0,0,0,0.8);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: clamp(60px, 30vw, 150px);
}

/* Dialog */
#dialog-area {
  flex-shrink: 0;
  padding: clamp(0.6em, 1.5vh, 1em) clamp(0.8em, 2.5vw, 1.5em);
  background: linear-gradient(0deg, #1a1522, rgba(26,21,34,0.95));
  max-height: min(30vh, 180px);
  overflow-y: auto;
  border-top: 1px solid #2a2030;
}
#dialog-text {
  font-size: clamp(0.82rem, 2.2vw, 1rem);
  line-height: 1.6;
  color: #d0c8b8;
}
#dialog-text .typing-cursor::after {
  content: '▊'; animation: blink 0.8s step-end infinite; color: #d4a853;
}
@keyframes blink { 50% { opacity: 0; } }
#dialog-text .italic { font-style: italic; color: #a09080; }
#dialog-text .narrator { color: #b0a090; font-size: clamp(0.78rem, 2vw, 0.92rem); }

/* Choices */
#choices-area {
  flex-shrink: 0;
  padding: 0.5em clamp(0.8em, 2.5vw, 1.5em) clamp(0.6em, 1.5vh, 1em);
  display: flex; flex-direction: column; gap: 0.5em;
}
.choice-btn {
  background: rgba(40,32,50,0.8); border: 1px solid #3a3048;
  color: #d0c8b8;
  padding: clamp(0.65em, 1.8vh, 0.9em) 1em;
  border-radius: 6px;
  font-family: 'Inter', sans-serif;
  font-size: clamp(0.8rem, 2.2vw, 0.95rem);
  cursor: pointer;
  transition: all 0.3s;
  text-align: left;
  line-height: 1.4;
  min-height: 44px;
  touch-action: manipulation;
}
.choice-btn:hover {
  border-color: #d4a853; background: rgba(60,48,70,0.8);
  transform: translateX(2px);
}
.choice-btn:active { transform: translateX(0); }
.choice-btn.alignment-dharma { border-left: 3px solid #6a9080; }
.choice-btn.alignment-adharma { border-left: 3px solid #906a6a; }
.choice-btn:disabled { opacity: 0.4; cursor: default; }

/* Fragment Popup */
#fragment-popup {
  position: fixed; top: 50%; left: 50%;
  transform: translate(-50%,-50%);
  padding: clamp(1.5em, 4vw, 2.5em);
  border-radius: 12px;
  background: linear-gradient(135deg, #1a2040, #0d1a30);
  border: 1px solid rgba(100,160,200,0.3);
  text-align: center; z-index: 100;
  min-width: min(200px, 70vw);
  max-width: 90vw;
  animation: fragmentAppear 0.5s ease;
}
#fragment-popup.hidden { display: none; }
@keyframes fragmentAppear {
  0% { transform: translate(-50%,-50%) scale(0.8); opacity: 0; }
  100% { transform: translate(-50%,-50%) scale(1); opacity: 1; }
}
.fragment-glow {
  width: clamp(40px, 10vw, 70px);
  height: clamp(40px, 10vw, 70px);
  margin: 0 auto 1em;
  border-radius: 50%; background: radial-gradient(circle, rgba(100,160,200,0.4), transparent);
  animation: pulse 2s ease-in-out infinite;
}
@keyframes pulse { 0%,100% {transform:scale(1);opacity:0.6} 50% {transform:scale(1.2);opacity:1} }
#fragment-text { color: #7ab0d0; font-weight: 600; font-size: clamp(0.85rem, 2.5vw, 1rem); }

/* Load Screen */
#load-screen {
  flex-direction: column; align-items: center; justify-content: center;
  padding: clamp(1em, 3vw, 2em);
  background: #0a0a0f;
}
#load-screen h2 {
  color: #d4a853;
  margin-bottom: 1.5em;
  font-size: clamp(1.2rem, 3.5vw, 1.8rem);
}
.save-slot {
  background: #12101a; border: 1px solid #2a2030; border-radius: 8px;
  padding: 1em;
  margin-bottom: 0.8em;
  min-width: min(280px, 85vw);
  max-width: 400px;
  width: 100%;
  cursor: pointer;
  transition: all 0.3s; text-align: left;
}
.save-slot:hover { border-color: #d4a853; background: #1a1522; }
.save-slot .slot-title { color: #c8a050; font-weight: 600; font-size: clamp(0.8rem, 2vw, 0.95rem); }
.save-slot .slot-detail { color: #6a6050; font-size: clamp(0.65rem, 1.6vw, 0.8rem); margin-top: 0.3em; }

/* Scrollbar */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: #1a1522; }
::-webkit-scrollbar-thumb { background: #3a3048; border-radius: 2px; }

/* === RESPONSIVE — PHONE PORTRAIT === */
@media (max-width: 480px) {
  #top-bar { min-height: 32px; padding: 0.2em 0.4em; gap: 0.2em; }
  #npc-img { width: 26px; height: 26px; }
  #npc-portrait { top: 4px; left: 4px; gap: 3px; }
  #npc-name { font-size: 0.55rem; max-width: 80px; }
  #dialog-area { max-height: 38vh; padding: 0.4em 0.6em calc(0.6em + env(safe-area-inset-bottom, 0px)); min-height: 50px; }
  #dialog-text { line-height: 1.4; font-size: 0.78rem; }
  #choices-area { padding-bottom: calc(0.5em + env(safe-area-inset-bottom, 0px)); }
  #fragment-popup { min-width: unset; width: 90vw; }
  .sound-btn { min-height: 30px; min-width: 30px; padding: 2px 5px; font-size: 0.8rem; }
  #chapter-indicator { font-size: 0.55rem; }
  #fragment-count { font-size: 0.5rem; }
  #align-track { width: 36px; }
  #align-label { font-size: 0.45rem; }
}

/* === RESPONSIVE — PHONE LANDSCAPE === */
@media (max-width: 900px) and (orientation: landscape) {
  #game-screen { flex-direction: row; flex-wrap: wrap; }
  
  #top-bar { width: 100%; min-height: 34px; padding: 0.3em 0.5em; }
  
  #scene-area { flex: 1 1 100%; height: 0; min-height: auto; }
  
  #dialog-area {
    max-height: none;
    min-height: 50px;
    max-height: 25vh;
    padding: 0.4em 0.7em;
    border-top: 1px solid #2a2030;
  }
  
  #choices-area {
    flex-direction: row;
    flex-wrap: wrap;
    padding: 0.3em 0.5em 0.5em;
  }
  .choice-btn {
    flex: 1 1 calc(50% - 0.3em);
    min-width: 140px;
    padding: 0.5em 0.8em;
    font-size: 0.78rem;
    min-height: 38px;
  }
  
  #npc-img { width: 24px; height: 24px; }
  #npc-portrait { top: 2px; left: 4px; gap: 3px; }
  #npc-name { font-size: 0.5rem; max-width: 80px; }
}

/* === RESPONSIVE — TABLET === */
@media (min-width: 481px) and (max-width: 1024px) {
  .title-main { font-size: clamp(3rem, 5vw, 4.5rem); letter-spacing: 0.3em; }
  .btn-primary, .btn-secondary { min-height: 52px; padding: 0.9em 2.5em; }
  #dialog-area { max-height: max(25vh, 140px); }
  .save-slot { min-width: 320px; }
}

/* === RESPONSIVE — DESKTOP === */
@media (min-width: 1025px) {
  #game-screen {
    max-width: 100vw;
    margin: 0 auto;
  }
  
  #scene-area {
    max-height: 75vh;
  }
  
  #dialog-area {
    max-height: 200px;
    padding: 1em 2em;
  }
  
  #choices-area {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 0.6em;
    padding: 0.6em 2em 1em;
  }
  .choice-btn {
    flex: 0 1 calc(50% - 0.3em);
    max-width: 500px;
  }
}

/* === CONTINUE OVERLAY — Balinese style "Lanjut" === */
#continue-overlay {
  position: absolute;
  bottom: 8px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 20;
  cursor: pointer;
  min-width: 80px;
  min-height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  flex-direction: row;
  padding: 6px 14px;
  border-radius: 8px;
  background: rgba(10,10,15,0.55);
  border: 1px solid rgba(212,168,83,0.25);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  animation: contFadeIn 0.5s ease, contPulse 2s ease-in-out infinite;
  touch-action: manipulation;
}
#continue-overlay.hidden { display: none; }

@keyframes contFadeIn {
  from { opacity: 0; transform: translateX(-50%) translateY(8px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}
@keyframes contPulse {
  0%, 100% { opacity: 0.7; }
  50% { opacity: 1; }
}

#continue-overlay .continue-bg {
  position: absolute;
  inset: 0;
  border-radius: 8px;
  opacity: 0.15;
  /* Balinese "cecek" pattern — dots simulating traditional woven fabric */
  background-image:
    radial-gradient(circle at 25% 25%, #d4a853 1px, transparent 1px),
    radial-gradient(circle at 75% 75%, #d4a853 1px, transparent 1px),
    radial-gradient(circle at 50% 50%, #c08040 1.2px, transparent 1.2px),
    radial-gradient(circle at 0% 50%, #d4a853 0.8px, transparent 0.8px),
    radial-gradient(circle at 100% 50%, #d4a853 0.8px, transparent 0.8px),
    radial-gradient(circle at 50% 0%, #d4a853 0.8px, transparent 0.8px),
    radial-gradient(circle at 50% 100%, #d4a853 0.8px, transparent 0.8px);
  background-size: 12px 12px;
  pointer-events: none;
}

#continue-overlay .continue-arrow {
  font-size: 0.8rem;
  color: #d4a853;
  line-height: 1;
  position: relative;
  z-index: 1;
  animation: contArrow 1s ease-in-out infinite;
}
@keyframes contArrow {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(2px); }
}

#continue-overlay .continue-label {
  font-size: 0.7rem;
  color: #e0d5c8;
  letter-spacing: 0.15em;
  font-weight: 600;
  position: relative;
  z-index: 1;
}

/* Mobile: smaller overlay */
@media (max-width: 480px) {
  #continue-overlay {
    min-height: 34px;
    min-width: 70px;
    padding: 4px 10px;
    bottom: 4px;
  }
  #continue-overlay .continue-arrow { font-size: 0.7rem; }
  #continue-overlay .continue-label { font-size: 0.6rem; }
}

/* Landscape: overlay */
@media (max-width: 900px) and (orientation: landscape) {
  #continue-overlay {
    min-height: 30px;
    min-width: 60px;
    padding: 3px 8px;
    bottom: 4px;
  }
}
