/* ==========================================================================
   台本ビューア (Script Viewer) - Clean & Optimized Stylesheet
   Fonts: BIZ UDPMincho (本文) & BIZ UDPGothic (UI / 発言者 400)
   ========================================================================== */

:root {
  --bg-surface: #ffffff;
  --bg-subtle: #f8fafc;
  --bg-container: #f1f5f9;
  --bg-high: #e2e8f0;
  
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-direction: #64748b;
  --border-line: #0f172a;
  --border-subtle: #cbd5e1;
  
  --highlight-bg: #fef9c3;
  --highlight-speaker: #fef08a;
  --highlight-accent: #ca8a04;
  --highlight-text: #713f12;
  
  --font-size-script: 18px;
  --line-height-script: 1.85;
  --speaker-height: 110px;
  --top-bar-height: 48px;
  
  --font-family-mincho: 'BIZ UDPMincho', 'BIZ UDP明朝', 'BIZ UDMincho', serif;
  --font-family-gothic: 'BIZ UDPGothic', 'BIZ UDPゴシック', 'BIZ UDGothic', sans-serif;
}

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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: var(--bg-surface);
  color: var(--text-primary);
  font-family: var(--font-family-mincho);
  font-size: 16px;
  user-select: none;
  -webkit-user-select: none;
}

/* 縦中横 (直立数字) */
.tcy {
  text-combine-upright: all;
  -webkit-text-combine: horizontal;
  display: inline;
  font-feature-settings: "pkna" 1;
  letter-spacing: 0;
  margin: 1px 0;
}

/* App Container */
.app-container {
  display: flex;
  flex-direction: column;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background-color: var(--bg-surface);
  position: relative;
}

/* Top App Bar */
.top-nav-bar {
  height: var(--top-bar-height);
  min-height: var(--top-bar-height);
  background-color: var(--bg-surface);
  border-bottom: 1px solid var(--bg-high);
  display: flex;
  align-items: center;
  padding: 0 12px;
  gap: 10px;
  z-index: 25;
  font-family: var(--font-family-gothic);
}

/* 場面バッジ (Fixed) */
.scene-badge-fixed {
  display: inline-block;
  height: 32px;
  line-height: 32px;
  padding: 0 14px;
  background: var(--text-primary);
  color: #ffffff;
  border-radius: 16px;
  font-size: 0.8rem;
  font-weight: 700;
  white-space: nowrap;
  flex-shrink: 0;
  max-width: 150px;
  overflow: hidden;
  text-overflow: ellipsis;
  vertical-align: middle;
  text-align: center;
}

/* 録音シーン一覧 (ミニマップ) */
.scene-minimap-container {
  flex: 1;
  height: 100%;
  display: flex;
  align-items: center;
  overflow-x: auto;
  overflow-y: hidden;
  direction: rtl;
  scrollbar-width: thin;
  scrollbar-color: var(--border-subtle) transparent;
  padding: 0 4px;
}

.scene-minimap-container::-webkit-scrollbar {
  display: block;
  height: 3px;
}
.scene-minimap-container::-webkit-scrollbar-thumb {
  background: var(--border-subtle);
  border-radius: 3px;
}

.minimap-strip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 100%;
  padding: 0 4px;
}

/* ミニマップ チップ */
.minimap-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  height: 30px;
  min-width: 32px;
  padding: 0 10px;
  border-radius: 8px;
  background-color: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  font-size: 0.76rem;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  direction: ltr;
}

.minimap-chip:hover {
  background-color: var(--bg-container);
}

/* 特殊シーン（RAP/Song等）の通常表示 */
.minimap-chip.is-special {
  border-color: #fecdd3;
  color: #be123c;
  background-color: #fff1f2;
}

/* 選択キャラクターが登場するシーン（数字・特殊シーン共通） */
.minimap-chip.is-char-active {
  background-color: var(--highlight-speaker);
  border-color: var(--highlight-accent);
  color: var(--highlight-text);
  font-weight: 700;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}
.minimap-chip.is-char-active::before {
  content: '●';
  font-size: 0.45rem;
  color: var(--highlight-accent);
}

/* 現在表示中の録音シーン（数字・特殊シーン共通でアクティブ強調） */
.minimap-chip.is-current,
.minimap-chip.is-special.is-current {
  background-color: var(--text-primary);
  border-color: var(--text-primary);
  color: #ffffff;
  font-weight: 700;
}

.minimap-chip.is-char-active.is-current,
.minimap-chip.is-special.is-char-active.is-current {
  background-color: var(--highlight-accent);
  border-color: #a16207;
  color: #ffffff;
}
.minimap-chip.is-char-active.is-current::before,
.minimap-chip.is-special.is-char-active.is-current::before {
  color: var(--highlight-speaker);
}

