:root {
  color-scheme: light dark;
  font-family: "Noto Sans JP", "Hiragino Kaku Gothic ProN", Meiryo, sans-serif;
  --primary-color: #2563eb;
  --secondary-color: #374151;
  --background-color: #f3f4f6;
  --card-background: #ffffffd9;
  --border-color: #d1d5db;
  --shadow-color: rgba(15, 23, 42, 0.1);
}

body {
  margin: 0;
  background: var(--background-color);
  color: #111827;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  height: 100vh;
  overflow: hidden;
}

.auth-overlay {
  position: fixed;
  inset: 0;
  background: radial-gradient(circle at top, rgba(37, 99, 235, 0.35), rgba(15, 23, 42, 0.85));
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 2rem;
  z-index: 1000;
  transition: opacity 0.3s ease;
}

.auth-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.auth-card {
  background: #0f172a;
  color: #f8fafc;
  border-radius: 24px;
  padding: 2.5rem;
  width: min(420px, 100%);
  box-shadow: 0 25px 50px rgba(15, 23, 42, 0.35);
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.auth-hero h1 {
  margin: 0 0 0.25rem;
  font-size: 1.6rem;
}

.auth-hero p {
  margin: 0;
  color: rgba(248, 250, 252, 0.8);
  font-size: 0.95rem;
}

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

.auth-form label {
  font-size: 0.85rem;
  color: rgba(248, 250, 252, 0.85);
}

.auth-form input {
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  padding: 0.85rem 1rem;
  background: rgba(15, 23, 42, 0.6);
  color: #f8fafc;
  font-size: 1rem;
}

.auth-form input:focus {
  outline: none;
  border-color: rgba(99, 102, 241, 0.8);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.35);
}

.auth-form button.large {
  width: 100%;
  padding: 0.9rem 1rem;
  font-size: 1rem;
}

.auth-hint {
  margin: 0.25rem 0 0;
  font-size: 0.85rem;
  color: rgba(248, 250, 252, 0.65);
}

.auth-error {
  min-height: 1.2rem;
  margin: 0;
  color: #fca5a5;
  font-size: 0.85rem;
}

body.resizing-x {
  cursor: col-resize;
  user-select: none;
}

body.resizing-y {
  cursor: row-resize;
  user-select: none;
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.5rem;
  background: linear-gradient(135deg, #1e3a8a, #2563eb);
  color: white;
  box-shadow: 0 2px 8px var(--shadow-color);
}

.toolbar h1 {
  margin: 0;
  font-size: 1.2rem;
}

.toolbar-buttons {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.toolbar-buttons button {
  margin-left: 0;
}

button {
  padding: 0.5rem 1rem;
  border-radius: 6px;
  border: 1px solid transparent;
  font-size: 0.95rem;
  cursor: pointer;
  transition: transform 0.1s ease, box-shadow 0.2s ease;
}

button.primary {
  background: #f9fafb;
  color: #1e3a8a;
  border-color: rgba(255, 255, 255, 0.4);
  font-weight: 600;
}

button.secondary {
  background: white;
  color: var(--secondary-color);
  border: 1px solid var(--border-color);
}

button.ghost {
  background: transparent;
  color: white;
  border-color: rgba(255, 255, 255, 0.4);
}

button:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 10px var(--shadow-color);
}

.hidden-control {
  display: none !important;
}

.username-pill {
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.2);
  font-weight: 600;
  min-width: 90px;
  text-align: center;
}

/* ===== ワークスペース：左右を flex で管理 ===== */

.workspace {
  flex: 1;
  display: flex;
  gap: 1rem;
  padding: 1rem 1.5rem 2rem;
  align-items: stretch;
  min-height: 0;
  overflow: hidden;
}

