:root {
  --bg: #f8f5ec;
  --ink: #1f2937;
  --accent: #0f766e;
  --accent-2: #d97706;
  --border: #d6d3d1;
  --line: rgba(0, 0, 0, 0.05);
  --page-width: 46%;
  --line-height: 28px;
  --font: "Noto Sans JP", "Hiragino Sans", system-ui, -apple-system, sans-serif;
}

/* ナイトモード */
body.dark,
body.dark :root {
  --bg: #1e293b;
  --ink: #e2e8f0;
  --accent: #2dd4bf;
  --accent-2: #fb923c;
  --border: #475569;
  --line: rgba(255, 255, 255, 0.06);
}
body.dark .topbar { background: #0f172ad9; border-color: var(--border); }
body.dark .sidebar { background: #172033; }
body.dark .section-header { color: #94a3b8; }
body.dark .drag-hint { color: #64748b; }
body.dark .list { background: #334155; border-color: var(--border); }
body.dark .list button { border-color: var(--border); color: var(--ink); }
body.dark .list button:hover { background: #475569; }
body.dark .list button.active { background: #134e4a; color: #5eead4; }
body.dark .list button.dragging { opacity: 0.5; }
body.dark .list button.drop-target { outline-color: var(--accent); }
body.dark button.primary { background: var(--accent); color: #0f172a; border-color: var(--accent); }
body.dark button.secondary { background: transparent; color: var(--accent); border-color: var(--accent); }
body.dark button.ghost { color: #94a3b8; border-color: var(--border); }
body.dark button.ghost:hover { background: #334155; }
body.dark .page { background: linear-gradient(90deg, rgba(255,255,255,0.03) 0 4px, transparent 4px); border-color: #475569; box-shadow: 0 12px 30px rgba(0,0,0,0.3); }
body.dark .page-title { background: #334155; border-color: #475569; color: var(--ink); }
body.dark .page-body { color: var(--ink); }
body.dark .page-body:empty::before { color: #64748b; }
body.dark .toolbar button { background: #334155; border-color: var(--border); color: var(--ink); }
body.dark .toolbar button:hover { background: #475569; }
body.dark .modal-content { background: #334155; border: 1px solid var(--border); }
body.dark .modal-header h2, body.dark .modal-section h3 { color: var(--ink); }
body.dark .inline-form input { background: #1e293b; border-color: var(--border); color: var(--ink); }
body.dark .help { color: #94a3b8; }
body.dark #status { color: #94a3b8; }
body.dark .logout-link { color: #94a3b8; }
body.dark .pages::before { background: #475569; }
body.dark #nightModeToggle { font-size: 1.1rem; }

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  min-height: 100vh;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 18px;
  border-bottom: 1px solid var(--border);
  background: #ffffffd9;
  backdrop-filter: blur(6px);
  position: sticky;
  top: 0;
  z-index: 20;
}
.brand { font-weight: 700; letter-spacing: 0.02em; }
.actions { display: flex; gap: 10px; align-items: center; }
.actions a.ghost { text-decoration: none; display: inline-flex; align-items: center; }
#status { font-size: 12px; color: #475569; }
.error-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 999px;
  background: #ef4444;
  color: white;
  font-size: 12px;
  font-weight: 700;
}

.workspace {
  display: grid;
  grid-template-columns: 260px 1fr;
  min-height: calc(100vh - 56px);
}

.sidebar {
  border-right: 1px solid var(--border);
  padding: 16px;
  background: #fdfcf8;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.section-header {
  font-weight: 700;
  margin-bottom: 6px;
  color: #334155;
}
.drag-hint { font-weight: 400; font-size: 11px; color: #64748b; }
.list {
  border: 1px solid var(--border);
  background: white;
  border-radius: 8px;
  min-height: 120px;
  overflow: auto;
}
.list button {
  display: block;
  width: 100%;
  background: none;
  border: none;
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
  cursor: pointer;
}
.list button:last-child { border-bottom: none; }
.list button.active { background: #ecfdf3; color: #047857; }
.list button:hover { background: #f8fafc; }
.list button.dragging { opacity: 0.5; }
.list button.drop-target { outline: 2px solid var(--accent); outline-offset: -2px; }
.list button[draggable="true"] { cursor: grab; }
.list button[draggable="true"]:active { cursor: grabbing; }
.files-header { margin-top: 8px; }

button.primary, button.secondary, button.ghost {
  border-radius: 8px;
  padding: 10px 12px;
  border: 1px solid transparent;
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
}
button.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
button.secondary { background: #fff; color: var(--accent); border-color: var(--accent); }
button.ghost { background: transparent; color: #475569; border-color: var(--border); }
button.danger { color: #b91c1c; border-color: #fca5a5; }
button.danger:hover { background: #fef2f2; }
button:disabled { opacity: 0.6; cursor: not-allowed; }

.notebook {
  position: relative;
  padding: 18px 24px 36px;
}

.toolbar {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}
.toolbar button { border-radius: 6px; padding: 8px 10px; border: 1px solid var(--border); background: white; cursor: pointer; }
.toolbar button:hover { background: #f8fafc; }
.toolbar button[data-cmd='bold'] { font-weight: 700; }
.toolbar button[data-cmd='underline'] { text-decoration: underline; }
.color-swatch { width: 32px; height: 32px; padding: 0; border: 2px solid var(--border); background: var(--swatch); }

.pages {
  display: grid;
  grid-template-columns: var(--page-width) var(--page-width);
  gap: 4%;
  position: relative;
  justify-content: center;
}
.pages::before {
  content: "";
  position: absolute;
  width: 1px;
  background: #cbd5e1;
  inset: 0;
  margin: auto;
}

.page {
  background: linear-gradient(90deg, rgba(0,0,0,0.02) 0 4px, transparent 4px);
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  min-height: 70vh;
  position: relative;
  overflow: hidden;
  box-shadow: 0 12px 30px rgba(15, 23, 42, 0.08);
}
.page-title {
  padding: 10px 14px;
  font-weight: 700;
  background: #f8fafc;
  border-bottom: 1px solid #e2e8f0;
}
.page-body {
  padding: 14px 18px 24px;
  min-height: 60vh;
  outline: none;
  font-size: 15px;
  line-height: var(--line-height);
  background: repeating-linear-gradient(
    180deg,
    transparent,
    transparent calc(var(--line-height) - 1px),
    var(--line) var(--line-height)
  );
  background-origin: content-box;
  background-clip: content-box;
}
.page-body:empty::before {
  content: "ここに入力";
  color: #cbd5e1;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.35);
  display: grid;
  place-items: center;
  z-index: 50;
}
.modal[hidden] { display: none; }
.modal-content {
  background: #fff;
  border-radius: 16px;
  padding: 18px;
  width: min(640px, 92vw);
  box-shadow: 0 18px 48px rgba(15, 23, 42, 0.18);
}
.modal-header { display: flex; justify-content: space-between; align-items: center; }
.modal-body { display: grid; gap: 16px; }
.modal-section h3 { margin: 0 0 8px; }
.inline-form { display: flex; gap: 8px; align-items: center; }
.inline-form input { flex: 1; padding: 10px; border-radius: 8px; border: 1px solid var(--border); }
.help { color: #6b7280; font-size: 13px; }

@media (max-width: 960px) {
  .workspace { grid-template-columns: 1fr; }
  .sidebar { flex-direction: row; flex-wrap: wrap; gap: 12px; }
  .list { min-height: 80px; max-height: 180px; }
  .pages { grid-template-columns: 1fr; gap: 20px; }
  .pages::before { display: none; }
  .page { min-height: 52vh; }
}
