:root {
  --bg: #121826;
  --bg2: #0d121c;
  --card: #1a2234;
  --card2: #212b40;
  --line: #2c374f;
  --text: #e8ebf1;
  --muted: #98a3b8;
  --silver: #c9d1df;
  --accent: #7fb0ff;
  --accent-d: #4d84dc;
  --zeke: #e6b36a;
  --julius: #8fbaff;
  --star: #e2bd6f;
  --danger: #ef7d7d;
  --ok: #7ed3a5;
  --radius: 14px;
  --serif: "Shippori Mincho", "Hiragino Mincho ProN", "Yu Mincho", "YuMincho", "Noto Serif JP", serif;
  --sans: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic UI", "Meiryo", sans-serif;
  --tabbar-h: 64px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100vh;
  background: radial-gradient(1200px 600px at 50% -200px, #1d2740 0%, var(--bg) 60%) fixed, var(--bg);
  color: var(--text); font-family: var(--sans); font-size: 16px; line-height: 1.65;
  -webkit-tap-highlight-color: transparent;
}
body.modal-open { overflow: hidden; }
h1, h2, h3 { font-family: var(--serif); font-weight: 600; letter-spacing: .04em; margin: 0 0 .6em; }
h2 { font-size: 1.12rem; }
h3 { font-size: 1rem; margin-top: 1.2em; color: var(--silver); }
a { color: var(--accent); }
p { margin: .4em 0 .8em; }

/* ---------- 入力 ---------- */
input, select, textarea, button { font: inherit; color: inherit; }
input[type=text], input[type=email], input[type=password], input[type=url], input[type=search], input[type=number], select, textarea {
  width: 100%; background: var(--bg2); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; font-size: 16px; /* iOS の自動拡大を防ぐ */
  outline: none; transition: border-color .15s;
}
select { width: auto; padding: 8px 10px; }
textarea { resize: vertical; line-height: 1.7; min-height: 3em; }
input:focus, select:focus, textarea:focus { border-color: var(--accent-d); }
input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--accent); margin: 0; flex: none; }
input.num { width: 6.5em; }
label { display: block; font-size: .85rem; color: var(--muted); margin: 0 0 12px; }
label > input, label > textarea, label > select, label > .chips, label > .rating { margin-top: 4px; color: var(--text); }
label > select { display: block; }
label > input.num { display: block; }
label.inline > select { display: inline-block; margin-top: 0; }
label.inline { display: inline-flex; align-items: center; gap: 6px; margin: 0; }
label.check { cursor: pointer; }

