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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #000;
  font-family: "Microsoft YaHei", "PingFang SC", "Hiragino Sans GB", sans-serif;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}

#game-container {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

#bg-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  transition: opacity 0.8s ease;
  z-index: 0;
}
#bg-layer.placeholder {
  background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
}

#char-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1;
}

.char-sprite {
  position: absolute;
  bottom: 0;
  max-height: 85%;
  max-width: 45%;
  object-fit: contain;
  opacity: 0;
  transition: opacity 0.6s ease, transform 0.6s ease;
}
.char-sprite.visible {
  opacity: 1;
}
.char-sprite.left {
  left: 2%;
  transform: translateX(-30px);
}
.char-sprite.left.visible {
  transform: translateX(0);
}
.char-sprite.right {
  right: 2%;
  transform: translateX(30px);
}
.char-sprite.right.visible {
  transform: translateX(0);
}
.char-sprite.center {
  left: 50%;
  transform: translate(-50%, 20px);
}
.char-sprite.center.visible {
  transform: translate(-50%, 0);
}
.char-sprite.placeholder {
  background: rgba(255, 255, 255, 0.08);
  border: 1px dashed rgba(255, 255, 255, 0.2);
  border-radius: 4px;
}

.char-sprite.shaking {
  animation: char-shake 0.55s ease-in-out;
}
.char-sprite.bouncing {
  animation: char-bounce 0.55s ease-in-out;
}

@keyframes char-shake {
  0%, 100% { margin-left: 0; }
  10%, 50%, 90% { margin-left: -8px; }
  30%, 70% { margin-left: 8px; }
}
@keyframes char-bounce {
  0%, 100% { margin-bottom: 0; }
  20%, 60% { margin-bottom: 14px; }
  40%, 80% { margin-bottom: 2px; }
}

#cg-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-size: contain;
  background-position: center;
  background-repeat: no-repeat;
  background-color: #000;
  z-index: 5;
  display: none;
  cursor: pointer;
}
#cg-overlay .cg-desc {
  position: absolute;
  bottom: 40px;
  left: 50%;
  transform: translateX(-50%);
  color: rgba(255, 255, 255, 0.7);
  font-size: 14px;
  background: rgba(0, 0, 0, 0.5);
  padding: 6px 16px;
  border-radius: 20px;
  pointer-events: none;
}
#cg-overlay.placeholder {
  background: linear-gradient(135deg, #2d1b69 0%, #1a1a3e 50%, #0d1b2a 100%);
}

#text-box {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  min-height: 140px;
  max-height: 35%;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.85) 15%, rgba(0, 0, 0, 0.92));
  padding: 30px 24px 24px;
  z-index: 2;
  cursor: pointer;
  transition: opacity 0.3s ease;
}
#text-box.hidden {
  opacity: 0;
  pointer-events: none;
}

#text-content {
  color: #eee;
  font-size: 18px;
  line-height: 1.8;
  letter-spacing: 1px;
  min-height: 54px;
  word-break: break-all;
}
#text-content .char-name {
  color: #ffb74d;
  font-weight: bold;
  display: block;
  margin-bottom: 4px;
  font-size: 16px;
}

#text-indicator {
  position: absolute;
  right: 24px;
  bottom: 16px;
  width: 0;
  height: 0;
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  border-top: 8px solid rgba(255, 255, 255, 0.5);
  animation: blink 0.8s infinite;
  display: none;
}
#text-indicator.show {
  display: block;
}
@keyframes blink {
  0%, 100% { opacity: 0.3; }
  50% { opacity: 1; }
}

#choice-panel {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 6;
  background: rgba(0, 0, 0, 0.7);
}
#choice-panel .choice-prompt {
  color: #ccc;
  font-size: 16px;
  margin-bottom: 24px;
  text-align: center;
  max-width: 80%;
  line-height: 1.6;
}
#choice-panel .choice-btn {
  display: block;
  width: 70%;
  max-width: 480px;
  padding: 14px 20px;
  margin: 8px 0;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.25);
  color: #fff;
  font-size: 17px;
  border-radius: 8px;
  cursor: pointer;
  text-align: center;
  transition: background 0.2s, border-color 0.2s;
}
#choice-panel .choice-btn:hover,
#choice-panel .choice-btn:active {
  background: rgba(255, 255, 255, 0.2);
  border-color: rgba(255, 255, 255, 0.5);
}

#scene-title {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: #fff;
  font-size: 28px;
  font-weight: bold;
  text-align: center;
  z-index: 4;
  display: none;
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.8);
  letter-spacing: 2px;
}
#scene-title .scene-sub {
  display: block;
  font-size: 14px;
  font-weight: normal;
  color: #aaa;
  margin-top: 8px;
  letter-spacing: 1px;
}

#menu-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.85);
  z-index: 10;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
#menu-overlay .menu-title {
  color: #fff;
  font-size: 24px;
  margin-bottom: 32px;
  letter-spacing: 3px;
}
#menu-overlay .menu-btn {
  display: block;
  width: 60%;
  max-width: 380px;
  padding: 14px 0;
  margin: 6px 0;
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.3);
  color: #ccc;
  font-size: 17px;
  border-radius: 6px;
  cursor: pointer;
  text-align: center;
  transition: all 0.2s;
  letter-spacing: 2px;
}
#menu-overlay .menu-btn:hover,
#menu-overlay .menu-btn:active {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  border-color: rgba(255, 255, 255, 0.6);
}

