/* ===== 慢岛 · Slow Isle · M1 Prototype ===== */

:root {
  --ink: #1F5673;
  --sand: #F5EFE2;
  --paper: #FAF7F0;
}

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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--paper);
  font-family: "Georgia", "Songti SC", "STSong", serif;
  color: var(--ink);
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

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

#game-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: block;
}

#ui-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 10;
}

/* ---- Title Card ---- */
#title-card {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(31, 86, 115, 0.72);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  transition: opacity 1.2s ease;
  pointer-events: auto;
  cursor: pointer;
  z-index: 20;
}

#title-card.hidden {
  opacity: 0;
  pointer-events: none;
}

.title-eyebrow {
  font-size: 14px;
  letter-spacing: 8px;
  color: #8FB8D0;
  margin-bottom: 8px;
  font-family: Georgia, serif;
}

.title-main {
  font-size: 72px;
  font-weight: bold;
  color: #FFFFFF;
  letter-spacing: 12px;
  text-shadow: 0 2px 20px rgba(0,0,0,0.3);
}

.title-sub {
  font-size: 16px;
  color: #CFE2EC;
  margin-top: 12px;
  letter-spacing: 2px;
}

.title-guide {
  width: min(420px, 78vw);
  margin-top: 24px;
  padding-top: 12px;
  border-top: 1px solid rgba(207, 226, 236, 0.12);
  text-align: center;
  opacity: 0.62;
}
.title-guide-row {
  font-size: 11px;
  color: rgba(207, 226, 236, 0.72);
  line-height: 1.75;
  letter-spacing: 0.25px;
}

.title-hint {
  font-size: 14px;
  color: #8FB8D0;
  margin-top: 32px;
  animation: pulse 2s ease-in-out infinite;
}

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

/* ---- HUD ---- */
#hud {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  padding: 16px 20px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  transition: opacity 0.6s ease;
}

#hud.hidden {
  opacity: 0;
}

#time-indicator {
  font-size: 13px;
  color: rgba(255, 255, 255, 0.7);
  text-shadow: 0 1px 4px rgba(0,0,0,0.3);
  letter-spacing: 1px;
}

#weather-indicator {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.6);
  text-shadow: 0 1px 4px rgba(0,0,0,0.3);
  letter-spacing: 1px;
  margin-top: 2px;
}

#season-indicator {
  font-size: 12px;
  color: rgba(255, 230, 180, 0.7);
  text-shadow: 0 1px 4px rgba(0,0,0,0.3);
  letter-spacing: 1px;
  margin-top: 1px;
}

#location-label {
  font-size: 15px;
  color: rgba(255, 255, 255, 0.85);
  text-shadow: 0 1px 4px rgba(0,0,0,0.3);
  letter-spacing: 2px;
  font-style: italic;
}

#quest-hint {
  font-size: 12px;
  color: rgba(255, 220, 160, 0.85);
  text-shadow: 0 1px 4px rgba(0,0,0,0.4);
  letter-spacing: 0.5px;
  max-width: 400px;
  line-height: 1.5;
  margin-top: 2px;
  opacity: 0.8;
}

/* ---- Joystick (touch) ---- */
#joystick-zone {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 50%;
  height: 50%;
  display: none;
}

.touch-only #joystick-zone {
  display: block;
}

#joystick {
  position: absolute;
  width: 120px;
  height: 120px;
  pointer-events: none;
  z-index: 15;
}

#joystick.visible {
  display: block;
}

#joystick.hidden {
  display: none;
}

#joystick-base {
  position: absolute;
  top: 0;
  left: 0;
  width: 120px;
  height: 120px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.3);
  background: rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

#joystick-thumb {
  position: absolute;
  top: 40px;
  left: 40px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.35);
  border: 1px solid rgba(255, 255, 255, 0.5);
}