/* Floating Character Button */
.floating-char-btn {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 50;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  background: #ffffff;
  color: var(--text-primary);
  border: 1px solid var(--border-subtle);
  border-radius: 16px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
  font-size: 0.86rem;
  font-weight: 700;
  cursor: pointer;
  font-family: var(--font-family-gothic);
}

.floating-char-btn:hover {
  background: var(--bg-subtle);
}

.floating-char-btn.is-filtering {
  background: var(--highlight-speaker);
  color: var(--highlight-text);
  border-color: var(--highlight-accent);
}

/* Main Viewport */
.script-stage {
  flex: 1;
  position: relative;
  overflow: hidden;
  background-color: var(--bg-surface);
  height: calc(100% - var(--top-bar-height));
}

.script-viewport {
  width: 100%;
  height: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  direction: rtl;
  display: block;
}

.script-flow {
  display: inline-flex;
  flex-direction: row;
  height: 100%;
  width: max-content;
  min-width: 100%;
  direction: rtl;
  padding: 0 16px;
  align-items: stretch;
  user-select: text;
  -webkit-user-select: text;
}

.loading-state {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  width: 100%;
  min-width: 300px;
  color: var(--text-secondary);
  direction: ltr;
}

/* Headings */
.scene-major-heading {
  display: flex;
  align-items: center;
  justify-content: center;
  height: calc(100% - 16px);
  margin: 8px 14px 8px 18px;
  padding: 18px 12px;
  background: var(--text-primary);
  color: #ffffff;
  border-radius: 8px;
  writing-mode: vertical-rl;
  -webkit-writing-mode: vertical-rl;
  direction: ltr;
  unicode-bidi: isolate;
  letter-spacing: 0.22em;
  font-family: var(--font-family-mincho);
  font-size: calc(var(--font-size-script) * 1.15);
  font-weight: 700;
  white-space: nowrap;
  cursor: default;
  flex-shrink: 0;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.12);
}

.rec-scene-heading {
  display: flex;
  align-items: center;
  justify-content: center;
  height: calc(100% - 16px);
  margin: 8px 8px 8px 42px;
  padding: 8px 8px;
  background: var(--bg-subtle);
  color: var(--text-secondary);
  border-right: 1.5px solid var(--border-subtle);
  border-left: 1.5px solid var(--border-subtle);
  border-radius: 6px;
  writing-mode: vertical-rl;
  -webkit-writing-mode: vertical-rl;
  direction: ltr;
  unicode-bidi: isolate;
  letter-spacing: 0.12em;
  font-family: var(--font-family-mincho);
  font-size: calc(var(--font-size-script) * 0.9);
  font-weight: 700;
  white-space: nowrap;
  cursor: default;
  flex-shrink: 0;
}

.rec-scene-heading.is-special {
  color: #be123c;
  border-color: #fca5a5;
  background-color: #fff1f2;
}

/* Script Column */
.script-column {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  height: 100%;
  margin: 0 1px;
  padding: 0;
  width: max-content;
  min-width: max-content;
  flex-shrink: 0;
}

/* 1. Upper Box: Speaker */
.speaker-box {
  height: var(--speaker-height);
  min-height: var(--speaker-height);
  max-height: var(--speaker-height);
  width: 100%;
  padding: 8px 2.5px 4px 2.5px;
  position: relative;
  writing-mode: vertical-rl;
  -webkit-writing-mode: vertical-rl;
  direction: ltr;
  unicode-bidi: isolate;
  font-family: var(--font-family-gothic);
  font-weight: 400;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  align-items: flex-start;
  overflow: visible;
  white-space: pre-wrap;
  word-break: break-all;
  flex-shrink: 0;
}

.speaker-box::after {
  content: '';
  position: absolute;
  bottom: 0;
  right: 3.5px;
  left: 3.5px;
  height: 1.5px;
  background-color: var(--border-line);
}

.speaker-item {
  font-family: var(--font-family-gothic);
  font-weight: 400;
  font-size: calc(var(--font-size-script) * 0.92);
  line-height: 1.3;
  letter-spacing: 0.08em;
  color: var(--text-primary);
  display: inline-block;
  white-space: nowrap;
}

.speaker-item + .speaker-item {
  margin-right: 4px;
}

/* 2. Lower Box: Dialogue */
.dialogue-box {
  flex: 1;
  height: calc(100% - var(--speaker-height));
  width: max-content;
  padding: 10px 2.5px 12px 2.5px;
  font-family: var(--font-family-mincho);
  font-size: var(--font-size-script);
  line-height: var(--line-height-script);
  letter-spacing: 0.06em;
  color: var(--text-primary);
  writing-mode: vertical-rl;
  -webkit-writing-mode: vertical-rl;
  direction: ltr;
  unicode-bidi: isolate;
  overflow: visible;
  word-break: break-all;
  white-space: pre-wrap;
  display: block;
}

