:root {
  --ink: #141310;
  --ink-2: #1b1814;
  --ink-3: #23201a;
  --cream: #efe6d4;
  --cream-dim: #b9b0a0;
  --mute: #8a8176;
  --accent: #C4602A;
  --accent-soft: rgba(196, 96, 42, 0.14);
  --line: rgba(239, 230, 212, 0.10);
  --ok: #5fae6b;
  --warn: #d9a441;
  --danger: #cf5b4a;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  background: var(--ink);
  color: var(--cream);
  font-family: "Hiragino Sans", "Noto Sans JP", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  line-height: 1.6;
}

a { color: inherit; }

button { font-family: inherit; }

.app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ---------- Header ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 14px 28px;
  background: rgba(20, 19, 16, 0.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand img {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  display: block;
}

.brand h1 {
  font-size: 16px;
  margin: 0;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.brand small {
  display: block;
  font-size: 11px;
  color: var(--mute);
  font-weight: 400;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.nav {
  display: flex;
  gap: 4px;
  margin-left: 12px;
  flex: 1;
  flex-wrap: wrap;
}

.nav button {
  background: none;
  border: 0;
  color: var(--cream-dim);
  font-size: 13.5px;
  padding: 8px 14px;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.nav button:hover { color: var(--cream); background: rgba(255, 255, 255, 0.04); }

.nav button.active {
  color: #fff;
  background: var(--accent-soft);
  box-shadow: inset 0 0 0 1px rgba(196, 96, 42, 0.4);
}

.connect-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 12.5px;
  color: var(--cream-dim);
  cursor: pointer;
  white-space: nowrap;
}

.connect-chip .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--warn);
}

.connect-chip.connected .dot { background: var(--ok); }

/* ---------- Layout ---------- */
main {
  flex: 1;
  width: 100%;
  max-width: 1180px;
  margin: 0 auto;
  padding: 30px 28px 64px;
}

.view { display: none; }
.view.active { display: block; animation: fade 0.25s ease; }

@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.view-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 22px;
  flex-wrap: wrap;
}

.view-head h2 {
  margin: 0;
  font-size: 24px;
  letter-spacing: 0.01em;
}

.view-head p {
  margin: 4px 0 0;
  color: var(--mute);
  font-size: 13.5px;
}

/* ---------- Cards / panels ---------- */
.panel {
  background: var(--ink-2);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 20px;
}

.stat-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 22px;
}

.stat {
  background: var(--ink-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px 18px;
}

.stat b {
  display: block;
  font-size: 26px;
  letter-spacing: 0.02em;
}

.stat span {
  font-size: 12px;
  color: var(--mute);
}

/* ---------- Book grid ---------- */
.toolbar {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

input, select, textarea {
  background: var(--ink-3);
  color: var(--cream);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 10px 12px;
  font-size: 14px;
  font-family: inherit;
  width: 100%;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: rgba(196, 96, 42, 0.6);
}

.toolbar input { max-width: 280px; }
.toolbar select { max-width: 200px; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
}

.book {
  background: var(--ink-2);
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: border-color 0.15s, transform 0.15s;
}

.book:hover { border-color: rgba(196, 96, 42, 0.5); transform: translateY(-2px); }

.book .cover {
  aspect-ratio: 3 / 4;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 40px;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.9);
  position: relative;
}

.book .cover small {
  position: absolute;
  bottom: 10px;
  left: 12px;
  font-size: 10px;
  letter-spacing: 0.14em;
  color: rgba(255, 255, 255, 0.75);
  font-weight: 600;
}

.book .body { padding: 14px; display: flex; flex-direction: column; gap: 8px; flex: 1; }

.book h3 { margin: 0; font-size: 14.5px; line-height: 1.45; }

.book .author { font-size: 12px; color: var(--mute); }

.book .actions { display: flex; gap: 8px; margin-top: auto; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  padding: 3px 9px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--cream-dim);
  width: fit-content;
}

.badge.published { color: #cfe9d2; border-color: rgba(95, 174, 107, 0.4); background: rgba(95, 174, 107, 0.12); }
.badge.draft { color: #e6d6b0; border-color: rgba(217, 164, 65, 0.4); background: rgba(217, 164, 65, 0.12); }
.badge.failed { color: #f0c4bd; border-color: rgba(207, 91, 74, 0.45); background: rgba(207, 91, 74, 0.14); }
.badge.ready { color: #c9d8ea; border-color: rgba(120, 160, 220, 0.35); background: rgba(120, 160, 220, 0.1); }

/* ---------- Buttons ---------- */
.btn {
  background: var(--accent);
  color: #fff;
  border: 0;
  border-radius: 9px;
  padding: 10px 16px;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  transition: filter 0.15s, opacity 0.15s;
}

.btn:hover { filter: brightness(1.08); }
.btn:disabled { opacity: 0.45; cursor: default; filter: none; }

.btn.small { padding: 7px 12px; font-size: 12.5px; }

.btn.ghost {
  background: transparent;
  color: var(--cream);
  border: 1px solid var(--line);
}

.btn.ghost:hover { border-color: rgba(196, 96, 42, 0.5); }

.btn.block { width: 100%; }

/* ---------- Compose ---------- */
.compose {
  display: grid;
  grid-template-columns: 1fr 380px;
  gap: 22px;
  align-items: start;
}

.field { margin-bottom: 16px; }
.field label { display: block; font-size: 12.5px; color: var(--mute); margin-bottom: 6px; }
.field .hint { font-size: 11.5px; color: var(--mute); margin-top: 6px; }

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 11px 0;
  border-bottom: 1px solid var(--line);
  font-size: 13.5px;
}

.switch {
  position: relative;
  width: 42px;
  height: 24px;
  border-radius: 999px;
  background: var(--ink-3);
  border: 1px solid var(--line);
  cursor: pointer;
  flex: none;
}

.switch::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--mute);
  transition: transform 0.18s, background 0.18s;
}

.switch.on { background: var(--accent-soft); border-color: rgba(196, 96, 42, 0.5); }
.switch.on::after { transform: translateX(18px); background: var(--accent); }

.steps-list { list-style: none; margin: 18px 0 0; padding: 0; }

.steps-list li {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  font-size: 13.5px;
  color: var(--mute);
  border-bottom: 1px solid var(--line);
}

.steps-list li .mark {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 1px solid var(--line);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  flex: none;
}

.steps-list li.doing { color: var(--cream); }
.steps-list li.doing .mark { border-color: var(--accent); color: var(--accent); animation: pulse 1s infinite; }
.steps-list li.done { color: var(--cream-dim); }
.steps-list li.done .mark { border-color: rgba(95, 174, 107, 0.6); color: var(--ok); }

@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.4; } }