/* ---- Audio Toggle ---- */
#audio-toggle {
  position: absolute;
  top: 50%;
  right: 16px;
  transform: translateY(-50%);
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  border: 1px solid rgba(255, 255, 255, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  color: rgba(255, 255, 255, 0.6);
  pointer-events: auto;
  cursor: pointer;
  z-index: 15;
  transition: background 0.2s;
}

#audio-toggle:active {
  background: rgba(255, 255, 255, 0.2);
}

#audio-toggle.muted {
  opacity: 0.4;
}

/* ---- Loading ---- */
#loading {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 14px;
  color: #8FB8D0;
  letter-spacing: 2px;
}

#loading.hidden {
  display: none;
}

/* ---- Dialogue UI ---- */
.dialogue-ui {
  pointer-events: auto;
  z-index: 25;
  transition: opacity 0.3s ease;
}

.dialogue-ui.hidden {
  opacity: 0;
  pointer-events: none;
}

/* 对话框 */
#dialogue-box {
  position: absolute;
  bottom: 40px;
  left: 50%;
  transform: translateX(-50%);
  width: min(600px, 90vw);
  background: rgba(250, 247, 240, 0.95);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid rgba(31, 86, 115, 0.2);
  border-radius: 12px;
  padding: 18px 24px 14px;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.15);
  cursor: pointer;
}

#dialogue-box.visible,
#message-display.visible,
#runes-display.visible {
  opacity: 1;
  pointer-events: auto;
}

#dialogue-name {
  font-size: 15px;
  font-weight: bold;
  color: #1F5673;
  margin-bottom: 6px;
  letter-spacing: 1px;
}

#dialogue-text {
  font-size: 15px;
  line-height: 1.7;
  color: #3A4A5A;
  min-height: 2em;
}

#dialogue-hint {
  font-size: 11px;
  color: #9AA8B8;
  text-align: right;
  margin-top: 8px;
  letter-spacing: 1px;
}

/* 分支选项 */
#dialogue-choices {
  display: none;
  flex-direction: column;
  gap: 6px;
  margin-top: 10px;
}

.dialogue-choice {
  padding: 8px 14px;
  background: rgba(245, 239, 226, 0.7);
  border: 1px solid rgba(31, 86, 115, 0.15);
  border-radius: 8px;
  font-size: 14px;
  color: #3A4A5A;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
  font-family: Georgia, "Songti SC", "STSong", serif;
  pointer-events: auto;
  user-select: none;
  -webkit-user-select: none;
}

.dialogue-choice:hover {
  background: rgba(255, 240, 200, 0.7);
  border-color: rgba(31, 86, 115, 0.35);
}

.dialogue-choice:active {
  background: rgba(255, 220, 160, 0.8);
  transform: scale(0.98);
}

/* 消息面板 */
#message-display {
  position: absolute;
  bottom: 40px;
  left: 50%;
  transform: translateX(-50%);
  width: min(500px, 88vw);
}

.message-panel {
  background: rgba(250, 247, 240, 0.95);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid rgba(31, 86, 115, 0.2);
  border-radius: 12px;
  padding: 18px 24px 14px;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.15);
  cursor: pointer;
}

#message-title {
  font-size: 14px;
  font-weight: bold;
  color: #1F5673;
  margin-bottom: 6px;
  letter-spacing: 1px;
}

#message-text {
  font-size: 15px;
  line-height: 1.7;
  color: #3A4A5A;
  min-height: 2em;
}

#message-hint {
  font-size: 11px;
  color: #9AA8B8;
  text-align: right;
  margin-top: 8px;
  letter-spacing: 1px;
}

/* 信件展示 */
#letter-display {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(31, 50, 70, 0.6);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

#letter-display.visible {
  opacity: 1;
  pointer-events: auto;
}

