/* ===================================
   Multi AI Story Game - Base Styles
   =================================== */

/* --- Reset & Base --- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  /* Colors - Classic Fantasy Theme */
  --color-bg: #1a1a2e;
  --color-bg-light: #16213e;
  --color-surface: #0f3460;
  --color-surface-light: rgba(15, 52, 96, 0.85);
  --color-primary: #e94560;
  --color-primary-hover: #ff6b81;
  --color-secondary: #53899a;
  --color-secondary-hover: #6bb5cc;
  --color-text: #eee;
  --color-text-dim: #aaa;
  --color-text-dark: #333;
  --color-accent-gold: #d4a843;
  --color-border: rgba(212, 168, 67, 0.3);
  --color-success: #27ae60;
  --color-warning: #f39c12;
  --color-danger: #e74c3c;

  /* Typography */
  --font-main: 'Segoe UI', 'Noto Sans JP', sans-serif;
  --font-title: 'Georgia', 'Noto Serif JP', serif;

  /* Spacing */
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 16px;
  --space-lg: 24px;
  --space-xl: 32px;

  /* Border Radius */
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 16px;

  /* Shadows */
  --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.5);
}

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: var(--font-main);
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.6;
}

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

/* --- Screens --- */
.screen {
  display: none;
  position: absolute;
  inset: 0;
  overflow-y: auto;
}

.screen.active {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

/* コンテンツが多い画面は上寄せ+スクロール */
#screen-party-setup.screen.active,
#screen-scenario.screen.active {
  justify-content: flex-start;
  padding-top: 24px;
  padding-bottom: 24px;
}

/* --- Title Screen --- */
.title-slideshow {
  position: absolute;
  inset: 0;
  z-index: 0;
}

.slideshow-img {
  position: absolute;
  inset: 0;
  background-size: cover;
  background-position: center;
  opacity: 0;
  transition: opacity 2s ease-in-out;
}

.slideshow-img.active {
  opacity: 1;
}

/* Dark overlay for readability */
.title-slideshow::after {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at center, rgba(26, 26, 46, 0.4) 0%, rgba(26, 26, 46, 0.8) 100%);
  pointer-events: none;
}

.title-container {
  position: relative;
  z-index: 1;
  text-align: center;
  animation: fadeIn 1s ease;
}

.game-title {
  font-family: var(--font-title);
  font-size: 3rem;
  color: var(--color-accent-gold);
  text-shadow: 0 2px 8px rgba(212, 168, 67, 0.4);
  margin-bottom: var(--space-sm);
}

.game-subtitle {
  font-size: 1.1rem;
  color: var(--color-text-dim);
  margin-bottom: var(--space-xl);
}

.title-menu {
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
  align-items: center;
}

/* --- Buttons --- */
.btn {
  font-family: var(--font-main);
  font-size: 1rem;
  padding: var(--space-sm) var(--space-lg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all 0.2s ease;
  min-width: 160px;
}

.btn-primary {
  background: var(--color-primary);
  color: #fff;
  border-color: var(--color-primary);
}

.btn-primary:hover:not(:disabled) {
  background: var(--color-primary-hover);
}

.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-secondary {
  background: var(--color-secondary);
  color: #fff;
  border-color: var(--color-secondary);
}

.btn-secondary:hover {
  background: var(--color-secondary-hover);
}

.btn-back {
  background: transparent;
  color: var(--color-text-dim);
  border-color: var(--color-text-dim);
}

.btn-back:hover {
  color: var(--color-text);
  border-color: var(--color-text);
}

.btn-icon {
  background: var(--color-surface-light);
  color: var(--color-text);
  border: none;
  min-width: auto;
  padding: var(--space-sm);
  font-size: 1.2rem;
  border-radius: var(--radius-sm);
}

.btn-icon:hover {
  background: var(--color-surface);
}

.btn-send {
  background: var(--color-primary);
  color: #fff;
  border: none;
  min-width: auto;
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--radius-sm);
}

