:root {
  --bg: #fbfaf8;
  --surface: #ffffff;
  --ink: #15140f;
  --ink-2: #4a4842;
  --ink-3: #8a877f;
  --ink-4: #b5b1a8;
  --line: #e7e3da;
  --line-2: #f0ece3;
  --hover: #f5f2ec;
  --select: #eef3ff;
  --new: #5a3a00;
  --new-bg: #fff4d6;
  --radius: 4px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Inter", "Hiragino Sans", "Yu Gothic UI", "Noto Sans JP", system-ui, sans-serif;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  font-feature-settings: "palt" 1;
  line-height: 1.55;
  font-size: 14px;
  overflow-x: hidden;
}

a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; background: none; border: none; padding: 0; color: inherit; }
input { font-family: inherit; }

/* ============== Hero ============== */
.hero {
  border-bottom: 1px solid var(--line);
  padding: 36px 32px 20px;
  background: var(--surface);
}
.hero-inner { max-width: 1200px; margin: 0 auto; }

.topbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-width: 0; }
.brand { min-width: 0; }
.brand h1 {
  font-size: 17px; font-weight: 600; letter-spacing: -0.005em; margin: 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.actions { display: flex; gap: 6px; flex-shrink: 0; }
.hbtn {
  font-size: 12px; padding: 7px 14px;
  border-radius: var(--radius); border: 1px solid var(--line);
  color: var(--ink-2); background: #fff;
  letter-spacing: 0.02em; transition: all .12s; white-space: nowrap;
}
.hbtn:hover { color: var(--ink); border-color: var(--ink-3); background: var(--hover); }
.hbtn.primary { background: var(--ink); color: #fff; border-color: var(--ink); }
.hbtn.primary:hover { background: #000; border-color: #000; color: #fff; }
.hbtn.primary.active { background: #fff; color: var(--ink); border-color: var(--ink); }
.hbtn.ghost { background: transparent; border-color: transparent; color: var(--ink-3); }
.hbtn.ghost:hover { color: var(--ink); background: var(--hover); }

.lang-toggle { padding: 6px 10px; font-size: 11px; letter-spacing: 0.04em; }
.lang-toggle .lang-ja, .lang-toggle .lang-en { color: var(--ink-4); transition: color .12s; }
.lang-toggle .lang-sep { color: var(--ink-4); margin: 0 2px; }
.lang-toggle.lang-ja-active .lang-ja { color: var(--ink); font-weight: 600; }
.lang-toggle.lang-en-active .lang-en { color: var(--ink); font-weight: 600; }

.search { margin-top: 20px; }
.search input {
  width: 100%; max-width: 100%;
  padding: 8px 0; font-size: 14px; color: var(--ink);
  border: none; border-bottom: 1px solid var(--line); background: transparent;
  outline: none; transition: border-color .2s;
}
.search input::placeholder { color: var(--ink-3); }
.search input:focus { border-bottom-color: var(--ink); }

/* ============== Filters / Layout switcher ============== */
.filters {
  max-width: 1200px; margin: 20px auto 0;
  padding: 0 32px;
  display: flex; align-items: center; gap: 24px; flex-wrap: wrap;
  border-bottom: 1px solid var(--line);
}
.chip {
  color: var(--ink-3); font-size: 13px; padding: 12px 0;
  border-bottom: 1px solid transparent; margin-bottom: -1px;
  transition: color .15s, border-color .15s; letter-spacing: 0.01em;
}
.chip:hover { color: var(--ink); }
.chip.is-active { color: var(--ink); border-bottom-color: var(--ink); font-weight: 500; }

.filters-spacer { flex: 1; }
.layout-switch { display: flex; gap: 2px; padding: 6px 0; }
.layout-switch button {
  width: 28px; height: 26px;
  border: 1px solid var(--line); border-radius: 4px;
  font-size: 13px; color: var(--ink-3); background: #fff;
  display: grid; place-items: center;
  transition: all .12s;
}
.layout-switch button:hover { color: var(--ink); border-color: var(--ink-3); }
.layout-switch button.active { background: var(--ink); color: #fff; border-color: var(--ink); }

/* ============== Container ============== */
.container { max-width: 1200px; margin: 0 auto; padding: 8px 32px 100px; }

/* ============== Section ============== */
.section { margin-top: 28px; }
.section:first-child { margin-top: 20px; }
.section.drag-over-section { background: var(--hover); border-radius: 6px; }

.section-head {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 8px; min-height: 28px;
  flex-wrap: wrap;
  cursor: default;
}
.section-toggle {
  font-size: 10px;
  color: var(--ink-3);
  width: 18px; height: 18px;
  display: grid; place-items: center;
  border-radius: 3px;
  transition: all .12s;
  flex-shrink: 0;
}
.section-toggle:hover { color: var(--ink); background: var(--hover); }

.section-name {
  font-size: 11px; font-weight: 500;
  letter-spacing: 0.12em; text-transform: uppercase; color: var(--ink-2);
  outline: none; cursor: text;
  border-radius: 3px; padding: 2px 6px; margin: -2px -6px;
  border: 1px solid transparent;
  min-width: 60px;
  transition: background .12s, border-color .12s;
}
.section-name:hover { background: var(--hover); border-color: var(--line-2); }
.section-name:focus { background: #fff; border-color: var(--line); }
.section-name[contenteditable="true"]:empty::before {
  content: attr(data-placeholder); color: var(--ink-4);
}

.section-head .count {
  color: var(--ink-3); font-size: 11px; font-variant-numeric: tabular-nums;
}
.section-link {
  font-size: 11px; color: var(--ink-3);
  padding: 2px 6px; border-radius: 3px;
  border: 1px solid transparent; transition: all .12s;
}
.section-link:hover { color: var(--ink); border-color: var(--line); background: #fff; }

.section-head.reorder { padding: 4px 0; }
.section-head.edit {
  padding: 4px 0;
  border-bottom: 1px dashed var(--line);
  flex-wrap: nowrap;
}
.section-head.edit .section-url-input {
  flex: 1 1 auto; font-size: 11px; color: var(--ink-3);
  border: 1px solid transparent; background: transparent;
  padding: 4px 6px; border-radius: 3px; outline: none; min-width: 0;
}
.section-head.edit .section-url-input:hover { background: var(--hover); }
.section-head.edit .section-url-input:focus { background: #fff; border-color: var(--line); }
.section-head .drag-handle {
  cursor: grab; color: var(--ink-4); font-size: 14px;
  user-select: none; padding: 0 4px; flex-shrink: 0;
}
.section-head .drag-handle:active { cursor: grabbing; }
.section-head.edit .section-delete {
  font-size: 11px; color: var(--ink-3);
  padding: 2px 8px; border-radius: 3px; flex-shrink: 0;
}
.section-head.edit .section-delete:hover { color: #b00020; background: #fdeeee; }

/* Collapsed section: hide list */
.section.collapsed .list { display: none; }

/* ============== List (1col / multi-col) ============== */
.list {
  border-top: 1px solid var(--line);
  min-height: 24px;
}

/* 1-column (default list view) */
.cols-1 .list { display: flex; flex-direction: column; }

/* multi-column card view */
.cols-2 .list, .cols-3 .list {
  display: grid; gap: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}
.cols-2 .list { grid-template-columns: repeat(2, 1fr); }
.cols-3 .list { grid-template-columns: repeat(3, 1fr); }
@media (max-width: 900px) {
  .cols-3 .list { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 600px) {
  .cols-2 .list, .cols-3 .list { grid-template-columns: 1fr; }
}

/* ============== Row (1col list mode) ============== */
.cols-1 .row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 240px 160px;
  gap: 20px;
  align-items: center;
  padding: 9px 4px;
  border-bottom: 1px solid var(--line);
  transition: background .12s;
}
.cols-1 .row:hover { background: var(--hover); }
.cols-1 .row-head { display: flex; align-items: center; gap: 12px; min-width: 0; }
.cols-1 .row-meta {
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cols-1 .row-actions {
  display: flex;
  justify-content: flex-end;
  gap: 4px;
  opacity: 0;
  transition: opacity .12s;
}
.cols-1 .row:hover .row-actions { opacity: 1; }
@media (max-width: 800px) {
  .cols-1 .row { grid-template-columns: minmax(0, 1fr) auto; }
  .cols-1 .row-meta { display: none; }
}

/* ============== Row (card mode) ============== */
.cols-2 .row, .cols-3 .row {
  display: flex; flex-direction: column;
  gap: 6px; padding: 12px 14px;
  border: 1px solid var(--line); border-radius: 6px;
  background: #fff;
  transition: border-color .12s, box-shadow .12s;
  min-width: 0;
}
.cols-2 .row:hover, .cols-3 .row:hover { border-color: var(--ink-3); box-shadow: 0 2px 6px rgba(0,0,0,.04); }
.cols-2 .row-head, .cols-3 .row-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.cols-2 .row-meta, .cols-3 .row-meta { padding-top: 2px; }
.cols-2 .row-actions, .cols-3 .row-actions {
  display: flex; flex-wrap: wrap; gap: 4px;
  margin-top: auto; padding-top: 4px;
}

/* shared row state */
.row.selected { background: var(--select) !important; border-color: #b9c8e8 !important; }
.row.dragging { opacity: 0.4; }
.row.drag-over-top { box-shadow: inset 0 2px 0 var(--ink); }
.row.drag-over-bottom { box-shadow: inset 0 -2px 0 var(--ink); }

.drag-handle {
  cursor: grab; color: var(--ink-4); font-size: 14px;
  user-select: none; padding: 0 2px; line-height: 1; flex-shrink: 0;
}
.drag-handle:active { cursor: grabbing; }

.row-check {
  width: 14px; height: 14px;
  cursor: pointer; accent-color: var(--ink); margin: 0; flex-shrink: 0;
}

.row-title {
  flex: 1;
  display: flex; align-items: baseline; gap: 8px;
  flex-wrap: wrap; min-width: 0;
}
.row-name {
  font-size: 14px; font-weight: 500; color: var(--ink);
  letter-spacing: -0.005em;
  background: none; border: none; padding: 0; cursor: pointer; text-align: left;
  font-family: inherit;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  max-width: 100%;
}
.row-name:hover { color: #000; text-decoration: underline; text-underline-offset: 3px; text-decoration-thickness: 1px; }
.row-name.is-fav::before {
  content: "★ ";
  color: #d4a300;
  font-weight: 600;
}

.row-meta {
  font-size: 11px; color: var(--ink-4);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
  white-space: nowrap;
}
.row-meta .meta-label {
  color: var(--ink-3);
  margin-right: 4px;
  letter-spacing: 0.04em;
}
.row-meta .meta-date {
  color: var(--ink-3);
}
.row-meta .meta-sep { color: var(--line); margin: 0 8px; }

.row-tags { display: flex; gap: 6px; flex-wrap: wrap; }
.tag {
  font-size: 10px; letter-spacing: 0.06em; color: var(--ink-3);
  text-transform: uppercase;
  padding: 1px 6px; border: 1px solid var(--line); border-radius: 2px;
  white-space: nowrap;
}
.tag.new {
  color: var(--new); background: var(--new-bg); border-color: var(--new-bg);
  font-weight: 600; cursor: pointer;
}

.btn {
  font-size: 11px; padding: 4px 8px;
  border-radius: var(--radius); border: 1px solid transparent;
  color: var(--ink-3); background: transparent;
  letter-spacing: 0.01em; transition: all .12s;
  white-space: nowrap; font-family: inherit;
}
.btn:hover { background: #fff; border-color: var(--line); color: var(--ink); }

/* ============== Mode toolbar / Add section ============== */
.mode-toolbar {
  display: flex; gap: 8px; flex-wrap: wrap;
  margin: 0 0 12px; padding: 8px 0;
  align-items: center;
}
.mode-toolbar .mode-label {
  font-size: 11px; color: var(--ink-3);
  letter-spacing: 0.04em; margin-right: auto;
}
.add-section {
  margin-top: 28px; padding: 10px 14px;
  width: 100%; text-align: left;
  border: 1px dashed var(--line); border-radius: var(--radius);
  color: var(--ink-3); font-size: 12px; letter-spacing: 0.02em;
  transition: all .15s;
}
.add-section:hover { border-color: var(--ink-3); color: var(--ink); background: var(--hover); }

.drop-placeholder {
  padding: 12px 4px;
  color: var(--ink-4); font-size: 11px; text-align: center;
  grid-column: 1 / -1;
}
.list.drag-over-list { background: var(--hover); }

.empty {
  text-align: center; color: var(--ink-3);
  padding: 60px 20px; font-size: 13px;
}

/* ============== Footer / Bulkbar / Toast ============== */
.foot {
  max-width: 1200px; margin: 0 auto;
  padding: 60px 32px 80px;
  color: var(--ink-3); font-size: 12px; text-align: center;
  letter-spacing: 0.01em;
}
.foot code {
  background: var(--line-2); padding: 1px 6px; border-radius: 2px;
  font-size: 11px; font-family: "SF Mono", "Consolas", monospace;
  color: var(--ink-2);
}

.bulkbar {
  display: none;
  position: fixed; bottom: 24px; left: 50%;
  transform: translateX(-50%);
  background: var(--ink); color: #fff;
  padding: 10px 12px 10px 18px; border-radius: 8px;
  font-size: 13px; letter-spacing: 0.01em;
  box-shadow: 0 8px 32px rgba(0,0,0,.18);
  align-items: center; gap: 16px;
  max-width: calc(100vw - 32px); z-index: 90;
}
.bulkbar.is-visible { display: flex; }
.bulkbar-actions { display: flex; gap: 4px; }
.bulkbar .hbtn { background: transparent; border-color: rgba(255,255,255,.25); color: #fff; }
.bulkbar .hbtn:hover { background: rgba(255,255,255,.1); border-color: rgba(255,255,255,.5); color: #fff; }
.bulkbar .hbtn.ghost { border-color: transparent; color: rgba(255,255,255,.7); }
.bulkbar .hbtn.ghost:hover { color: #fff; background: rgba(255,255,255,.1); }

.toast {
  position: fixed; bottom: 32px; left: 50%;
  transform: translateX(-50%) translateY(8px);
  background: var(--ink); color: #fff;
  padding: 10px 18px; border-radius: var(--radius);
  font-size: 13px; letter-spacing: 0.02em;
  opacity: 0; pointer-events: none;
  transition: opacity .15s, transform .15s;
  z-index: 100;
  max-width: calc(100vw - 32px); text-align: center;
  box-shadow: 0 4px 16px rgba(0,0,0,.15);
}
.toast.is-visible { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (max-width: 640px) {
  .hero { padding: 24px 16px 16px; }
  .container { padding: 8px 16px 100px; }
  .filters { padding: 0 16px; gap: 18px; }
  .cols-1 .row-actions { opacity: 1; }
  .section-head.edit { flex-wrap: wrap; }
  .section-head.edit .section-url-input { flex: 1 1 100%; width: 100%; }
}