.letter-paper {
  width: min(440px, 85vw);
  max-height: 75vh;
  overflow-y: auto;
  background: #FAF7F0;
  border-radius: 4px;
  padding: 32px 28px;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.3);
  background-image: linear-gradient(rgba(196, 168, 138, 0.03) 50%, transparent 50%);
  background-size: 100% 28px;
  cursor: pointer;
}

#letter-title {
  font-size: 18px;
  font-weight: bold;
  color: #1F5673;
  text-align: center;
  margin-bottom: 16px;
  letter-spacing: 2px;
}

#letter-body {
  font-size: 15px;
  line-height: 2;
  color: #3A4A5A;
  text-indent: 2em;
  white-space: pre-wrap;
}

#letter-author {
  font-size: 13px;
  color: #6A7A8A;
  text-align: right;
  margin-top: 16px;
  font-style: italic;
}

#letter-close-hint {
  font-size: 11px;
  color: #9AA8B8;
  text-align: center;
  margin-top: 16px;
  letter-spacing: 1px;
}

/* 符文展示 */
#runes-display {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(20, 30, 40, 0.7);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

#runes-display.visible {
  opacity: 1;
  pointer-events: auto;
}

.runes-panel {
  width: min(360px, 80vw);
  background: rgba(42, 58, 68, 0.95);
  border: 1px solid rgba(143, 232, 208, 0.3);
  border-radius: 8px;
  padding: 32px 28px;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.4);
  cursor: pointer;
}

#runes-symbols {
  font-size: 32px;
  text-align: center;
  color: #8FE8D0;
  line-height: 1.8;
  margin-bottom: 20px;
  text-shadow: 0 0 12px rgba(143, 232, 208, 0.4);
}

#runes-translation {
  font-size: 15px;
  line-height: 1.8;
  color: #B0C8D8;
  text-align: center;
  white-space: pre-wrap;
}

#runes-hint {
  font-size: 11px;
  color: #6A8A9A;
  text-align: center;
  margin-top: 16px;
  letter-spacing: 1px;
}

/* 发现提示 */
#discover-toast {
  position: absolute;
  top: 60px;
  right: 20px;
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(250, 247, 240, 0.95);
  border: 1px solid rgba(31, 86, 115, 0.2);
  border-radius: 8px;
  padding: 10px 16px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
  opacity: 0;
  transform: translateX(100%);
  transition: opacity 0.4s ease, transform 0.4s ease;
  pointer-events: none;
  z-index: 30;
}

#discover-toast.show {
  opacity: 1;
  transform: translateX(0);
}

.discover-icon {
  font-size: 20px;
  color: #E8A87C;
}

.discover-label {
  font-size: 10px;
  color: #9AA8B8;
  letter-spacing: 1px;
}

#discover-name {
  font-size: 14px;
  color: #1F5673;
  font-weight: bold;
}

/* 图鉴按钮 */
#codex-toggle {
  position: absolute;
  top: 50%;
  left: 16px;
  transform: translateY(-50%);
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  border: 1px solid rgba(255, 255, 255, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  pointer-events: auto;
  cursor: pointer;
  z-index: 15;
  transition: background 0.2s;
}

#codex-toggle:active {
  background: rgba(255, 255, 255, 0.2);
}

#codex-toggle.hidden {
  opacity: 0;
  pointer-events: none;
}

/* 图鉴面板 */
#codex-panel {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(31, 50, 70, 0.7);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

#codex-panel.visible {
  opacity: 1;
  pointer-events: auto;
}

.codex-content {
  width: min(520px, 90vw);
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  background: rgba(250, 247, 240, 0.97);
  border-radius: 12px;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.3);
  overflow: hidden;
}

.codex-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid rgba(31, 86, 115, 0.1);
}

.codex-title {
  font-size: 18px;
  font-weight: bold;
  color: #1F5673;
  letter-spacing: 2px;
}

#codex-close-btn {
  font-size: 18px;
  color: #9AA8B8;
  cursor: pointer;
  padding: 4px 8px;
}

