/* AI開発会社 PWA — iPhone優先。1画面1目的、大きなタップ領域、少ない情報量。 */

:root {
  --bg: #0b1220;
  --surface: #131c2e;
  --surface-2: #1b263c;
  --line: #2a3550;
  --text: #eaf0fb;
  --muted: #94a3b8;
  --accent: #38bdf8;
  --accent-ink: #04222f;
  --ok: #34d399;
  --warn: #fbbf24;
  --danger: #f87171;
  --radius: 14px;
  --tap: 48px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f6fb;
    --surface: #ffffff;
    --surface-2: #eef2f9;
    --line: #d6ddea;
    --text: #101828;
    --muted: #5a6678;
    --accent: #0369a1;
    --accent-ink: #ffffff;
    --ok: #047857;
    --warn: #b45309;
    --danger: #b91c1c;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic", "Noto Sans JP", sans-serif;
  font-size: 17px;
  line-height: 1.6;
  overscroll-behavior-y: none;
}

body { min-height: 100dvh; }

#app { min-height: 100dvh; display: flex; flex-direction: column; }

.boot { padding: 40px; text-align: center; color: var(--muted); }

/* ---------- ヘッダ ---------- */
header.top {
  position: sticky; top: 0; z-index: 20;
  padding: calc(var(--safe-t) + 10px) 16px 10px;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 12px;
}
header.top h1 { font-size: 18px; margin: 0; font-weight: 700; letter-spacing: .02em; flex: 1; }
.conn { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--danger); }
.dot.on { background: var(--ok); }

.badge {
  min-width: 22px; height: 22px; padding: 0 6px; border-radius: 11px;
  background: var(--danger); color: #fff; font-size: 12px; font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center;
}

/* ---------- 本文 ---------- */
main { flex: 1; padding: 16px 16px calc(96px + var(--safe-b)); max-width: 720px; width: 100%; margin: 0 auto; }
h2 { font-size: 20px; margin: 0 0 4px; }
h3 { font-size: 16px; margin: 20px 0 8px; }
p.lead { color: var(--muted); margin: 0 0 16px; font-size: 14px; }

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; margin-bottom: 12px;
}
.card.tappable { cursor: pointer; }
.card.tappable:active { background: var(--surface-2); }
.card h3 { margin: 0 0 6px; font-size: 17px; }
.card .meta { color: var(--muted); font-size: 13px; }

.row { display: flex; align-items: center; gap: 10px; }
.row.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.pill {
  display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px;
  background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); white-space: nowrap;
}
.pill.ok { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 40%, transparent); }
.pill.warn { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 40%, transparent); }
.pill.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, transparent); }
.pill.run { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 40%, transparent); }

