:root {
  --bg: #0b0c0f; --panel: #14161b; --card: #1a1d23; --card-2: #22262e; --line: #2a2f38;
  --text: #eceef2; --muted: #8b93a3; --accent: #c6f432; --accent-text: #0b0c0f;
  --ok: #3ddc84; --warn: #f5a524; --err: #ff5d5d; --info: #6aa7ff; --radius: 12px;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f3f4f7; --panel: #ffffff; --card: #ffffff; --card-2: #f0f1f5; --line: #e1e4ea;
    --text: #15171c; --muted: #6b7280; --accent: #1f3a6b; --accent-text: #ffffff;
  }
}
:root[data-theme="dark"] { color-scheme: dark; }
* { box-sizing: border-box; }
html { background: var(--bg); }
body { margin: 0; font-family: -apple-system, "Hiragino Sans", "Noto Sans JP", sans-serif; color: var(--text); background: var(--bg); font-size: 14px; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--err); white-space: pre-wrap; }
.center { text-align: center; }
.spacer { flex: 1; }
button { font: inherit; color: inherit; cursor: pointer; }
input, select, textarea { font: inherit; color: var(--text); background: var(--card-2); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; }
textarea { resize: vertical; width: 100%; }
label { display: flex; flex-direction: column; gap: 4px; color: var(--muted); font-size: 13px; }
label.check { flex-direction: row; align-items: center; gap: 6px; color: var(--text); }

/* buttons */
.btn-primary { background: var(--accent); color: var(--accent-text); border: none; border-radius: 10px; padding: 10px 16px; font-weight: 700; }
.btn-ghost { background: transparent; border: 1px solid var(--line); border-radius: 8px; padding: 6px 12px; }
.btn-ghost:hover { background: var(--card-2); }
.btn-small { background: var(--card-2); border: 1px solid var(--line); border-radius: 7px; padding: 4px 9px; font-size: 12px; }
.btn-small:hover { border-color: var(--muted); }
.btn-small.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 700; }
.btn-danger { color: var(--err); }

/* top bar */
.topbar { display: flex; align-items: center; gap: 10px; padding: 10px 18px; border-bottom: 1px solid var(--line); background: var(--panel); position: sticky; top: 0; z-index: 20; }
.brand { font-weight: 800; letter-spacing: .06em; font-size: 16px; display: flex; align-items: center; gap: 9px; }
.brand-mark { height: 24px; width: auto; color: var(--text); flex: none; }
.brand.big { font-size: 22px; flex-direction: column; align-items: flex-start; gap: 12px; }
.brand.big .brand-mark { height: 48px; }
.pill { font-size: 12px; padding: 3px 10px; border-radius: 999px; background: var(--card-2); border: 1px solid var(--line); color: var(--muted); }
.pill.warn { color: var(--warn); border-color: var(--warn); }
.model-pill { color: var(--text); }
.menu-wrap { position: relative; }
.menu { position: absolute; right: 0; top: calc(100% + 6px); background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 6px; display: flex; flex-direction: column; min-width: 160px; box-shadow: 0 12px 30px rgba(0,0,0,.35); }
.menu button { background: none; border: none; text-align: left; padding: 8px 10px; border-radius: 6px; }
.menu button:hover { background: var(--card-2); }
.banner { background: rgba(245,165,36,.12); color: var(--warn); padding: 8px 18px; border-bottom: 1px solid var(--line); }

/* layout */
.workspace { display: grid; grid-template-columns: 420px 1fr; min-height: calc(100vh - 53px); }
.panel { background: var(--panel); border-right: 1px solid var(--line); padding: 16px; display: flex; flex-direction: column; gap: 12px; position: sticky; top: 53px; height: calc(100vh - 53px); overflow-y: auto; }
.feed { padding: 16px 20px 60px; min-width: 0; }

/* model picker */
.model-pick { position: relative; }
.model-btn { width: 100%; display: flex; align-items: center; gap: 10px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; text-align: left; }
.model-btn:hover { border-color: var(--muted); }
.model-btn .name { font-weight: 800; }
.model-btn .sub { font-size: 11px; color: var(--muted); }
.model-list { position: absolute; left: 0; right: 0; top: calc(100% + 6px); z-index: 15; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 6px; box-shadow: 0 14px 30px rgba(0,0,0,.4); }
.model-list button { display: flex; flex-direction: column; gap: 2px; width: 100%; background: none; border: none; text-align: left; padding: 8px 10px; border-radius: 8px; }
.model-list button:hover, .model-list button.active { background: var(--card-2); }
.model-list .name { font-weight: 700; }
.model-list .sub { font-size: 11px; color: var(--muted); }
.seg button:disabled { opacity: .35; cursor: not-allowed; }

