:root {
  --bg:       #1a1b26;
  --bg2:      #16161e;
  --bg3:      #13131a;
  --surface:  #1f2335;
  --surface2: #24283b;
  --border:   #2a2e47;
  --blue:     #7aa2f7;
  --cyan:     #7dcfff;
  --green:    #9ece6a;
  --yellow:   #e0af68;
  --orange:   #ff9e64;
  --red:      #f7768e;
  --purple:   #bb9af7;
  --text:     #c0caf5;
  --muted:    #565f89;
  --comment:  #444b6a;
  --mono: 'JetBrains Mono', monospace;
  --sidebar-w: 48px;
}

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

body {
  background: var(--bg3);
  color: var(--text);
  font-family: var(--mono);
  min-height: 100vh;
  overflow: hidden;
}



/* ── Hamburger ── */
.hamburger {
  background: none;
  border: none;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 8px;
}

.hamburger span {
  display: block;
  width: 16px;
  height: 1.5px;
  background: var(--muted);
  transition: background 0.15s;
}

.hamburger:hover span { background: var(--text); }

/* ── Main area ── */
.main {
  margin-bottom: 26px;
  height: calc(100vh - 26px);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

/* ── Add form ── */
.add-form-bar {
  background: var(--bg3);
  border-bottom: 1px solid var(--border);
  padding: 14px 24px;
  flex-shrink: 0;
  transition: transform 0.3s ease, opacity 0.3s ease, max-height 0.3s ease, padding 0.3s ease;
  transform: translateY(0);
  opacity: 1;
  max-height: 80px;
  overflow: hidden;
}

.add-form-bar.hidden {
  transform: translateY(-100%);
  opacity: 0;
  max-height: 0;
  padding: 0;
  pointer-events: none;
}

/* ── Code block ── */
.code-block {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 16px;
}

.code-line {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  font-size: 13px;
  line-height: 2;
}

.kw { color: var(--purple); }
.fn { color: var(--blue); }

.str-input {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 5px 12px;
  color: var(--green);
  font-family: var(--mono);
  font-size: 13px;
  outline: none;
  transition: border-color 0.15s;
  flex: 1;
  min-width: 200px;
}

.str-input:focus { border-color: var(--blue); }
.str-input::placeholder { color: var(--comment); font-style: italic; }
.title-input { flex: 0.5; min-width: 140px; }

.btn-exec {
  background: var(--blue);
  color: var(--bg2);
  border: none;
  border-radius: 4px;
  padding: 6px 18px;
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
  white-space: nowrap;
}

.btn-exec:hover { opacity: 0.85; transform: translateY(-1px); }
.btn-exec:active { transform: translateY(0); }

/* ── Content ── */
.content {
  padding: 24px 32px 24px 24px;
  flex: 1;
}

.sec-comment {
  font-size: 12px;
  color: var(--comment);
  font-style: italic;
  margin-bottom: 10px;
  margin-top: 28px;
  user-select: none;
}

.sec-comment:first-child { margin-top: 0; }

/* ── Gallery ── */
.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 16px;
}

/* ── Card ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  cursor: pointer;
  transition: border-color 0.2s, box-shadow 0.2s, transform 0.2s;
  position: relative;
}

.card:hover {
  border-color: var(--blue);
  box-shadow: 0 0 0 1px var(--blue), 0 8px 32px rgba(122,162,247,0.1);
  transform: translateY(-2px);
}

.card-bar {
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  padding: 5px 10px;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
}

.dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.dot-r { background: var(--red); }
.dot-y { background: var(--yellow); }
.dot-g { background: var(--green); }

.card-bar-title {
  flex: 1;
  color: var(--text);
  font-size: 11px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.btn-delete {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
  padding: 0 2px;
  transition: color 0.15s;
  line-height: 1;
  font-family: var(--mono);
}

.btn-delete:hover { color: var(--red); }

.thumb-wrap {
  position: relative;
  width: 100%;
  padding-top: 56.25%;
  background: var(--bg3);
  overflow: hidden;
}

.thumb-wrap img {
  position: absolute;
  inset: 0; width: 100%; height: 100%;
  object-fit: cover;
  transition: opacity 0.3s;
}

.thumb-wrap iframe, .thumb-wrap video {
  position: absolute;
  inset: 0; width: 100%; height: 100%;
  border: none;
  opacity: 0;
  transition: opacity 0.4s;
  pointer-events: none;
}

.play-btn {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.2s;
}

.play-btn svg { width: 48px; height: 48px; filter: drop-shadow(0 2px 8px rgba(0,0,0,0.7)); transition: transform 0.2s; }
.card:hover .play-btn svg { transform: scale(1.08); }

.card-foot {
  padding: 7px 12px 9px;
  font-size: 10px;
  color: var(--muted);
  display: flex;
  gap: 6px;
}

.vid-id { color: var(--yellow); }

.card.active-mobile .thumb-wrap img { opacity: 0; }
.card.active-mobile .thumb-wrap iframe,
.card.active-mobile .thumb-wrap video { opacity: 1; pointer-events: auto; }
.card.active-mobile .play-btn { opacity: 0; }

/* ── Thumb placeholder ── */
.thumb-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface2);
  color: var(--muted);
  font-size: 13px;
  font-family: var(--mono);
  letter-spacing: 1px;
}

/* ── Drag & Drop ── */
.card.dragging { opacity: 0.4; transform: scale(0.98); }
.card.drag-over {
  border-color: var(--cyan);
  box-shadow: 0 0 0 2px var(--cyan), 0 8px 32px rgba(125,207,255,0.15);
  transform: translateY(-4px);
}

/* ── Empty ── */
.empty {
  grid-column: 1/-1;
  padding: 60px 20px;
  text-align: center;
  color: var(--comment);
  font-size: 12px;
  font-style: italic;
  line-height: 2.2;
}