.left-pane,
.right-pane {
  border-radius: 16px;
  box-shadow: 0 4px 16px var(--shadow-color);
  padding: 1rem;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

.left-pane {
  background: var(--card-background);
  flex: 0 0 40%;
  min-width: 280px;
  min-height: 0;
}

.right-pane {
  background: #1e1e1e;
  color: #f9fafb;
  flex: 1 1 auto;
  gap: 1rem;
  min-width: 320px;
  min-height: 0;
}

/* 左右のスプリッター */

.splitter {
  background: #d1d5db;
  flex-shrink: 0;
}

.splitter.vertical {
  width: 6px;
  cursor: col-resize;
  border-radius: 999px;
}

/* 上下スプリッター（右ペイン内） */

.splitter.horizontal {
  width: 100%;
  height: 6px;
  cursor: row-resize;
  border-radius: 999px;
  background: #4b5563;
}

/* タブまわり */

.tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.tab {
  flex: 1;
  background: #e5e7eb;
  border: none;
  padding: 0.5rem 0.75rem;
  border-radius: 12px;
  font-weight: 600;
  color: #1f2937;
}

.tab.active {
  background: #2563eb;
  color: white;
}

.tab-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.tab-panel {
  display: none;
  height: 100%;
  min-height: 0;
  overflow: hidden;
}

.tab-panel.active {
  display: flex;
  flex-direction: column;
  flex: 1;
}

/* プロットエリア（left-paneいっぱいにフィットさせる） */

.plot-area {
  width: 100%;
  min-height: 320px;
  flex: 1;
}

#bokeh-plot {
  width: 100%;
  height: 100%;
}

/* Bokeh が吐く要素を left-pane にフィットさせる調整 */

#bokeh-plot .bk-root,
#bokeh-plot .bk-figure,
#bokeh-plot .bk-layout-fixed,
#bokeh-plot .bk-layout {
  width: 100% !important;
  height: 100% !important;
}

#bokeh-plot .bk-layer > div {
  top: 0 !important;
  bottom: 0 !important;
  height: 100% !important;
  right: 0 !important;
  left: auto !important;
}

#bokeh-plot .bk-Toolbar.bk-right {
  height: 100% !important;
}

/* ログ出力 */

.log-output {
  background: #111827;
  color: #f9fafb;
  padding: 0.75rem;
  border-radius: 8px;
  min-height: 3rem;
  overflow-x: auto;
}

.log-output.error {
  background: #7f1d1d;
  color: #fde8e8;
}

/* ===== モーダル ===== */

.modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.6);
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 2rem;
  z-index: 999;
  transition: opacity 0.2s ease;
}

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

.modal-content {
  background: white;
  border-radius: 16px;
  max-width: 720px;
  width: 100%;
  max-height: 90vh;
  overflow: auto;
  padding: 1.5rem;
  box-shadow: 0 20px 40px rgba(15, 23, 42, 0.2);
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.modal-content.wide {
  max-width: 960px;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

.modal-header h2 {
  margin: 0;
}

.icon-button {
  padding-left: 0.67rem;
  padding-top: 0.4rem;
  border-radius: 999px;
  width: 36px;
  height: 36px;
  border: 1px solid var(--border-color);
  background: white;
  font-size: 1.1rem;
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.history-entry {
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 1rem;
  background: rgba(243, 244, 246, 0.6);
}

.history-entry header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
}

.history-entry pre {
  background: #111827;
  color: #f9fafb;
  padding: 0.75rem;
  border-radius: 8px;
  overflow-x: auto;
}

.history-entry .history-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  font-size: 0.9rem;
  color: #374151;
}

.history-entry .history-label {
  margin: 0.5rem 0 0.25rem;
  font-weight: 600;
  font-size: 0.9rem;
  color: #1f2937;
}

.status-badge {
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
}

.status-badge.success {
  background: #ecfdf5;
  color: #047857;
}

.status-badge.fail {
  background: #fef2f2;
  color: #b91c1c;
}

/* 教材 */

.lesson-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
}

.lesson-controls button + button {
  margin-left: 0.5rem;
}

.lesson-content {
  line-height: 1.6;
  font-size: 0.95rem;
  color: #1f2937;
  overflow: auto;
  flex: 1 1 auto;
}