#save-panel {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.9);
  z-index: 11;
  display: none;
  flex-direction: column;
  overflow-y: auto;
  padding: 20px;
}
#save-panel .save-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0 16px;
  flex-shrink: 0;
}
#save-panel .save-header h2 {
  color: #fff;
  font-size: 20px;
  letter-spacing: 2px;
}
#save-panel .save-header .close-btn {
  color: #aaa;
  font-size: 28px;
  cursor: pointer;
  padding: 0 8px;
  background: none;
  border: none;
}
#save-panel .save-header .close-btn:hover {
  color: #fff;
}
#save-panel .save-header .save-actions {
  display: flex;
  gap: 10px;
}
#save-panel .save-header .save-actions button {
  padding: 6px 14px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.25);
  color: #ccc;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
}
#save-panel .save-header .save-actions button:hover {
  background: rgba(255, 255, 255, 0.2);
  color: #fff;
}
#save-panel .save-slots {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: center;
}
#save-panel .save-slot {
  width: calc(50% - 6px);
  max-width: 280px;
  min-height: 70px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 8px;
  padding: 12px;
  cursor: pointer;
  color: #ccc;
  transition: all 0.2s;
  text-align: left;
}
#save-panel .save-slot:hover {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.4);
}
#save-panel .save-slot .slot-num {
  font-size: 13px;
  color: #888;
}
#save-panel .save-slot .slot-title {
  font-size: 15px;
  color: #eee;
  margin: 4px 0;
  font-weight: bold;
}
#save-panel .save-slot .slot-preview {
  font-size: 12px;
  color: #999;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#save-panel .save-slot .slot-time {
  font-size: 11px;
  color: #666;
  margin-top: 4px;
}
#save-panel .save-slot.empty {
  color: #555;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
}

#history-panel {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.92);
  z-index: 9;
  display: none;
  flex-direction: column;
  overflow-y: auto;
  padding: 30px 20px;
}
#history-panel .history-item {
  color: #bbb;
  font-size: 15px;
  line-height: 1.7;
  padding: 6px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}
#history-panel .history-scene {
  color: #ffb74d;
  font-size: 13px;
  font-weight: bold;
  margin-top: 16px;
  margin-bottom: 4px;
}

#title-screen {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(135deg, #0f0c29, #302b63, #24243e);
  z-index: 20;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
#title-screen .title-logo {
  color: #fff;
  font-size: 36px;
  font-weight: bold;
  letter-spacing: 6px;
  margin-bottom: 16px;
  text-shadow: 0 0 30px rgba(255, 180, 100, 0.3);
}
#title-screen .title-sub {
  color: #888;
  font-size: 14px;
  letter-spacing: 3px;
  margin-bottom: 48px;
}
#title-screen .title-start {
  padding: 12px 48px;
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.4);
  color: #ddd;
  font-size: 18px;
  border-radius: 4px;
  cursor: pointer;
  letter-spacing: 4px;
  transition: all 0.3s;
}
#title-screen .title-start:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.8);
  color: #fff;
}
#title-screen .title-load {
  margin-top: 16px;
  padding: 8px 24px;
  background: transparent;
  border: none;
  color: #777;
  font-size: 14px;
  cursor: pointer;
  letter-spacing: 2px;
}
#title-screen .title-load:hover {
  color: #aaa;
}

#loading-screen {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: #000;
  z-index: 30;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
#loading-screen .loading-text {
  color: #888;
  font-size: 16px;
  letter-spacing: 3px;
}
#loading-screen .loading-bar {
  width: 200px;
  height: 2px;
  background: rgba(255, 255, 255, 0.1);
  margin-top: 16px;
  border-radius: 1px;
  overflow: hidden;
}
#loading-screen .loading-bar-inner {
  height: 100%;
  width: 0%;
  background: rgba(255, 255, 255, 0.5);
  transition: width 0.3s;
}

#fullscreen-btn {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 3;
  width: 36px;
  height: 36px;
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 4px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgba(255, 255, 255, 0.6);
  font-size: 16px;
  transition: all 0.2s;
}
#fullscreen-btn:hover {
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
}

#settings-btn {
  position: absolute;
  top: 12px;
  right: 56px;
  z-index: 3;
  width: 36px;
  height: 36px;
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 4px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgba(255, 255, 255, 0.6);
  font-size: 16px;
  transition: all 0.2s;
}
#settings-btn:hover {
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
}

@media (max-width: 600px) {
  #text-content {
    font-size: 16px;
    line-height: 1.7;
  }
  #text-box {
    padding: 24px 16px 16px;
    min-height: 120px;
  }
  #choice-panel .choice-btn {
    width: 85%;
    font-size: 15px;
    padding: 12px 16px;
  }
  #scene-title {
    font-size: 22px;
  }
  #save-panel .save-slot {
    width: 100%;
    max-width: none;
  }
  #menu-overlay .menu-btn {
    width: 75%;
  }
  .char-sprite {
    max-height: 70%;
    max-width: 42%;
  }
}
