/* ── 基本リセット・フォント ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: 'Hiragino Kaku Gothic Pro', 'Meiryo', sans-serif;
  font-size: 14px; color: #333; background: #f0f2f5;
}

/* ── アプリ全体レイアウト ── */
.app { display: flex; height: 100vh; overflow: hidden; }

/* ── 左パネル ── */
.panel {
  width: 260px; min-width: 260px; background: #fff;
  border-right: 1px solid #e0e0e0; overflow-y: auto;
  display: flex; flex-direction: column; gap: 0;
}
.panel-header {
  padding: 16px 16px 12px; border-bottom: 1px solid #eee;
  font-size: 15px; font-weight: 700; color: #333;
  display: flex; align-items: center; gap: 8px;
}
.panel-header .badge {
  font-size: 10px; background: #e8f0fe; color: #3a7bd5;
  border-radius: 4px; padding: 2px 6px; font-weight: 600;
}
.panel-section { padding: 14px 16px; border-bottom: 1px solid #f0f0f0; }
.panel-section label { display: block; font-size: 12px; font-weight: 600; color: #666; margin-bottom: 8px; }
.panel-section input[type=number] {
  width: 100%; padding: 6px 8px;
  border: 1px solid #ccc; border-radius: 6px;
  font-size: 13px; background: #fafafa;
}
.panel-section input[type=number]:focus { outline: none; border-color: #3a7bd5; }
.divider { border: none; border-top: 1px solid #eee; margin: 0; }

/* ── ピルボタン ── */
.pill-group { display: flex; flex-wrap: wrap; gap: 6px; }
.pill {
  padding: 5px 12px; border: 1.5px solid #ddd; border-radius: 20px;
  background: #fff; font-size: 13px; font-weight: 600; cursor: pointer;
  color: #555; transition: all .15s; user-select: none;
}
.pill:hover { border-color: #3a7bd5; color: #3a7bd5; }
.pill.active { background: #3a7bd5; border-color: #3a7bd5; color: #fff; }

/* ── トグルスイッチ ── */
.toggle-row { display: flex; align-items: center; justify-content: space-between; }
.toggle { position: relative; display: inline-block; width: 40px; height: 22px; }
.toggle input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute; cursor: pointer; inset: 0;
  background: #ccc; border-radius: 22px; transition: .2s;
}
.slider::before {
  content: ''; position: absolute;
  width: 16px; height: 16px; border-radius: 50%;
  background: #fff; left: 3px; top: 3px; transition: .2s;
}
input:checked + .slider { background: #3a7bd5; }
input:checked + .slider::before { transform: translateX(18px); }
.locked { opacity: .4; pointer-events: none; }

/* ── 問題数バッジ ── */
.count-badge {
  display: inline-block; background: #e8f0fe; color: #3a7bd5;
  border-radius: 12px; padding: 2px 10px; font-size: 12px;
  font-weight: 700; margin-top: 6px;
}

/* ── ボタン ── */
.btn {
  width: 100%; padding: 10px; border: none; border-radius: 8px;
  font-size: 14px; font-weight: 700; cursor: pointer; transition: background .15s;
}
.btn-primary { background: #3a7bd5; color: #fff; }
.btn-primary:hover { background: #2f6bbf; }
.btn-primary:disabled { background: #b0c4e8; cursor: default; }
.btn-secondary { background: #f0f2f5; color: #333; margin-top: 8px; }
.btn-secondary:hover { background: #e0e2e5; }
.btn-secondary:disabled { opacity: .4; cursor: default; }

/* ── タイトル・指示フォーム ── */
.title-input {
  width: 100%; border: 1px solid #ddd; border-radius: 6px;
  padding: 6px 8px; font-size: 13px; font-family: inherit;
}
.title-input:focus { outline: none; border-color: #3a7bd5; }
.instruction-toolbar { display: flex; align-items: center; gap: 6px; margin-bottom: 4px; font-size: 11px; color: #999; }
.inst-size-btn {
  width: 20px; height: 20px; padding: 0; border: 1px solid #ddd;
  border-radius: 4px; background: #f5f5f5; color: #555;
  font-size: 13px; display: flex; align-items: center; justify-content: center; cursor: pointer;
}
.inst-size-btn:hover { background: #e8e8e8; }
#instSizeDisplay { font-size: 12px; color: #555; min-width: 18px; text-align: center; }

/* ── 上部ボタン（印刷確認） ── */
.top-btns { position: fixed; top: 16px; right: 20px; z-index: 200; display: flex; gap: 8px; }
.top-btn { padding: 8px 18px; border: none; border-radius: 8px; font-size: 13px; font-weight: 600; cursor: pointer; box-shadow: 0 2px 8px rgba(0,0,0,.18); transition: opacity .15s, transform .1s; }
.top-btn:hover   { opacity: .88; }
.top-btn:active  { transform: translateY(1px); }
.top-btn:disabled { opacity: .4; cursor: default; transform: none; }
.top-btn-settings { background: #fff; color: #333; }
.top-btn-settings.current { background: #e8edf2; color: #555; box-shadow: none; cursor: default; }
.top-btn-preview  { background: #e67e22; color: #fff; }
.top-btn-print    { background: #27ae60; color: #fff; }
.top-btn-answer   { background: #f0f2f5; color: #333; }
.top-btn-answer.active { background: #2ecc71; color: #fff; }
@media print { .top-btns { display: none; } }

/* ── プレビューエリア ── */
.preview-area {
  flex: 1; overflow: auto; padding: 24px;
  display: flex; flex-direction: column; align-items: center;
}
.sheet-wrapper { flex-shrink: 0; }

/* ── シートコンテナ（複数枚） ── */
#sheetsContainer { display: flex; flex-direction: column; align-items: center; gap: 20px; }

/* ── プリントシート（横向きA4）── */
.print-sheet {
  background: #fff;
  width: 297mm; height: 210mm;
  overflow: hidden;
  padding: 12mm 16mm;
  box-shadow: 0 2px 12px rgba(0,0,0,.12);
  transform-origin: top left;
}

/* ── シートヘッダー ── */
.sheet-header { display: flex; align-items: flex-end; gap: 16px; margin-bottom: 5mm; }
.sheet-title {
  flex: 1; min-width: 40mm; outline: none;
  font-family: 'M PLUS Rounded 1c', 'Hiragino Maru Gothic Pro', sans-serif;
  font-size: 26px; font-weight: 800;
}
.sheet-title[contenteditable="true"]:empty::before { content: attr(data-placeholder); color: #ccc; }
.header-field { display: flex; align-items: flex-end; gap: 4px; font-size: 16px; white-space: nowrap; }
.header-field .line { display: inline-block; width: 60px; border-bottom: 1px solid #333; }
.header-field .name-line { width: 60mm; }
.sheet-instruction {
  min-height: 5mm; margin-bottom: 4mm;
  font-size: 14px; line-height: 1.7; color: #222;
  outline: none; white-space: pre-wrap;
}
.sheet-instruction:empty::before { content: attr(data-placeholder); color: #bbb; }
.sheet-instruction[contenteditable="true"] { border-bottom: 1px dashed #ccc; padding-bottom: 2px; cursor: text; }

/* ── 問題グリッド（3列固定）── */
.problems-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  column-gap: var(--col-gap, 8mm);
  row-gap: var(--row-gap, 6mm);
  align-items: start;
  justify-items: center;
}
.print-sheet .problems-grid {
  min-height: var(--grid-min-h, 155mm);
  align-content: space-evenly;
}

/* ── さくらんぼ問題セル ── */
.sak-problem {
  display: flex;
  flex-direction: column;
  gap: calc(var(--C) * 0.2);
  width: fit-content;
}

/* ── 式 ── */
.sak-formula {
  display: flex;
  align-items: center;
  gap: calc(var(--C) * 0.25);
  white-space: nowrap;
}
.sak-label {
  font-size: calc(var(--C) * 0.5);
  font-weight: 600;
  color: #555;
  min-width: calc(var(--C) * 1.8);
  text-align: right;
  flex-shrink: 0;
}
.sak-num {
  font-size: calc(var(--C) * 1.0);
  font-weight: 700;
  min-width: calc(var(--C) * 1.3);
  text-align: center;
  color: #222;
}
.sak-op {
  font-size: calc(var(--C) * 1.0);
  font-weight: 400;
  width: calc(var(--C) * 0.9);
  text-align: center;
  color: #333;
}
.sak-ans {
  font-size: calc(var(--C) * 1.0);
  font-weight: 700;
  min-width: calc(var(--C) * 1.8);
  height: calc(var(--C) * 1.2);
  text-align: center;
  border-bottom: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #222;
}

/* ── さくらんぼ図 ── */
.sak-tree { width: 100%; }
.sak-svg {
  display: block;
  width: 100%;
  height: calc(var(--C) * 4.0);
  color: #333;
}

/* ── ズームバー ── */
.zoom-bar {
  position: fixed; bottom: 20px; right: 24px; z-index: 150;
  display: flex; align-items: center; gap: 1px;
  background: rgba(255,255,255,.88); backdrop-filter: blur(10px);
  border: 1px solid rgba(0,0,0,.10); border-radius: 20px;
  padding: 3px 5px; box-shadow: 0 2px 10px rgba(0,0,0,.10);
  opacity: .55; transition: opacity .2s; user-select: none;
}
.zoom-bar:hover { opacity: 1; }
.zoom-btn {
  width: 26px; height: 26px; border: none; border-radius: 13px;
  background: transparent; font-size: 15px; font-weight: 700;
  color: #444; cursor: pointer; line-height: 1;
  display: flex; align-items: center; justify-content: center; transition: background .12s;
}
.zoom-btn:hover { background: rgba(0,0,0,.07); }
.zoom-reset {
  min-width: 42px; border: none; border-radius: 4px;
  background: transparent; font-size: 12px; font-weight: 600;
  color: #555; cursor: pointer; padding: 2px 4px;
  transition: background .12s; border-left: 1px solid rgba(0,0,0,.09); margin-left: 2px; padding-left: 7px;
}
.zoom-reset:hover { background: rgba(0,0,0,.07); }
.zoom-slider {
  -webkit-appearance: none; appearance: none;
  width: 90px; height: 3px; background: rgba(0,0,0,.18);
  border-radius: 2px; outline: none; cursor: pointer; margin: 0 2px;
}
.zoom-slider::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 13px; height: 13px; border-radius: 50%;
  background: #3a7bd5; box-shadow: 0 1px 3px rgba(58,123,213,.4); transition: transform .1s;
}
.zoom-slider::-webkit-slider-thumb:hover { transform: scale(1.2); }
.zoom-slider::-moz-range-thumb {
  width: 13px; height: 13px; border-radius: 50%; border: none;
  background: #3a7bd5; box-shadow: 0 1px 3px rgba(58,123,213,.4);
}

/* ── 印刷 ── */
@page { size: A4 landscape; margin: 0; }
@media print {
  body { background: #fff; }
  .app { display: block; height: auto; }
  .panel { display: none; }
  .preview-area { padding: 0; overflow: visible; display: block; }
  .sheet-wrapper { width: auto !important; height: auto !important; }
  .print-sheet { box-shadow: none; margin: 0; transform: none !important; page-break-after: always; }
  #sheetsContainer { gap: 0; }
  .print-sheet:last-child { page-break-after: avoid; }
  .sheet-instruction { border: none; padding: 0; }
  .sheet-instruction.print-hide { display: none; }
  .zoom-bar { display: none; }
  .top-btns { display: none; }
}
.sak-ans-val { color: #e25c4a; font-weight: 700; }
@media print { .sak-ans-val { color: #e25c4a !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; } }