/* segmented */
.seg { display: flex; background: var(--card-2); border: 1px solid var(--line); border-radius: 10px; padding: 3px; gap: 3px; }
.seg button { flex: 1; background: none; border: none; padding: 8px 6px; border-radius: 8px; color: var(--muted); font-weight: 600; }
.seg button.active { background: var(--card); color: var(--text); box-shadow: 0 1px 0 var(--line); }
.seg.small button { flex: none; padding: 6px 12px; font-size: 13px; }

/* slots */
.slot-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.slot-title { font-size: 12px; color: var(--muted); margin: 2px 0 6px; display: flex; justify-content: space-between; }
.tile { position: relative; aspect-ratio: 16 / 10; border: 1.5px dashed var(--line); border-radius: var(--radius); background: var(--card); display: flex; align-items: center; justify-content: center; flex-direction: column; gap: 4px; color: var(--muted); overflow: hidden; cursor: pointer; }
.tile:hover, .tile.drag { border-color: var(--accent); color: var(--text); }
.tile.filled { border-style: solid; cursor: default; }
.tile img { width: 100%; height: 100%; object-fit: cover; }
.tile .tag { position: absolute; left: 6px; top: 6px; background: rgba(0,0,0,.65); color: #fff; font-size: 11px; padding: 2px 6px; border-radius: 6px; font-weight: 700; }
.tile .meta { position: absolute; left: 6px; bottom: 6px; background: rgba(0,0,0,.65); color: #fff; font-size: 11px; padding: 2px 6px; border-radius: 6px; max-width: calc(100% - 40px); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile .remove { position: absolute; right: 6px; top: 6px; background: rgba(0,0,0,.65); color: #fff; border: none; width: 22px; height: 22px; border-radius: 50%; line-height: 1; }
.tile .progress { position: absolute; left: 0; bottom: 0; height: 3px; background: var(--accent); }
.tile .kind-icon { font-size: 26px; }
.tile.big { aspect-ratio: 16 / 9; }
.tray { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.tray .tile { aspect-ratio: 1; }
.add-menu { position: absolute; z-index: 5; background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 6px; display: flex; flex-direction: column; box-shadow: 0 10px 25px rgba(0,0,0,.35); }
.add-menu button { background: none; border: none; text-align: left; padding: 7px 10px; border-radius: 6px; white-space: nowrap; }
.add-menu button:hover { background: var(--card-2); }

/* prompt & mentions */
.prompt-wrap { position: relative; }
.mention-menu { position: absolute; left: 8px; top: 100%; z-index: 10; background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 4px; min-width: 200px; box-shadow: 0 10px 25px rgba(0,0,0,.35); }
.mention-menu button { display: flex; gap: 8px; align-items: center; width: 100%; background: none; border: none; text-align: left; padding: 6px 8px; border-radius: 6px; }
.mention-menu button.active, .mention-menu button:hover { background: var(--card-2); }
.mention-menu img { width: 32px; height: 22px; object-fit: cover; border-radius: 4px; }
.label-input { width: 100%; }

/* chips */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { display: inline-flex; align-items: center; gap: 6px; background: var(--card-2); border: 1px solid var(--line); border-radius: 999px; padding: 5px 12px; font-size: 13px; }
.chip select { background: transparent; border: none; padding: 0; color: var(--text); }
.chip.toggle.on { border-color: var(--accent); color: var(--accent); }
.chip .k { color: var(--muted); }
.chip button.step { background: none; border: none; color: var(--muted); padding: 0 2px; font-size: 15px; }

.panel-msg { font-size: 12px; color: var(--warn); min-height: 1em; white-space: pre-wrap; }
.panel-msg.err { color: var(--err); }
.btn-generate { display: flex; justify-content: space-between; align-items: center; width: 100%; padding: 14px 18px; border: none; border-radius: 12px; background: var(--accent); color: var(--accent-text); font-weight: 800; font-size: 15px; letter-spacing: .04em; }
.btn-generate:disabled { opacity: .45; cursor: not-allowed; }
.btn-generate .price { font-weight: 700; opacity: .85; }
.hint { font-size: 11px; color: var(--muted); }

/* feed */
.feed-bar { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.feed-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; display: flex; flex-direction: column; }
.card .media { position: relative; aspect-ratio: 16 / 9; background: #000; cursor: pointer; }
.card .media img, .card .media video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.card .media .badges { position: absolute; left: 8px; top: 8px; display: flex; gap: 4px; z-index: 2; }
.card .media .fav { position: absolute; right: 8px; top: 6px; z-index: 2; background: rgba(0,0,0,.55); border: none; color: #fff; border-radius: 50%; width: 28px; height: 28px; font-size: 15px; }
.card .media .fav.on { color: #ffd23f; }
.card .body { padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 6px; }
.card .prompt { font-size: 12px; color: var(--text); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card .meta { font-size: 11px; color: var(--muted); }
.card .actions { display: flex; flex-wrap: wrap; gap: 6px; }
.skeleton { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; color: #cfd3dc; font-size: 13px;
  background: linear-gradient(110deg, #15171c 8%, #232731 18%, #15171c 33%); background-size: 200% 100%; animation: shimmer 1.4s linear infinite; }
@keyframes shimmer { to { background-position-x: -200%; } }
.failed-box { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; padding: 14px; text-align: center; color: var(--err); font-size: 12px; background: #1b1012; }
.badge { font-size: 11px; padding: 2px 7px; border-radius: 6px; font-weight: 700; background: rgba(0,0,0,.65); color: #fff; }
.badge.ok { background: rgba(61,220,132,.9); color: #062012; }
.badge.run { background: rgba(106,167,255,.9); color: #071425; }
.badge.err { background: rgba(255,93,93,.9); color: #250707; }
.badge.draft { background: rgba(245,165,36,.95); color: #241500; }
.empty { color: var(--muted); padding: 40px; text-align: center; border: 1px dashed var(--line); border-radius: var(--radius); }

/* modal */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 20px; }
.modal-card { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; width: min(1100px, 100%); max-height: calc(100vh - 40px); overflow: auto; padding: 18px; position: relative; }
.modal-card.narrow { width: min(460px, 100%); }
.modal-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.modal-head h2 { margin: 0; font-size: 17px; }
.modal-close { background: none; border: none; font-size: 22px; color: var(--muted); }
.viewer { display: grid; grid-template-columns: 1fr 320px; gap: 16px; }
.viewer video, .viewer img { width: 100%; max-height: 70vh; background: #000; border-radius: 10px; }
.viewer .side { display: flex; flex-direction: column; gap: 10px; font-size: 13px; }
.viewer .side pre { white-space: pre-wrap; background: var(--card-2); padding: 10px; border-radius: 8px; margin: 0; font-family: inherit; }
.kv { display: grid; grid-template-columns: 90px 1fr; gap: 4px 8px; }
.kv .k { color: var(--muted); }
.lib-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.lib-item { background: var(--card); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; cursor: pointer; position: relative; }
.lib-item:hover { border-color: var(--accent); }
.lib-item .thumb { aspect-ratio: 16 / 10; background: #000; display: flex; align-items: center; justify-content: center; font-size: 24px; color: var(--muted); }
.lib-item .thumb img { width: 100%; height: 100%; object-fit: cover; }
.lib-item .name { font-size: 11px; padding: 6px 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lib-item .del { position: absolute; right: 4px; top: 4px; background: rgba(0,0,0,.65); color: #fff; border: none; border-radius: 50%; width: 22px; height: 22px; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th, .table td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.table.small { font-size: 12px; }
.secret { background: rgba(245,165,36,.12); color: var(--warn); border: 1px solid var(--warn); padding: 10px; border-radius: 8px; margin: 10px 0; }
.secret code { font-size: 13px; user-select: all; color: var(--text); word-break: break-all; }
.form-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 10px; }
.section { margin-bottom: 18px; }
.section h3 { font-size: 14px; margin: 0 0 8px; }

.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: var(--card); border: 1px solid var(--line); padding: 10px 16px; border-radius: 10px; z-index: 60; box-shadow: 0 10px 30px rgba(0,0,0,.4); max-width: 90vw; }

/* login */
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login-card { width: 100%; max-width: 360px; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 24px; display: flex; flex-direction: column; gap: 12px; }

#user-menu-btn, .pill { white-space: nowrap; }
@media (max-width: 600px) {
  .topbar { padding: 10px 12px; gap: 6px; flex-wrap: wrap; }
  .topbar .spacer { display: none; }
  .menu-wrap { margin-left: auto; }
  .model-pill { display: none; }
  .brand { font-size: 15px; white-space: nowrap; }
}
@media (max-width: 900px) {
  .workspace { grid-template-columns: 1fr; }
  .panel { position: static; height: auto; border-right: none; border-bottom: 1px solid var(--line); }
  .viewer { grid-template-columns: 1fr; }
  .feed { padding: 16px; }
  .table { display: block; overflow-x: auto; white-space: nowrap; }
}

/* 2FA enrollment */
.enroll-title { font-size: 17px; margin: 4px 0 0; }
.enroll-steps { margin: 0; padding-left: 18px; color: var(--muted); font-size: 13px; line-height: 1.7; }
.qr-box { background: #fff; border-radius: 12px; padding: 12px; display: flex; justify-content: center; }
.qr-box img { width: 200px; height: 200px; image-rendering: pixelated; }
.secret-key { display: block; word-break: break-all; margin-top: 6px; font-size: 13px; color: var(--text); user-select: all; }
.token-row { display: flex; gap: 8px; align-items: center; justify-content: space-between; padding: 6px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.expiry { color: var(--warn); }
