:root {
  --green: #1f6f43;
  --green-d: #15502f;
  --green-l: #e7f3ec;
  --accent: #f2b134;
  --bg: #f4f6f4;
  --card: #ffffff;
  --text: #1c2420;
  --muted: #6b7670;
  --line: #dfe5e1;
  --danger: #d64545;
  --warn: #b7791f;
  --warn-bg: #fff6e0;
  --female: #d1477a;
  --radius: 14px;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --tabh: 58px;
  /* タブ下の余白: セーフエリア or Netlifyバッジの高さ(--badge-offset, JSで設定)の大きい方 */
  --bpad: max(var(--sab), var(--badge-offset, 0px));
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1412; --card: #1a211d; --text: #e8eee9; --muted: #95a29a; --line: #2b352f;
    --green-l: #1d3326; --warn-bg: #3a2f14; color-scheme: dark;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", sans-serif;
  background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.5;
  -webkit-text-size-adjust: 100%; overscroll-behavior-y: none;
}
button { font: inherit; color: inherit; cursor: pointer; }
input, select, textarea { font: inherit; color: inherit; font-size: 16px; }

/* ===== Splash ===== */
#splash {
  position: fixed; inset: 0; z-index: 100; background: var(--green);
  display: flex; flex-direction: column; align-items: center; justify-content: center; color: #fff;
  transition: opacity .45s ease;
}
#splash.hide { opacity: 0; pointer-events: none; }
.splash-title { font-size: 30px; font-weight: 800; margin-top: 18px; letter-spacing: .04em; }
.splash-sub { opacity: .85; font-size: 13px; }

/* ===== Logo placeholder ===== */
.logo-ph {
  border: 2px dashed rgba(255,255,255,.7); color: rgba(255,255,255,.9); border-radius: 10px;
  display: flex; align-items: center; justify-content: center; text-align: center;
  font-weight: 700; letter-spacing: .1em; line-height: 1.2;
}
.logo-ph small { font-weight: 400; font-size: 10px; letter-spacing: 0; opacity: .8; }
.logo-ph--splash { width: 160px; height: 160px; font-size: 22px; }
.logo-ph--header { width: 100px; height: 30px; font-size: 12px; flex: none; }
.header-logo { width: 100px; height: 30px; object-fit: contain; flex: none; }

/* ===== Header ===== */
.app-header {
  position: sticky; top: 0; z-index: 20; background: var(--green); color: #fff;
  padding: calc(var(--sat) + 10px) 16px 10px; display: flex; gap: 12px; align-items: center;
}
.header-info { min-width: 0; }
.header-comp { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.header-sub { font-size: 12px; opacity: .85; }

/* ===== Layout ===== */
.view { max-width: 720px; margin: 0 auto; padding: 14px 14px calc(var(--tabh) + var(--bpad) + 90px); }
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: flex;
  background: var(--card); border-top: 1px solid var(--line); padding-bottom: var(--bpad);
}
.tabbar button {
  flex: 1; height: var(--tabh); border: 0; background: none; display: flex; flex-direction: column;
  align-items: center; justify-content: center; font-size: 11px; color: var(--muted); gap: 1px;
}
.tabbar button .ti { font-size: 20px; filter: grayscale(1); opacity: .65; }
.tabbar button.active { color: var(--green); font-weight: 700; }
.tabbar button.active .ti { filter: none; opacity: 1; }