/* ---------- ボタン ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line); background: var(--card2); border-radius: 999px;
  padding: 9px 18px; cursor: pointer; white-space: nowrap; transition: background .15s, opacity .15s, transform .05s;
}
.btn:active { transform: scale(.97); }
.btn.primary { background: linear-gradient(180deg, #8bb8ff, #5f95ea); color: #0b1222; border-color: transparent; font-weight: 600; }
.btn.ghost { background: transparent; }
.btn.danger { background: var(--danger); color: #1b0d0d; border-color: transparent; font-weight: 600; }
.btn.small { padding: 5px 12px; font-size: .85rem; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .45; cursor: default; }
.btn.busy { opacity: .6; pointer-events: none; }
.danger-text { color: var(--danger) !important; }
.icon-btn { background: transparent; border: 0; color: var(--silver); cursor: pointer; width: 40px; height: 40px; border-radius: 50%; display: inline-grid; place-items: center; font-size: 1.05rem; flex: none; }
.icon-btn:disabled { opacity: .3; }
.icon-btn.small { width: 32px; height: 32px; font-size: .95rem; }
.icon-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- 並び ---------- */
.row { display: flex; align-items: center; gap: 8px; }
.row.wrap { flex-wrap: wrap; }
.row.end { justify-content: flex-end; flex-wrap: wrap; margin-top: 8px; }
.spacer { flex: 1; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.hint { color: var(--muted); font-size: .85rem; background: rgba(127, 176, 255, .06); border-left: 3px solid var(--accent-d); padding: 8px 12px; border-radius: 0 8px 8px 0; }
.empty { text-align: center; padding: 28px 0; }
.error-text { color: var(--danger); }

/* ---------- 外枠 ---------- */
#app { max-width: 820px; margin: 0 auto; min-height: 100vh; }
#app.dim { opacity: .5; pointer-events: none; }
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 8px;
  padding: calc(env(safe-area-inset-top) + 8px) 12px 8px 16px;
  background: rgba(18, 24, 38, .86); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid rgba(255, 255, 255, .05);
}
.brand-sm { font-family: var(--serif); font-size: 1.05rem; letter-spacing: .12em; color: var(--silver); flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#backup-warn { flex: none; }
.demo-badge { font-family: var(--sans); font-size: .7rem; letter-spacing: 0; margin-left: 8px; padding: 1px 8px; border-radius: 99px; background: var(--zeke); color: #201505; vertical-align: middle; }
.warn-pill { border: 0; background: rgba(226, 189, 111, .16); color: var(--star); border-radius: 99px; padding: 4px 12px; font-size: .8rem; cursor: pointer; white-space: nowrap; }
main#view { padding: 14px 14px calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 90px); }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: flex; justify-content: center;
  background: rgba(13, 18, 28, .94); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
}
.tab { flex: 1; max-width: 160px; height: var(--tabbar-h); background: none; border: 0; color: var(--muted); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: .72rem; cursor: pointer; }
.tab svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.tab.active { color: var(--accent); }
.tab.active svg { stroke-width: 2; }

/* ---------- カード ---------- */
.card { background: var(--card); border: 1px solid rgba(255, 255, 255, .05); border-radius: var(--radius); padding: 14px 16px; margin: 0 0 12px; }
.section-title { font-size: .95rem; color: var(--silver); margin: 22px 4px 10px; }
.item-card { cursor: pointer; transition: background .15s; }
.item-card:hover { background: #1e2740; }
.item-card.done { opacity: .55; }
.line-text { font-family: var(--serif); font-size: 1.04rem; line-height: 1.85; white-space: pre-wrap; word-break: break-word; }
.clip { white-space: pre-wrap; word-break: break-word; font-size: .92rem; color: var(--silver); max-height: 7.5em; overflow: hidden; }
.meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; margin-top: 8px; font-size: .78rem; color: var(--muted); }
.stars { color: var(--star); letter-spacing: 1px; }
.tag { background: rgba(127, 176, 255, .12); color: var(--julius); padding: 1px 8px; border-radius: 99px; font-size: .75rem; white-space: nowrap; }
.tag.added { background: rgba(126, 211, 165, .15); color: var(--ok); }
.tag.removed { background: rgba(239, 125, 125, .15); color: var(--danger); }
.tag.changed { background: rgba(226, 189, 111, .15); color: var(--star); }
.src { border: 1px solid var(--line); padding: 0 7px; border-radius: 6px; }
.ctx::before { content: "場面："; }
.note { margin-top: 8px; font-size: .85rem; color: #d7c7a6; background: rgba(226, 189, 111, .06); border-radius: 8px; padding: 6px 10px; white-space: pre-wrap; }

.turns { display: flex; flex-direction: column; gap: 6px; }
.turn { display: grid; grid-template-columns: 5.2em 1fr; gap: 8px; font-size: .94rem; }
.turn b { font-weight: 600; font-size: .78rem; padding-top: 3px; }
.turn.zeke b { color: var(--zeke); }
.turn.julius b { color: var(--julius); }
.turn.julius span { font-family: var(--serif); }
.turn span { white-space: pre-wrap; word-break: break-word; display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }

/* ---------- チップ ---------- */
.chips { display: flex; gap: 6px; }
.chips.wrap { flex-wrap: wrap; }
.chips.scroll { overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; margin: 8px -14px; padding-left: 14px; padding-right: 14px; }
.chips.scroll::-webkit-scrollbar { display: none; }
.chip { border: 1px solid var(--line); background: transparent; border-radius: 99px; padding: 4px 12px; font-size: .85rem; cursor: pointer; white-space: nowrap; color: var(--silver); }
.chip.on { background: rgba(127, 176, 255, .16); border-color: var(--accent-d); color: var(--text); }
.chip.editable { display: inline-flex; align-items: center; gap: 2px; padding-right: 4px; cursor: default; }
.chip-x { background: none; border: 0; color: var(--muted); cursor: pointer; padding: 0 5px; font-size: .85rem; }
.tag-add { width: 9em !important; padding: 4px 10px !important; border-radius: 99px !important; font-size: 16px; }

.rating { display: flex; gap: 4px; }
.star { background: none; border: 0; font-size: 1.7rem; line-height: 1; color: #3a4560; cursor: pointer; padding: 2px 4px; }
.star.on { color: var(--star); }

/* ---------- 絞り込み ---------- */
.filters { position: sticky; top: calc(env(safe-area-inset-top) + 57px); z-index: 10; background: var(--bg); margin: -14px -14px 0; padding: 12px 14px 6px; border-bottom: 1px solid rgba(255, 255, 255, .04); }
.filters .row select { font-size: .85rem; padding: 6px 8px; }
.count { margin: 10px 4px; }
.fab {
  position: fixed; right: max(18px, calc(50vw - 400px)); bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 18px); z-index: 25;
  width: 58px; height: 58px; border-radius: 50%; border: 0; cursor: pointer; font-size: 1.8rem; line-height: 1;
  background: linear-gradient(180deg, #8bb8ff, #5f95ea); color: #0b1222; box-shadow: 0 6px 20px rgba(0, 0, 0, .4);
}

/* ---------- 取り込み ---------- */
.paste { min-height: 8em; }
.parse-top { margin-bottom: 10px; flex-wrap: wrap; }
.block { border-left: 3px solid var(--line); }
.block.julius { border-left-color: var(--julius); }
.block.zeke { border-left-color: var(--zeke); }
.block.sel { background: #1f2b46; box-shadow: 0 0 0 1px var(--accent-d) inset; }
.block.saved { opacity: .7; }
.block-head { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; font-size: .85rem; flex-wrap: wrap; }
.block-text { white-space: pre-wrap; word-break: break-word; font-size: .95rem; }
.block.julius .block-text { font-family: var(--serif); }
.saved-mark { color: var(--ok); font-size: .78rem; }
.saved-mark::before { content: "✓ "; }
.role-chip { border: 1px solid; border-radius: 99px; padding: 2px 12px; font-size: .8rem; background: transparent; cursor: pointer; white-space: nowrap; }
.role-chip.julius { color: var(--julius); border-color: rgba(143, 186, 255, .5); }
.role-chip.zeke { color: var(--zeke); border-color: rgba(230, 179, 106, .5); }
.actionbar {
  position: sticky; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 8px); z-index: 15;
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  background: rgba(33, 43, 64, .96); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border: 1px solid var(--line); border-radius: 16px; padding: 8px 10px; margin: 12px 0;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .35);
}

/* ---------- シート ---------- */
.sheet-top { margin-bottom: 12px; }
.sheet-sec .sec-title { font-family: var(--serif); font-size: 1.05rem; font-weight: 600; background: transparent; border-color: transparent; padding-left: 4px; }
.sheet-sec .sec-title:focus { border-color: var(--accent-d); background: var(--bg2); }
.sheet-sec .sec-body { margin: 6px 0 8px; font-size: .95rem; }
.sheet-sec.excluded { opacity: .55; }
.version-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.version-row .tag { margin-left: 8px; }
.diff-sec h3 { margin-top: 16px; }
pre.diff { background: var(--bg2); border-radius: 10px; padding: 10px; font-size: .82rem; white-space: pre-wrap; word-break: break-word; font-family: var(--sans); margin: 0; }
.dadd { color: var(--ok); background: rgba(126, 211, 165, .07); }
.ddel { color: var(--danger); background: rgba(239, 125, 125, .07); text-decoration: line-through; text-decoration-color: rgba(239, 125, 125, .5); }
.deq { color: var(--muted); }

/* ---------- 書き出し ---------- */
textarea.output { font-size: .82rem; line-height: 1.6; background: #0a0e16; color: var(--silver); min-height: 10em; }

/* ---------- モーダル ---------- */
.modal-back { position: fixed; inset: 0; z-index: 100; background: rgba(4, 7, 13, .7); display: flex; align-items: flex-end; justify-content: center; animation: fade .15s ease; }
.modal {
  background: var(--card); width: 100%; max-width: 560px; max-height: 92vh; overflow-y: auto; overscroll-behavior: contain;
  border-radius: 20px 20px 0 0; padding: 20px 18px calc(18px + env(safe-area-inset-bottom));
  border: 1px solid var(--line); animation: up .2s ease;
}
.modal.wide { max-width: 720px; }
.modal textarea.big { font-family: var(--serif); font-size: 1.05rem; }
.modal-foot { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.confirm-text { white-space: pre-wrap; }
.turn-editor { display: flex; flex-direction: column; gap: 10px; margin-bottom: 14px; }
.turn-edit { border-left: 3px solid var(--line); padding-left: 10px; }
.turn-edit.zeke { border-left-color: var(--zeke); }
.turn-edit.julius { border-left-color: var(--julius); }
.turn-edit textarea { margin-top: 4px; }
.turn-edit.julius textarea { font-family: var(--serif); }
@media (min-width: 700px) {
  .modal-back { align-items: center; }
  .modal { border-radius: 20px; }
}
@keyframes fade { from { opacity: 0; } }
@keyframes up { from { transform: translateY(30px); opacity: 0; } }

/* ---------- ログイン等 ---------- */
.center-card { max-width: 420px; margin: 12vh auto 0; padding: 28px 24px; background: var(--card); border-radius: 20px; border: 1px solid var(--line); display: flex; flex-direction: column; gap: 12px; }
.center-card label { margin: 0; }
.brand { text-align: center; font-size: 1.5rem; letter-spacing: .2em; color: var(--silver); margin-bottom: 4px; }
.loading { display: flex; flex-direction: column; align-items: center; gap: 14px; padding-top: 30vh; color: var(--muted); }
.spinner { width: 28px; height: 28px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

#toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 90px); transform: translate(-50%, 20px);
  background: #2b3753; color: var(--text); padding: 10px 18px; border-radius: 12px; font-size: .9rem; z-index: 200;
  opacity: 0; pointer-events: none; transition: all .2s; max-width: calc(100vw - 40px); box-shadow: 0 8px 24px rgba(0, 0, 0, .4);
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.error { background: #5a2b33; }

@media (max-width: 420px) {
  .grid2 { grid-template-columns: 1fr; }
  main#view { padding-left: 12px; padding-right: 12px; }
  .card { padding: 12px 13px; }
}
