:root {
  --bg: #0d1210;
  --panel: #161d1a;
  --panel-2: #1d2622;
  --line: #29352f;
  --text: #e8f0eb;
  --muted: #8d9f96;
  --accent: #5fd38a;
  --accent-strong: #44bf73;
  --danger: #ef6b6b;
  --warn: #f2c14e;
  --radius: 14px;
  --shadow: 0 1px 0 #ffffff08 inset, 0 8px 24px #0004;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text); min-height: 100vh;
  font-family: "Segoe UI", "Hiragino Sans", "Noto Sans JP", system-ui, sans-serif; line-height: 1.6;
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--accent); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 0.82rem; }
.center { text-align: center; }
.error-text { color: var(--danger) !important; }
code { background: var(--panel-2); padding: 2px 6px; border-radius: 6px; word-break: break-all; font-size: 0.85em; }

/* スプラッシュ */
.splash { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; align-content: center; gap: 20px; background: var(--bg); }
.splash img { width: 72px; height: 72px; border-radius: 16px; }
.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--accent); animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ヘッダー */
.topbar {
  position: sticky; top: 0; z-index: 10; display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 10px max(20px, env(safe-area-inset-right)) 10px max(20px, env(safe-area-inset-left));
  border-bottom: 1px solid var(--line); background: #161d1ae6; backdrop-filter: blur(10px);
}
.brand { display: flex; align-items: center; gap: 10px; font-size: 1.05rem; min-width: 0; }
.brand b { color: var(--accent); }
.logo { width: 34px; height: 34px; border-radius: 8px; object-fit: cover; flex: none; }
.user { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 0.88rem; min-width: 0; }
.user-email { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 220px; }
.avatar { width: 30px; height: 30px; flex: none; border-radius: 50%; display: grid; place-items: center; background: var(--panel-2); border: 1px solid var(--line); color: var(--accent); font-weight: 700; }

main { max-width: 1080px; margin: 0 auto; padding: 24px 16px 80px; }