.lesson-content pre {
  background: #1f2937;
  color: #f3f4f6;
  padding: 0.75rem;
  border-radius: 8px;
  overflow-x: auto;
}

.lesson-content h2,
.lesson-content h3 {
  margin-top: 1.5rem;
}

.materials-list {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  overflow: auto;
}

.materials-list p {
  margin: 0;
  color: #4b5563;
}

.materials-list-items {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.materials-list-item {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1rem;
  border-radius: 12px;
  border: 1px solid var(--border-color);
  background: rgba(243, 244, 246, 0.8);
  color: inherit;
  font-size: 0.95rem;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.materials-list-item.current {
  border-color: var(--primary-color);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.2);
}

.materials-list-item:hover {
  border-color: var(--primary-color);
}

.materials-list-item .material-title {
  flex: 1;
  margin-right: 0.75rem;
  font-weight: 600;
}

.materials-list-item .material-status {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  border: 1px solid transparent;
}

.materials-list-item .material-status.lock {
  background: #fef2f2;
  color: #991b1b;
  border-color: rgba(185, 28, 28, 0.2);
}

.materials-list-item .material-status.unlock {
  background: #ecfdf5;
  color: #047857;
  border-color: rgba(16, 185, 129, 0.3);
}

/* エディタ・ログ（右ペイン内） */

.editor-toolbar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.editor-toolbar label {
  font-size: 0.9rem;
}

.editor-toolbar input[type="range"] {
  flex: 0 0 160px;
}

.editor-toolbar span {
  font-size: 0.9rem;
}

.editor-log-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.editor {
  border-radius: 12px;
  overflow: hidden;
  width: 100%;
  /* 初期高さは flex で決まるが、最低は確保 */
  min-height: 220px;
  flex: 1 1 auto;
}

.log-area {
  background: rgba(17, 24, 39, 0.85);
  padding: 1rem;
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  overflow: auto;
  min-height: 80px;
  flex: 0 0 160px; /* 初期高さ */
}

.log-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
}

.log-header h2 {
  margin: 0;
  font-size: 1rem;
}

.toolbar-buttons .accent {
  background: #fbbf24;
  color: #78350f;
  border-color: rgba(120, 53, 15, 0.2);
  font-weight: 600;
}

.toolbar-buttons .accent:hover {
  color: #422006;
}

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

@media (max-width: 1024px) {
  .workspace {
    flex-direction: column;
  }

  .left-pane,
  .right-pane {
    min-height: 400px;
    min-width: auto;
    width: auto;
  }

  #vertical-splitter {
    display: none;
  }
}

/* ===== ダークモード ===== */

@media (prefers-color-scheme: dark) {
  body {
    background: #0f172a;
    color: #e2e8f0;
  }

  .left-pane {
    background: rgba(30, 41, 59, 0.8);
    color: inherit;
  }

  .right-pane {
    background: #111827;
    color: #e2e8f0;
  }

  .tab {
    background: rgba(71, 85, 105, 0.6);
    color: #e2e8f0;
  }

  .tab.active {
    background: #60a5fa;
    color: #0f172a;
  }

  .log-output {
    background: rgba(15, 23, 42, 0.9);
  }

  .log-output.error {
    background: rgba(127, 29, 29, 0.8);
  }

  .log-area {
    background: rgba(30, 41, 59, 0.85);
  }

  .splitter.horizontal {
    background: #6b7280;
  }

  .materials-list-item {
    background: rgba(30, 41, 59, 0.7);
    border-color: rgba(148, 163, 184, 0.3);
  }

  .materials-list-item .material-status.lock {
    background: rgba(127, 29, 29, 0.2);
    color: #fecaca;
    border-color: rgba(239, 68, 68, 0.3);
  }

  .materials-list-item .material-status.unlock {
    background: rgba(16, 185, 129, 0.15);
    color: #6ee7b7;
    border-color: rgba(16, 185, 129, 0.3);
  }
}
