/* v1.0.4 */
.tw-wrap{position:relative;width:100%;}


* { box-sizing: border-box; margin: 0; padding: 0; }
.tw-wrap { font-family: "BIZ UDPGothic","Yu Gothic","Hiragino Kaku Gothic ProN",sans-serif; background: #F0F2F5; min-height: 100vh; }

/* ヘッダー */
#hdr { background: #1e3a5f; border-top: 3px solid #d4af37; border-bottom: 3px solid #d4af37; color: #fff; height: 52px; display: flex; align-items: center; justify-content: space-between; padding: 0 16px; gap: 8px; position: sticky; top: 0; z-index: 100; }
#hdr h1 { font-size: 1.1rem; white-space: nowrap; }
.hbtn { background: rgba(255,255,255,0.15); color: #fff; border: 2px solid rgba(255,255,255,0.35); border-radius: 8px; padding: 5px 14px; font-size: 0.9rem; font-family: inherit; font-weight: 700; cursor: pointer; white-space: nowrap; }
.hbtn:hover { background: rgba(255,255,255,0.28); }
.hbtn.active { background: #d4af37; color: #1e3a5f; border-color: #d4af37; }
.hbtn.gold { background: #d4af37; color: #1e3a5f; border-color: #d4af37; }
.hbtn.gold:hover { background: #b8961e; }

.page { display: none; }
.page.show { display: block; }

/* ===== 設定画面 ===== */
#pg-setting { padding: 16px; max-width: 900px; margin: 0 auto; }
.scard { background: #fff; border-radius: 14px; padding: 18px; margin-bottom: 16px; box-shadow: 0 2px 8px rgba(0,0,0,0.07); }
.scard h2 { font-size: 1rem; font-weight: 700; color: #1e3a5f; border-bottom: 3px solid #d4af37; padding-bottom: 6px; margin-bottom: 14px; }

/* 児童名3列 */
.name-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 5px; margin-bottom: 10px; }
.name-item { display: flex; align-items: center; gap: 3px; background: #f4f8fc; border: 0.5px solid #d0dcea; border-radius: 8px; padding: 5px 7px; }
.name-item input[type=text] { flex: 1; border: 1px solid #c0cfe0; border-radius: 6px; padding: 4px 6px; font-size: 0.88rem; font-family: inherit; min-width: 0; }
.gsel { display: flex; gap: 2px; }
.gbtn { padding: 2px 6px; border-radius: 10px; border: 1px solid #c0cfe0; background: #fff; font-size: 0.75rem; font-weight: 700; cursor: pointer; color: #888; }
.gbtn.m.on { background: #1a5fa8; border-color: #1a5fa8; color: #fff; }
.gbtn.f.on { background: #b83280; border-color: #b83280; color: #fff; }
.gbtn.n.on { background: #555; border-color: #555; color: #fff; }
.del-btn { background: none; border: none; color: #c0392b; font-size: 1rem; cursor: pointer; padding: 0 2px; line-height: 1; }
.add-row { display: flex; gap: 8px; align-items: flex-start; flex-wrap: wrap; margin-top: 8px; }
.add-row textarea { flex: 1; min-width: 200px; height: 72px; border: 1px solid #c0cfe0; border-radius: 8px; padding: 8px; font-size: 0.88rem; font-family: inherit; resize: vertical; }
.sbtn { background: #1e3a5f; color: #fff; border: none; border-radius: 8px; padding: 7px 14px; font-size: 0.88rem; font-family: inherit; font-weight: 700; cursor: pointer; }
.sbtn:hover { background: #2a5080; }
.sbtn.gold { background: #d4af37; color: #1e3a5f; }
.sbtn.gold:hover { background: #b8961e; }
.sbtn.red { background: #c0392b; color: #fff; }
.hint { font-size: 0.8rem; color: #888; margin-top: 6px; }

/* グループ設定 */
.grp-block { border: 1px solid #d0dcea; border-radius: 10px; margin-bottom: 10px; overflow: hidden; }
.grp-hdr { background: #1e3a5f; color: #fff; padding: 8px 12px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.grp-hdr input[type=text] { flex: 1; min-width: 80px; background: rgba(255,255,255,0.15); border: 1px solid rgba(255,255,255,0.3); border-radius: 6px; padding: 5px 8px; color: #fff; font-size: 0.95rem; font-family: inherit; font-weight: 700; }
.grp-hdr input::placeholder { color: rgba(255,255,255,0.5); }
.grp-hdr input:focus { outline: none; border-color: #d4af37; }
.grp-hdr label { font-size: 0.78rem; color: rgba(255,255,255,0.8); white-space: nowrap; }
.grp-hdr input[type=number] { width: 44px; background: rgba(255,255,255,0.15); border: 1px solid rgba(255,255,255,0.3); border-radius: 6px; padding: 4px 6px; color: #fff; font-size: 0.88rem; font-family: inherit; text-align: center; }
.grp-del { background: rgba(255,255,255,0.15); color: #fff; border: 1px solid rgba(255,255,255,0.3); border-radius: 6px; padding: 4px 10px; font-size: 0.8rem; font-family: inherit; font-weight: 700; cursor: pointer; white-space: nowrap; }
.grp-del:hover { background: #c0392b; border-color: #c0392b; }
.grp-.tw-wrap { padding: 10px 12px; }
.task-row { display: flex; align-items: center; gap: 6px; margin-bottom: 5px; flex-wrap: wrap; }
.task-row input[type=text] { flex: 1; min-width: 100px; border: 1px solid #c0cfe0; border-radius: 6px; padding: 5px 8px; font-size: 0.88rem; font-family: inherit; }
.task-row input[type=number] { width: 42px; border: 1px solid #c0cfe0; border-radius: 6px; padding: 5px 4px; font-size: 0.88rem; font-family: inherit; text-align: center; }
.task-row .nm { border-color: #8ab0d8; }
.task-row .nf { border-color: #d89ab0; }
.task-row label { font-size: 0.8rem; color: #555; white-space: nowrap; }
.add-task-row { display: flex; align-items: center; gap: 6px; margin-top: 6px; flex-wrap: wrap; }
.add-task-row input[type=text] { flex: 1; min-width: 100px; border: 1px solid #c0cfe0; border-radius: 6px; padding: 5px 8px; font-size: 0.88rem; font-family: inherit; }
.add-task-row input[type=number] { width: 42px; border: 1px solid #c0cfe0; border-radius: 6px; padding: 5px 4px; font-size: 0.88rem; font-family: inherit; text-align: center; }
.add-task-btn { background: #1e3a5f; color: #fff; border: none; border-radius: 6px; padding: 5px 10px; font-size: 0.82rem; font-family: inherit; font-weight: 700; cursor: pointer; white-space: nowrap; }
.add-task-btn:hover { background: #2a5080; }

/* 印刷設定 */
.print-cfg { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.print-cfg label { font-size: 0.88rem; color: #555; }
.print-cfg input[type=number] { width: 52px; border: 1px solid #c0cfe0; border-radius: 6px; padding: 5px 8px; font-size: 0.95rem; font-family: inherit; text-align: center; }

/* JSON */
.json-btns { display: flex; gap: 8px; flex-wrap: wrap; }

/* ===== 結果画面 ===== */
#pg-result { padding: 8px; background: #F0F2F5; }
#no-data { text-align: center; padding: 60px 20px; color: #888; font-size: 1rem; }

/* PC表示：画面フル活用 */
.a4-wrap {
  background: #fff;
  box-shadow: 0 4px 20px rgba(30,58,95,0.12);
  width: 100%;
  aspect-ratio: 297 / 210;
  max-height: calc(100vh - 72px);
  overflow: hidden;
}

/* カードグリッド */
.toban-grid { display: grid; gap: 4px; padding: 6px; width: 100%; height: 100%; }

/* 当番カード */
.toban-card { border: 1px solid #E8E8E8; display: flex; flex-direction: column; overflow: hidden; border-radius: 4px; box-shadow: 0 1px 4px rgba(30,58,95,0.06); }
.card-loc { font-weight: 900; display: flex; align-items: center; justify-content: center; padding: 3px 6px; white-space: nowrap; flex-shrink: 0; letter-spacing: 0.05em; overflow: hidden; text-overflow: ellipsis; }
.card-inner { flex: 1; display: flex; flex-direction: column; min-width: 0; overflow: hidden; }
.task-line { display: flex; align-items: stretch; border-bottom: 1px solid rgba(0,0,0,0.07); flex: 1; min-height: 0; }
.task-line:last-child { border-bottom: none; }
.task-job { writing-mode: vertical-rl; display: flex; align-items: center; justify-content: center; border-right: 1px solid rgba(0,0,0,0.1); flex-shrink: 0; line-height: 1.2; overflow: hidden; padding: 2px 2px; font-weight: 700; word-break: break-all; }
.task-job.is-repeat { opacity: 0.4; font-size: 10px; }
.task-names { display: flex; align-items: center; justify-content: center; flex: 1; overflow: hidden; padding: 0 4px; }
.name-chip { font-weight: 700; display: flex; align-items: center; justify-content: center; border-radius: 4px; padding: 0 4px; border: 1px solid transparent; max-width: 100%; overflow: hidden; white-space: nowrap; }
.name-chip.m { background: #e6f0fa; color: #1e3a5f; border-color: #b8d0ea; }
.name-chip.f { background: #fdf6dc; color: #7a5c00; border-color: #e8d48a; }
.name-chip.n { background: #F5F5F5; color: #2C3E50; border-color: #E8E8E8; }

/* 列数インジケーター */
.result-info { font-size: 0.78rem; color: #888; margin-bottom: 6px; text-align: center; }

@media print {
  #hdr { display: none !important; }
  #pg-setting { display: none !important; }
  #pg-result { display: block !important; padding: 0; }
  .result-info { display: none !important; }
  .tw-wrap { background: #fff; }
  .a4-wrap {
    box-shadow: none !important;
    margin: 0 !important;
    width: 297mm !important;
    height: 210mm !important;
  }
  @page { size: A4 landscape; margin: 0; }
  * { -webkit-print-color-adjust: exact !important; print-color-adjust: exact !important; }
}

/* ===== 当番表上を飛び回るチップ ===== */
#fly-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 400;
}
.fly-chip {
  position: fixed;
  font-weight: 900;
  border-radius: 10px;
  padding: 8px 18px;
  font-size: 26px;
  pointer-events: none;
  z-index: 401;
  will-change: left, top, opacity;
  white-space: nowrap;
  letter-spacing: 0.03em;
}
.fly-chip.m { background: #e6f0fa; color: #1e3a5f; border: 2px solid #b8d0ea; box-shadow: 0 4px 16px rgba(30,58,95,0.22); }
.fly-chip.f { background: #fdf6dc; color: #7a5c00; border: 2px solid #e8d48a; box-shadow: 0 4px 16px rgba(212,175,55,0.22); }
.fly-chip.n { background: #F5F5F5; color: #2C3E50; border: 2px solid #E8E8E8; box-shadow: 0 4px 16px rgba(0,0,0,0.12); }

/* ===== アニメーションオーバーレイ ===== */
#anim-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(15,30,58,0.93);
  z-index: 500;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
}
#anim-overlay.show { display: flex; }

/* シャッフル */
#shuffle-stage { position: relative; width: 100vw; height: calc(100vh - 52px); overflow: hidden; }
.s-chip {
  position: absolute;
  font-weight: 900;
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 18px;
  pointer-events: none;
  transition: left 0.5s cubic-bezier(.4,0,.2,1), top 0.5s cubic-bezier(.4,0,.2,1), opacity 0.3s;
}
.s-chip.m { background: #e6f0fa; color: #1e3a5f; border: 1px solid #b8d0ea; }
.s-chip.f { background: #fdf6dc; color: #7a5c00; border: 1px solid #e8d48a; }
.s-chip.n { background: #F5F5F5; color: #2C3E50; border: 1px solid #E8E8E8; }

/* ドラフト */
#draft-wrap { text-align: center; display: flex; flex-direction: column; align-items: center; }
#draft-card-box {
  background: #fff;
  border-radius: 20px;
  padding: 32px 48px 28px;
  box-shadow: 0 12px 48px rgba(30,58,95,0.35);
  min-width: 340px;
  max-width: 82vw;
  opacity: 0;
  transform: scale(0.82);
  transition: opacity 0.3s, transform 0.35s cubic-bezier(.22,.68,0,1.3);
  border-top: 6px solid #d4af37;
}
#draft-card-box.show { opacity: 1; transform: scale(1); }
/* 役割と名前を横並びで同サイズ */
#draft-main-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
#draft-role {
  font-size: clamp(2.0rem,6vw,4.0rem);
  font-weight: 900;
  color: #1e3a5f;
  background: #e6f0fa;
  border: 2px solid #b8d0ea;
  border-radius: 12px;
  padding: 6px 20px;
  line-height: 1.2;
}
#draft-sep {
  font-size: clamp(1.4rem,4vw,2.5rem);
  color: #d4af37;
  font-weight: 900;
}
#draft-name {
  font-size: clamp(2.0rem,6vw,4.0rem);
  font-weight: 900;
  color: #1e3a5f;
  line-height: 1.2;
}
#draft-arrow { font-size: 1.2rem; color: #d4af37; margin: 2px 0 10px; }
#draft-place {
  font-size: clamp(0.95rem,2.5vw,1.4rem);
  font-weight: 700;
  color: #7F8C8D;
  background: #F5F5F5;
  border-radius: 8px;
  padding: 5px 16px;
  display: inline-block;
}
#draft-counter { font-size: 0.85rem; color: rgba(255,255,255,0.55); margin-top: 16px; }
#draft-progress { display: flex; gap: 5px; flex-wrap: wrap; justify-content: center; margin-top: 8px; max-width: 80vw; }
.d-dot { width: 8px; height: 8px; border-radius: 50%; background: rgba(255,255,255,0.2); transition: background 0.2s; flex-shrink: 0; }
.d-dot.done { background: #d4af37; }
#draft-skip-btn {
  margin-top: 18px;
  background: rgba(255,255,255,0.15);
  color: #fff;
  border: 2px solid rgba(255,255,255,0.3);
  border-radius: 10px;
  padding: 8px 24px;
  font-size: 1rem;
  font-family: inherit;
  font-weight: 700;
  cursor: pointer;
}
#draft-skip-btn:hover { background: rgba(255,255,255,0.25); }

/* スロット：当番表上に浮かせる */
#slot-overlay-inner {
  position: fixed;
  inset: 52px 0 0 0;
  background: rgba(15,30,58,0.82);
  z-index: 450;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
}
#slot-overlay-inner.show { display: flex; }
#slot-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 8px;
  width: 92vw;
  max-width: 1100px;
  max-height: 80vh;
  overflow: hidden;
}
.slot-cell {
  background: rgba(255,255,255,0.07);
  border: 1.5px solid rgba(212,175,55,0.3);
  border-radius: 8px;
  padding: 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  overflow: hidden;
}
.slot-cell-label { font-size: 9px; color: #d4af37; font-weight: 700; text-align: center; line-height: 1.3; }
.slot-reel { height: 32px; overflow: hidden; width: 100%; position: relative; }
.slot-reel-inner { display: flex; flex-direction: column; align-items: center; }
.slot-reel-inner span { height: 32px; line-height: 32px; font-size: 15px; font-weight: 700; color: #fff; white-space: nowrap; }
.slot-cell.locked { border-color: #d4af37; background: rgba(212,175,55,0.12); }
.slot-cell.locked .slot-reel-inner span { color: #d4af37; }
#slot-msg { font-size: 1.1rem; color: rgba(255,255,255,0.8); font-weight: 700; }
@keyframes chipFly { 0%{opacity:1} 100%{opacity:0;transform:scale(0.5)} }

/* ===== タブ ===== */
#app-tabs { display: flex; gap: 0; background: #F0F2F5; border-bottom: 2px solid #d4af37; padding: 0 16px; }
.app-tab { padding: 8px 20px; font-size: 0.95rem; font-weight: 700; cursor: pointer; color: #888; border-bottom: 3px solid transparent; margin-bottom: -2px; background: none; border-top: none; border-left: none; border-right: none; font-family: inherit; }
.app-tab.active { color: #1e3a5f; border-bottom-color: #1e3a5f; background: #fff; border-radius: 8px 8px 0 0; }
.app-tab:hover:not(.active) { color: #1e3a5f; }
.app-section { display: none; }
.app-section.show { display: block; }

/* ===== 給食当番 ===== */
#kyushoku-hdr-btns { display: flex; gap: 6px; }
#pg-kyushoku-result { padding: 8px; background: #F0F2F5; }
#pg-kyushoku-setting { padding: 16px; max-width: 900px; margin: 0 auto; }

/* 班カード（設定） */
.han-block { border: 1px solid #d0dcea; border-radius: 10px; margin-bottom: 8px; overflow: hidden; }
.han-hdr { background: #1e3a5f; color: #fff; padding: 7px 12px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.han-hdr input[type=text] { width: 60px; background: rgba(255,255,255,0.15); border: 1px solid rgba(255,255,255,0.3); border-radius: 6px; padding: 4px 8px; color: #fff; font-size: 0.95rem; font-family: inherit; font-weight: 700; }
.han-hdr input[type=number] { width: 44px; background: rgba(255,255,255,0.15); border: 1px solid rgba(255,255,255,0.3); border-radius: 6px; padding: 4px 6px; color: #fff; font-size: 0.88rem; font-family: inherit; text-align: center; }
.han-hdr label { font-size: 0.78rem; color: rgba(255,255,255,0.8); white-space: nowrap; }
.han-del { background: rgba(255,255,255,0.15); color: #fff; border: 1px solid rgba(255,255,255,0.3); border-radius: 6px; padding: 3px 8px; font-size: 0.8rem; font-family: inherit; cursor: pointer; }
.han-del:hover { background: #c0392b; border-color: #c0392b; }
.han-.tw-wrap { padding: 8px 12px; }
.han-members { display: grid; grid-template-columns: repeat(5, minmax(0,1fr)); gap: 4px; }
.han-member { background: #f4f8fc; border: 1px solid #d0dcea; border-radius: 6px; padding: 3px 6px; font-size: 0.82rem; display: flex; align-items: center; gap: 3px; }
.han-member input { flex:1; border:none; background:transparent; font-family:inherit; font-size:0.82rem; min-width:0; }
.han-member input:focus { outline: none; border-bottom: 1px solid #1e3a5f; }

/* 給食役割設定 */
.kyushoku-role-row { display: flex; align-items: center; gap: 8px; margin-bottom: 5px; }
.kyushoku-role-row input[type=text] { flex: 1; border: 1px solid #c0cfe0; border-radius: 6px; padding: 5px 8px; font-size: 0.88rem; font-family: inherit; }
.kyushoku-role-row input[type=number] { width: 48px; border: 1px solid #c0cfe0; border-radius: 6px; padding: 5px 4px; font-size: 0.88rem; font-family: inherit; text-align: center; }

/* ローテーション */
.rotation-bar { display: flex; align-items: center; gap: 10px; padding: 8px 12px; background: #fff; border-radius: 10px; margin-bottom: 10px; box-shadow: 0 1px 4px rgba(30,58,95,0.06); flex-wrap: wrap; }
.rotation-bar .cur-han { font-size: 1.1rem; font-weight: 900; color: #1e3a5f; background: #e6f0fa; border: 2px solid #b8d0ea; border-radius: 8px; padding: 4px 16px; }
.rotation-bar .rot-count { font-size: 0.82rem; color: #888; }

/* 給食結果カード */
.kyushoku-grid { display: grid; gap: 3px; padding: 5px; width: 100%; height: 100%; }
.kyushoku-han-card { border: 1px solid #E8E8E8; border-radius: 4px; overflow: hidden; box-shadow: 0 1px 4px rgba(30,58,95,0.06); display: flex; flex-direction: column; }
.kyushoku-han-hdr { font-weight: 900; font-size: 11px; display: flex; align-items: center; justify-content: center; padding: 3px 6px; letter-spacing: 0.05em; flex-shrink: 0; background: #1e3a5f; color: #fff; }
.kyushoku-role-line { display: flex; align-items: stretch; border-bottom: 1px solid rgba(0,0,0,0.07); flex: 1; min-height: 0; }
.kyushoku-role-line:last-child { border-bottom: none; }
.kyushoku-role-label { display: flex; align-items: center; border-right: 1px solid rgba(0,0,0,0.1); flex-shrink: 0; padding: 0 3px; font-weight: 700; background: #e6f0fa; color: #1e3a5f; }
.kyushoku-role-names { display: flex; align-items: center; justify-content: center; flex: 1; padding: 0 4px; background: #f8fafc; gap: 3px; flex-wrap: wrap; }
/* 表組み方式 */
.kyushoku-table-row { display: flex; align-items: stretch; border-bottom: 1px solid #E8E8E8; }
.kyushoku-table-row:last-child { border-bottom: none; }
.kyushoku-role-cell { display: flex; align-items: center; font-weight: 700; padding: 2px 5px; border-right: 1px solid rgba(0,0,0,0.1); flex-shrink: 0; line-height: 1.25; overflow: hidden; background: #e6f0fa; color: #1e3a5f; word-break: break-all; }
.kyushoku-name-cell { flex: 1; display: flex; align-items: center; justify-content: center; gap: 3px; flex-wrap: wrap; padding: 2px 4px; border-right: 1px solid #E8E8E8; overflow: hidden; }
.kyushoku-name-cell:last-child { border-right: none; }
.kyushoku-name-chip { font-weight: 700; border-radius: 4px; padding: 0 4px; border: 1px solid transparent; }
.kyushoku-name-chip.m { background: #e6f0fa; color: #1e3a5f; border-color: #b8d0ea; }
.kyushoku-name-chip.f { background: #fdf6dc; color: #7a5c00; border-color: #e8d48a; }
.kyushoku-name-chip.n { background: #F5F5F5; color: #2C3E50; border-color: #E8E8E8; }

/* ===== ペア決め ===== */
#pg-pair-result { padding: 8px; background: #F0F2F5; }
#pg-pair-setting { padding: 16px; max-width: 900px; margin: 0 auto; }
.pair-grid { display: grid; gap: 4px; padding: 6px; width: 100%; height: 100%; }
.pair-card { border: 1px solid #E8E8E8; border-radius: 4px; overflow: hidden; box-shadow: 0 1px 4px rgba(30,58,95,0.06); display: flex; flex-direction: column; }
.pair-card-hdr { font-weight: 900; display: flex; align-items: center; justify-content: center; padding: 3px 6px; letter-spacing: 0.05em; flex-shrink: 0; }
.pair-member-list { flex: 1; display: flex; flex-direction: column; }
.pair-member-row { flex: 1; display: flex; align-items: center; justify-content: center; border-bottom: 1px solid rgba(0,0,0,0.07); }
.pair-member-row:last-child { border-bottom: none; }
.pair-name-chip { font-weight: 700; border-radius: 4px; padding: 0 4px; border: 1px solid transparent; }
.pair-name-chip.m { background: #e6f0fa; color: #1e3a5f; border-color: #b8d0ea; }
.pair-name-chip.f { background: #fdf6dc; color: #7a5c00; border-color: #e8d48a; }
.pair-name-chip.n { background: #F5F5F5; color: #2C3E50; border-color: #E8E8E8; }
