*, *::before, *::after { box-sizing: border-box; }

:root {
  --bg: #f6f6f4;
  --panel: #fff;
  --ink: #1c1c1a;
  --muted: #6b6b66;
  --line: #d8d8d2;
  --accent: #1a5fb4;
  --ok: #1a7f37;
  --warn: #9a6700;
  --ng: #c01c28;
}

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  padding: 16px 16px 64px;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.7 -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP", "Yu Gothic UI", sans-serif;
}

header { max-width: 900px; margin: 0 auto 16px; }
h1 { font-size: 1.25rem; margin: 0 0 4px; }
.phase { font-size: .75rem; font-weight: 500; color: var(--muted); margin-left: .5em; }
.lead { margin: 0; font-size: .85rem; color: var(--muted); }

.muted { color: var(--muted); font-size: .85rem; }

/* ---- 取込 ---- */
.drop {
  max-width: 900px;
  margin: 0 auto;
  padding: 24px 16px;
  background: var(--panel);
  border: 2px dashed var(--line);
  border-radius: 12px;
  text-align: center;
}
.drop.over { border-color: var(--accent); background: #eef4fd; }
.drop p { margin: 6px 0 0; }
.pick { display: inline-block; }
.pick input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.pick span {
  display: inline-block;
  padding: 10px 22px;
  background: var(--accent);
  color: #fff;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
}
.pick input:focus-visible + span { outline: 3px solid #7aa6e8; outline-offset: 2px; }
.docname { font-size: .85rem; font-weight: 600; margin-top: 10px !important; }

.status {
  max-width: 900px;
  margin: 12px auto;
  font-size: .85rem;
  color: var(--muted);
  min-height: 1.7em;
}
.status.err { color: var(--ng); }

/* ---- ステージ ---- */
.stage { max-width: 900px; margin: 0 auto; }

.bar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 20px;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px 10px 0 0;
}
.pager { display: flex; align-items: center; gap: 10px; }
.pager span { font-variant-numeric: tabular-nums; font-size: .9rem; min-width: 4.5em; text-align: center; }

button {
  font: inherit;
  font-size: .85rem;
  padding: 7px 14px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 7px;
  cursor: pointer;
}
button:hover:not(:disabled) { background: #f0f0ec; }
button:disabled { opacity: .4; cursor: default; }

.meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; font-size: .8rem; }
.meta .k { color: var(--muted); }
.meta .v { font-weight: 600; font-variant-numeric: tabular-nums; }
.tag { padding: 2px 8px; border-radius: 999px; font-size: .75rem; font-weight: 600; background: #eee; }
.tag.ok { background: #dcfce0; color: var(--ok); }
.tag.warn { background: #fdf1d0; color: var(--warn); }

/* ---- ページ表示 ---- */
.canvas-wrap {
  position: relative;
  background: #8a8a84;
  border: 1px solid var(--line);
  border-top: 0;
  overflow: auto;
  max-height: 72vh;
  /* 縮小時に中央、拡大時は左上から流す */
  display: grid;
  place-items: start center;
  padding: 12px;
}
.canvas-wrap canvas {
  grid-area: 1 / 1;
  width: calc(100% * var(--zoom));
  max-width: none;
  height: auto;
  background: #fff;
  box-shadow: 0 2px 12px rgba(0,0,0,.25);
}
#overlay { background: transparent; box-shadow: none; touch-action: manipulation; }

/* ---- 操作 ---- */
.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 20px;
  align-items: center;
  padding: 12px 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-top: 0;
  border-radius: 0 0 10px 10px;
  font-size: .85rem;
}
.controls label { display: flex; align-items: center; gap: 6px; cursor: pointer; }
.zoomctl input { width: 130px; }
#zoomLabel { font-variant-numeric: tabular-nums; min-width: 3.5em; }

.probe {
  margin-top: 12px;
  padding: 12px 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: .85rem;
  line-height: 1.9;
}
.probe b { font-weight: 600; margin-right: .4em; }

/* ---- 規律の確認 ---- */
.contract {
  margin-top: 12px;
  padding: 12px 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: .85rem;
}
.contract summary { cursor: pointer; font-weight: 600; }
.contract p { margin: 10px 0; }
.result { font-weight: 600; }
.result.ok { color: var(--ok); }
.result.ng { color: var(--ng); }

@media (max-width: 600px) {
  body { padding: 12px 10px 48px; }
  .bar, .controls { gap: 8px 12px; }
  .canvas-wrap { max-height: 60vh; padding: 8px; }
}

/* ---- ツールパレット（A2） ---- */
.tools {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  align-items: center;
  padding: 10px 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-top: 0;
}
.tool { font-weight: 600; }
.tool.is-on { background: var(--accent); color: #fff; border-color: var(--accent); }
.tool.is-on:hover { background: var(--accent); }
.hint { font-size: .8rem; color: var(--muted); }

/* ---- 入力欄 ---- */
.editor {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 10px;
  align-items: center;
  padding: 12px 14px;
  background: #eef4fd;
  border: 1px solid var(--accent);
  border-top: 0;
}
.editor input[type="text"] {
  font: inherit;
  font-size: .9rem;
  padding: 8px 10px;
  min-width: 14em;
  flex: 1 1 14em;
  border: 1px solid var(--line);
  border-radius: 7px;
}
.fitinfo { font-size: .8rem; color: var(--muted); font-variant-numeric: tabular-nums; }

/* ---- 検証パネル ---- */
.contract .row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  align-items: center;
  margin: 12px 0;
}
.contract .row label { display: flex; align-items: center; gap: 6px; }
.contract input[type="number"] { font: inherit; font-size: .85rem; width: 5em; padding: 5px 7px; border: 1px solid var(--line); border-radius: 6px; }
#dilateLabel { font-variant-numeric: tabular-nums; min-width: 3em; }
#gridResult { line-height: 1.9; font-weight: 400; }
#gridResult b { font-weight: 700; }
.probe .ng, .ng { color: var(--ng); }
.controls select { font: inherit; font-size: .85rem; padding: 5px 7px; border: 1px solid var(--line); border-radius: 6px; }

/* ---- A3: 枠切替と自由変形 ---- */
#cycleRect { white-space: nowrap; }
#rectKind { font-weight: 400; color: var(--muted); }
#bandInfo { color: var(--muted); }
#overlay { cursor: crosshair; }