#codex-close-btn:hover {
  color: #1F5673;
}

#codex-body {
  overflow-y: auto;
  padding: 14px 18px 20px;
  scrollbar-width: thin;
  scrollbar-color: rgba(31, 86, 115, 0.22) transparent;
}

/* ---- 总进度条 ---- */
.codex-overall {
  background: rgba(31, 86, 115, 0.06);
  border-radius: 8px;
  padding: 12px 14px;
  margin-bottom: 16px;
  text-align: center;
}
.codex-overall-title {
  font-size: 13px;
  color: #6A7A8A;
  margin-bottom: 8px;
  letter-spacing: 1px;
}
.codex-progress-bar {
  position: relative;
  width: 100%;
  height: 24px;
  background: rgba(31, 86, 115, 0.08);
  border-radius: 12px;
  overflow: hidden;
}
.codex-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #6AB8A0, #F0C850);
  border-radius: 12px;
  transition: width 0.4s ease;
  min-width: 3px;
}
.codex-progress-text {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 12px;
  font-weight: bold;
  color: #3A4A5A;
  text-shadow: 0 1px 2px rgba(255,255,255,0.8);
}
.codex-progress-percent {
  font-size: 18px;
  font-weight: bold;
  color: #1F5673;
  margin-top: 6px;
}

/* ---- 分类 ---- */
.codex-category {
  margin-bottom: 14px;
  padding: 12px 12px 10px;
  background: rgba(255, 255, 255, 0.46);
  border: 1px solid rgba(31, 86, 115, 0.09);
  border-radius: 8px;
}

.codex-cat-title {
  font-size: 14px;
  font-weight: bold;
  color: #1F5673;
  margin-bottom: 6px;
  letter-spacing: 1px;
  display: flex;
  align-items: center;
  gap: 4px;
}

.codex-cat-icon {
  font-size: 15px;
}

.codex-count {
  font-size: 11px;
  color: #8A9AAA;
  font-weight: normal;
  margin-left: auto;
}

/* 分类进度条 */
.codex-cat-progress {
  width: 100%;
  height: 4px;
  background: rgba(31, 86, 115, 0.06);
  border-radius: 2px;
  overflow: hidden;
  margin-bottom: 8px;
}
.codex-cat-progress-fill {
  height: 100%;
  background: #6AB8A0;
  border-radius: 2px;
  transition: width 0.3s ease;
  min-width: 2px;
}

/* ---- 物品网格 ---- */
.codex-items-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}

.codex-item {
  min-width: 0;
  padding: 8px 9px;
  background: rgba(245, 239, 226, 0.48);
  border: 1px solid rgba(31, 86, 115, 0.06);
  border-radius: 5px;
}

.codex-item-header {
  display: flex;
  align-items: flex-start;
  gap: 5px;
  min-width: 0;
  margin-bottom: 3px;
}

.codex-item-name {
  min-width: 0;
  flex: 1;
  font-size: 13px;
  color: #3A4A5A;
  font-weight: bold;
  line-height: 1.35;
}

.codex-item-desc {
  font-size: 11px;
  color: #6A7A8A;
  line-height: 1.5;
}

/* 未发现占位 */
.codex-item-locked {
  opacity: 0.55;
}
.codex-name-locked {
  color: #B0B8C0;
  font-weight: normal;
  letter-spacing: 2px;
}
.codex-desc-locked {
  font-style: italic;
  color: #A8B0B8;
}
.codex-rarity-locked {
  opacity: 0.4;
}

/* 稀有度色标 */
.codex-rarity-badge {
  font-size: 10px;
  padding: 1px 5px;
  border: 1px solid;
  border-radius: 3px;
  font-weight: normal;
  white-space: nowrap;
}

.codex-empty {
  font-size: 13px;
  color: #B0B8C0;
  font-style: italic;
  padding: 8px 0;
}