h2.sec { font-size: 13px; color: var(--muted); font-weight: 600; margin: 20px 4px 8px; }
h2.sec:first-child { margin-top: 4px; }
.card { background: var(--card); border-radius: var(--radius); padding: 14px; border: 1px solid var(--line); }
.card + .card { margin-top: 10px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.row { display: flex; gap: 8px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.spacer { height: 10px; }
.center { text-align: center; }

/* ===== Buttons ===== */
.btn {
  border: 1px solid var(--line); background: var(--card); border-radius: 10px; padding: 9px 14px;
  font-weight: 600; font-size: 14px; display: inline-flex; align-items: center; gap: 6px; justify-content: center;
}
.btn.primary { background: var(--green); color: #fff; border-color: var(--green); }
.btn.accent { background: var(--accent); border-color: var(--accent); color: #3a2a00; }
.btn.danger { color: var(--danger); border-color: #f0c4c4; }
.btn.block { width: 100%; padding: 13px; font-size: 16px; }
.btn.sm { padding: 6px 10px; font-size: 13px; }
.btn:disabled { opacity: .45; }
.btn:active { transform: scale(.98); }
.fab {
  position: fixed; right: 18px; bottom: calc(var(--tabh) + var(--bpad) + 16px); z-index: 25;
  width: 56px; height: 56px; border-radius: 50%; border: 0; background: var(--green); color: #fff;
  font-size: 28px; box-shadow: 0 6px 18px rgba(0,0,0,.25);
}
.stickybar {
  position: fixed; left: 0; right: 0; bottom: calc(var(--tabh) + var(--bpad)); z-index: 24;
  padding: 10px 14px; background: linear-gradient(transparent, var(--bg) 30%);
}
.stickybar > div { max-width: 720px; margin: 0 auto; display: flex; gap: 8px; }

/* ===== Forms ===== */
.field { margin-bottom: 12px; }
.field > label, .lbl { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; font-weight: 600; }
.input, select.input, textarea.input {
  width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; background: var(--card);
}
textarea.input { min-height: 120px; font-family: ui-monospace, Menlo, monospace; font-size: 13px; }
.seg { display: flex; background: var(--bg); border-radius: 10px; padding: 3px; gap: 3px; border: 1px solid var(--line); }
.seg button { flex: 1; border: 0; background: none; padding: 8px 4px; border-radius: 8px; font-size: 13px; }
.seg button.on { background: var(--card); box-shadow: 0 1px 3px rgba(0,0,0,.15); font-weight: 700; color: var(--green); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.switch-row:last-child { border-bottom: 0; }
.switch-row .t { font-size: 14px; }
.switch-row .d { font-size: 12px; color: var(--muted); }
.toggle { position: relative; width: 50px; height: 30px; flex: none; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle span { position: absolute; inset: 0; background: #c9d1cc; border-radius: 30px; transition: .2s; }
.toggle span::before { content: ""; position: absolute; width: 26px; height: 26px; left: 2px; top: 2px; background: #fff; border-radius: 50%; transition: .2s; box-shadow: 0 1px 3px rgba(0,0,0,.3); }
.toggle input:checked + span { background: var(--green); }
.toggle input:checked + span::before { transform: translateX(20px); }
.chk { display: inline-flex; align-items: center; gap: 6px; padding: 6px 0; font-size: 14px; }
.chk input { width: 20px; height: 20px; accent-color: var(--green); }

/* ===== Players ===== */
.stats { display: flex; gap: 8px; flex-wrap: wrap; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 6px 10px; font-size: 12px; }
.stat b { font-size: 16px; margin-right: 2px; }
.plist { list-style: none; margin: 0; padding: 0; }
.pitem {
  display: flex; align-items: center; gap: 10px; padding: 11px 12px; background: var(--card);
  border: 1px solid var(--line); border-radius: 12px; margin-bottom: 6px;
}
.pitem.absent { opacity: .5; }
.pitem .pname { font-weight: 700; }
.pitem .pmeta { font-size: 12px; color: var(--muted); display: flex; gap: 6px; flex-wrap: wrap; }
.avatar {
  width: 36px; height: 36px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  background: var(--green-l); color: var(--green); font-weight: 800; flex: none; font-size: 14px;
}
.avatar.f { background: #fbe3ec; color: var(--female); }
.mark { font-weight: 700; margin-left: 2px; }
.mark.org { color: #c8860a; }
.mark.sub { color: #2e86ab; }
.mark.flag { color: #8e44ad; }
.tag { display: inline-block; font-size: 11px; padding: 1px 6px; border-radius: 6px; background: var(--bg); border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.tag.smoke { background: #f3ece4; color: #7a5a3a; border-color: #e6d6c3; }
.tag.role { background: #fff3d6; color: #8a5a00; border-color: #f2dc9e; }
.tag.flag { background: #f1e6f7; color: #6c2f8a; border-color: #dfc6ec; }
.tag.car { background: #e3f0fa; color: #1d5f8a; border-color: #c4def1; }
.search { position: relative; }
.search input { padding-left: 34px; }
.search::before { content: "🔍"; position: absolute; left: 10px; top: 50%; transform: translateY(-50%); font-size: 14px; opacity: .6; }

/* ===== Rules ===== */
.rule { display: flex; align-items: center; gap: 8px; padding: 10px 12px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; margin-bottom: 6px; }
.rule .badge { font-size: 12px; font-weight: 700; padding: 3px 8px; border-radius: 8px; flex: none; }
.badge.ok { background: #dff3e6; color: var(--green); }
.badge.ng { background: #fde2e2; color: var(--danger); }

/* ===== Result ===== */
.groups { display: grid; gap: 10px; }
@media (min-width: 640px) { .groups { grid-template-columns: 1fr 1fr; } }
.gcard { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.gcard.has-warn { border-color: #f0d48a; }
.gcard.drop-target { outline: 3px solid var(--accent); }
.ghead { display: flex; align-items: center; gap: 8px; padding: 8px 10px; background: var(--green-l); }
.gnum { font-weight: 800; color: var(--green); font-size: 16px; }
.gtime { font-size: 12px; color: var(--muted); }
.handle { margin-left: auto; touch-action: none; padding: 4px 10px; font-size: 18px; color: var(--muted); cursor: grab; user-select: none; -webkit-user-select: none; }
.gbody { padding: 8px; display: flex; flex-direction: column; gap: 6px; min-height: 48px; }
.chip {
  display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 10px; background: var(--bg);
  border: 1px solid var(--line); user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}
.chip.sel { outline: 2px solid var(--accent); background: var(--warn-bg); }
.chip .cname { font-weight: 700; }
.chip .ctags { margin-left: auto; display: flex; gap: 3px; flex-wrap: wrap; justify-content: flex-end; }
.chip.f .cname { color: var(--female); }
.gwarn { font-size: 12px; color: var(--warn); background: var(--warn-bg); padding: 6px 10px; border-top: 1px solid #f0e0b0; }
.gwarn div::before { content: "⚠️ "; }
.notice { background: var(--warn-bg); color: var(--warn); border-radius: 12px; padding: 10px 12px; font-size: 13px; margin-bottom: 10px; }
.notice.ok { background: var(--green-l); color: var(--green); }
.notice ul { margin: 4px 0 0; padding-left: 18px; }
.empty { text-align: center; color: var(--muted); padding: 40px 10px; }
.empty .big { font-size: 44px; }
.drag-ghost {
  position: fixed; z-index: 200; pointer-events: none; opacity: .92; transform: rotate(2deg) scale(1.03);
  box-shadow: 0 12px 30px rgba(0,0,0,.25);
}
.dragging-src { opacity: .3; }
.legend { font-size: 12px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 4px 12px; margin: 6px 4px 10px; }

/* ===== Amida ===== */
.amida-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 0; }
.amida-inner { position: relative; margin: 0 auto; }
.amida-labels { display: flex; }
.amida-labels > * { width: 56px; flex: none; display: flex; justify-content: center; }
.amida-top button {
  writing-mode: vertical-rl; border: 1px solid var(--line); background: var(--green-l); color: var(--green);
  border-radius: 8px; padding: 6px 3px; font-weight: 700; font-size: 13px; max-height: 110px; overflow: hidden;
}
.amida-top button.done { background: var(--bg); color: var(--muted); }
.amida-bottom span {
  writing-mode: vertical-rl; border-radius: 8px; padding: 6px 3px; font-weight: 700; font-size: 13px;
  background: var(--warn-bg); color: #8a5a00; min-height: 44px; text-align: center;
}
.amida-bottom span.hidden { background: #555; color: #555; }
.amida-v { stroke: var(--muted); stroke-width: 2; }
.amida-h { stroke: var(--muted); stroke-width: 2; }
.amida-path { fill: none; stroke-width: 5; stroke-linecap: round; stroke-linejoin: round; opacity: .9; }
.amida-result { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 6px; }
.amida-result div { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 6px 10px; font-size: 13px; }

/* ===== Sheet (modal) ===== */
.sheet-wrap { position: fixed; inset: 0; z-index: 60; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.4); animation: fade .2s; }
.sheet {
  position: absolute; left: 0; right: 0; bottom: 0; max-height: 92vh; overflow-y: auto; background: var(--card);
  border-radius: 18px 18px 0 0; padding: 8px 16px calc(var(--sab) + 18px); animation: up .25s ease;
  max-width: 720px; margin: 0 auto;
}
.sheet .grab { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 4px auto 10px; }
.sheet h3 { margin: 0 0 12px; font-size: 18px; }
@keyframes up { from { transform: translateY(100%); } to { transform: none; } }
@keyframes fade { from { opacity: 0; } }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabh) + var(--bpad) + 80px); transform: translateX(-50%); z-index: 90;
  background: rgba(20,30,25,.92); color: #fff; padding: 10px 16px; border-radius: 22px; font-size: 14px; max-width: 90vw;
}

@media print {
  .tabbar, .app-header, .stickybar, .fab, .handle, .no-print { display: none !important; }
  .view { padding: 0; }
  .gcard { break-inside: avoid; }
}