.btn-send:hover {
  background: var(--color-primary-hover);
}

/* --- Panel (generic centered card) --- */
.panel {
  background: var(--color-surface-light);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-xl);
  max-width: 640px;
  width: 90%;
  box-shadow: var(--shadow-lg);
}

.panel h2 {
  font-family: var(--font-title);
  color: var(--color-accent-gold);
  margin-bottom: var(--space-lg);
  text-align: center;
}

/* --- Form --- */
.form-group {
  margin-bottom: var(--space-md);
}

.form-group label {
  display: block;
  margin-bottom: var(--space-xs);
  color: var(--color-text-dim);
  font-size: 0.9rem;
}

.form-group input[type="range"] {
  width: 100%;
  accent-color: var(--color-primary);
}

.form-group input[type="number"] {
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  color: var(--color-text);
  padding: var(--space-sm);
  border-radius: var(--radius-sm);
  width: 100%;
  font-size: 1rem;
}

/* --- Player Profile Section --- */
.player-profile-section {
  margin-bottom: var(--space-md);
}

.section-heading {
  color: var(--color-accent-gold);
  font-size: 1.1rem;
  margin-bottom: var(--space-md);
  padding-bottom: var(--space-xs);
  border-bottom: 1px solid var(--color-border);
}

.section-divider {
  border-top: 1px solid var(--color-border);
  margin: var(--space-lg) 0;
}

.required {
  color: var(--color-primary);
  font-size: 0.8rem;
  margin-left: var(--space-xs);
}

.radio-group {
  display: flex;
  gap: var(--space-md);
}

.radio-label {
  display: flex !important;
  align-items: center;
  gap: var(--space-xs);
  color: var(--color-text) !important;
  cursor: pointer;
  font-size: 0.95rem !important;
}

.radio-label input[type="radio"] {
  accent-color: var(--color-primary);
  cursor: pointer;
}

.select-input {
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  color: var(--color-text);
  padding: var(--space-sm);
  border-radius: var(--radius-sm);
  width: 100%;
  font-size: 1rem;
  cursor: pointer;
}

.icon-presets {
  display: flex;
  gap: var(--space-sm);
  flex-wrap: wrap;
}

.icon-preset-btn {
  width: 48px;
  height: 48px;
  font-size: 1.4rem;
  background: var(--color-bg);
  border: 2px solid var(--color-border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: border-color 0.2s, transform 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.icon-preset-btn:hover {
  border-color: var(--color-secondary);
  transform: scale(1.1);
}

.icon-preset-btn.selected {
  border-color: var(--color-accent-gold);
  background: rgba(212, 168, 67, 0.15);
  box-shadow: 0 0 8px rgba(212, 168, 67, 0.3);
}

/* アイコンプリセット: 画像表示、絵文字フォールバック非表示（layout-v2.cssで上書き） */

/* --- Player Icon in Dialogue --- */
.player-icon-emoji {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  background: var(--color-surface);
  border-radius: 50%;
}

/* --- Inventory Modal --- */
.modal-inventory {
  max-width: 400px;
}

.modal-error {
  max-width: 420px;
  border-top: 3px solid var(--color-danger);
}

.modal-error h3 {
  color: var(--color-danger);
}

.modal-error p {
  color: var(--color-text);
  line-height: 1.6;
  margin-bottom: var(--space-md);
  word-break: break-word;
}

.inventory-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  margin-bottom: var(--space-md);
  max-height: 400px;
  overflow-y: auto;
}

.inventory-item {
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: var(--space-sm) var(--space-md);
  color: var(--color-text);
  font-size: 0.95rem;
}

.inventory-item::before {
  content: '📦 ';
}

.inventory-empty {
  text-align: center;
  color: var(--color-text-dim);
  padding: var(--space-lg);
}

/* --- Navigation Buttons --- */
.nav-buttons {
  display: flex;
  justify-content: space-between;
  margin-top: var(--space-lg);
  gap: var(--space-md);
}

/* --- Scenario Panel --- */
.scenario-panel {
  max-width: 900px;
}

/* --- Scenario Controls (Filter + Sort) --- */
.scenario-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-sm);
  margin-bottom: var(--space-md);
  padding-bottom: var(--space-sm);
  border-bottom: 1px solid var(--color-border);
}