/* ---- Story Log ---- */
.story-section {
  margin-top: 16px;
  padding-top: 12px;
  border-top: 2px dotted rgba(31, 86, 115, 0.15);
}
.story-chapter-title {
  font-size: 16px;
  font-weight: bold;
  color: var(--ink);
  margin-bottom: 4px;
  letter-spacing: 1px;
}
.story-chapter-progress {
  font-size: 11px;
  color: #8A9AAA;
  margin-bottom: 8px;
}
.story-quest {
  font-size: 13px;
  color: #6A7A8A;
  background: rgba(255, 220, 160, 0.1);
  border-left: 3px solid rgba(255, 200, 100, 0.5);
  padding: 8px 10px;
  border-radius: 0 4px 4px 0;
  margin-bottom: 12px;
  line-height: 1.5;
}
.story-entry {
  margin: 8px 0;
  padding: 8px 10px;
  background: rgba(245, 239, 226, 0.5);
  border-radius: 4px;
}
.story-entry-title {
  font-size: 13px;
  font-weight: bold;
  color: var(--ink);
  margin-bottom: 3px;
}
.story-entry-text {
  font-size: 12px;
  color: #5A6A7A;
  line-height: 1.6;
  white-space: pre-line;
}

/* 交互提示HUD */
#interact-hint {
  position: absolute;
  bottom: 120px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 13px;
  color: rgba(255, 255, 255, 0.8);
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
  letter-spacing: 1px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s ease;
  z-index: 14;
}

#interact-hint.visible {
  opacity: 1;
}

/* ---- Responsive ---- */
@media (max-width: 768px) {
  .title-main {
    font-size: 48px;
    letter-spacing: 8px;
  }
  .title-sub {
    font-size: 13px;
  }
  .title-guide {
    width: min(340px, 84vw);
    margin-top: 18px;
    padding-top: 9px;
    opacity: 0.52;
  }
  .title-guide-row {
    font-size: 10px;
    line-height: 1.65;
  }
  .title-hint {
    margin-top: 24px;
    font-size: 13px;
  }
  #location-label {
    font-size: 13px;
  }
  #dialogue-box,
  #message-display {
    bottom: 20px;
    width: 92vw;
  }
  .letter-paper {
    padding: 24px 20px;
  }
  #letter-title {
    font-size: 16px;
  }
  #letter-body {
    font-size: 14px;
    line-height: 1.9;
  }
  /* M4: 移动端 HUD 缩小 */
  #hud {
    padding: 10px 14px;
  }
  #time-indicator { font-size: 11px; }
  #weather-indicator { font-size: 10px; }
  #season-indicator { font-size: 10px; }
  #quest-hint { font-size: 10px; max-width: 200px; }
  #codex-toggle, #audio-toggle {
    width: 36px; height: 36px; font-size: 16px;
  }
  .codex-content {
    width: min(94vw, 520px);
    max-height: 88dvh;
    border-radius: 9px;
  }
  .codex-header {
    padding: 13px 15px;
  }
  #codex-body {
    padding: 12px 13px 16px;
  }
  .codex-category {
    padding: 10px 9px 8px;
    margin-bottom: 10px;
  }
  .codex-items-grid {
    grid-template-columns: 1fr;
    gap: 4px;
  }
  .codex-item {
    padding: 7px 8px;
  }
}

/* M4: 移动端浮动交互按钮 */
#action-btn {
  position: absolute;
  bottom: 80px;
  right: 30px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: rgba(255, 220, 160, 0.3);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  border: 2px solid rgba(255, 220, 160, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  font-weight: bold;
  color: rgba(255, 240, 200, 0.9);
  pointer-events: auto;
  cursor: pointer;
  z-index: 16;
  transition: opacity 0.3s ease, transform 0.15s ease;
  opacity: 0;
  transform: scale(0.8);
}

#action-btn.visible {
  opacity: 1;
  transform: scale(1);
}

