:root {
  --bg-main: #030712;
  --bg-surface: #020617;
  --bg-surface-alt: #020617;
  --bg-elevated: #0b1120;
  --border-subtle: #1f2937;
  --border-strong: #4b5563;

  --text-main: #e5e7eb;
  --text-muted: #9ca3af;
  --text-soft: #6b7280;
  --accent: #3b82f6;
  --accent-soft: #1d4ed8;
  --accent-border: #2563eb;
  --accent-bg-soft: rgba(37, 99, 235, 0.1);
  --danger: #ef4444;

  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 10px;

  --shadow-soft: 0 12px 40px rgba(0, 0, 0, 0.55);
  --shadow-subtle: 0 1px 2px rgba(15, 23, 42, 0.6);
  --sidebar-width: 270px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text-main);
  background: var(--bg-main);
}

body {
  -webkit-font-smoothing: antialiased;
}

/* 共通 UI パーツ -------------------------------------------------------- */

.hidden {
  display: none !important;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.45rem 0.9rem;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: #111827;
  color: var(--text-main);
  font-size: 0.85rem;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease,
    box-shadow 0.15s ease, transform 0.05s ease;
}

.btn.primary {
  background: var(--accent-soft);
  border-color: var(--accent-border);
}

.btn.primary:hover {
  background: #1e40af;
  border-color: #1d4ed8;
}

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

.btn.secondary:hover {
  background: #1f2937;
}

.btn.subtle {
  background: transparent;
  border-color: var(--border-subtle);
}

.btn.subtle:hover {
  background: #111827;
}

.btn.danger {
  border-color: rgba(248, 113, 113, 0.7);
  color: #fecaca;
}

.btn.danger:hover {
  background: rgba(248, 113, 113, 0.1);
}

.btn.small {
  font-size: 0.78rem;
  padding: 0.3rem 0.6rem;
}

.btn.block {
  width: 100%;
  justify-content: center;
}

.btn.tiny {
  font-size: 0.7rem;
  padding: 0.2rem 0.45rem;
}

.btn:active {
  transform: translateY(1px);
}

/* フィールド */

.field {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.field-label {
  font-size: 0.78rem;
  color: var(--text-soft);
}

.field input,
.field textarea,
.field select {
  padding: 0.40rem 0.55rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
  background: #020617;
  color: var(--text-main);
  font-size: 0.84rem;
}

.field input:focus,
.field textarea:focus,
.field select:focus {
  outline: 1px solid var(--accent);
  border-color: var(--accent-border);
}

/* トースト */

.toast {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  padding: 0.65rem 1.1rem;
  border-radius: 999px;
  background: #111827;
  border: 1px solid var(--border-subtle);
  color: var(--text-main);
  font-size: 0.8rem;
  box-shadow: var(--shadow-soft);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 80;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, -4px);
}

.toast.hidden {
  display: none;
}

/* 認証ビュー ------------------------------------------------------------ */

