* {
  box-sizing: border-box;
  user-select: none;
  -webkit-user-select: none;
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  max-height: 100dvh;
  min-height: 0 !important;
  background-color: #030712;
  color: #f8fafc;
  font-family: 'Press Start 2P', monospace;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

#canvasFrame {
  width: 100%;
  height: 100dvh;
  max-width: 1280px;
  max-height: 92dvh;
  aspect-ratio: 16 / 9;
}

@media (max-height: 500px), (pointer: coarse) {
  body {
    padding: 0 !important;
  }
  #canvasFrame {
    width: 100% !important;
    height: 100vh !important;
    height: 100dvh !important;
    max-width: 100% !important;
    max-height: 100dvh !important;
    aspect-ratio: auto !important;
    border-radius: 0 !important;
    border-width: 0 !important;
  }
  #canvasFrame > header {
    padding: 6px 10px !important;
    white-space: nowrap;
  }
  #canvasFrame > header * {
    white-space: nowrap;
  }
}

.font-cinzel {
  font-family: 'Cinzel', serif;
}

.font-scroll-title {
  font-family: 'Cinzel Decorative', 'Cinzel', serif;
}

.font-scroll-body {
  font-family: 'EB Garamond', serif;
}

#gameCanvas {
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  display: block;
  image-rendering: -moz-crisp-edges;
  image-rendering: -webkit-crisp-edges;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.hud-glass {
  background: rgba(10, 16, 31, 0.90);
  border: 1.5px solid rgba(245, 158, 11, 0.5);
  backdrop-filter: blur(8px);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.8);
}

#gameCanvas,
.dpad-cross,
.action-btn,
.touch-btn {
  touch-action: none;
}

.touch-btn {
  background: rgba(15, 23, 42, 0.42);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  border: 1.5px solid rgba(245, 158, 11, 0.48);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.mobile-touch-controls {
  bottom: 12px !important;
  padding-left: 14px !important;
  padding-right: 14px !important;
}

.mobile-touch-controls > div:last-child {
  gap: 12px !important;
}

.mobile-touch-controls .dpad-cross {
  gap: 3px !important;
}

.mobile-touch-controls .dpad-row {
  gap: 3px !important;
}

.mobile-touch-controls .dpad-center {
  width: 34px;
  height: 42px;
  border-radius: 10px;
  background: rgba(15, 23, 42, 0.35);
  border: 1px solid rgba(148, 163, 184, 0.22);
  pointer-events: none;
}

#btnUp,
#btnDown,
#btnLeft,
#btnRight {
  width: 48px !important;
  height: 42px !important;
  gap: 1px;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

#btnAttack,
#btnJump {
  width: 64px !important;
  height: 64px !important;
  gap: 3px;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

#btnInteract {
  width: 60px !important;
  height: 60px !important;
  gap: 2px;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

#btnAttack span:first-child,
#btnJump span:first-child {
  font-size: 18px !important;
  line-height: 1 !important;
}

#btnInteract span:first-child {
  font-size: 15px !important;
  line-height: 1 !important;
}

#btnUp span:first-child,
#btnDown span:first-child,
#btnLeft span:first-child,
#btnRight span:first-child {
  font-size: 14px !important;
  line-height: 1 !important;
}

#btnAttack span:last-child,
#btnJump span:last-child,
#btnInteract span:last-child {
  font-size: 7.5px !important;
  line-height: 1.1 !important;
  letter-spacing: 0.03em;
}

#btnUp span:last-child,
#btnDown span:last-child,
#btnLeft span:last-child,
#btnRight span:last-child {
  font-size: 6px !important;
  line-height: 1.05 !important;
  letter-spacing: 0.02em;
}

@media (pointer: coarse), (hover: none) {
  .desktop-controls-overlay {
    display: none !important;
  }
  .mobile-touch-controls {
    display: flex !important;
  }
}

body.is-touch-device .desktop-controls-overlay {
  display: none !important;
}