#action-btn:active {
  background: rgba(255, 220, 160, 0.5);
  transform: scale(0.92);
}

#action-btn.hidden {
  display: none;
}

/* M4: 非 touch 设备隐藏 action-btn */
#action-btn:not(.touch-only) {
  display: none;
}

/* M4: 移动端 viewport 高度修正 */
#game-container {
  height: 100vh;
  height: 100dvh; /* dynamic viewport height, addresses mobile browser chrome */
}

@media (max-width: 768px) {
  #action-btn {
    bottom: 90px;
    right: 20px;
    width: 50px;
    height: 50px;
    font-size: 18px;
  }
  /* 摇杆区域稍微调小，避免误触 */
  #joystick-zone {
    width: 60%;
    height: 60%;
  }
  /* M5: 移动端设置按钮缩小 */
  #settings-toggle {
    width: 36px;
    height: 36px;
    font-size: 16px;
  }
}

/* ---- Settings / Save Manager (M5) ---- */
#settings-toggle {
  position: absolute;
  top: 50%;
  right: 16px;
  transform: translateY(calc(-50% + 52px));
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  border: 1px solid rgba(255, 255, 255, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  color: rgba(255, 255, 255, 0.6);
  pointer-events: auto;
  cursor: pointer;
  z-index: 15;
  transition: background 0.2s, opacity 0.3s;
}

#settings-toggle:active {
  background: rgba(255, 255, 255, 0.2);
}

#settings-toggle.hidden {
  opacity: 0;
  pointer-events: none;
}

#settings-panel {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(31, 50, 70, 0.7);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 20;
  opacity: 0;
  transition: opacity 0.25s;
  pointer-events: none;
}

#settings-panel.visible {
  opacity: 1;
  pointer-events: auto;
}

.settings-content {
  width: min(440px, 90vw);
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  background: rgba(250, 247, 240, 0.97);
  border-radius: 12px;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.3);
  overflow: hidden;
}

.settings-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid rgba(31, 86, 115, 0.1);
}

.settings-title {
  font-size: 18px;
  font-weight: bold;
  color: #1F5673;
  letter-spacing: 2px;
}

#settings-close-btn {
  font-size: 18px;
  color: #999;
  cursor: pointer;
  padding: 4px 8px;
  transition: color 0.2s;
}

#settings-close-btn:hover {
  color: #333;
}

#settings-body {
  padding: 16px 20px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.settings-section {
  margin-bottom: 20px;
}

.settings-section:last-child {
  margin-bottom: 0;
}

.settings-section-title {
  font-size: 13px;
  font-weight: bold;
  color: #1F5673;
  margin-bottom: 10px;
  letter-spacing: 1px;
}

.settings-info-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 16px;
}

.info-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.info-label {
  font-size: 11px;
  color: #999;
}

.info-value {
  font-size: 14px;
  color: #333;
  font-weight: 500;
}

.settings-empty {
  font-size: 14px;
  color: #999;
  text-align: center;
  padding: 20px 0;
}

.settings-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.settings-btn {
  padding: 12px 16px;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
  background: rgba(31, 86, 115, 0.08);
  color: #1F5673;
}

.settings-btn:active {
  transform: scale(0.98);
}

.settings-btn.primary {
  background: #1F5673;
  color: #fff;
}

.settings-btn.primary:active {
  background: #164460;
}

.settings-btn.danger {
  background: rgba(180, 40, 40, 0.1);
  color: #B42828;
}

.settings-btn.danger:active {
  background: rgba(180, 40, 40, 0.2);
}

.settings-hint {
  font-size: 12px;
  color: #999;
  line-height: 1.6;
  margin-top: 12px;
  text-align: center;
}

.settings-toast {
  position: relative;
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 13px;
  margin-top: 10px;
  text-align: center;
  animation: fadeInUp 0.3s ease;
}