/* ---------- ボタン ---------- */
button, .btn {
  min-height: var(--tap); padding: 12px 18px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface-2); color: var(--text); font-size: 16px; font-weight: 600;
  font-family: inherit; cursor: pointer; white-space: nowrap;
}
button:active { transform: scale(.985); }
button:disabled { opacity: .45; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
button.danger { background: var(--danger); color: #fff; border-color: transparent; }
button.ghost { background: transparent; }
button.full { width: 100%; }
button.small, .btn.small { min-height: 44px; padding: 8px 14px; font-size: 14px; }

input, textarea, select {
  width: 100%; min-height: var(--tap); padding: 12px 14px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface-2); color: var(--text);
  font-size: 16px; font-family: inherit;
}
textarea { min-height: 96px; resize: vertical; line-height: 1.5; }
label { display: block; font-size: 14px; color: var(--muted); margin: 12px 0 6px; }

/* ---------- 会話 ---------- */
.chat { display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 88%; padding: 12px 14px; border-radius: 16px; font-size: 16px; white-space: pre-wrap; word-break: break-word; }
.msg.user { align-self: flex-end; background: var(--accent); color: var(--accent-ink); border-bottom-right-radius: 4px; }
.msg.ai { align-self: flex-start; background: var(--surface); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.msg.sys { align-self: center; background: transparent; color: var(--muted); font-size: 13px; padding: 2px; }
.msg.thinking { color: var(--muted); font-style: italic; }
.msg h1, .msg h2, .msg h3 { font-size: 16px; margin: 8px 0 4px; }
.msg code { background: rgba(127,127,127,.18); padding: 1px 5px; border-radius: 5px; font-size: 14px; }
.msg ul { margin: 6px 0; padding-left: 20px; }

.mic-wrap { display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 18px 0 6px; }
.mic {
  width: 92px; height: 92px; border-radius: 50%; border: none;
  background: var(--accent); color: var(--accent-ink); font-size: 34px;
  display: grid; place-items: center; box-shadow: 0 8px 26px rgba(56,189,248,.28);
}
.mic.listening { background: var(--danger); color: #fff; animation: pulse 1.3s ease-in-out infinite; }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 0 rgba(248,113,113,.5); } 50% { box-shadow: 0 0 0 18px rgba(248,113,113,0); } }
.mic-hint { font-size: 13px; color: var(--muted); text-align: center; min-height: 20px; }

.composer { display: flex; gap: 8px; align-items: flex-end; }
.composer button { flex: 0 0 auto; }
.composer textarea { min-height: var(--tap); max-height: 140px; }

/* ---------- 確認ダイアログ ---------- */
.sheet-backdrop {
  position: fixed; inset: 0; background: rgba(2,6,20,.62); z-index: 60;
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet {
  background: var(--surface); border-top-left-radius: 20px; border-top-right-radius: 20px;
  width: 100%; max-width: 560px; padding: 22px 18px calc(22px + var(--safe-b));
  border: 1px solid var(--line); border-bottom: none;
}
.sheet h3 { margin-top: 0; font-size: 19px; }
.sheet .danger-note {
  background: color-mix(in srgb, var(--danger) 14%, transparent);
  border: 1px solid color-mix(in srgb, var(--danger) 45%, transparent);
  color: var(--text); border-radius: 12px; padding: 12px; font-size: 14px; margin: 12px 0;
}
.phrase {
  font-size: 22px; font-weight: 800; letter-spacing: .12em; text-align: center;
  padding: 12px; background: var(--surface-2); border-radius: 12px; margin: 10px 0;
}

/* ---------- タブバー ---------- */
nav.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: color-mix(in srgb, var(--surface) 96%, transparent);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  padding-bottom: var(--safe-b);
}
nav.tabs a {
  min-height: 58px; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; color: var(--muted); text-decoration: none; font-size: 11px; position: relative;
}
nav.tabs a .ico { font-size: 20px; line-height: 1; }
nav.tabs a.active { color: var(--accent); }
nav.tabs a .badge { position: absolute; top: 6px; right: 50%; transform: translateX(22px); }

/* ---------- 進捗 ---------- */
.steps { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0; }
.step { font-size: 12px; padding: 4px 9px; border-radius: 8px; background: var(--surface-2); color: var(--muted); }
.step.done { color: var(--ok); }
.step.current { background: var(--accent); color: var(--accent-ink); font-weight: 700; }

.timeline { border-left: 2px solid var(--line); margin-left: 8px; padding-left: 14px; }
.timeline .item { margin-bottom: 14px; position: relative; }
.timeline .item::before {
  content: ''; position: absolute; left: -21px; top: 7px; width: 9px; height: 9px;
  border-radius: 50%; background: var(--line);
}
.timeline .item.ok::before { background: var(--ok); }
.timeline .item.bad::before { background: var(--danger); }
.timeline .t { font-size: 12px; color: var(--muted); }
.timeline .d { font-size: 14px; }

.score { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--line); }
.score:last-child { border-bottom: none; }
.score .v { font-weight: 700; }
.score .v.ok { color: var(--ok); }
.score .v.bad { color: var(--danger); }

pre.out {
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px;
  padding: 12px; overflow-x: auto; font-size: 12px; line-height: 1.5; max-height: 320px;
}

.empty { text-align: center; color: var(--muted); padding: 42px 16px; }
.empty .ico { font-size: 42px; display: block; margin-bottom: 10px; opacity: .6; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(80px + var(--safe-b)); z-index: 80;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 18px; font-size: 14px; max-width: 92vw; box-shadow: 0 8px 26px rgba(0,0,0,.35);
}
.toast.err { border-color: var(--danger); color: var(--danger); }

.tree { list-style: none; padding-left: 0; margin: 0; }
.tree ul { list-style: none; padding-left: 18px; border-left: 1px dashed var(--line); margin: 4px 0; }
.tree li { padding: 4px 0; }
.tree li > .row { flex-wrap: wrap; row-gap: 4px; }
.tree .name { font-weight: 600; }
.tree .rid { color: var(--muted); font-size: 12px; }

.login-wrap { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.login { width: 100%; max-width: 360px; }
.login h1 { font-size: 22px; text-align: center; margin-bottom: 4px; }
.login p { text-align: center; color: var(--muted); font-size: 14px; margin-top: 0; }

.err { color: var(--danger); font-size: 14px; min-height: 20px; }
.ok-text { color: var(--ok); font-size: 14px; }
.mut { color: var(--muted); font-size: 13px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }
hr { border: none; border-top: 1px solid var(--line); margin: 18px 0; }
