:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --border: #d9dee3;
  --text: #2b3138;
  --muted: #7b8794;
  --primary: #2563eb;
  --accent: #059669;
  --danger: #dc2626;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic", Meiryo, sans-serif;
  color: var(--text);
  background: var(--bg);
}

body { display: flex; flex-direction: column; height: 100vh; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.topbar h1 { font-size: 17px; margin: 0; font-weight: 700; flex: 1; }
.topbar-actions { display: flex; align-items: center; gap: 14px; }
.topbar .panel-toggle { display: none; font-size: 18px; padding: 5px 10px; }
.btn-label-short { display: none; }
.unit-field {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}
.unit-field select {
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 7px;
  font-size: 13px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
}

.pager { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.pager #pageInfo { min-width: 56px; text-align: center; }

.layout { display: flex; flex: 1; min-height: 0; }

:root { --panel-w: 380px; }

.panel {
  width: var(--panel-w);
  flex-shrink: 0;
  background: var(--panel);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 14px;
}

.panel-resizer {
  flex-shrink: 0;
  width: 6px;
  cursor: col-resize;
  background: transparent;
  border-right: 1px solid var(--border);
  transition: background .12s;
}
.panel-resizer:hover, .panel-resizer.dragging { background: var(--primary); }

.card {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  margin-bottom: 14px;
  background: #fff;
}
.card h2 { font-size: 14px; margin: 0 0 8px; }

/* 折り畳みカード */
details.card { padding: 0; }
.card-summary {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  padding: 12px 14px;
  cursor: pointer;
  list-style: none;
  user-select: none;
}
.card-summary::-webkit-details-marker { display: none; }
.card-summary-title {
  font-size: 14px;
  font-weight: 700;
}
.card-summary-title::before {
  content: "▸";
  margin-right: 6px;
  color: var(--muted);
  display: inline-block;
  transition: transform .15s;
}
details[open] .card-summary-title::before { transform: rotate(90deg); }
.card-body { padding: 0 14px 12px; }
.badge {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 10px;
  background: #eef0f3;
  color: var(--muted);
  white-space: nowrap;
}
.badge.set { background: #e3f6ee; color: var(--accent); }
.hint { font-size: 11.5px; color: var(--muted); margin: 0 0 10px; line-height: 1.5; }

.field { margin-bottom: 10px; }
.field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }

.row { display: flex; gap: 8px; align-items: center; }
.row input[type="number"] { flex: 1; min-width: 0; }

input[type="number"], .field input[type="text"] {
  padding: 7px 9px;
  border: 1px solid var(--border);
  border-radius: 7px;
  font-size: 13px;
  width: 100%;
}
input[type="number"]:focus, .field input[type="text"]:focus { outline: none; border-color: var(--primary); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: #fff;
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
  transition: background .12s, border-color .12s;
}
.btn:hover { background: #f0f2f5; }
.btn:active { transform: translateY(1px); }
.btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: #1d4ed8; }
.btn-accent { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-accent:hover { background: #047857; }
.btn-ghost { color: var(--muted); }
.btn.cancel { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn.cancel:hover { background: #b91c1c; }
.btn:disabled { opacity: .45; cursor: default; }
.btn:disabled:hover { background: #fff; }
.btn-accent:disabled:hover { background: var(--accent); }

.item-list {
  list-style: none;
  margin: 8px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.item-list:empty { margin: 0; }
.item-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fbfcfd;
  font-size: 12.5px;
  font-variant-numeric: tabular-nums;
}
.item-list li.hl { border-color: var(--primary); background: #eef4ff; }
.item-list li.sel { border-color: #0891b2; background: #e6f7fb; box-shadow: 0 0 0 1px #0891b2 inset; }
.item-list .item-val { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-list .item-del {
  flex-shrink: 0;
  width: 20px; height: 20px;
  line-height: 1;
  border: none;
  border-radius: 4px;
  background: transparent;
  color: var(--muted);
  font-size: 15px;
  cursor: pointer;
}
.item-list .item-del:hover { background: #fde2e2; color: var(--danger); }
.item-list .wall-h {
  width: 58px;
  flex-shrink: 0;
  padding: 3px 5px;
  font-size: 12px;
  border: 1px solid var(--border);
  border-radius: 5px;
}
.item-list .wall-h:focus { outline: none; border-color: var(--primary); }
.item-list .wall-eq { flex-shrink: 0; white-space: nowrap; }
.item-list .rect-num { flex-shrink: 0; color: var(--muted); }
.item-list .rect-name {
  flex: 1 1 64px;
  min-width: 56px;
  padding: 3px 6px;
  font-size: 12px;
  border: 1px solid var(--border);
  border-radius: 5px;
}
.item-list .rect-name:focus { outline: none; border-color: var(--primary); }

.scale-status, .result {
  margin-top: 8px;
  padding: 8px 10px;
  border-radius: 7px;
  background: #f1f5f9;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}
.scale-status { font-size: 12px; color: var(--muted); white-space: pre-line; }
.result { font-weight: 600; }
.save-status {
  margin-top: 4px;
  padding: 7px 10px;
  border-radius: 7px;
  background: #f1f5f9;
  font-size: 12px;
  color: var(--muted);
}

.panel-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(0, 0, 0, .35);
}

.stage {
  position: relative;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  background:
    repeating-conic-gradient(#e9edf1 0% 25%, #f4f6f8 0% 50%) 50% / 22px 22px;
}
#canvas { display: block; width: 100%; height: 100%; cursor: crosshair; }
.stage.panning #canvas { cursor: grabbing; }
.stage.idle #canvas { cursor: grab; }

.stage-hint {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  text-align: center;
  pointer-events: none;
}
.stage-hint p { margin: 4px; }
.stage-hint .sub { font-size: 12px; }
.stage-hint { overflow-y: auto; padding: 24px; }

.seo-about {
  pointer-events: auto;
  max-width: 640px;
  margin: 26px auto 0;
  text-align: left;
  font-size: 13px;
  line-height: 1.75;
  color: #5a6573;
}
.seo-about h2 { font-size: 16px; color: var(--text); margin: 0 0 10px; }
.seo-about h3 { font-size: 13.5px; color: var(--text); margin: 16px 0 6px; }
.seo-about ul, .seo-about ol { margin: 0; padding-left: 20px; }
.seo-about li { margin: 3px 0; }
.seo-about strong { color: var(--text); }

.modebar {
  position: absolute;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  background: rgba(20, 24, 28, .85);
  color: #fff;
  padding: 7px 14px;
  border-radius: 20px;
  font-size: 13px;
  display: none;
  pointer-events: none;
}
.modebar.show { display: block; }

.annot-input {
  position: absolute;
  display: none;
  z-index: 50;
  width: 200px;
  padding: 6px 9px;
  border: 2px solid #7c3aed;
  border-radius: 7px;
  font-size: 13px;
  background: #fff;
  box-shadow: 0 4px 14px rgba(0,0,0,.18);
  transform: translateY(-50%);
}
.annot-input:focus { outline: none; }

.drop-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(37, 99, 235, .12);
  backdrop-filter: blur(2px);
  pointer-events: none;
}
.drop-overlay.show { display: flex; }
.drop-box {
  border: 3px dashed var(--primary);
  border-radius: 16px;
  background: rgba(255, 255, 255, .95);
  padding: 40px 64px;
  text-align: center;
  color: var(--primary);
}
.drop-box p { margin: 4px; font-size: 18px; font-weight: 700; }
.drop-box .sub { font-size: 13px; font-weight: 500; color: var(--muted); }
.drop-icon { font-size: 48px; line-height: 1; margin-bottom: 8px; }

.toast {
  position: fixed;
  top: 64px;
  left: 50%;
  transform: translateX(-50%) translateY(-12px);
  z-index: 1100;
  background: rgba(20, 24, 28, .9);
  color: #fff;
  padding: 9px 16px;
  border-radius: 8px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s, transform .18s;
  max-width: 80vw;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 1200;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(244, 246, 248, .72);
  backdrop-filter: blur(2px);
}
.loading-overlay.show { display: flex; }
.loading-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 28px 40px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, .15);
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
}
.spinner {
  width: 34px;
  height: 34px;
  border: 4px solid #dbe2e8;
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== レスポンシブ ===== */

/* 狭い画面: パネルをドロワー化 */
@media (max-width: 760px) {
  .topbar { padding: 8px 12px; gap: 8px; }
  .topbar h1 { font-size: 15px; }
  .topbar .panel-toggle { display: inline-flex; }
  .panel-resizer { display: none; }
  .btn-label-full { display: none; }
  .btn-label-short { display: inline; }

  .panel {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 86%;
    max-width: 340px;
    z-index: 50;
    transform: translateX(-100%);
    transition: transform .22s ease;
    box-shadow: 4px 0 20px rgba(0, 0, 0, .15);
    padding-top: 16px;
  }
  body.panel-open .panel { transform: translateX(0); }
  body.panel-open .panel-backdrop { display: block; }

  .modebar { font-size: 12px; padding: 6px 10px; bottom: 12px; max-width: 92vw; text-align: center; }
  .annot-input { width: 180px; }
  .drop-box { padding: 28px 32px; }
  .drop-box p { font-size: 16px; }
}

/* 極小幅 */
@media (max-width: 420px) {
  .panel { width: 92%; }
  .topbar h1 { font-size: 14px; }
  .pager #pageInfo { min-width: 44px; font-size: 13px; }
}

/* タッチ端末: クリック判定を少し緩める見た目 */
@media (pointer: coarse) {
  .btn { padding: 9px 12px; }
}
