/* 編集画面の UI */

:root {
  --ui-bg: #f3f4f6;
  --ui-panel: #ffffff;
  --ui-border: #d4d7dd;
  --ui-text: #1f2328;
  --ui-muted: #6b7280;
  --ui-accent: #2563eb;
  --ui-accent-bg: #dbe7ff;
  --stage-bg: #5b6270;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--ui-bg);
  color: var(--ui-text);
  font: 14px "Yu Gothic UI", "Segoe UI", "Meiryo", sans-serif;
  overflow: hidden;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100%;
}

/* ---- ツールバー ---- */
#toolbar {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 6px 10px 4px;
  background: var(--ui-panel);
  border-bottom: 1px solid var(--ui-border);
  user-select: none;
}

#toolbar .row {
  display: flex;
  align-items: center;
  gap: 6px 10px;
  min-width: 0;
}
/* 2段目（ツールごとの設定）は高さを固定し、ツールを切り替えてもページの位置が動かないようにする */
#toolbar .row2 {
  height: 40px;
  overflow: hidden;
}
#toolbar .hint { color: var(--ui-muted); font-size: 13px; padding-left: 4px; }
#toolbar .group {
  display: flex;
  align-items: center;
  gap: 4px;
  padding-right: 10px;
  border-right: 1px solid var(--ui-border);
}
#toolbar .group:last-child { border-right: 0; }
#toolbar .spacer { flex: 1; }