.auth-view {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: radial-gradient(circle at top left, #111827 0, #020617 40%, #020617 100%);
}

.auth-header {
  padding: 1.5rem 2rem 0.5rem;
}

.auth-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.brand-mark {
  width: 32px;
  height: 32px;
  border-radius: 10px;
  background: #111827;
  border: 1px solid #374151;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  letter-spacing: 0.06em;
  color: var(--accent);
}

.brand-text {
  display: flex;
  flex-direction: column;
}

.brand-title {
  font-weight: 600;
  font-size: 1.1rem;
}

.brand-sub {
  font-size: 0.8rem;
  color: var(--text-soft);
}

.auth-main {
  flex: 1;
  padding: 1rem 2rem 2rem;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
}

.auth-card {
  background: #020617;
  border-radius: var(--radius-lg);
  padding: 1.5rem 1.7rem;
  box-shadow: var(--shadow-soft);
  border: 1px solid #111827;
}

.auth-card-title {
  margin: 0 0 1rem;
  font-size: 1rem;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.auth-error {
  min-height: 1.1rem;
  font-size: 0.78rem;
  color: #fecaca;
}

.auth-footer {
  padding: 0.75rem 2rem 1.2rem;
  font-size: 0.75rem;
  color: var(--text-soft);
}

/* アプリシェル ---------------------------------------------------------- */

.app-view {
  height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  height: 48px;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0 0.9rem;
  border-bottom: 1px solid #111827;
  background: #020617;
}

.topbar-logo {
  width: 22px;
  height: 22px;
  border-radius: 7px;
  border: 1px solid #374151;
  background: #020617;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  letter-spacing: 0.08em;
  color: var(--accent);
}

.topbar-title {
  font-size: 0.95rem;
  font-weight: 600;
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.topbar-spacer {
  flex: 1;
}

.topbar-user {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.topbar-user-text {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}

.topbar-user-name {
  font-size: 0.82rem;
}

.topbar-user-email {
  font-size: 0.75rem;
  color: var(--text-soft);
}

.topbar-icon-button {
  display: none;
  border: none;
  background: transparent;
  color: var(--text-main);
  font-size: 1.1rem;
  cursor: pointer;
}

/* サイドバー + メイン -------------------------------------------------- */

.app-shell {
  flex: 1;
  display: flex;
  min-height: 0;
}

.sidebar {
  width: var(--sidebar-width);
  border-right: 1px solid #111827;
  background: #020617;
  padding: 0.75rem 0.75rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.sidebar-section-header {
  padding-bottom: 0.25rem;
  border-bottom: 1px solid #111827;
}

.sidebar-app-name {
  font-size: 0.88rem;
  font-weight: 600;
}

.sidebar-caption {
  font-size: 0.78rem;
  color: var(--text-soft);
  margin-top: 0.15rem;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.nav-main-item {
  text-align: left;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  padding: 0.4rem 0.55rem;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.8rem;
  cursor: pointer;
}

.nav-main-item.active {
  background: #111827;
  border-color: #1e293b;
  color: var(--text-main);
}

.nav-main-item:hover {
  background: #020617;
  border-color: #1f2937;
}

.sidebar-section {
  font-size: 0.8rem;
}

.sidebar-label {
  font-size: 0.75rem;
  color: var(--text-soft);
  margin-bottom: 0.25rem;
}

.sidebar-current-title {
  font-size: 0.85rem;
}

.sidebar-current-meta {
  font-size: 0.75rem;
  color: var(--text-soft);
}

.sidebar-project-list {
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.project-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 100%;
  overflow-y: auto;
}

.project-item {
  padding: 0.35rem 0.45rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.project-item:hover {
  background: #020617;
}

.project-item.active {
  background: #111827;
}

.project-item-title {
  font-size: 0.82rem;
}

.project-item-meta {
  font-size: 0.72rem;
  color: var(--text-soft);
  margin-top: 0.1rem;
}

/* メインエリア */

.main {
  flex: 1;
  min-width: 0;
  padding: 0.9rem 1.1rem 1.1rem;
  overflow: auto;
}

.main-view {
  display: none;
}

.main-view.visible {
  display: block;
}

.page-title {
  margin: 0 0 0.9rem;
  font-size: 1.05rem;
}

/* ダッシュボード */

.metric-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.75rem;
}

.metric-card {
  background: #020617;
  border-radius: var(--radius-md);
  padding: 0.75rem 0.9rem;
  border: 1px solid #111827;
}

.metric-label {
  font-size: 0.75rem;
  color: var(--text-soft);
}

.metric-value {
  margin-top: 0.4rem;
  font-size: 1.15rem;
  font-weight: 600;
}

.metric-value-text {
  font-size: 0.9rem;
}

/* プロジェクトエディタ ------------------------------------------------ */

.project-editor {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.project-header {
  background: #020617;
  border-radius: var(--radius-md);
  padding: 0.75rem 0.9rem;
  border: 1px solid #111827;
}

.project-meta-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.75rem;
  color: var(--text-soft);
  margin-bottom: 0.45rem;
}

.project-header-grid {
  display: grid;
  grid-template-columns: 2.3fr 1.4fr 1.4fr;
  gap: 0.6rem;
}

.badge {
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  border: 1px solid var(--border-subtle);
  font-size: 0.7rem;
}

.badge-muted {
  background: #020617;
}

.project-updated {
  margin-left: auto;
}

.save-state {
  color: var(--text-soft);
}

.editor-tabs {
  margin-top: 0.75rem;
  display: inline-flex;
  gap: 0.25rem;
  background: #020617;
  border-radius: 999px;
  padding: 0.25rem;
  border: 1px solid #111827;
}

.editor-tab {
  border-radius: 999px;
  border: none;
  background: transparent;
  color: var(--text-soft);
  padding: 0.25rem 0.9rem;
  font-size: 0.78rem;
  cursor: pointer;
}

.editor-tab.active {
  background: #111827;
  color: var(--text-main);
}

.editor-tab-panel {
  margin-top: 0.75rem;
  display: none;
}

.editor-tab-panel.visible {
  display: block;
}

.panel-section {
  background: #020617;
  border-radius: var(--radius-md);
  padding: 0.75rem 0.9rem;
  border: 1px solid #111827;
  margin-bottom: 0.6rem;
}

.panel-header {
  margin-bottom: 0.5rem;
}

.panel-header-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.75rem;
}

.panel-title {
  margin: 0;
  font-size: 0.9rem;
}

.panel-title.small {
  font-size: 0.85rem;
}

.panel-help {
  margin: 0.25rem 0 0;
  font-size: 0.75rem;
  color: var(--text-soft);
}

.panel-actions {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.panel-textarea {
  width: 100%;
  min-height: 7rem;
  resize: vertical;
}

.panel-textarea.small {
  min-height: 4.2rem;
}

/* Plot board */

.plot-lanes {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.6rem;
}

.plot-lane {
  background: #020617;
  border-radius: var(--radius-md);
  border: 1px solid #111827;
  padding: 0.55rem 0.6rem 0.6rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.plot-lane-header {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.plot-lane-title {
  flex: 1;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
  background: #020617;
  color: var(--text-main);
  padding: 0.3rem 0.4rem;
  font-size: 0.82rem;
}

.plot-lane-desc {
  font-size: 0.74rem;
  color: var(--text-soft);
}

.plot-beats {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.plot-beat {
  border-radius: var(--radius-sm);
  border: 1px solid #111827;
  background: #020617;
  padding: 0.35rem 0.4rem 0.4rem;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.plot-beat-title {
  width: 100%;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
  background: #020617;
  padding: 0.25rem 0.35rem;
  font-size: 0.8rem;
  color: var(--text-main);
}

.plot-beat-summary {
  width: 100%;
  min-height: 3.5rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
  background: #020617;
  padding: 0.25rem 0.35rem;
  font-size: 0.78rem;
  color: var(--text-main);
  resize: vertical;
}

.plot-beat-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.35rem;
}

.plot-badge-type {
  font-size: 0.72rem;
  border-radius: 999px;
  padding: 0.18rem 0.5rem;
  border: 1px solid var(--accent-border);
  background: var(--accent-bg-soft);
  color: #bfdbfe;
}

.plot-beat-type-select {
  flex: 1;
  font-size: 0.75rem;
}

.plot-beat-delete {
  font-size: 0.72rem;
  background: transparent;
  border: none;
  color: #fca5a5;
  cursor: pointer;
}

/* Characters */

.characters-layout {
  display: grid;
  grid-template-columns: 230px minmax(0, 1fr);
  gap: 0.75rem;
}

.characters-list-pane,
.scenes-list-pane {
  background: #020617;
  border-radius: var(--radius-md);
  padding: 0.6rem 0.7rem;
  border: 1px solid #111827;
}

.characters-editor-pane,
.scenes-editor-pane {
  background: transparent;
  border-radius: var(--radius-md);
  padding: 0;
}

.character-list {
  list-style: none;
  padding: 0;
  margin: 0.4rem 0 0;
  max-height: calc(100vh - 210px);
  overflow-y: auto;
}

.character-row {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.35rem 0.35rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.character-row:hover {
  background: #020617;
}

.character-row.active {
  background: #111827;
}

.character-badge {
  width: 22px;
  height: 22px;
  border-radius: 999px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.78rem;
  color: white;
}

.character-row-main {
  display: flex;
  flex-direction: column;
}

.character-row-name {
  font-size: 0.82rem;
}

.character-row-role {
  font-size: 0.72rem;
  color: var(--text-soft);
}

.character-editor {
  background: #020617;
  border-radius: var(--radius-md);
  border: 1px solid #111827;
  padding: 0.7rem 0.8rem 0.8rem;
}

.character-header {
  display: grid;
  grid-template-columns: auto 1.6fr auto;
  gap: 0.7rem;
  align-items: start;
  margin-bottom: 0.5rem;
}

.character-avatar {
  width: 40px;
  height: 40px;
  border-radius: 999px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  font-weight: 600;
  color: white;
}

.character-header-main {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.character-header-side {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.character-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.5rem;
}

/* Scenes */

.scenes-layout {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  gap: 0.75rem;
}

.scene-list {
  list-style: none;
  margin: 0.4rem 0 0;
  padding: 0;
  max-height: calc(100vh - 210px);
  overflow-y: auto;
}

.scene-row {
  padding: 0.35rem 0.35rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.scene-row:hover {
  background: #020617;
}

.scene-row.active {
  background: #111827;
}

.scene-row-title {
  font-size: 0.82rem;
}

.scene-row-meta {
  font-size: 0.72rem;
  color: var(--text-soft);
}

.scene-editor {
  background: #020617;
  border-radius: var(--radius-md);
  border: 1px solid #111827;
  padding: 0.7rem 0.8rem 0.85rem;
}

.scene-header-grid {
  display: grid;
  grid-template-columns: 1.6fr 0.9fr 1.1fr 1.1fr;
  gap: 0.55rem;
  margin-bottom: 0.5rem;
}

/* Dialogue */

.scene-dialogue {
  margin-top: 0.6rem;
}

.dialogue-toolbar {
  display: grid;
  grid-template-columns: 0.9fr 3.1fr auto;
  gap: 0.4rem;
  margin-bottom: 0.5rem;
}

.dialogue-char-select {
  font-size: 0.8rem;
}

.dialogue-input {
  min-height: 3rem;
  resize: vertical;
}

.dialogue-list {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  max-height: calc(50vh - 140px);
  overflow-y: auto;
}

.dialogue-row {
  display: flex;
  gap: 0.5rem;
  align-items: flex-start;
}

.dialogue-avatar {
  width: 26px;
  height: 26px;
  border-radius: 999px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.78rem;
  color: white;
}

.dialogue-bubble {
  flex: 1;
  background: #020617;
  border-radius: 12px;
  border: 1px solid #111827;
  padding: 0.35rem 0.45rem 0.3rem;
}

.dialogue-meta {
  font-size: 0.72rem;
  color: var(--text-soft);
  margin-bottom: 0.1rem;
}

.dialogue-textarea {
  width: 100%;
  border-radius: 6px;
  border: 1px solid var(--border-subtle);
  background: transparent;
  color: var(--text-main);
  font-size: 0.8rem;
  resize: vertical;
  min-height: 2.4rem;
  padding: 0.25rem 0.3rem;
}

.dialogue-row-footer {
  display: flex;
  justify-content: flex-end;
  margin-top: 0.15rem;
}

.dialogue-delete-btn {
  background: transparent;
  border: none;
  color: #fca5a5;
  font-size: 0.72rem;
  cursor: pointer;
}

/* Notes / Settings */

.settings-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.5rem;
}

.account-panel {
  max-width: 420px;
}

/* Empty state */

.empty-state {
  padding: 1.2rem 1.3rem;
  border-radius: var(--radius-md);
  border: 1px dashed #4b5563;
  background: #020617;
  font-size: 0.82rem;
  color: var(--text-soft);
}

.empty-state.small {
  padding: 0.9rem 1rem;
}

/* textarea の右下 resize ハンドル削除 */
textarea {
  resize: none;
}

/* スクロールバーの下に変な余白が出ないようにする */
body, html {
  overflow-x: hidden;
}

/* main wrapper のズレ防止 */
.main-content {
  padding-bottom: 0 !important;
  margin-bottom: 0 !important;
}

/* レスポンシブ ---------------------------------------------------------- */

@media (max-width: 960px) {
  .auth-main {
    grid-template-columns: 1fr;
  }

  .auth-card {
    max-width: 460px;
    margin: 0 auto;
  }

  .topbar-icon-button {
    display: inline-flex;
  }

  .app-shell {
    position: relative;
  }

  .sidebar {
    position: fixed;
    inset: 48px auto 0 0;
    width: 250px;
    transform: translateX(-100%);
    transition: transform 0.18s ease;
    z-index: 60;
    box-shadow: var(--shadow-soft);
  }

  .sidebar.sidebar-open {
    transform: translateX(0);
  }

  .main {
    padding: 0.7rem 0.6rem 1rem;
  }

  .metric-grid {
    grid-template-columns: 1fr;
  }

  .project-header-grid {
    grid-template-columns: 1fr;
  }

  .plot-lanes {
    grid-template-columns: 1fr;
  }

  .characters-layout,
  .scenes-layout {
    grid-template-columns: 1fr;
  }

  .character-list,
  .scene-list {
    max-height: 260px;
  }

  .dialogue-toolbar {
    grid-template-columns: 1fr;
  }

  .scene-header-grid,
  .settings-grid {
    grid-template-columns: 1fr;
  }

  .editor-tabs {
    width: 100%;
    overflow-x: auto;
  }

  .editor-tab {
    white-space: nowrap;
  }
}