.settings-toast.success {
  background: rgba(45, 160, 80, 0.1);
  color: #2DA050;
}

.settings-toast.error {
  background: rgba(180, 40, 40, 0.1);
  color: #B42828;
}

@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ===== P2: 移动端深度调优 ===== */

/* P2: 安全区适配（notch / 刘海屏 / 底部横条） */
#hud {
  padding-top: max(16px, env(safe-area-inset-top));
  padding-left: max(20px, env(safe-area-inset-left));
  padding-right: max(20px, env(safe-area-inset-right));
}

#audio-toggle {
  top: 50%;
  right: max(16px, env(safe-area-inset-right));
  transform: translateY(-50%);
}

#codex-toggle {
  top: 50%;
  left: max(16px, env(safe-area-inset-left));
  transform: translateY(-50%);
}

#settings-toggle {
  top: 50%;
  right: max(16px, env(safe-area-inset-right));
  transform: translateY(calc(-50% + 52px));
}

#action-btn {
  bottom: max(80px, calc(80px + env(safe-area-inset-bottom)));
  right: max(20px, env(safe-area-inset-right));
}

#dialogue-box,
#message-display {
  bottom: max(40px, calc(40px + env(safe-area-inset-bottom)));
}

/* P2: 固定摇杆样式 */
.touch-only #joystick.fixed-joystick {
  opacity: 0.35;
}

.touch-only #joystick.fixed-joystick.visible {
  opacity: 0.55;
}

/* P2: 移动端面板优化 */
@media (max-width: 768px) {
  /* 制作面板 / 装饰面板缩小 */
  .codex-content {
    width: 94vw;
    max-height: 80vh;
  }
  #codex-body {
    padding: 12px 14px;
  }
  .codex-item-name {
    font-size: 13px;
  }
  .codex-item-desc {
    font-size: 11px;
  }
  /* 设置面板移动端适配 */
  .settings-content {
    width: 94vw;
    max-height: 75vh;
  }
  .settings-info-grid {
    grid-template-columns: 1fr;
    gap: 6px;
  }
  /* 对话框移动端更紧凑 */
  #dialogue-box {
    padding: 14px 18px 10px;
  }
  #dialogue-text {
    font-size: 14px;
    line-height: 1.6;
  }
  .dialogue-choice {
    padding: 10px 14px;
    font-size: 13px;
  }
  /* 信件面板 */
  .letter-paper {
    width: 90vw;
    padding: 20px 16px;
  }
  #letter-body {
    font-size: 13px;
    line-height: 1.8;
  }
}

/* P2: 触控设备禁用文字选择和高亮 */
.touch-only * {
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
}

/* P2: 横屏优化 */
@media (max-width: 500px) and (orientation: landscape) {
  #hud {
    padding: 8px 14px;
  }
  #time-indicator { font-size: 10px; }
  #quest-hint { font-size: 9px; max-width: 180px; }
  #action-btn {
    bottom: max(80px, calc(80px + env(safe-area-inset-bottom)));
    width: 44px;
    height: 44px;
    font-size: 16px;
  }
}

/* P2: 设置面板新增项 */
.settings-toggle-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid rgba(31, 86, 115, 0.06);
}

.settings-toggle-row:last-child {
  border-bottom: none;
}

.settings-toggle-label {
  font-size: 13px;
  color: #3A4A5A;
}

.settings-toggle-desc {
  font-size: 11px;
  color: #999;
  margin-top: 2px;
}

/* P2: 开关样式 */
.toggle-switch {
  position: relative;
  width: 40px;
  height: 22px;
  border-radius: 11px;
  background: rgba(31, 86, 115, 0.15);
  cursor: pointer;
  transition: background 0.2s;
  flex-shrink: 0;
}

.toggle-switch.active {
  background: #6AB8A0;
}

.toggle-switch::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
  transition: left 0.2s;
}

.toggle-switch.active::after {
  left: 20px;
}