body.is-touch-device .mobile-touch-controls {
  display: flex !important;
}

.touch-btn:active {
  transform: scale(0.92);
  background: rgba(14, 165, 233, 0.5);
}

.hud-crystal-canvas {
  width: 20px;
  height: 26px;
  image-rendering: pixelated;
  image-rendering: -moz-crisp-edges;
  image-rendering: crisp-edges;
  transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1), filter 0.25s ease;
}

kbd {
  font-family: inherit;
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.6);
}

/* WADAH GULUNGAN NASKAH KUNO - SENTIASA CENTER & ANJAL IKUT TINGGI SKRIN */
/* KAWASAN TEKS & BUTANG DI DALAM PERKAMEN */

/* ===== UNIFIED CHAPTER SCROLL (all stages) ===== */
.scroll-frame-wrapper {
  position: relative;
  width: min(94vw, calc(92vh * 880 / 495), 1040px);
  aspect-ratio: 880 / 495;
  container-type: inline-size;
  background-image: url('scroll.png');
  background-size: 100% 100%;
  background-repeat: no-repeat;
  background-position: center;
  filter: drop-shadow(0 20px 50px rgba(0, 0, 0, 0.95)) drop-shadow(0 0 40px rgba(245, 158, 11, 0.3));
}
.scroll-inner-content {
  position: absolute;
  inset: 19% 13% 14.5% 13% !important;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 0.35cqw !important;
  padding: 0 6px 0 0 !important;
  color: #381a05;
  text-shadow: 0 1px 1px rgba(254, 243, 199, 0.8);
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-x pan-y pinch-zoom;
  overflow-wrap: break-word;
  text-align: center;
}
.scroll-inner-content::-webkit-scrollbar { display: none; }
.sc-badge {
  display: inline-flex; align-items: center; gap: 0.6cqw; padding: 0.3cqw 1.6cqw; border-radius: 999px;
  background: rgba(69, 26, 3, 0.88); color: #fcd34d; border: 1px solid rgba(217, 119, 6, 0.6);
  font-family: 'Press Start 2P', monospace; font-size: clamp(5px, 0.75cqw, 9px); letter-spacing: 0.12em;
}
.sc-kicker { font-size: clamp(6px, 0.95cqw, 11px); font-weight: 700; letter-spacing: 0.14em; text-transform: uppercase; color: #78350f; }
.sc-title { font-size: clamp(10px, 2.1cqw, 24px); font-weight: 900; letter-spacing: 0.05em; line-height: 1.1; color: #381a05; margin: 0; }
.sc-role { font-style: italic; font-weight: 700; font-size: clamp(8px, 1.3cqw, 15px); color: #78350f; }
.sc-date { font-size: clamp(7px, 1.02cqw, 12px); font-weight: 700; color: #92400e; letter-spacing: 0.08em; }
.sc-divider { display: none; }
.sc-grid { width: 100%; flex: 1; min-height: 0; display: grid; grid-template-columns: 1.55fr 1fr !important; gap: 1cqw; text-align: left; }
.sc-panel {
  background: rgba(69, 26, 3, 0.06); border: 1px solid rgba(120, 53, 15, 0.28); border-radius: 0.8cqw;
  padding: 0.7cqw 1.1cqw; padding-right: 6px; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; touch-action: pan-x pan-y pinch-zoom; scrollbar-width: none; overflow-wrap: break-word; word-break: break-word;
}
.sc-panel::-webkit-scrollbar { display: none; }
.sc-panel-title { font-size: clamp(6.5px, 0.95cqw, 11px); font-weight: 900; letter-spacing: 0.1em; text-transform: uppercase; color: #451a03; margin: 0 0 0.4cqw; }
.sc-list { margin: 0; padding-left: 0; list-style: none; }
.sc-list li { position: relative; padding-left: 1.2cqw; padding-right: 6px; margin-bottom: 0.35cqw; font-size: clamp(7px, 1.12cqw, 13px); line-height: 1.22; font-weight: 600; color: #291304; overflow-wrap: break-word; word-break: break-word; }
.sc-list li::before { content: '◆'; position: absolute; left: 0; top: 0.05em; font-size: 0.7em; color: #b45309; }
.sc-chips { display: flex; flex-wrap: wrap; gap: 0.4cqw; }
.sc-chip {
  padding: 0.25cqw 0.8cqw; border-radius: 999px; background: rgba(120, 53, 15, 0.14); border: 1px solid rgba(120, 53, 15, 0.45);
  font-size: clamp(6px, 0.92cqw, 11px); font-weight: 700; color: #451a03; white-space: nowrap;
}
.sc-stats { display: flex; flex-direction: column; gap: 0.35cqw; }
.sc-stat { display: flex; align-items: center; gap: 0.9cqw; }
.sc-stat b {
  flex: 0 0 auto; min-width: 4.8cqw; text-align: center; padding: 0.2cqw 0.6cqw; border-radius: 0.5cqw; background: #451a03; color: #fde68a;
  font-family: 'Cinzel', serif; font-size: clamp(7px, 1.2cqw, 14px); text-shadow: none;
}
.sc-stat span { font-size: clamp(6px, 0.88cqw, 10.5px); line-height: 1.2; font-weight: 600; color: #291304; overflow-wrap: break-word; word-break: break-word; padding-right: 6px; }
.scroll-inner-content > div:last-child { flex-shrink: 0; margin-top: 0.2cqw !important; }
.scroll-inner-content button { padding: 0.5cqw 1.5cqw !important; font-size: clamp(5px, 0.8cqw, 9px) !important; }
@media (max-width: 640px) { .sc-grid { grid-template-columns: 1fr !important; } .sc-panel-skills { display: none; } }

@media (max-height: 500px), (max-width: 960px) {
  .scroll-frame-wrapper {
    width: min(96vw, calc(96dvh * 880 / 495), 1040px);
  }
  .scroll-inner-content {
    overflow-y: auto !important;
    overflow-x: hidden !important;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-x pan-y pinch-zoom;
    padding-right: 6px !important;
    overflow-wrap: break-word;
  }
  .sc-grid {
    min-height: 110px;
  }
  .sc-panel {
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-x pan-y pinch-zoom;
    overflow-wrap: break-word;
    word-break: break-word;
    padding-right: 6px !important;
  }
  .sc-badge {
    font-size: clamp(6px, 0.9cqw, 10px);
  }
  .sc-kicker {
    font-size: clamp(7.5px, 1.12cqw, 13px);
  }
  .sc-title {
    font-size: clamp(12px, 2.35cqw, 26px);
  }
  .sc-role {
    font-size: clamp(9.5px, 1.5cqw, 17px);
  }
  .sc-date {
    font-size: clamp(8.5px, 1.2cqw, 14px);
  }
  .sc-panel-title {
    font-size: clamp(8px, 1.15cqw, 13px);
  }
  .sc-list li {
    font-size: clamp(8.5px, 1.32cqw, 15px);
    line-height: 1.38;
    overflow-wrap: break-word;
    word-break: break-word;
    padding-right: 6px;
  }
  .sc-stat b {
    font-size: clamp(8.5px, 1.38cqw, 15px);
  }
  .sc-stat span {
    font-size: clamp(7.5px, 1.08cqw, 12.5px);
    line-height: 1.35;
    overflow-wrap: break-word;
    word-break: break-word;
    padding-right: 4px;
  }
  .sc-chip {
    font-size: clamp(7px, 1.08cqw, 12px);
  }
  .scroll-inner-content button {
    font-size: clamp(6.5px, 0.95cqw, 10.5px) !important;
    padding: 0.6cqw 1.6cqw !important;
  }
}


#scrollModal {
  touch-action: pan-x pan-y pinch-zoom;
  overflow-y: auto;
}

.sc-top-bar {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  flex-wrap: wrap;
  flex-shrink: 0;
}

.scroll-inner-content button.sc-zoom-btn,
.sc-zoom-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 0.28cqw 1.1cqw !important;
  border-radius: 999px;
  background: rgba(69, 26, 3, 0.92);
  color: #fde68a;
  border: 1px solid rgba(245, 158, 11, 0.75);
  font-family: 'Press Start 2P', monospace;
  font-size: clamp(5.5px, 0.72cqw, 8.5px) !important;
  letter-spacing: 0.06em;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
  transition: transform 0.15s ease, background 0.15s ease;
  touch-action: manipulation;
}

.scroll-inner-content button.sc-zoom-btn:hover,
.scroll-inner-content button.sc-zoom-btn.is-active,
.sc-zoom-btn:hover,
.sc-zoom-btn.is-active {
  background: #78350f;
  color: #ffffff;
  border-color: #fbbf24;
}

.scroll-frame-wrapper.is-zoomed {
  width: min(98vw, calc(98dvh * 880 / 495), 1120px) !important;
}

.scroll-inner-content.is-zoomed {
  overflow-y: auto !important;
  overflow-x: hidden !important;
  touch-action: pan-x pan-y pinch-zoom !important;
  justify-content: flex-start !important;
  gap: 6px !important;
  padding: 4px 8px 10px 4px !important;
}

.scroll-inner-content.is-zoomed button.sc-zoom-btn {
  font-size: clamp(7.5px, 1cqw, 11px) !important;
  padding: 0.35cqw 1.25cqw !important;
}

.scroll-inner-content.is-zoomed .sc-badge {
  font-size: clamp(7.5px, 1.15cqw, 13px) !important;
}

.scroll-inner-content.is-zoomed .sc-kicker {
  font-size: clamp(9.5px, 1.45cqw, 17px) !important;
}

.scroll-inner-content.is-zoomed .sc-title {
  font-size: clamp(14px, 2.9cqw, 32px) !important;
  line-height: 1.15 !important;
}

.scroll-inner-content.is-zoomed .sc-role {
  font-size: clamp(12px, 1.9cqw, 21px) !important;
}

.scroll-inner-content.is-zoomed .sc-date {
  font-size: clamp(10.5px, 1.5cqw, 17px) !important;
}

.scroll-inner-content.is-zoomed .sc-grid {
  flex: 0 0 auto !important;
  min-height: auto !important;
  grid-template-columns: 1fr !important;
  gap: 8px !important;
}

.scroll-inner-content.is-zoomed .sc-panel-skills {
  display: block !important;
}

.scroll-inner-content.is-zoomed .sc-panel {
  overflow: visible !important;
  max-height: none !important;
  padding: 8px 10px !important;
}

.scroll-inner-content.is-zoomed .sc-panel-title {
  font-size: clamp(10.5px, 1.5cqw, 17px) !important;
  margin-bottom: 5px !important;
}

.scroll-inner-content.is-zoomed .sc-list li {
  font-size: clamp(11.5px, 1.78cqw, 19.5px) !important;
  line-height: 1.45 !important;
  margin-bottom: 5px !important;
}

.scroll-inner-content.is-zoomed .sc-stat b {
  font-size: clamp(11px, 1.8cqw, 19.5px) !important;
}

.scroll-inner-content.is-zoomed .sc-stat span {
  font-size: clamp(10px, 1.45cqw, 16.5px) !important;
  line-height: 1.4 !important;
}

.scroll-inner-content.is-zoomed .sc-chip {
  font-size: clamp(9.5px, 1.4cqw, 15.5px) !important;
  padding: 3px 9px !important;
}

.scroll-inner-content.is-zoomed > div:last-child {
  position: sticky;
  bottom: 0;
  width: 100%;
  padding: 6px 0 2px !important;
  background: linear-gradient(180deg, rgba(245, 222, 179, 0) 0%, rgba(235, 205, 155, 0.96) 30%);
  z-index: 5;
  flex-shrink: 0 !important;
}