.scenario-filters {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-xs);
  flex: 1;
}

.filter-btn {
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  color: var(--color-text-dim);
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}

.filter-btn:hover {
  border-color: var(--color-accent-gold);
  color: var(--color-text);
}

.filter-btn.active {
  background: var(--color-accent-gold);
  border-color: var(--color-accent-gold);
  color: var(--color-text-dark);
  font-weight: bold;
}

.scenario-sort {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  font-size: 0.85rem;
  color: var(--color-text-dim);
}

.scenario-sort select {
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  color: var(--color-text);
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  cursor: pointer;
}

/* --- Scenario List (Grid) --- */
.scenario-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: var(--space-sm);
  margin-bottom: var(--space-md);
  max-height: 480px;
  overflow-y: auto;
  padding-right: var(--space-xs);
}

.scenario-item {
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-md);
  cursor: pointer;
  transition: border-color 0.2s, transform 0.15s;
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
}

.scenario-item:hover {
  border-color: var(--color-secondary-hover);
  transform: translateY(-1px);
}

.scenario-item.selected {
  border-color: var(--color-accent-gold);
  box-shadow: 0 0 8px rgba(212, 168, 67, 0.3);
}

.scenario-item.hidden {
  display: none;
}

.scenario-item .scenario-title {
  font-weight: bold;
  color: var(--color-text);
  font-size: 0.95rem;
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  flex-wrap: wrap;
}

.scenario-item .scenario-desc {
  font-size: 0.8rem;
  color: var(--color-text-dim);
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.scenario-item .scenario-meta {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  margin-top: auto;
  padding-top: var(--space-xs);
  border-top: 1px solid rgba(255,255,255,0.05);
}

.upload-area {
  border: 2px dashed var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-lg);
  text-align: center;
  color: var(--color-text-dim);
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
}

.upload-area:hover,
.upload-area.dragover {
  border-color: var(--color-accent-gold);
  background: rgba(212, 168, 67, 0.05);
}

.validation-result {
  margin-top: var(--space-md);
  padding: var(--space-md);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
}

.validation-result.success {
  background: rgba(39, 174, 96, 0.15);
  border: 1px solid var(--color-success);
  color: var(--color-success);
}

.validation-result.error {
  background: rgba(231, 76, 60, 0.15);
  border: 1px solid var(--color-danger);
  color: var(--color-danger);
}

.validation-result.warning {
  background: rgba(243, 156, 18, 0.15);
  border: 1px solid var(--color-warning);
  color: var(--color-warning);
}

.validation-result ul {
  margin: var(--space-sm) 0 0;
  padding-left: var(--space-lg);
}

.validation-result li {
  margin-bottom: var(--space-xs);
}

.validation-header {
  font-weight: bold;
  margin-bottom: var(--space-xs);
}

.scenario-badge {
  display: inline-block;
  font-size: 0.65rem;
  color: #fff;
  padding: 2px 8px;
  border-radius: 10px;
  vertical-align: middle;
  font-weight: bold;
  letter-spacing: 0.3px;
}

.scenario-badge.badge-builtin {
  background: var(--color-secondary);
}

.scenario-badge.badge-category {
  font-size: 0.65rem;
  padding: 2px 7px;
}

