:root {
  --red: #b3352c;
  --red-deep: #8f2a23;
  --ink: #1f2328;
  --muted: #6b7280;
  --line: #e5e7eb;
  --bg: #ffffff;
  --soft: #f6f7f9;
  --ok: #2f7d4f;
  --font: system-ui, -apple-system, 'Segoe UI', 'Hiragino Sans', 'Noto Sans JP', 'Yu Gothic UI', sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: var(--font); color: var(--ink); background: var(--bg); font-size: 18px; line-height: 1.5; -webkit-text-size-adjust: 100%; display: flex; flex-direction: column; min-height: 100%; }
button, input, textarea { font: inherit; color: inherit; }
a { color: inherit; }
[hidden] { display: none !important; }

/* ---------- header ---------- */
.top {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px; padding-top: calc(10px + env(safe-area-inset-top, 0px));
  border-bottom: 3px solid var(--red); background: #fff; position: sticky; top: 0; z-index: 10;
}
.brand { display: inline-flex; align-items: center; gap: 10px; text-decoration: none; font-weight: 800; font-size: 20px; letter-spacing: 0.04em; }
.brand .mark { width: 30px; height: 30px; border-radius: 8px; background: var(--red); color: #fff; display: inline-flex; align-items: center; justify-content: center; font-size: 17px; }
.model { font-size: 12px; color: var(--muted); }
.worker { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); border: 1px solid var(--line); border-radius: 999px; padding: 4px 10px; }
.worker .dot { width: 9px; height: 9px; border-radius: 50%; background: #9ca3af; }
.worker.on .dot { background: var(--ok); }
.worker.busy .dot { background: #d97706; animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: 0.3; } }
.offline { background: #fde8e6; color: var(--red-deep); border-radius: 12px; padding: 10px 14px; font-size: 15px; margin: 0 0 14px; text-align: left; }

/* ---------- common ---------- */
.view { flex: 1; }
.btn {
  border: 1.5px solid var(--line); background: #fff; border-radius: 12px; padding: 10px 16px; min-height: 46px;
  cursor: pointer; font-weight: 700; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 6px; white-space: nowrap;
}
.btn:hover { background: var(--soft); }
.btn.primary { background: var(--red); color: #fff; border-color: var(--red); }
.btn.primary:hover { background: var(--red-deep); }
.btn.ghost { border-color: transparent; }
.btn.big { font-size: 20px; padding: 14px 28px; min-height: 56px; }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn.mic { font-size: 18px; }
.btn.mic.on { background: #fde8e6; border-color: var(--red); color: var(--red); animation: pulse 1s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 6px rgba(179, 53, 44, 0.15); } }
textarea, input[type=text] {
  width: 100%; border: 2px solid var(--line); border-radius: 14px; padding: 14px 16px; font-size: 19px; background: #fff; resize: vertical; line-height: 1.5;
}
textarea:focus, input:focus { outline: none; border-color: var(--red); }
.note { color: var(--muted); font-size: 16px; }
.err { color: var(--red); font-size: 15px; }
.card { background: #fff; border: 1px solid var(--line); border-radius: 18px; padding: 24px; box-shadow: 0 6px 24px rgba(0, 0, 0, 0.06); }
.card.narrow { max-width: 460px; margin: 60px auto; }
.card h1 { font-size: 22px; margin: 0 0 8px; }
.card form { display: flex; flex-direction: column; gap: 12px; margin-top: 14px; }

/* ---------- home ---------- */
.hero { max-width: 820px; margin: 0 auto; padding: 36px 16px 8px; text-align: center; }
.hero h1 { font-size: 30px; margin: 0 0 8px; letter-spacing: 0.02em; }
.lead { color: var(--muted); font-size: 17px; margin: 0 0 20px; }
.ask { display: flex; flex-direction: column; gap: 10px; text-align: left; }
.ask-row { display: flex; justify-content: flex-end; gap: 10px; align-items: center; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 18px; }
.chip { border: 1.5px solid var(--line); background: #fff; border-radius: 999px; padding: 8px 14px; font-size: 15px; cursor: pointer; }
.chip:hover { border-color: var(--red); color: var(--red); }
.list-head { max-width: 1100px; margin: 36px auto 10px; padding: 0 16px; display: flex; align-items: baseline; gap: 10px; }
.list-head h2 { font-size: 20px; margin: 0; }
.count { color: var(--muted); font-size: 14px; }
.grid { max-width: 1100px; margin: 0 auto 40px; padding: 0 16px; display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; }
.app-card { border: 1px solid var(--line); border-radius: 16px; padding: 16px; background: #fff; display: flex; flex-direction: column; gap: 8px; box-shadow: 0 2px 10px rgba(0, 0, 0, 0.04); }
.app-card .t { font-weight: 800; font-size: 19px; }
.app-card .s { color: var(--muted); font-size: 14px; min-height: 1.4em; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.app-card .d { color: #9ca3af; font-size: 12px; }
.app-card .row { display: flex; gap: 8px; margin-top: 4px; }
.app-card .row .btn { flex: 1; }
.empty { max-width: 1100px; margin: 0 auto 40px; padding: 0 16px; color: var(--muted); }

/* ---------- studio ---------- */
.studio { display: flex; flex-direction: column; min-height: 0; height: calc(100vh - 56px); height: calc(100dvh - 56px); }
.studio-head { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.studio-title { flex: 1; min-width: 160px; }
.studio-title input { width: 100%; border: 1.5px solid transparent; border-radius: 10px; padding: 6px 10px; font-size: 20px; font-weight: 800; background: transparent; }
.studio-title input:hover, .studio-title input:focus { border-color: var(--line); background: #fff; outline: none; }
.studio-actions { display: flex; gap: 6px; align-items: center; }
.menu-wrap { position: relative; }
.menu { position: absolute; right: 0; top: calc(100% + 6px); background: #fff; border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.12); min-width: 240px; padding: 6px; z-index: 20; }
.menu-sec { font-size: 12px; color: var(--muted); padding: 6px 10px 2px; }
.menu-sep { height: 1px; background: var(--line); margin: 6px 4px; }
.menu-item { display: block; width: 100%; text-align: left; background: none; border: none; padding: 10px; border-radius: 8px; cursor: pointer; font-size: 15px; }
.menu-item:hover { background: var(--soft); }
.menu-item.danger { color: var(--red); }
.menu-item.on { font-weight: 800; }
.menu-item small { color: var(--muted); font-weight: 400; margin-left: 6px; }
.tabs { display: none; border-bottom: 1px solid var(--line); }
.tab { flex: 1; background: none; border: none; padding: 10px; font-weight: 700; color: var(--muted); border-bottom: 3px solid transparent; }
.tab.on { color: var(--red); border-bottom-color: var(--red); }
.studio-body { flex: 1; display: grid; grid-template-columns: minmax(320px, 420px) 1fr; min-height: 0; }
.pane { min-height: 0; display: flex; flex-direction: column; }
.pane.chat { border-right: 1px solid var(--line); }
.messages { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 92%; padding: 10px 14px; border-radius: 16px; font-size: 16px; white-space: pre-wrap; word-break: break-word; }
.msg.user { align-self: flex-end; background: var(--red); color: #fff; border-bottom-right-radius: 4px; }
.msg.ai { align-self: flex-start; background: var(--soft); border-bottom-left-radius: 4px; }
.msg.ai.err { background: #fde8e6; color: var(--red-deep); }
.msg .v { display: block; margin-top: 6px; font-size: 12px; color: var(--muted); }
.msg .v button { background: none; border: 1px solid var(--line); border-radius: 8px; padding: 2px 8px; font-size: 12px; cursor: pointer; margin-left: 6px; }
.msg.typing { color: var(--muted); font-style: normal; }
.composer { border-top: 1px solid var(--line); padding: 10px; display: flex; flex-direction: column; gap: 8px; background: #fff; padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px)); }
.composer textarea { font-size: 17px; padding: 10px 12px; border-radius: 12px; }
.composer-row { display: flex; justify-content: flex-end; gap: 8px; }
.pane.preview { background: var(--soft); }
.preview-frame { flex: 1; position: relative; margin: 10px; border: 1px solid var(--line); border-radius: 14px; overflow: hidden; background: #fff; }
.preview-frame iframe { width: 100%; height: 100%; border: 0; display: block; }
.preview-empty { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: var(--muted); pointer-events: none; }
.preview-busy { position: absolute; inset: 0; background: rgba(255, 255, 255, 0.92); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; text-align: center; padding: 20px; }
.spinner { width: 46px; height: 46px; border-radius: 50%; border: 5px solid #f1d4d1; border-top-color: var(--red); animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.busy-text { font-weight: 800; font-size: 20px; }
.busy-sub { color: var(--muted); font-size: 14px; max-width: 420px; }

.toast { position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 12px; z-index: 100; font-size: 16px; max-width: 92vw; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25); }

/* ---------- mobile ---------- */
@media (max-width: 760px) {
  body { font-size: 17px; }
  .hero { padding-top: 22px; }
  .hero h1 { font-size: 24px; }
  .studio { height: auto; min-height: calc(100dvh - 56px); }
  .studio-head { padding: 8px; }
  .studio-actions .btn { padding: 8px 10px; min-height: 40px; font-size: 14px; }
  .tabs { display: flex; }
  .studio-body { display: block; flex: 1; }
  .pane { display: none; height: calc(100dvh - 56px - 52px - 48px); }
  .pane.on { display: flex; }
  .pane.chat { border-right: 0; }
  .preview-frame { margin: 6px; }
  .model { display: none; }
}