/* Action Notes in Dialogue */
.dialogue-action-note {
  display: inline;
  font-size: 0.74em;
  color: #4b5563;
  background-color: #f1f3f7;
  border: 1px solid #d9dce3;
  border-radius: 4px;
  padding: 3px 3px;
  margin: 6px 1px;
  line-height: 1.35;
  letter-spacing: 0.04em;
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
}

.script-column.is-highlighted .dialogue-action-note {
  background-color: rgba(0, 0, 0, 0.045);
  border-color: rgba(0, 0, 0, 0.09);
  color: #64748b;
}

/* Non-speaker rows */
.script-column.is-no-speaker .speaker-box::after {
  background-color: var(--border-line);
}

.script-column.is-no-speaker .dialogue-box {
  color: var(--text-direction);
  font-size: calc(var(--font-size-script) * 0.93);
  letter-spacing: 0.09em;
  opacity: 0.88;
}

/* Highlighted Column */
.script-column.is-highlighted {
  background-color: var(--highlight-bg);
  border-radius: 4px;
}
.script-column.is-highlighted .speaker-box {
  background-color: var(--highlight-speaker);
  border-radius: 4px 4px 0 0;
}

/* Modal Dialog */
.modal-backdrop {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  background: rgba(15, 23, 42, 0.6);
  z-index: 100;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  font-family: var(--font-family-gothic);
}

.modal-backdrop.is-active {
  display: flex;
}

.modal-card {
  width: 100%;
  max-width: 440px;
  max-height: 85vh;
  background: var(--bg-surface);
  border-radius: 20px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  font-family: var(--font-family-gothic);
}

.modal-header {
  padding: 20px 24px 14px 24px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
}

.app-branding-title {
  font-size: 1.3rem;
  font-weight: 800;
  color: var(--text-primary);
}

.app-branding-subtitle {
  font-size: 0.82rem;
  color: var(--text-secondary);
  margin-top: 2px;
}

.modal-close-btn {
  background: var(--bg-container);
  border: none;
  font-size: 1.2rem;
  line-height: 1;
  color: var(--text-secondary);
  cursor: pointer;
  width: 32px;
  height: 32px;
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-body {
  flex: 1;
  overflow-y: auto;
  padding: 8px 24px 16px 24px;
}

.character-badges-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

.char-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  font-size: 0.88rem;
  font-family: var(--font-family-gothic);
  cursor: pointer;
  background: var(--bg-surface);
  color: var(--text-primary);
}

.char-badge:hover {
  background-color: var(--bg-container);
}

.char-badge.is-selected {
  border-color: var(--highlight-accent);
  background-color: var(--highlight-speaker);
  color: #854d0e;
  font-weight: 700;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
}

.char-count {
  font-size: 0.72rem;
  color: var(--text-direction);
  background: rgba(0, 0, 0, 0.06);
  padding: 2px 6px;
  border-radius: 8px;
}

.modal-footer {
  padding: 16px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: var(--bg-surface);
  border-top: 1px solid var(--bg-high);
}

.btn-secondary {
  background: transparent;
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  font-size: 0.86rem;
  font-weight: 600;
  font-family: var(--font-family-gothic);
  padding: 9px 16px;
  border-radius: 16px;
  cursor: pointer;
}

.btn-primary {
  flex: 1;
  background: var(--text-primary);
  border: none;
  color: #ffffff;
  font-size: 0.88rem;
  font-weight: 700;
  font-family: var(--font-family-gothic);
  padding: 10px 18px;
  border-radius: 16px;
  cursor: pointer;
  text-align: center;
}

/* Mobile Tweaks */
@media (max-width: 600px) {
  :root {
    --font-size-script: 16px;
    --speaker-height: 100px;
    --top-bar-height: 44px;
  }

  .script-column {
    margin: 0 1px;
  }

  .rec-scene-heading {
    margin-right: 27px;
    margin-left: 6px;
    padding: 8px 5px;
  }

  .speaker-box {
    padding: 6px 2px 4px 2px;
  }

  .speaker-box::after {
    right: 2.5px;
    left: 2.5px;
  }

  .dialogue-box {
    padding: 8px 2px 10px 2px;
  }

  .dialogue-action-note {
    font-size: 0.72em;
    padding: 2px 2px;
    margin: 4px 1px;
  }

  .scene-badge-fixed {
    max-width: 110px;
    font-size: 0.72rem;
    padding: 0 10px;
  }

  .floating-char-btn {
    bottom: 16px;
    right: 16px;
    padding: 8px 14px;
    font-size: 0.8rem;
    border-radius: 12px;
  }
}
