/* らくらく席替えくん（sup/seki） */
:root {
  --primary: #3d8fe8;
  --accent: #e8860f;
  --bg: #FDFBF7;
  --text: #444;
  --boy: #E3F2FD;
  --boy-border: #90CAF9;
  --girl: #FCE4EC;
  --girl-border: #F48FB1;
  --select: #ff9f43;
  --font-ui: 'M PLUS Rounded 1c', 'Gowun Dodum', 'Hiragino Maru Gothic ProN', 'Hiragino Sans', 'BIZ UDPGothic', 'Meiryo', 'Apple SD Gothic Neo', 'Malgun Gothic', sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
body {
  font-family: var(--font-ui);
  background-color: var(--bg);
  color: var(--text);
  padding: calc(72px + env(safe-area-inset-top, 0px)) 16px calc(30px + env(safe-area-inset-bottom, 0px));
  background-image: linear-gradient(rgba(255, 255, 255, 0.75), rgba(255, 255, 255, 0.75)), url('images/bg.webp');
  background-size: auto, 400px;
  background-repeat: repeat;
  background-attachment: scroll;
  min-height: 100dvh;
  position: relative;
}

/* UI要塞化（スクロールする ページなので 高さも 0 に） */
.hidden {
  opacity: 0 !important;
  pointer-events: none !important;
  visibility: hidden !important;
  z-index: -1 !important;
  position: absolute !important;
  max-height: 0 !important; max-width: 0 !important;
  overflow: hidden !important;
}

.lang-slot {
  position: absolute;
  top: calc(10px + env(safe-area-inset-top, 0px));
  right: calc(10px + env(safe-area-inset-right, 0px));
  z-index: 100;
}

.container { max-width: 1040px; margin: 0 auto; position: relative; }
.header-area { text-align: center; margin-bottom: 12px; position: relative; min-height: 60px; }
.title-img { width: 300px; max-width: 80%; height: auto; }
.title-text { color: var(--primary); font-size: 2rem; margin: 10px 0; font-weight: 900; }

h2 { color: var(--primary); font-size: 1.2rem; margin: 0 0 12px; }
.center { text-align: center; }
.small { font-size: 0.88rem; }
.accent { color: var(--accent); font-weight: 700; }

.tabs { display: flex; gap: 10px; margin-bottom: 16px; justify-content: center; flex-wrap: wrap; }
.tab-btn {
  min-height: 48px;
  padding: 10px 22px;
  background: #eee;
  border: none;
  border-radius: 30px;
  font-family: inherit;
  font-weight: 800;
  color: #888;
  cursor: pointer;
  font-size: 1rem;
}
.tab-btn.active { background: var(--primary); color: #fff; box-shadow: 0 4px 10px rgba(61, 143, 232, 0.35); }

.panel { background: rgba(255, 255, 255, 0.94); padding: 26px; border-radius: 20px; box-shadow: 0 4px 15px rgba(0, 0, 0, 0.05); }

.footer-nav { margin-top: 26px; padding-top: 18px; border-top: 2px dashed #eee; display: flex; justify-content: space-between; gap: 10px; }
.btn-nav {
  border: none; min-height: 52px; padding: 10px 26px; border-radius: 50px;
  font-family: inherit; font-size: 1rem; font-weight: 800; cursor: pointer;
}
.btn-next { background: var(--primary); color: #fff; box-shadow: 0 4px 0 #2a6fb9; }
.btn-next::after { content: " ▶"; font-size: 0.8em; }
.btn-back { background: #eee; color: #555; box-shadow: 0 4px 0 #ccc; }
.btn-back::before { content: "⬅ "; }
.btn-nav:active { transform: translateY(4px); box-shadow: none; }

.guide-box { background: #f8f9fa; border: 2px dashed #ddd; border-radius: 10px; padding: 14px; margin-bottom: 14px; font-size: 0.92rem; color: #555; }
.guide-title { font-weight: 800; color: var(--primary); margin-bottom: 4px; display: block; }
.guide-row { margin-bottom: 4px; }
.guide-note { margin: 4px 0 0; font-size: 0.82rem; color: #888; }
.badge { display: inline-block; background: #e6e6e6; padding: 1px 6px; border-radius: 4px; font-size: 0.8rem; margin-right: 6px; font-weight: 700; }
.input-area { width: 100%; height: 150px; padding: 10px; border: 2px solid #ddd; border-radius: 10px; font-family: var(--font-ui); font-size: 1rem; resize: vertical; }
.privacy { font-size: 0.85rem; color: #666; margin: 12px 0 0; }

.btn-row { display: flex; justify-content: center; gap: 12px; margin-top: 14px; flex-wrap: wrap; }
.btn-primary, .btn-secondary, .btn-outline, .btn-danger {
  font-family: inherit; font-weight: 800; font-size: 1rem; min-height: 48px; padding: 8px 20px; border-radius: 10px; cursor: pointer;
}
.btn-primary { background: var(--accent); color: #fff; border: none; box-shadow: 0 4px 0 #b9680a; }
.btn-primary.big { font-size: 1.15rem; min-height: 56px; padding: 10px 28px; }
.btn-secondary { background: #8d8d8d; color: #fff; border: none; box-shadow: 0 4px 0 #6a6a6a; }
.btn-outline { background: #fff; color: var(--primary); border: 2px solid var(--primary); }
.btn-danger { background: #ff6b6b; color: #fff; border: none; font-size: 0.9rem; min-height: 44px; }
.btn-primary:active, .btn-secondary:active { transform: translateY(4px); box-shadow: none; }

.edit-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.roster-scroll { margin-top: 10px; max-height: 420px; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.roster-table { width: 100%; border-collapse: collapse; }
.roster-table th { background: #f0f0f0; padding: 8px; text-align: left; font-size: 0.9rem; position: sticky; top: 0; z-index: 2; }
.roster-table td { border-bottom: 1px solid #eee; padding: 6px 8px; }
.roster-input { width: 100%; padding: 8px; min-height: 44px; border: 1px solid #ddd; border-radius: 6px; font-size: 1rem; font-family: inherit; }
.gender-select { min-height: 44px; padding: 4px 8px; border-radius: 6px; border: 1px solid #ddd; font-family: inherit; font-size: 1rem; }
.gender-select.male { background: var(--boy); }
.gender-select.female { background: var(--girl); }
.front-check { width: 26px; height: 26px; }
.count-line { text-align: right; margin: 10px 0 0; }
.count-line strong { color: var(--primary); }

/* 机の並び */
.layout-controls { display: flex; gap: 16px; margin-bottom: 12px; align-items: center; justify-content: center; flex-wrap: wrap; }
.layout-controls input { width: 64px; min-height: 44px; padding: 6px; font-size: 1rem; border: 2px solid #ccc; border-radius: 8px; font-family: inherit; }
.board-mini { max-width: 360px; margin: 0 auto 8px; background: #364f38; color: #fff; text-align: center; border-radius: 4px; padding: 2px; font-size: 0.85rem; letter-spacing: 4px; }
.grid-editor { display: grid; gap: 8px; justify-content: center; margin: 0 auto; background: #eee; padding: 16px; border-radius: 10px; width: fit-content; max-width: 100%; }
.grid-cell {
  width: 64px; height: 52px; background: #fafafa; border: 2px dashed #ccc; border-radius: 8px;
  display: flex; align-items: center; justify-content: center; cursor: pointer;
  font-size: 1rem; color: #bbb; font-weight: 800; user-select: none; font-family: inherit;
}
.grid-cell.active { background: #fff; border: 2px solid var(--primary); color: var(--primary); box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1); }
.grid-cell.trace-mode { border-color: var(--accent); border-style: dashed; }
.grid-cell.trace-assigned { background: var(--primary); color: #fff; border-color: var(--primary); border-style: solid; }
.trace-box { background: #f0f8ff; padding: 14px; border-radius: 10px; margin-top: 18px; }
.trace-title { font-weight: 800; color: var(--primary); margin: 0 0 6px; }
.trace-status { color: var(--accent); font-weight: 800; text-align: center; margin: 10px 0 0; font-size: 1.05rem; }

/* 席替え */
.result-controls { display: flex; gap: 12px; align-items: center; justify-content: center; flex-wrap: wrap; margin-bottom: 10px; }
.result-controls label { font-weight: 800; }
.result-controls select { min-height: 48px; font-size: 1rem; font-family: inherit; padding: 6px 10px; border-radius: 8px; border: 2px solid #ccc; max-width: 100%; }
.print-options {
  display: flex; gap: 8px 18px; justify-content: center; align-items: center;
  background: #f0f8ff; padding: 10px; border-radius: 8px; margin: 10px 0; border: 1px solid #d0e8ff; flex-wrap: wrap;
}
.print-options label { display: inline-flex; align-items: center; gap: 4px; min-height: 40px; }
.print-options input { width: 22px; height: 22px; }

.seat-map-container { display: flex; flex-direction: column; gap: 20px; background: #fff; padding: 30px 20px; align-items: center; margin-top: 14px; border-radius: 12px; overflow-x: auto; }
.seat-map-container.teacher-mode { flex-direction: column-reverse; }
.seat-map-container.teacher-mode .final-grid { transform: rotate(180deg); }
.seat-map-container.teacher-mode .final-seat { transform: rotate(180deg); }
.blackboard {
  height: 40px; background: #364f38; color: #fff; display: flex; align-items: center; justify-content: center;
  margin-bottom: 40px; border-radius: 4px; width: 100%; max-width: 600px; font-weight: 800; letter-spacing: 5px;
  position: relative; border: 4px solid #d4a058; flex-shrink: 0;
}
.blackboard::after {
  content: attr(data-desk); position: absolute; bottom: -30px; left: 50%; transform: translateX(-50%);
  font-size: 12px; color: #555; background: #ddd; padding: 2px 10px; border-radius: 4px; letter-spacing: 1px;
}
.seat-map-container.teacher-mode .blackboard { margin-bottom: 0; margin-top: 40px; }
.seat-map-container.teacher-mode .blackboard::after { bottom: auto; top: -30px; }
.final-grid { display: grid; gap: 10px; justify-content: center; margin: 0 auto; }
.final-seat {
  width: 92px; height: 66px; border: 2px solid #ccc; border-radius: 10px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  position: relative; background: #fff; padding: 2px; box-shadow: 0 2px 0 rgba(0, 0, 0, 0.1); cursor: pointer;
  font-family: inherit; color: #333;
}
.final-seat.empty { visibility: hidden; pointer-events: none; }
.final-seat.boy { background: var(--boy); border-color: var(--boy-border); }
.final-seat.girl { background: var(--girl); border-color: var(--girl-border); }
.final-seat.selected { border: 3px solid var(--select) !important; box-shadow: 0 0 10px var(--select); z-index: 10; }
.name-box { width: 100%; text-align: center; line-height: 1.2; font-weight: 800; color: #333; word-break: keep-all; overflow-wrap: anywhere; pointer-events: none; }
.seat-number { position: absolute; top: 2px; left: 5px; font-size: 10px; color: #666; font-weight: 800; display: none; pointer-events: none; }
.memo-line { display: none; pointer-events: none; }
.vacant { color: #bbb; font-size: 11px; }
.text-single { font-size: 14px; }
.text-split { font-size: 12px; line-height: 1.15; }
.seat-map-container.print-bw .final-seat { background: #fff !important; border: 2px solid #333 !important; }
.seat-map-container.show-number .seat-number { display: block; }

@media (max-width: 700px) {
  body { padding-top: calc(120px + env(safe-area-inset-top, 0px)); padding-left: 8px; padding-right: 8px; }
  .lang-slot { top: calc(66px + env(safe-area-inset-top, 0px)); }
  .panel { padding: 16px 12px; }
  .final-seat { width: 70px; height: 56px; }
  .grid-cell { width: 44px; height: 44px; }
}

/* A4 横 1枚に ぴったり入れる印刷 */
@media print {
  @page { size: A4 landscape; margin: 0; }
  body * { visibility: hidden; }
  #result-container, #result-container * { visibility: visible; }
  html { height: 100vh !important; overflow: hidden !important; }
  body { background-image: none !important; margin: 0 !important; padding: 0 !important; width: 100vw !important; height: 100vh !important; min-height: 0 !important; overflow: hidden !important; }
  .lang-slot, .dd-toast-wrap { display: none !important; }
  #step3 { position: static !important; max-height: none !important; overflow: visible !important; }
  #result-container {
    position: absolute; top: 0; left: 0; width: 100vw !important; height: 100vh !important;
    margin: 0; padding: 10mm 15mm; display: flex; flex-direction: column; align-items: center; background: #fff; border-radius: 0; overflow: hidden;
  }
  #result-container.teacher-mode { flex-direction: column-reverse !important; }
  .blackboard { -webkit-print-color-adjust: exact; print-color-adjust: exact; width: 80%; height: 35px; min-height: 35px; margin-bottom: 15px; }
  #result-container.teacher-mode .blackboard { margin-bottom: 0 !important; margin-top: 15px !important; }
  .final-seat.boy { -webkit-print-color-adjust: exact; print-color-adjust: exact; background: #E3F2FD !important; }
  .final-seat.girl { -webkit-print-color-adjust: exact; print-color-adjust: exact; background: #FCE4EC !important; }
  .seat-map-container.print-bw .final-seat { background: #fff !important; border: 2px solid #000 !important; color: #000 !important; box-shadow: none; }
  .final-seat.selected { border-width: 1px !important; border-color: #999 !important; box-shadow: none !important; }
  .final-grid { width: 100%; flex-grow: 1; gap: 5px; grid-auto-rows: minmax(0, 1fr); align-content: stretch; }
  .final-seat {
    width: 100%; height: 100%; min-height: 0 !important; justify-content: flex-start; padding: 8px 5px 2px;
    border-width: 1px; border-color: #999; box-shadow: none; overflow: hidden;
  }
  .final-seat.empty { visibility: hidden !important; }
  .name-box { margin-bottom: 2px; line-height: 1.1; }
  .text-single { font-size: 15px; }
  .text-split { font-size: 12px; }
  .memo-line { display: block; width: 90%; border-bottom: 1px dashed #555; margin: auto auto 2px; height: 10px; }
  .seat-number { top: 2px; left: 3px; font-size: 9px; }
}