/* ── Statusline ── */
.statusline {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: 26px;
  background: var(--blue);
  display: flex;
  align-items: center;
  font-size: 11px;
  font-weight: 500;
  z-index: 200;
  font-family: var(--mono);
}

.sl-mode {
  background: var(--bg2);
  color: var(--blue);
  padding: 0 14px;
  height: 100%;
  display: flex;
  align-items: center;
  font-weight: 700;
  letter-spacing: 1px;
}

.sl-file { color: var(--bg2); padding: 0 14px; font-weight: 500; }
.sl-spacer { flex: 1; }
.sl-right { color: var(--bg2); padding: 0 14px; display: flex; gap: 16px; }

/* ── Toast ── */
.toast {
  position: fixed;
  bottom: 40px;
  left: 50%;
  transform: translateX(-50%) translateY(60px);
  background: var(--surface2);
  border: 1px solid var(--green);
  color: var(--green);
  padding: 8px 20px;
  border-radius: 4px;
  font-size: 12px;
  font-family: var(--mono);
  z-index: 999;
  pointer-events: none;
  transition: transform 0.25s ease, opacity 0.25s;
  opacity: 0;
  white-space: nowrap;
}

.toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }
.toast.err { border-color: var(--red); color: var(--red); }

/* ── Drawer ── */
.drawer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(2px);
  z-index: 300;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s;
}

.drawer-overlay.open { opacity: 1; pointer-events: auto; }

.drawer {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: 260px;
  background: var(--bg2);
  border-right: 1px solid var(--border);
  z-index: 400;
  transform: translateX(-100%);
  transition: transform 0.25s ease;
  display: flex;
  flex-direction: column;
  padding-bottom: 26px;
}

.drawer.open { transform: translateX(0); }

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}

.drawer-title { font-size: 12px; color: var(--comment); font-style: italic; }

.drawer-close {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 14px;
  font-family: var(--mono);
  transition: color 0.15s;
}

.drawer-close:hover { color: var(--red); }

.drawer-section {
  padding: 16px;
  border-bottom: 1px solid var(--border);
}

.drawer-section-label {
  font-size: 11px;
  color: var(--comment);
  font-style: italic;
  margin-bottom: 12px;
}

.drawer-tab-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
  color: var(--muted);
  transition: background 0.15s, color 0.15s;
  user-select: none;
  margin-bottom: 2px;
}

.drawer-tab-item:hover { background: var(--surface2); color: var(--text); }
.drawer-tab-item.active { background: var(--surface2); color: var(--blue); }
.drawer-tab-item .tab-icon { color: var(--comment); font-size: 10px; }
.drawer-tab-item.active .tab-icon { color: var(--green); }
.drawer-tab-item .tab-count { margin-left: auto; color: var(--comment); font-size: 10px; }

.drawer-add-tab {
  background: none;
  border: 1px dashed var(--border);
  border-radius: 4px;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 12px;
  padding: 7px 12px;
  cursor: pointer;
  width: 100%;
  text-align: left;
  margin-top: 8px;
  transition: border-color 0.15s, color 0.15s;
}

.drawer-add-tab:hover { border-color: var(--blue); color: var(--blue); }

/* ── Context menu ── */
.context-menu {
  position: fixed;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px;
  z-index: 500;
  display: none;
  flex-direction: column;
  min-width: 120px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}

.context-menu.open { display: flex; }

.context-menu button {
  background: none;
  border: none;
  color: var(--text);
  font-family: var(--mono);
  font-size: 12px;
  padding: 8px 12px;
  text-align: left;
  cursor: pointer;
  border-radius: 4px;
  transition: background 0.15s;
}

.context-menu button:hover { background: var(--surface); }
.context-menu button.danger { color: var(--red); }
.context-menu button.danger:hover { background: rgba(247,118,142,0.1); }

/* ── Mobile ── */
@media (max-width: 640px) {
  .content { padding: 14px; }
  .gallery { grid-template-columns: 1fr; gap: 12px; }
  .str-input { min-width: 100%; }
  .card.center-active {
    border-color: var(--cyan);
    box-shadow: 0 0 0 1px var(--cyan);
  }
}

/* ── Hamburger box ── */
.hamburger-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
}

/* ── Mobile fixes ── */
@media (max-width: 768px) {
  .code-line {
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
  }

  /* 1行目: ハンバーガー + URL */
  .hamburger-wrap {
    flex-shrink: 0;
  }

  .str-input {
    flex: 1;
    min-width: 0;
  }

  /* 2行目: タイトル + Addボタン */
  .title-input {
    flex: 1;
    min-width: 0;
  }

  .btn-exec {
    flex-shrink: 0;
    white-space: nowrap;
  }

  .kw, .fn {
    display: none;
  }

  .add-form-bar {
    padding: 10px 12px;
    flex-shrink: 0;
  }

  .code-block {
    padding: 10px 12px;
  }

  .content {
    padding: 16px 12px;
  }

  .gallery {
    grid-template-columns: 1fr;
    gap: 12px;
  }
}

/* ── Mobile 2行レイアウト ── */
@media (max-width: 768px) {
  /* ハンバーガー+URLで1行目を強制 */
  .hamburger-wrap {
    order: 1;
  }

  .url-input {
    order: 2;
    flex: 1;
    min-width: 0;
  }

  /* タイトル+Addで2行目 */
  .title-input {
    order: 3;
    flex: 1;
    min-width: 0;
  }

  .btn-exec {
    order: 4;
    flex-shrink: 0;
  }

  /* kw/fnはハンバーガーの後に来るので非表示 */
  .kw, .fn {
    display: none;
  }
}