.badge-rpg { background: #2ecc71; }
.badge-cthulhu { background: #8e44ad; }
.badge-scp { background: #e67e22; }
.badge-horror { background: #c0392b; }
.badge-slice_of_life { background: #f39c12; color: var(--color-text-dark); }
.badge-dark_fantasy { background: #7f1d1d; }

.scenario-time-badge {
  display: inline-block;
  font-size: 0.7rem;
  padding: 2px 8px;
  border-radius: 10px;
  font-weight: bold;
}

.time-short { background: rgba(46, 204, 113, 0.2); color: #2ecc71; }
.time-medium { background: rgba(52, 152, 219, 0.2); color: #3498db; }
.time-long { background: rgba(231, 76, 60, 0.2); color: #e74c3c; }

.scenario-meta {
  font-size: 0.75rem;
  color: var(--color-text-dim);
}

/* --- Difficulty Badge --- */
.scenario-difficulty-badge {
  display: inline-block;
  font-size: 0.7rem;
  padding: 2px 8px;
  border-radius: 10px;
  font-weight: bold;
  margin-left: auto;
}

.difficulty-easy { background: rgba(46, 204, 113, 0.2); color: #2ecc71; }
.difficulty-normal { background: rgba(243, 156, 18, 0.2); color: #f39c12; }
.difficulty-hard { background: rgba(231, 76, 60, 0.2); color: #e74c3c; }

/* --- Text Input --- */
.text-input {
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  color: var(--color-text);
  padding: var(--space-sm);
  border-radius: var(--radius-sm);
  width: 100%;
  font-size: 0.9rem;
  font-family: var(--font-main);
}

.btn-small {
  min-width: auto;
  padding: var(--space-xs) var(--space-md);
  font-size: 0.85rem;
}

.llm-status {
  font-size: 0.85rem;
  margin-left: var(--space-sm);
}

.llm-status.ok { color: var(--color-success); }
.llm-status.error { color: var(--color-danger); }
.llm-status.testing { color: var(--color-text-dim); }

/* --- Party Cards --- */
.party-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: var(--space-md);
  margin-bottom: var(--space-md);
}

.character-card {
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-md);
  text-align: center;
}

.character-card .char-portrait {
  width: 100%;
  max-width: 150px;
  height: auto;
  border-radius: var(--radius-sm);
  margin-bottom: var(--space-sm);
  background: var(--color-bg-light);
  aspect-ratio: 2 / 3;
  object-fit: cover;
}

.character-card .char-name {
  font-family: var(--font-title);
  font-size: 1.1rem;
  color: var(--color-accent-gold);
}

.character-card .char-role {
  font-size: 0.85rem;
  color: var(--color-text-dim);
}

.character-card .char-speech {
  font-size: 0.8rem;
  color: var(--color-text-dim);
  margin-top: var(--space-sm);
  font-style: italic;
}

/* --- Play Screen --- */
.play-background {
  position: absolute;
  inset: 0;
  background-size: cover;
  background-position: center;
  filter: brightness(0.4);
  z-index: 0;
  transition: opacity 0.5s ease-in-out;
}
.play-background.bg-fade-out {
  opacity: 0;
}
.play-background.bg-fade-in {
  opacity: 1;
}

.play-layout {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  height: 100vh;
  padding: var(--space-md);
}

/* Objective Widget */
.objective-widget {
  background: var(--color-surface-light);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-sm) var(--space-md);
  margin-bottom: var(--space-sm);
}

.objective-label {
  font-size: 0.75rem;
  color: var(--color-accent-gold);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.objective-text {
  font-size: 0.95rem;
  margin: var(--space-xs) 0;
}

.progress-bar {
  height: 6px;
  background: var(--color-bg);
  border-radius: 3px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--color-primary), var(--color-accent-gold));
  border-radius: 3px;
  transition: width 0.5s ease;
}

/* Dialogue Area */
.dialogue-area {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-sm);
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.dialogue-bubble {
  display: flex;
  gap: var(--space-sm);
  max-width: 85%;
  animation: slideIn 0.3s ease;
}

.dialogue-bubble.player {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.dialogue-bubble .bubble-icon {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--color-surface);
  flex-shrink: 0;
  object-fit: cover;
}

.dialogue-bubble .bubble-content {
  background: var(--color-surface-light);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-sm) var(--space-md);
}

.dialogue-bubble.player .bubble-content {
  background: rgba(233, 69, 96, 0.2);
  border-color: rgba(233, 69, 96, 0.4);
}

.dialogue-bubble.gm .bubble-content {
  background: rgba(212, 168, 67, 0.15);
  border-color: rgba(212, 168, 67, 0.3);
}

.dialogue-bubble.npc .bubble-content {
  background: rgba(83, 137, 154, 0.2);
  border-color: rgba(83, 137, 154, 0.4);
}

.bubble-speaker {
  font-size: 0.75rem;
  color: var(--color-accent-gold);
  margin-bottom: 2px;
}

.bubble-text {
  font-size: 0.95rem;
  line-height: 1.5;
}

/* Typing Indicator */
.typing-indicator {
  opacity: 0.7;
}

.typing-dots {
  display: flex;
  gap: 2px;
  font-size: 1.5rem;
  line-height: 1;
  color: var(--color-text-dim);
}

.typing-dots span {
  animation: typingBounce 1.2s infinite;
}

.typing-dots span:nth-child(2) {
  animation-delay: 0.2s;
}

.typing-dots span:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes typingBounce {
  0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-4px); }
}

/* Turn Separator */
.turn-separator {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  margin: var(--space-sm) 0;
  color: var(--color-accent-gold);
  font-size: 0.8rem;
  opacity: 0.8;
  animation: slideIn 0.3s ease;
}

.turn-separator::before,
.turn-separator::after {
  content: '';
  flex: 1;
  height: 1px;
  background: linear-gradient(to right, transparent, var(--color-accent-gold), transparent);
}

.turn-separator span {
  white-space: nowrap;
}

/* Choice Panel */
.choice-panel {
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
  padding: var(--space-sm);
  background: var(--color-surface-light);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-sm);
}

.choice-btn {
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: var(--space-sm) var(--space-md);
  color: var(--color-text);
  cursor: pointer;
  text-align: left;
  font-size: 0.9rem;
  transition: border-color 0.2s, background 0.2s;
}

.choice-btn:hover {
  border-color: var(--color-accent-gold);
  background: rgba(212, 168, 67, 0.1);
}

/* Character Select Bar (個別会話) */
.character-select-bar {
  display: flex;
  gap: var(--space-xs);
  flex-wrap: wrap;
  padding: 0 var(--space-xs);
}

.char-select-btn {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 2px 10px;
  color: var(--color-text-dim);
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.2s;
  font-family: var(--font-main);
}

.char-select-btn:hover {
  background: var(--color-accent);
  color: var(--color-bg);
  border-color: var(--color-accent);
}

/* Debug Panel */
.debug-panel {
  position: absolute;
  top: 50px;
  right: var(--space-md);
  background: rgba(0, 0, 0, 0.9);
  border: 1px solid var(--color-accent);
  border-radius: var(--radius-md);
  padding: var(--space-sm) var(--space-md);
  z-index: 100;
  max-width: 360px;
  font-size: 0.75rem;
  color: var(--color-text);
}

.debug-title {
  font-weight: bold;
  color: var(--color-accent);
  margin-bottom: var(--space-xs);
  font-size: 0.85rem;
}

.debug-table {
  width: 100%;
  border-collapse: collapse;
}

.debug-table th,
.debug-table td {
  padding: 2px 6px;
  text-align: left;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.debug-table th {
  color: var(--color-text-dim);
  white-space: nowrap;
  width: 1%;
}

.debug-section {
  color: var(--color-accent) !important;
  padding-top: 6px;
  font-size: 0.8rem;
}

.debug-warn {
  color: #ff6b6b;
  font-weight: bold;
}

.debug-flags {
  word-break: break-all;
  font-family: monospace;
  font-size: 0.7rem;
}

/* Chat Input */
.chat-input-area {
  display: flex;
  gap: var(--space-sm);
}

.chat-input-area input {
  flex: 1;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: var(--space-sm) var(--space-md);
  color: var(--color-text);
  font-size: 1rem;
  font-family: var(--font-main);
}

.chat-input-area input::placeholder {
  color: var(--color-text-dim);
}

/* Play Toolbar */
.play-toolbar {
  position: absolute;
  top: var(--space-md);
  right: var(--space-md);
  display: flex;
  gap: var(--space-xs);
  z-index: 2;
}

/* --- Modal --- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal[hidden] {
  display: none;
}

.modal-content {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-xl);
  max-width: 480px;
  width: 90%;
  box-shadow: var(--shadow-lg);
}

.modal-content h3 {
  font-family: var(--font-title);
  color: var(--color-accent-gold);
  margin-bottom: var(--space-lg);
  text-align: center;
}

.modal-actions {
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
  margin-bottom: var(--space-lg);
}

/* --- Party Info Modal --- */
.modal-party {
  max-width: 640px;
  max-height: 85vh;
  overflow-y: auto;
}

.party-info-cards {
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
  margin-bottom: var(--space-lg);
}

.party-info-card {
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-md);
  display: flex;
  gap: var(--space-md);
}

.party-info-card .info-portrait {
  width: 80px;
  height: 120px;
  border-radius: var(--radius-sm);
  background: var(--color-bg-light);
  object-fit: cover;
  flex-shrink: 0;
}

.party-info-card .info-details {
  flex: 1;
  min-width: 0;
}

.party-info-card .info-name {
  font-family: var(--font-title);
  font-size: 1.1rem;
  color: var(--color-accent-gold);
}

.party-info-card .info-role {
  font-size: 0.85rem;
  color: var(--color-text-dim);
  margin-bottom: var(--space-xs);
}

.party-info-card .info-row {
  font-size: 0.8rem;
  color: var(--color-text);
  margin-top: var(--space-xs);
  line-height: 1.5;
}

.party-info-card .info-label {
  color: var(--color-text-dim);
  margin-right: var(--space-xs);
}

/* --- Ending Screen --- */
.ending-container {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100vh;
  text-align: center;
  padding: var(--space-xl);
}

.ending-title {
  font-family: var(--font-title);
  font-size: 2.5rem;
  color: var(--color-accent-gold);
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.6);
  margin-bottom: var(--space-lg);
  opacity: 0;
  animation: endingFadeIn 0.8s ease forwards;
  animation-delay: 0.3s;
}

.ending-summary {
  font-size: 1.1rem;
  max-width: 600px;
  line-height: 1.8;
  margin-bottom: var(--space-xl);
  opacity: 0;
  animation: endingFadeIn 0.8s ease forwards;
  animation-delay: 1.0s;
}

.ending-actions {
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
  opacity: 0;
  animation: endingFadeIn 0.8s ease forwards;
  animation-delay: 2.0s;
}

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

/* --- Scrollbar --- */
::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--color-border);
  border-radius: 3px;
}

/* --- Animations --- */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

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

/* --- GM Narration (語り調) --- */
.dialogue-bubble.gm {
  justify-content: center;
  max-width: 90%;
  align-self: center;
}

.dialogue-bubble.gm .bubble-content {
  background: rgba(212, 168, 67, 0.08);
  border: none;
  border-left: 3px solid rgba(212, 168, 67, 0.4);
  font-style: italic;
  text-align: center;
}

/* --- Emotion Bubble Decorations --- */
.dialogue-bubble.emotion-happy .bubble-content { border-left: 3px solid #f1c40f; }
.dialogue-bubble.emotion-angry .bubble-content { border-left: 3px solid #e74c3c; }
.dialogue-bubble.emotion-sad .bubble-content { border-left: 3px solid #3498db; }
.dialogue-bubble.emotion-scared .bubble-content { border-left: 3px solid #9b59b6; }
.dialogue-bubble.emotion-surprised .bubble-content { border-left: 3px solid #e67e22; }

/* --- Autosave Indicator --- */
.autosave-indicator {
  position: fixed;
  bottom: 80px;
  right: var(--space-md);
  background: rgba(39, 174, 96, 0.9);
  color: #fff;
  padding: var(--space-xs) var(--space-md);
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  z-index: 200;
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.3s, transform 0.3s;
  pointer-events: none;
}

.autosave-indicator.visible {
  opacity: 1;
  transform: translateY(0);
}

/* --- Timeout Overlay --- */
.timeout-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 150;
}

.timeout-overlay[hidden] {
  display: none;
}

.timeout-content {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-xl);
  text-align: center;
  box-shadow: var(--shadow-lg);
}

.timeout-content p {
  margin-bottom: var(--space-lg);
  font-size: 1.1rem;
}

.timeout-actions {
  display: flex;
  gap: var(--space-md);
  justify-content: center;
}

/* --- Ending Fade Overlay --- */
.ending-fade-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  z-index: 100;
  transition: opacity 2.2s ease-in;
}

.ending-fade-overlay.fade-white {
  background: #fff;
}

.ending-fade-overlay.fade-black {
  background: #000;
}

.ending-fade-overlay.active {
  opacity: 1;
  pointer-events: all;
}

/* --- Replay Bar --- */
.replay-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-sm) var(--space-md);
  background: rgba(212, 168, 67, 0.15);
  border-top: 1px solid rgba(212, 168, 67, 0.3);
}

.replay-bar-label {
  color: var(--color-accent);
  font-style: italic;
  font-size: 0.95rem;
}

.replay-bar[hidden] {
  display: none;
}

/* --- Mis-choice Warning Flash --- */
.mis-warn-1 {
  animation: misFlash1 1s ease;
}
.mis-warn-2 {
  animation: misFlash2 1s ease;
}
.mis-warn-3 {
  animation: misFlash3 1s ease;
}

@keyframes misFlash1 {
  0%, 100% { box-shadow: none; }
  50% { box-shadow: inset 0 0 30px rgba(255, 200, 0, 0.3); }
}
@keyframes misFlash2 {
  0%, 100% { box-shadow: none; }
  50% { box-shadow: inset 0 0 40px rgba(255, 120, 0, 0.4); }
}
@keyframes misFlash3 {
  0%, 100% { box-shadow: none; }
  50% { box-shadow: inset 0 0 50px rgba(255, 0, 0, 0.5); }
}

/* --- Beat Transition Overlay --- */
.beat-transition-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 120;
  opacity: 0;
  transition: opacity 0.5s ease;
  pointer-events: none;
}