.progress {
  height: 6px;
  border-radius: 999px;
  background: var(--ink-3);
  overflow: hidden;
  margin: 18px 0;
}

.progress i { display: block; height: 100%; width: 0; background: var(--accent); transition: width 0.3s; }

/* ---------- Phone preview ---------- */
.phone {
  width: 100%;
  max-width: 330px;
  margin: 0 auto;
  border-radius: 26px;
  border: 1px solid var(--line);
  background: #0c0b09;
  padding: 10px;
  box-shadow: 0 22px 60px rgba(0, 0, 0, 0.45);
}

.phone .screen {
  border-radius: 18px;
  overflow: hidden;
  background: #000;
  aspect-ratio: 9 / 16;
  position: relative;
}

.phone video, .phone img.screen-img, .phone .screen-fallback {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.screen-fallback {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--mute);
  font-size: 13px;
  text-align: center;
  padding: 24px;
  background: linear-gradient(160deg, #1d1a16, #0c0b09);
}

.screen-fallback .ph-icon {
  width: 54px;
  height: 54px;
  border-radius: 14px;
  border: 2px solid var(--accent);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 26px;
  font-weight: 700;
}

.phone .caption-overlay {
  position: absolute;
  bottom: 62px;
  left: 14px;
  right: 14px;
  font-size: 13px;
  font-weight: 700;
  text-align: center;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.9);
  pointer-events: none;
}

/* ---------- Account / scopes ---------- */
.account {
  display: flex;
  gap: 18px;
  align-items: center;
  flex-wrap: wrap;
}

.account .avatar {
  width: 62px;
  height: 62px;
  border-radius: 50%;
  border: 2px solid var(--accent);
  overflow: hidden;
  flex: none;
}

.account .avatar img { width: 100%; height: 100%; display: block; }

.account .who b { display: block; font-size: 17px; }
.account .who span { color: var(--mute); font-size: 13px; }

.account .metrics {
  display: flex;
  gap: 26px;
  margin-left: auto;
}

.account .metrics div { text-align: right; }
.account .metrics b { display: block; font-size: 19px; }
.account .metrics span { font-size: 11.5px; color: var(--mute); }

.scope-chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }

.scope-chips span {
  font-size: 12px;
  padding: 5px 11px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--mute);
}

.scope-chips span.granted {
  color: #cfe9d2;
  border-color: rgba(95, 174, 107, 0.4);
  background: rgba(95, 174, 107, 0.1);
}

/* ---------- Table ---------- */
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { text-align: left; padding: 12px 10px; border-bottom: 1px solid var(--line); }
th { color: var(--mute); font-weight: 500; font-size: 12px; }
td .badge { font-size: 10.5px; }

/* ---------- Log / status ---------- */
.log {
  margin-top: 16px;
  background: #0c0b09;
  border-left: 3px solid var(--accent);
  border-radius: 0 9px 9px 0;
  padding: 13px 15px;
  font-size: 13px;
  white-space: pre-wrap;
  color: var(--cream-dim);
  display: none;
}

.log.show { display: block; }

.note {
  margin-top: 14px;
  font-size: 12.5px;
  color: var(--mute);
}

.section-title {
  font-size: 13px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--mute);
  margin: 0 0 14px;
}

.split { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }

/* ---------- Legal / prose ---------- */
.doc { max-width: 760px; }
.doc h1 { font-size: 26px; margin: 0 0 4px; }
.doc .updated { color: var(--mute); font-size: 12.5px; margin: 0 0 26px; }
.doc h2 { font-size: 16px; margin: 28px 0 8px; }
.doc p, .doc li { color: var(--cream-dim); font-size: 14px; }
.doc ul { padding-left: 20px; }
.doc li { margin: 4px 0; }
.doc a { color: var(--cream); }
.doc-back { display: inline-block; margin-bottom: 18px; font-size: 13px; color: var(--mute); text-decoration: none; }
.doc-back:hover { color: var(--cream); }

/* ---------- Footer ---------- */
footer {
  border-top: 1px solid var(--line);
  padding: 22px 28px;
  color: var(--mute);
  font-size: 12.5px;
}

footer .inner {
  max-width: 1180px;
  margin: 0 auto;
  display: flex;
  gap: 18px;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
}

footer a { color: var(--cream-dim); text-decoration: none; }
footer a:hover { color: var(--cream); }

@media (max-width: 900px) {
  .compose { grid-template-columns: 1fr; }
  .stat-row { grid-template-columns: repeat(2, 1fr); }
  .split { grid-template-columns: 1fr; }
  .account .metrics { margin-left: 0; }
}

@media (max-width: 620px) {
  .topbar { flex-wrap: wrap; }
  .brand small { display: none; }
  main { padding: 20px 16px 48px; }
  .nav { order: 3; width: 100%; }
}
