/* Zamaa Creator - Mobile & Web Visual Novel Player Styles */
:root {
  --bg-color: #0d1014;
  --panel-bg: rgba(15, 20, 26, 0.88);
  --accent-color: #5aa7ff;
  --accent-hover: #2870c8;
  --accent-border: rgba(90, 167, 255, 0.4);
  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --choice-bg: rgba(24, 32, 42, 0.92);
  --choice-border: rgba(90, 167, 255, 0.25);
  --choice-hover-bg: #2563eb;
  --toolbar-bg: rgba(18, 23, 30, 0.85);
  --toolbar-border: rgba(255, 255, 255, 0.08);
  --app-bg: radial-gradient(circle at center, #151a21 0%, #080a0d 100%);
  --viewport-border: #232a34;
  --modal-bg: rgba(8, 11, 15, 0.94);
  --top-bar-bg: linear-gradient(180deg, rgba(0, 0, 0, 0.7) 0%, rgba(0, 0, 0, 0) 100%);
  --icon-btn-bg: rgba(20, 26, 35, 0.8);
  --icon-btn-border: rgba(255, 255, 255, 0.12);
  --node-pill-bg: rgba(30, 42, 58, 0.85);
  --speaker-badge-bg: rgba(30, 42, 58, 0.9);
  --viewport-bg: #0a0e14;
  --fade-color: #000000;
}

html.light-theme, body.light-theme, [data-theme="light"] {
  --bg-color: #f0f5ff;
  --panel-bg: rgba(255, 255, 255, 0.94);
  --accent-color: #3b82f6;
  --accent-hover: #2563eb;
  --accent-border: rgba(59, 130, 246, 0.4);
  --text-primary: #1e293b;
  --text-secondary: #64748b;
  --text-muted: #94a3b8;
  --choice-bg: rgba(255, 255, 255, 0.95);
  --choice-border: rgba(59, 130, 246, 0.35);
  --choice-hover-bg: #3b82f6;
  --toolbar-bg: rgba(255, 255, 255, 0.9);
  --toolbar-border: rgba(0, 0, 0, 0.12);
  --app-bg: radial-gradient(circle at center, #e0eaff 0%, #cbd5e1 100%);
  --viewport-border: #cbd5e1;
  --viewport-bg: #f0f5ff;
  --fade-color: #f0f5ff;
  --modal-bg: rgba(255, 255, 255, 0.96);
  --top-bar-bg: linear-gradient(180deg, rgba(255, 255, 255, 0.85) 0%, rgba(255, 255, 255, 0) 100%);
  --icon-btn-bg: rgba(255, 255, 255, 0.85);
  --icon-btn-border: rgba(0, 0, 0, 0.15);
  --node-pill-bg: rgba(219, 234, 254, 0.95);
  --speaker-badge-bg: rgba(219, 234, 254, 0.95);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: var(--bg-color);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background-color 0.2s ease, color 0.2s ease;
}

/* Desktop framing container */
#app-wrapper {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--app-bg);
  position: relative;
}

/* Desktop Aspect Ratio Toolbar */
#desktop-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  background: var(--toolbar-bg);
  padding: 4px 10px;
  border-radius: 20px;
  border: 1px solid var(--toolbar-border);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  z-index: 100;
}

#desktop-toolbar span {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: bold;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.ratio-btn {
  background: transparent;
  border: 1px solid var(--toolbar-border);
  color: var(--text-secondary);
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 12px;
  cursor: pointer;
  outline: none;
  -webkit-tap-highlight-color: transparent;
  transition: background-color 0.25s ease, color 0.25s ease, border-color 0.25s ease, transform 0.15s ease;
}

@media (hover: hover) and (pointer: fine) {
  .ratio-btn:hover {
    background: var(--accent-color);
    color: #fff;
    border-color: var(--accent-color);
  }
}

.ratio-btn.active {
  background: var(--accent-color);
  color: #fff;
  border-color: var(--accent-color);
}

.ratio-btn:active {
  transform: scale(0.94);
}

/* Mobile Screen Container */
#game-viewport {
  position: relative;
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  overflow: hidden;
  background: var(--viewport-bg);
  display: flex;
  flex-direction: column;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
  border-radius: 0px;
  aspect-ratio: 9 / 18;
}

@media (min-width: 600px) {
  #game-viewport {
    height: 92vh;
    max-height: 900px;
    width: auto;
    border-radius: 16px;
    border: 2px solid var(--viewport-border);
  }
}

@media (max-width: 599px) {
  #desktop-toolbar {
    display: none !important;
  }
  #game-viewport {
    height: 100dvh !important;
    width: 100vw !important;
    max-height: none !important;
    aspect-ratio: unset !important;
    border: none !important;
    border-radius: 0 !important;
  }
}

/* Background Layers */
#bg-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  z-index: 1;
  display: none;
}

#bg-layer[src]:not([src=""]) {
  display: block;
}

#video-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  z-index: 1;
  display: none;
}

/* Screen Fade Overlay */
#fade-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: var(--fade-color);
  opacity: 1;
  pointer-events: none;
  z-index: 2;
  transition: opacity 0.8s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Main Interactive Stage */