/* 認証カード */
.auth-card {
  max-width: 420px; margin: 32px auto; background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 28px; box-shadow: var(--shadow); animation: fadein 0.2s ease;
}
.auth-card h1 { margin: 0 0 12px; font-size: 1.35rem; }
.hero-icon { display: block; width: 112px; height: 112px; margin: 0 auto 16px; border-radius: 22px; box-shadow: 0 6px 24px #3cb96c33; }
@keyframes fadein { from { opacity: 0; transform: translateY(4px); } }
form { display: grid; gap: 14px; }
label { display: grid; gap: 6px; font-size: 0.88rem; color: var(--muted); }
input[type=email], input[type=password], input:not([type]) {
  background: var(--bg); border: 1px solid var(--line); color: var(--text); border-radius: 10px;
  padding: 12px 14px; font-size: 16px; width: 100%;
}
input:focus-visible, button:focus-visible, .drop:focus-visible, summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
input.otp { font-size: 1.6rem; letter-spacing: 0.4em; text-align: center; font-variant-numeric: tabular-nums; padding: 10px; }
.steps { margin: 0 0 8px; padding-left: 1.3em; color: var(--muted); font-size: 0.9rem; }

/* ボタン */
button {
  position: relative; background: var(--accent); color: #06210f; border: 0; border-radius: 10px; padding: 11px 16px;
  font: inherit; font-weight: 700; font-size: 0.95rem; cursor: pointer; transition: background 0.15s, opacity 0.15s, transform 0.05s;
}
button:hover:not(:disabled) { background: var(--accent-strong); }
button:active:not(:disabled) { transform: translateY(1px); }
button:disabled { opacity: 0.45; cursor: not-allowed; }
button.ghost { background: transparent; color: var(--text); border: 1px solid var(--line); font-weight: 500; }
button.ghost:hover:not(:disabled) { border-color: var(--accent); background: transparent; }
button.secondary { background: var(--panel-2); color: var(--text); border: 1px solid var(--line); }
button.secondary:hover:not(:disabled) { background: var(--line); }
button.danger { color: var(--danger); }
button.danger:hover:not(:disabled) { border-color: var(--danger); }
button.danger-fill { background: var(--danger); color: #2a0606; }
button.danger-fill:hover:not(:disabled) { background: #e05555; }
button.sm { padding: 6px 12px; font-size: 0.85rem; }
button.big { width: 100%; padding: 14px; font-size: 1.02rem; margin-top: 10px; }
button.link { background: none; color: var(--accent); padding: 0; font-weight: 500; text-decoration: underline; font-size: inherit; }
button.loading { color: transparent !important; pointer-events: none; }
button.loading::after {
  content: ""; position: absolute; inset: 0; margin: auto; width: 18px; height: 18px; border-radius: 50%;
  border: 2px solid currentColor; border-color: #06210f55; border-top-color: #06210f; animation: spin 0.7s linear infinite;
}
button.ghost.loading::after, button.secondary.loading::after { border-color: #ffffff33; border-top-color: var(--text); }
.btn-row { display: flex; gap: 10px; margin-bottom: 12px; }
.btn-row > button { flex: 1; }
.btn-row.end { justify-content: flex-end; margin: 18px 0 0; }
.btn-row.end > button { flex: none; }
.icon-btn { background: none; color: var(--muted); padding: 2px 8px; font-size: 1.1rem; line-height: 1; border-radius: 6px; }
.icon-btn:hover:not(:disabled) { background: var(--line); color: var(--text); }

.qr { display: grid; place-items: center; background: #fff; border-radius: 12px; padding: 10px; width: fit-content; margin: 8px auto; }
.qr img { width: 190px; height: 190px; display: block; }
.codes { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 0; list-style: none; font-family: ui-monospace, Consolas, monospace; font-size: 1.02rem; }
.codes li { background: var(--panel-2); padding: 8px; border-radius: 8px; text-align: center; letter-spacing: 0.05em; }

/* ダッシュボード */
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.chip { display: inline-flex; align-items: center; gap: 7px; font-size: 0.82rem; padding: 5px 12px; border-radius: 999px; background: var(--panel); border: 1px solid var(--line); color: var(--muted); }
.chip .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.chip.ok .dot { background: var(--accent); box-shadow: 0 0 8px var(--accent); }
.chip.warn .dot { background: var(--warn); }
.chip.bad .dot { background: var(--danger); }
.chip.ok, .chip.warn, .chip.bad { color: var(--text); }

.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; margin-bottom: 16px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; margin-bottom: 16px; box-shadow: var(--shadow); }
.grid .card { margin-bottom: 0; display: flex; flex-direction: column; }
.grid .card .big { margin-top: auto; }
.card h2 { margin: 0; font-size: 1.05rem; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; min-height: 32px; }

.versions { display: flex; align-items: center; gap: 16px; margin: 4px 0 8px; }
.ver-box { display: grid; }
.versions .label { font-size: 0.75rem; color: var(--muted); }
.versions .ver { font-size: 1.45rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.versions .accent { color: var(--accent); }
.arrow { color: var(--muted); font-size: 1.3rem; }
.options { margin: 4px 0 8px; font-size: 0.9rem; }
.options summary { cursor: pointer; color: var(--muted); padding: 4px 0; user-select: none; }
.options[open] summary { margin-bottom: 6px; }
.options .check { margin: 6px 0; }
.check { display: flex; align-items: center; gap: 10px; color: var(--text); font-size: 0.9rem; cursor: pointer; }
.check input { accent-color: var(--accent); width: 18px; height: 18px; flex: none; }
.power { display: flex; gap: 8px; margin-top: 10px; }
.power button { flex: 1; }

.skeleton { color: transparent !important; background: linear-gradient(90deg, var(--panel-2), var(--line), var(--panel-2)); background-size: 200% 100%; animation: shimmer 1.2s infinite; border-radius: 6px; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ドロップ */
.drop {
  display: grid; place-items: center; text-align: center; gap: 4px; min-height: 130px; margin-bottom: 10px;
  border: 2px dashed var(--line); border-radius: 12px; cursor: pointer; color: var(--text); padding: 16px; transition: border-color 0.15s, background 0.15s;
}
.drop-icon { font-size: 1.4rem; color: var(--accent); }
.drop:hover, .drop.over { border-color: var(--accent); background: #5fd38a0d; }
.drop.has-file { min-height: 90px; }
.file-list { list-style: none; padding: 0; margin: 0 0 10px; display: grid; gap: 6px; }
.file { display: flex; align-items: center; gap: 10px; background: var(--panel-2); border-radius: 8px; padding: 6px 6px 6px 12px; font-size: 0.88rem; }
.file-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* バッジ・進捗 */
.badge { font-size: 0.78rem; padding: 3px 10px; border-radius: 999px; background: var(--panel-2); color: var(--muted); white-space: nowrap; }
.badge:empty { display: none; }
.badge.ok { background: #1f3d2b; color: var(--accent); }
.badge.warn { background: #3d3420; color: var(--warn); }
.badge.bad { background: #452424; color: var(--danger); }
.badge.run { background: #1f3d2b; color: var(--accent); }
.job-line { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.job-step { font-size: 0.95rem; }
.bar { height: 8px; background: var(--panel-2); border-radius: 999px; overflow: hidden; margin: 10px 0 12px; }
.bar div { height: 100%; width: 0; background: linear-gradient(90deg, var(--accent-strong), var(--accent)); transition: width 0.5s ease; border-radius: 999px; }
.bar div.error { background: var(--danger); }
details > summary { cursor: pointer; color: var(--muted); font-size: 0.88rem; }
.log {
  background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 12px; margin: 8px 0 0;
  max-height: 300px; overflow: auto; font-size: 0.8rem; white-space: pre-wrap; word-break: break-all; font-family: ui-monospace, Consolas, monospace;
}

/* パック一覧 */
.packs { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.pack { display: flex; align-items: center; gap: 12px; padding: 10px 12px; background: var(--panel-2); border-radius: 10px; min-height: 52px; }
.pack.disabled { opacity: 0.6; }
.pack-body { flex: 1; min-width: 0; display: grid; }
.pack-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.skeleton-row { background: linear-gradient(90deg, var(--panel-2), var(--line), var(--panel-2)); background-size: 200% 100%; animation: shimmer 1.2s infinite; }
.tag { font-size: 0.72rem; font-weight: 700; padding: 4px 7px; border-radius: 6px; flex: none; }
.tag.behavior { background: #1e3147; color: #8ec5ff; }
.tag.resource { background: #3d2f1c; color: #f5b971; }
.empty { padding: 12px 4px; list-style: none; }
#packsMeta { margin: 10px 0 0; }

/* 履歴 */
.history { list-style: none; padding: 0; margin: 0; }
.hist { display: flex; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.hist:last-child { border-bottom: 0; }
.hist-icon { width: 28px; height: 28px; flex: none; display: grid; place-items: center; border-radius: 8px; background: var(--panel-2); color: var(--muted); font-size: 0.85rem; }
.hist.update .hist-icon { color: var(--accent); }
.hist.addon .hist-icon { color: #8ec5ff; }
.hist.addon-remove .hist-icon { color: var(--danger); }
.hist-body { display: grid; min-width: 0; flex: 1; }
.hist-detail { font-size: 0.9rem; word-break: break-word; }
.hist-meta { display: flex; gap: 10px; font-size: 0.78rem; color: var(--muted); }
.who { font-weight: 600; }
.who.me { color: var(--accent); }

.warn { background: #3b3220; border: 1px solid #5c4c26; color: var(--warn); padding: 12px 16px; border-radius: var(--radius); margin-bottom: 16px; font-size: 0.9rem; }

/* トースト・ダイアログ */
.toast {
  position: fixed; bottom: max(20px, env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%); z-index: 60; width: max-content; max-width: calc(100% - 32px);
  background: var(--panel-2); border: 1px solid var(--line); border-left: 4px solid var(--muted); padding: 12px 18px; border-radius: 10px; box-shadow: 0 8px 30px #0009;
  animation: toastin 0.2s ease;
}
.toast.success { border-left-color: var(--accent); }
.toast.error { border-left-color: var(--danger); color: #ffd6d6; }
@keyframes toastin { from { opacity: 0; transform: translate(-50%, 8px); } }
.dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; width: min(420px, calc(100% - 32px)); box-shadow: 0 20px 60px #000a; }
.dialog::backdrop { background: #000a; backdrop-filter: blur(2px); }
.dialog form { display: block; }
#confirmText { margin: 0; white-space: pre-line; }

/* スマホ */
@media (max-width: 640px) {
  main { padding: 16px 12px 80px; }
  .topbar { padding: 8px 12px; }
  .brand-text { font-size: 0.92rem; }
  .user-email { display: none; }
  .auth-card { margin: 12px auto; padding: 22px 18px; }
  .grid { grid-template-columns: 1fr; gap: 12px; margin-bottom: 12px; }
  .card { padding: 16px; margin-bottom: 12px; }
  .versions .ver { font-size: 1.25rem; }
  .drop { min-height: 100px; }
}
@media (max-width: 400px) {
  .brand-text { font-size: 0.85rem; }
  .avatar { display: none; }
}
@media (max-width: 330px) {
  .brand-text { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