button {
  font: inherit;
  min-height: 36px;
  padding: 4px 10px;
  border: 1px solid var(--ui-border);
  border-radius: 6px;
  background: #fff;
  color: var(--ui-text);
  cursor: pointer;
  touch-action: manipulation;
}
button:hover { background: #f0f3f8; }
button.on {
  background: var(--ui-accent-bg);
  border-color: var(--ui-accent);
  color: #0b3a9c;
}
button:disabled { opacity: 0.4; cursor: default; }

#tools button { display: inline-flex; align-items: center; gap: 4px; }
.ico { font-weight: 700; font-size: 16px; width: 16px; text-align: center; }
.ico.hl { color: #e0b800; }

.swatch {
  width: 32px;
  min-height: 32px;
  height: 32px;
  padding: 0;
  border-radius: 50%;
  border: 2px solid #fff;
  box-shadow: 0 0 0 1px var(--ui-border);
}
.swatch.on { box-shadow: 0 0 0 3px var(--ui-accent); }

.size-btn { width: 38px; padding: 0; display: inline-flex; align-items: center; justify-content: center; }
.size-btn i { display: block; border-radius: 50%; background: currentColor; }

#colors, #sizes, #text-sizes { display: inline-flex; gap: 4px; align-items: center; }
#sizes { margin-left: 6px; }
.fmt { width: 38px; font-size: 16px; }

#toolbar .sep { width: 1px; align-self: stretch; margin: 4px 3px; background: var(--ui-border); }
button.icon { width: 38px; padding: 0; font-size: 18px; }
.ico-svg { width: 18px; height: 18px; display: block; }
#tools button .ico-svg { display: inline-block; vertical-align: -3px; margin-right: 3px; }
#tools button.icon .ico-svg { margin: 0 auto; display: block; }
.fmt sub, .fmt sup { font-size: 0.65em; }
.fmt.tcolor { width: 34px; padding: 0; display: inline-flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; }
.fmt.tcolor span { font-weight: 700; font-size: 15px; line-height: 1; }
.fmt.tcolor i { display: block; width: 18px; height: 4px; border-radius: 2px; }
.fmt.tmarker { width: 36px; padding: 0; }
.fmt.tmarker span { padding: 1px 4px; border-radius: 2px; opacity: 0.85; }
.fmt.box-btn span { border: 1.5px solid currentColor; padding: 0 3px; }
.fontsize { display: inline-flex; align-items: stretch; height: 36px; border: 1px solid var(--ui-border); border-radius: 6px; overflow: hidden; background: #fff; }
.fontsize input { width: 46px; border: 0; padding: 0 4px; font: inherit; font-size: 15px; text-align: right; outline: none; }
.fontsize input:focus { background: #eef4ff; }
.fontsize .fs-drop { min-height: 0; height: auto; width: 22px; padding: 0; border: 0; border-left: 1px solid var(--ui-border); border-radius: 0; font-size: 11px; }
#toolbar .unit { color: var(--ui-muted); font-size: 12px; margin: 0 2px 0 -1px; }
.fs-step { font-weight: 700; }
.fs-step small { font-size: 8px; margin-left: 1px; vertical-align: 1px; }
.popup {
  position: fixed;
  z-index: 50;
  background: #fff;
  border: 1px solid var(--ui-border);
  border-radius: 8px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.18);
  padding: 4px;
  max-height: 70vh;
  overflow-y: auto;
}
.popup button { display: block; width: 100%; min-height: 30px; border: 0; text-align: right; padding: 2px 14px; border-radius: 4px; }
.popup button.on { background: var(--ui-accent-bg); color: #0b3a9c; }
#text-colors, #text-markers { display: inline-flex; gap: 3px; }
#text-opts .on { box-shadow: inset 0 0 0 1px var(--ui-accent); }

#btn-pin.on, #btn-black.on, #btn-white.on { background: #fff4d6; border-color: #d99a00; color: #7a5200; }
#btn-present.on { background: #e8f7ec; border-color: #2f9e55; color: #17652f; }

/* ---- 本体 ---- */
#main {
  flex: 1;
  display: flex;
  min-height: 0;
}

#sidebar {
  width: 200px;
  display: flex;
  flex-direction: column;
  background: var(--ui-panel);
  border-right: 1px solid var(--ui-border);
}
#thumbs {
  flex: 1;
  overflow-y: auto;
  padding: 10px 10px 4px;
}
.thumb {
  display: flex;
  gap: 6px;
  margin-bottom: 10px;
  cursor: pointer;
  user-select: none;
}
.thumb .num { width: 18px; text-align: right; color: var(--ui-muted); font-size: 12px; padding-top: 2px; }
.thumb .frame {
  position: relative;
  width: 154px;
  height: 86.625px;
  overflow: hidden;
  border: 1px solid var(--ui-border);
  border-radius: 3px;
  pointer-events: none;
}
.thumb.current .frame { outline: 3px solid var(--ui-accent); outline-offset: 1px; }
.thumb.presented .num { color: #17a34a; font-weight: 700; }
#page-ops {
  display: flex;
  gap: 6px;
  padding: 8px 10px;
  border-top: 1px solid var(--ui-border);
}
#page-ops button:first-child { flex: 1; }

#stage {
  flex: 1;
  position: relative;
  overflow: hidden;
  background: var(--stage-bg);
  touch-action: none;
}

#pagewrap {
  position: absolute;
  left: 0;
  top: 0;
  width: 1920px;
  height: 1080px;
  transform-origin: 0 0;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.35);
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}
#pagewrap.tool-pen, #pagewrap.tool-marker { cursor: crosshair; }
#pagewrap.tool-eraser { cursor: none; }
#pagewrap.tool-text { cursor: text; }

/* テキスト：文字ツールのときだけ触れる */
#pagewrap .bpage .text, #pagewrap .bpage .table { pointer-events: none; }
#pagewrap.tool-text .bpage .text, #pagewrap.tool-text .bpage .table { pointer-events: auto; }
#pagewrap .bpage .table .content { -webkit-user-select: text; user-select: text; cursor: text; }
#pagewrap.tool-text .bpage .table td:focus-within { box-shadow: inset 0 0 0 calc(2px * var(--inv)) rgba(37, 99, 235, 0.8); }
#pagewrap .bpage .text .content { -webkit-user-select: text; user-select: text; }
#pagewrap.tool-text .bpage .text:hover {
  outline: calc(1.5px * var(--inv)) dashed rgba(37, 99, 235, 0.55);
  outline-offset: calc(4px * var(--inv));
}
#pagewrap .bpage .text:focus-within {
  outline: calc(1.5px * var(--inv)) solid rgba(37, 99, 235, 0.9);
  outline-offset: calc(4px * var(--inv));
}