.beat-transition-overlay[hidden] {
  display: none;
}

.beat-transition-overlay.active {
  opacity: 1;
  pointer-events: all;
}

.beat-transition-content {
  text-align: center;
  animation: beatSlideIn 0.5s ease;
}

.beat-transition-name {
  font-family: var(--font-title);
  font-size: 2rem;
  color: var(--color-accent-gold);
  text-shadow: 0 2px 12px rgba(212, 168, 67, 0.5);
  margin-bottom: var(--space-md);
}

.beat-transition-objective {
  font-size: 1rem;
  color: var(--color-text);
  opacity: 0.85;
}

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

/* --- Tutorial Badge --- */
.badge-tutorial { background: #1abc9c; }

/* --- Help Guide Modal --- */
.modal-help {
  max-width: 580px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
}

.modal-help h3 {
  flex-shrink: 0;
}

.help-scroll {
  flex: 1;
  overflow-y: auto;
  margin-bottom: var(--space-md);
  padding-right: var(--space-xs);
}

.help-section {
  margin-bottom: var(--space-lg);
}

.help-section h4 {
  font-size: 1rem;
  color: var(--color-accent-gold);
  border-bottom: 1px solid var(--color-border);
  padding-bottom: var(--space-xs);
  margin-bottom: var(--space-sm);
}

.help-list {
  display: grid;
  gap: var(--space-sm);
}

.help-list dt {
  font-weight: bold;
  font-size: 0.9rem;
  color: var(--color-text);
  padding: 2px 0;
}

.help-list dd {
  font-size: 0.85rem;
  color: var(--color-text-dim);
  line-height: 1.6;
  margin-bottom: var(--space-xs);
  padding-left: var(--space-md);
}

/* Help sample visual markers */
.help-sample {
  padding-left: var(--space-sm);
  border-left: 3px solid transparent;
}

.help-sample-objective {
  border-left-color: var(--color-accent-gold);
}

.help-sample-gm {
  border-left-color: rgba(212, 168, 67, 0.4);
  font-style: italic;
}

.help-sample-player {
  border-left-color: rgba(233, 69, 96, 0.6);
}

.help-sample-char {
  border-left-color: var(--color-secondary);
}

.help-sample-npc {
  border-left-color: rgba(83, 137, 154, 0.6);
}

.help-sample-mis1 {
  border-left-color: rgba(255, 200, 0, 0.7);
}

.help-sample-mis2 {
  border-left-color: rgba(255, 120, 0, 0.7);
}

.help-sample-mis3 {
  border-left-color: rgba(255, 0, 0, 0.7);
}

.help-tips {
  list-style: none;
  padding: 0;
}

.help-tips li {
  font-size: 0.85rem;
  color: var(--color-text-dim);
  line-height: 1.6;
  padding: var(--space-xs) 0 var(--space-xs) var(--space-md);
  position: relative;
}

.help-tips li::before {
  content: '💡';
  position: absolute;
  left: 0;
}

/* --- Theme Switcher --- */
.theme-switcher {
  position: fixed;
  bottom: 16px;
  left: 16px;
  z-index: 300;
}

.theme-switcher-toggle {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s, box-shadow 0.2s;
  box-shadow: var(--shadow-md);
}

.theme-switcher-toggle:hover {
  transform: scale(1.1);
  box-shadow: var(--shadow-lg);
}

.theme-switcher.open .theme-switcher-toggle {
  transform: rotate(180deg);
}

.theme-switcher-icon {
  font-size: 1.3rem;
  line-height: 1;
}

.theme-switcher-menu {
  position: absolute;
  bottom: 50px;
  left: 0;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  min-width: 200px;
  overflow: hidden;
  animation: themeMenuIn 0.15s ease;
}

.theme-switcher-menu[hidden] {
  display: none;
}

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

.theme-option {
  display: flex;
  flex-direction: column;
  width: 100%;
  padding: 10px 14px;
  border: none;
  background: transparent;
  color: var(--color-text);
  cursor: pointer;
  text-align: left;
  transition: background 0.12s;
  font-family: var(--font-main);
  font-size: 0.9rem;
}

.theme-option:hover {
  background: rgba(255, 255, 255, 0.06);
}

.theme-option.active {
  background: rgba(212, 168, 67, 0.12);
}

.theme-option.active .theme-option-name::after {
  content: ' ✓';
  color: var(--color-accent-gold);
  font-size: 0.8rem;
}

.theme-option-name {
  font-weight: 600;
  font-size: 0.88rem;
}

.theme-option-desc {
  font-size: 0.72rem;
  color: var(--color-text-dim);
  margin-top: 1px;
}

.theme-option + .theme-option {
  border-top: 1px solid rgba(255, 255, 255, 0.05);
}

/* --- Theme Switcher Sections --- */
.theme-switcher-section {
  padding: 8px 14px 6px;
}

.theme-switcher-section-label {
  font-size: 0.7rem;
  color: var(--color-text-dim);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 6px 14px 4px;
  font-weight: 600;
}

.theme-switcher-divider {
  height: 1px;
  background: rgba(255, 255, 255, 0.08);
  margin: 4px 0;
}

/* --- Responsive --- */
@media (max-width: 768px) {
  .game-title { font-size: 2rem; }
  .panel { padding: var(--space-md); }
  .party-cards { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
}