#stage {
  position: relative;
  width: 100%;
  height: 100%;
  z-index: 10;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  cursor: pointer;
}

/* TOP SYSTEM BAR */
#top-bar {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: var(--top-bar-bg);
  z-index: 30;
}

#notch {
  width: 50px;
  height: 8px;
  background: #000;
  border-radius: 4px;
  margin: 0 auto;
}

#node-pill {
  font-size: 10px;
  font-weight: bold;
  color: var(--accent-color);
  background: var(--node-pill-bg);
  border: 1px solid var(--accent-border);
  padding: 2px 7px;
  border-radius: 10px;
}

.top-controls {
  display: flex;
  gap: 6px;
}

.icon-btn {
  background: var(--icon-btn-bg);
  border: 1px solid var(--icon-btn-border);
  color: var(--text-secondary);
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 6px;
  cursor: pointer;
  outline: none;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  transition: background-color 0.35s ease, color 0.35s ease, border-color 0.35s ease, transform 0.15s ease;
}

@media (hover: hover) and (pointer: fine) {
  .icon-btn:hover {
    background: var(--accent-color);
    color: #fff;
    border-color: var(--accent-color);
  }
}

.icon-btn:active {
  background: var(--accent-hover);
  color: #fff;
  border-color: var(--accent-hover);
  transform: scale(0.92);
  transition: all 0.05s ease;
}

.icon-btn:focus:not(:focus-visible) {
  outline: none;
}

/* CENTER CHARACTER / SCENE STAGE */
#center-stage {
  flex: 1;
  width: 100%;
  position: relative;
  pointer-events: none;
}

/* LOWER THIRD: THUMB ZONE */
#thumb-zone {
  width: 100%;
  max-width: 800px;
  margin: 0 auto;
  padding: 0 10px 12px 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 30;
}

/* CHOICES CONTAINER */
#choices-container {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 100%;
}

.choice-btn {
  width: 100%;
  padding: 10px 14px;
  min-height: 42px;
  background: var(--choice-bg);
  border: 1px solid var(--choice-border);
  border-radius: 8px;
  color: var(--text-primary);
  font-size: 13.5px;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
  outline: none;
  -webkit-tap-highlight-color: transparent;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  transition: background-color 0.25s ease, border-color 0.25s ease, color 0.25s ease, opacity 0.25s ease, transform 0.15s ease, box-shadow 0.25s ease;
  display: flex;
  align-items: center;
}

@media (hover: hover) and (pointer: fine) {
  .choice-btn:hover {
    background: var(--choice-hover-bg);
    border-color: var(--accent-hover);
    color: #fff;
    transform: translateY(-1px);
    box-shadow: 0 6px 16px rgba(59, 130, 246, 0.3);
  }
}

.choice-btn:active, .choice-btn.selected {
  background: var(--choice-hover-bg) !important;
  border-color: var(--accent-hover) !important;
  color: #fff !important;
  transform: scale(0.98);
  box-shadow: 0 0 16px rgba(59, 130, 246, 0.6) !important;
}

.choice-btn.dimmed {
  opacity: 0.35;
  pointer-events: none;
  transform: scale(0.97);
}

/* DIALOGUE BOX */
#dialogue-box {
  display: none;
  position: relative;
  background: var(--panel-bg);
  border: 1px solid var(--toolbar-border);
  border-radius: 10px;
  padding: 12px 14px;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  min-height: 86px;
  flex-direction: column;
  justify-content: flex-start;
}

#speaker-badge {
  display: inline-block;
  align-self: flex-start;
  font-size: 11.5px;
  font-weight: 700;
  color: var(--accent-color);
  background: var(--speaker-badge-bg);
  border: 1px solid var(--accent-border);
  padding: 2px 8px;
  border-radius: 4px;
  margin-bottom: 6px;
}

#speaker-badge.hidden {
  display: none;
}

#dialogue-text {
  font-size: 14px;
  line-height: 1.45;
  color: var(--text-primary);
  word-wrap: break-word;
  padding-right: 18px;
}

/* Pulsing Tap-to-Advance Indicator */
#tap-indicator {
  position: absolute;
  bottom: 8px;
  right: 12px;
  font-size: 11px;
  color: var(--accent-color);
  animation: pulse-down 1.2s infinite ease-in-out;
}

@keyframes pulse-down {
  0%, 100% { transform: translateY(0); opacity: 0.4; }
  50% { transform: translateY(3px); opacity: 1; }
}

/* History Modal */
#history-modal {
  display: none;
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: var(--modal-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  z-index: 50;
  flex-direction: column;
  padding: 16px;
}

#history-modal.active {
  display: flex;
}

#history-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--toolbar-border);
  margin-bottom: 12px;
}

#history-header h3 {
  font-size: 14px;
  color: var(--text-primary);
}

#history-content {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.history-item {
  font-size: 12.5px;
  line-height: 1.4;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--toolbar-border);
  padding-bottom: 6px;
}

.history-speaker {
  font-weight: bold;
  color: var(--accent-color);
}