.handle { display: none; position: absolute; }
#pagewrap .text:focus-within .handle, #pagewrap .table:focus-within .handle { display: block; }
.col-handle {
  display: none;
  position: absolute;
  top: 0;
  bottom: 0;
  width: calc(12px * var(--inv));
  margin-left: calc(-6px * var(--inv));
  cursor: col-resize;
  z-index: 2;
}
#pagewrap.tool-text .table:hover .col-handle, #pagewrap.tool-text .table:focus-within .col-handle { display: block; }
.col-handle:hover { background: rgba(37, 99, 235, 0.35); }
.h-move {
  left: calc(-30px * var(--inv));
  top: 0;
  width: calc(22px * var(--inv));
  height: calc(22px * var(--inv));
  border-radius: calc(4px * var(--inv));
  background: var(--ui-accent) radial-gradient(circle, #fff 18%, transparent 20%) 0 0 / 33% 33%;
  cursor: move;
}
.h-width {
  right: calc(-10px * var(--inv));
  top: 0;
  bottom: 0;
  width: calc(10px * var(--inv));
  background: rgba(37, 99, 235, 0.45);
  border-radius: calc(3px * var(--inv));
  cursor: ew-resize;
}
.h-del {
  right: calc(-36px * var(--inv));
  top: calc(-26px * var(--inv));
  width: calc(22px * var(--inv));
  height: calc(22px * var(--inv));
  line-height: calc(20px * var(--inv));
  font-size: calc(18px * var(--inv));
  text-align: center;
  border-radius: 50%;
  background: #d33;
  color: #fff;
  font-family: "Segoe UI", sans-serif;
  font-weight: 400;
  cursor: pointer;
}

/* 選択枠（編集画面だけのレイヤー。提示画面には出ない） */
.sel-layer {
  position: absolute;
  left: 0;
  top: 0;
  width: 1920px;
  height: 1080px;
  pointer-events: none;
  z-index: 8;
}
.sel-box, .sel-group, .marquee { position: absolute; }
.sel-box { outline: calc(1px * var(--inv)) dashed rgba(37, 99, 235, 0.7); }
.sel-group { outline: calc(1.5px * var(--inv)) solid rgba(37, 99, 235, 0.95); outline-offset: calc(3px * var(--inv)); }
.marquee { border: calc(1px * var(--inv)) dashed #2563eb; background: rgba(37, 99, 235, 0.08); }
.sel-handle {
  position: absolute;
  width: calc(16px * var(--inv));
  height: calc(16px * var(--inv));
  background: #fff;
  border: calc(2px * var(--inv)) solid #2563eb;
  border-radius: 50%;
  pointer-events: auto;
}
.sel-handle.nw { left: calc(-11px * var(--inv)); top: calc(-11px * var(--inv)); cursor: nwse-resize; }
.sel-handle.ne { right: calc(-11px * var(--inv)); top: calc(-11px * var(--inv)); cursor: nesw-resize; }
.sel-handle.sw { left: calc(-11px * var(--inv)); bottom: calc(-11px * var(--inv)); cursor: nesw-resize; }
.sel-handle.se { right: calc(-11px * var(--inv)); bottom: calc(-11px * var(--inv)); cursor: nwse-resize; }
#pagewrap.tool-select { cursor: default; }
#pagewrap.tool-shape { cursor: crosshair; }

.eraser-cursor {
  display: none;
  position: absolute;
  border: calc(1.5px * var(--inv)) solid #444;
  background: rgba(255, 255, 255, 0.5);
  border-radius: 50%;
  pointer-events: none;
  z-index: 10;
}

/* ---- ステータスバー ---- */
#status {
  display: flex;
  gap: 16px;
  align-items: center;
  padding: 3px 12px;
  font-size: 12px;
  color: var(--ui-muted);
  background: var(--ui-panel);
  border-top: 1px solid var(--ui-border);
}
#status .spacer { flex: 1; }
#present-state.on { color: #17a34a; font-weight: 700; }
#present-state.warn { color: #b26b00; }
#toast { color: var(--ui-text); transition: opacity 0.4s; }
#toast.hide { opacity: 0; }

/* ---- PDF出力の案内 ---- */
#print-guide {
  max-width: 520px;
  border: 1px solid var(--ui-border);
  border-radius: 10px;
  padding: 20px 24px;
  color: var(--ui-text);
  line-height: 1.7;
}
#print-guide::backdrop { background: rgba(0, 0, 0, 0.35); }
#print-guide h2 { margin: 0 0 8px; font-size: 18px; }
#print-guide p { margin: 0 0 10px; }
#print-guide .note { font-size: 13px; color: var(--ui-muted); }
#print-guide label { display: block; margin-top: 12px; font-size: 13px; }
#print-guide .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
button.primary { background: var(--ui-accent); border-color: var(--ui-accent); color: #fff; }
button.primary:hover { background: #1d4fd0; }

/* ---- 印刷（PDF出力） ---- */
#print-root { display: none; }

@page {
  size: 1920px 1080px;
  margin: 0;
}

@media print {
  html, body { height: auto; overflow: visible; background: #fff; }
  #app { display: none !important; }
  #print-root { display: block; }
  .print-page {
    position: relative;
    width: 1920px;
    height: 1080px;
    overflow: hidden;
    break-after: page;
  }
  .print-page:last-child { break-after: auto; }
}

/* ---- 第3段階 ---- */
#theme-select {
  font: inherit;
  height: 36px;
  padding: 0 6px;
  border: 1px solid var(--ui-border);
  border-radius: 6px;
  background: #fff;
}
.eraser-cursor.partial { border-style: dashed; }
#eraser-sizes { display: inline-flex; gap: 4px; }
#page-ops button { flex: 1; padding: 4px 6px; }

/* ページ一覧のドラッグ並べ替え */
#thumbs { position: relative; }
.thumb.dragging { opacity: 0.4; }
.drop-line {
  position: absolute;
  left: 8px;
  right: 8px;
  height: 3px;
  border-radius: 2px;
  background: var(--ui-accent);
  pointer-events: none;
}

#drop-hint {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(37, 99, 235, 0.15);
  border: 4px dashed var(--ui-accent);
  color: #0b3a9c;
  font-size: 22px;
  font-weight: 700;
  pointer-events: none;
}
#drop-hint[hidden] { display: none; }

dialog {
  border: 1px solid var(--ui-border);
  border-radius: 10px;
  padding: 20px 24px;
  color: var(--ui-text);
  line-height: 1.7;
}
dialog::backdrop { background: rgba(0, 0, 0, 0.35); }
dialog h2 { margin: 0 0 8px; font-size: 18px; }
dialog p { margin: 0 0 10px; }
dialog .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
#restore-dialog { max-width: 520px; }
.restore-info { background: var(--ui-bg); border-radius: 6px; padding: 8px 12px; }
.theme-choice { margin-bottom: 12px; padding-bottom: 10px; border-bottom: 1px solid var(--ui-border); }
.theme-choice p { margin-bottom: 4px; }
label.radio { display: block; margin: 2px 0 2px 8px; font-size: 14px; }
#help-dialog { max-width: 720px; width: 90vw; }
#pptx-dialog { max-width: 560px; }
#table-grid { display: grid; grid-template-columns: repeat(8, 22px); gap: 3px; padding: 4px; }
#table-grid i { width: 22px; height: 22px; border: 1px solid var(--ui-border); border-radius: 2px; cursor: pointer; }
#table-grid i.on { background: var(--ui-accent-bg); border-color: var(--ui-accent); }
#table-size { text-align: center; font-size: 12px; color: var(--ui-muted); padding: 2px 0 4px; }
#table-ops button { text-align: left; }
/* ボタン＋▾ の組 */
.split { display: inline-flex; }
.split > button:first-child { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.split > .drop { width: 15px; min-width: 15px; padding: 0; border-left: 0; border-top-left-radius: 0; border-bottom-left-radius: 0; font-size: 9px; color: var(--ui-muted); }
#btn-align { width: 38px; }
.menu-colors { padding: 6px; }
.menu-colors .mtitle { font-size: 12px; color: var(--ui-muted); margin: 2px 4px 4px; text-align: left; }
.menu-colors .row { display: flex; gap: 4px; margin-bottom: 6px; }
.menu-colors .row button { width: auto; min-width: 34px; text-align: center; padding: 2px 6px; }
.menu-colors .sw { display: inline-block; width: 18px; height: 18px; border-radius: 4px; vertical-align: -4px; }
#ol-menu button, #align-menu button { text-align: left; white-space: nowrap; }
#align-menu hr { border: 0; border-top: 1px solid var(--ui-border); margin: 4px 0; }
#align-menu .mtitle { font-size: 12px; color: var(--ui-muted); margin: 2px 6px; }
#align-menu .row { display: flex; gap: 4px; padding: 0 4px 4px; }
#align-menu .row button { text-align: center; padding: 2px 10px; }
#align-menu .ico-svg, #ol-menu .ico-svg { display: inline-block; vertical-align: -4px; margin-right: 6px; }
.tmarker.main span { padding: 1px 5px; }
#table-ops hr { border: 0; border-top: 1px solid var(--ui-border); margin: 4px 0; }
#table-ops .mtitle { font-size: 12px; color: var(--ui-muted); margin: 2px 6px 4px; }
#table-ops .row { display: flex; gap: 3px; padding: 0 4px 5px; }
#table-ops .row button { width: auto; text-align: center; padding: 2px 8px; white-space: nowrap; }
#table-ops .bd-style button { font-weight: 700; }
#pptx-dialog .opt-title { margin: 12px 0 2px; font-weight: 700; }
#pptx-dialog label.radio { margin: 4px 0 4px 8px; }
#pptx-dialog .note { font-size: 12px; color: var(--ui-muted); }
#pptx-dialog #pptx-hint { margin: 6px 0 0 8px; }
body.busy, body.busy * { cursor: progress !important; }
#help-body { max-height: 65vh; overflow-y: auto; }
#help-body table { border-collapse: collapse; width: 100%; font-size: 13px; }
#help-body th { text-align: left; padding: 10px 6px 4px; font-size: 14px; border-bottom: 1px solid var(--ui-border); }
#help-body td { padding: 3px 6px; border-bottom: 1px solid #eef0f3; vertical-align: top; }
#help-body td:first-child { white-space: nowrap; width: 40%; }
#help-body kbd {
  display: inline-block;
  padding: 0 5px;
  border: 1px solid var(--ui-border);
  border-bottom-width: 2px;
  border-radius: 4px;
  background: #fafafa;
  font: 12px "Segoe UI", sans-serif;
}
#toolbar button, #toolbar select { white-space: nowrap; flex-shrink: 0; }

/* 1段目を Surface（1368px）の幅に収める */
#toolbar .row { gap: 6px 6px; }
#toolbar .group { padding-right: 6px; gap: 3px; }
#toolbar .row:first-child button { padding-left: 8px; padding-right: 8px; }
#toolbar .row:first-child button.icon { padding: 0; }
#page-ops button { white-space: nowrap; }
#help-body { outline: none; }
