/* ポジショニングマップメーカー：エンタメパンダ ツールズと同じ白・墨・パンダ朱 */
:root {
  --ink: #1F1D1B;
  --sub: #66615C;
  --line: #E8E3DD;
  --surface: #F6F3EF;
  --blush: #FDF0EB;
  --shu: #E5452B;
  --shu-deep: #C93A22;
  --shu-text: #C93A22;
  --axis: #A39A90;
  --grid: #E3DCD3;
  --font: "Zen Kaku Gothic New", "Hiragino Sans", "Yu Gothic", "Noto Sans JP", system-ui, sans-serif;
  --shadow: 0 12px 32px rgba(31, 29, 27, .12);
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; overflow: hidden; }
body {
  display: flex; flex-direction: column; height: 100vh; height: 100dvh;
  background: #FFFFFF; color: var(--ink);
  font-family: var(--font); font-size: 15px; line-height: 1.6; letter-spacing: .02em;
  -webkit-font-smoothing: antialiased; -webkit-text-size-adjust: 100%;
}
/* 朱の細い線（エンタメパンダ本体のヘッダーと同じ） */
body::before { content: ""; display: block; flex-shrink: 0; height: 4px; background: var(--shu); }
a { color: inherit; text-decoration: none; }
img { display: block; max-width: 100%; }
h1, h2 { margin: 0; }
button, input, select { font: inherit; color: inherit; letter-spacing: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; }
:focus-visible { outline: 3px solid var(--ink); outline-offset: 3px; border-radius: 8px; }
[hidden] { display: none !important; }
svg { flex-shrink: 0; }

/* サイト共通ヘッダー */
.hd { flex-shrink: 0; display: flex; align-items: center; gap: 8px 32px; height: 60px; padding: 0 40px; border-bottom: 1px solid var(--line); }
.logo { display: flex; align-items: center; gap: 10px; min-height: 44px; margin-right: auto; min-width: 0; }
.logo img { width: 34px; height: 34px; object-fit: contain; }
.logo b { display: block; font-size: 19px; font-weight: 900; line-height: 1.1; letter-spacing: .04em; white-space: nowrap; }
.logo b span { color: var(--shu-text); }
.logo small { display: block; margin-top: 1px; font-size: 12px; font-weight: 700; letter-spacing: .06em; color: var(--sub); line-height: 1.4; }
.nav { display: flex; align-items: center; gap: 28px; font-size: 14px; font-weight: 700; white-space: nowrap; }
.nav a { display: flex; align-items: center; gap: 6px; min-height: 44px; transition: color .2s; }
.nav a:hover { color: var(--shu-text); }
.nav svg { width: 13px; height: 13px; }

/* ボタン */
.tbtn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 40px; padding: 0 14px; border: 1px solid var(--line); border-radius: 999px; background: #FFFFFF; font-size: 13px; font-weight: 700; white-space: nowrap; }
.tbtn svg { width: 16px; height: 16px; }
.tbtn:hover { border-color: var(--ink); }
.tbtn.primary { border-color: var(--ink); background: var(--ink); color: #FFFFFF; }
.tbtn[aria-pressed="true"], .tbtn[aria-expanded="true"] { border-color: var(--shu-deep); background: var(--blush); color: var(--shu-text); }
#savePng.primary { border-color: var(--shu-deep); background: var(--shu-deep); }
#savePng.primary:hover { border-color: var(--ink); background: var(--ink); }
.icon-btn { display: grid; place-items: center; width: 44px; height: 44px; padding: 0; border: 1px solid var(--line); border-radius: 50%; background: #FFFFFF; }
.icon-btn:hover { border-color: var(--ink); }
.icon-btn svg { width: 20px; height: 20px; }
.text-btn { min-height: 44px; padding: 0; border: 0; background: none; font-size: 13px; font-weight: 700; color: var(--sub); text-decoration: underline; }
.image-row .text-btn { min-width: 44px; padding: 0 8px; }
.text-btn:disabled { opacity: .45; text-decoration: none; }
.danger { color: var(--shu-text); }

/* ツールの操作列 */
.pm-bar { position: relative; z-index: 20; flex-shrink: 0; display: flex; align-items: center; gap: 16px; min-height: 56px; padding: 6px 40px; border-bottom: 1px solid var(--line); background: #FFFFFF; }
.pm-name { font-size: 15px; font-weight: 900; white-space: nowrap; }
.top-actions { position: relative; display: flex; align-items: center; gap: 8px; margin-left: auto; }
.top-actions .icon-btn { width: 40px; height: 40px; border-color: transparent; }
.top-actions .icon-btn:hover { border-color: var(--line); }
.more-menu { position: absolute; right: 0; top: calc(100% + 8px); min-width: 220px; padding: 6px; border: 1px solid var(--line); border-radius: 14px; background: #FFFFFF; box-shadow: var(--shadow); }
.more-menu button { display: block; width: 100%; min-height: 44px; padding: 0 12px; border: 0; border-radius: 10px; background: #FFFFFF; font-size: 14px; font-weight: 700; text-align: left; }
.more-menu button:hover { background: var(--surface); }

/* 作業面 */
.workspace { flex: 1; min-height: 0; padding: 12px 16px; background: #FFFFFF; }
.map-shell { position: relative; height: 100%; max-width: 1400px; margin: 0 auto; }
.map { position: relative; height: 100%; overflow: hidden; border: 1px solid var(--line); border-radius: 16px; background: var(--surface); touch-action: none; user-select: none; cursor: crosshair; }
/* グリッドは縦横10等分（PNGも同じ） */
.map.grid { background-image: linear-gradient(var(--grid) 1px, transparent 1px), linear-gradient(90deg, var(--grid) 1px, transparent 1px); background-size: 10% 10%; background-position: -1px -1px; }

.axis { position: absolute; background: var(--axis); pointer-events: none; }
.axis.horizontal { left: 14%; right: 14%; top: 50%; height: 2px; margin-top: -1px; }
.axis.vertical { top: 12%; bottom: 12%; left: 50%; width: 2px; margin-left: -1px; }
.axis::before, .axis::after { content: ""; position: absolute; width: 9px; height: 9px; border: solid var(--axis); border-width: 2px 2px 0 0; }
.axis.horizontal::before { left: -1px; top: -4.5px; transform: rotate(-135deg); }
.axis.horizontal::after { right: -1px; top: -4.5px; transform: rotate(45deg); }
.axis.vertical::before { top: -1px; left: -4.5px; transform: rotate(-45deg); }
.axis.vertical::after { bottom: -1px; left: -4.5px; transform: rotate(135deg); }

.axis-label { position: absolute; z-index: 4; width: 140px; min-height: 40px; padding: 6px 8px; border: 1px solid var(--line); border-radius: 10px; background: #FFFFFF; color: var(--ink); font-size: 14px; font-weight: 700; text-align: center; cursor: text; user-select: text; }
.axis-label:hover { border-color: var(--sub); }
.axis-label:focus-visible { outline: 3px solid var(--ink); outline-offset: 1px; }
.axis-label.top { top: 3%; left: 50%; transform: translateX(-50%); }
.axis-label.bottom { bottom: 3%; left: 50%; transform: translateX(-50%); }
.axis-label.left { top: 50%; left: 1.5%; width: 112px; transform: translateY(-50%); }
.axis-label.right { top: 50%; right: 1.5%; width: 112px; transform: translateY(-50%); }

.map-empty { position: absolute; left: 50%; top: 50%; z-index: 3; margin: 0; padding: 6px 14px; border-radius: 999px; background: #FFFFFF; color: var(--sub); font-size: 13px; font-weight: 700; transform: translate(-50%, calc(-50% - 36px)); white-space: nowrap; pointer-events: none; }

/* アイテム */
.item { position: absolute; z-index: 5; display: flex; flex-direction: column; align-items: center; gap: 4px; min-width: 44px; min-height: 44px; padding: 2px; border: 0; border-radius: 12px; background: transparent; color: var(--ink); transform: translate(-50%, -50%); cursor: grab; touch-action: none; }
.item:active { cursor: grabbing; }
.item.selected { z-index: 8; }
.item.dragging { z-index: 9; }
.avatar { display: grid; place-items: center; width: 64px; height: 64px; overflow: hidden; border: 3px solid var(--item-color, var(--sub)); border-radius: 50%; background: var(--item-tint, #FFFFFF); color: var(--item-color, var(--sub)); }
.avatar img { width: 100%; height: 100%; object-fit: cover; pointer-events: none; }
.avatar svg { width: 62%; height: 62%; margin-top: 12%; fill: currentColor; }
.item.selected .avatar { box-shadow: 0 0 0 3px #FFFFFF, 0 0 0 5px var(--ink); }
.item-name { max-width: 160px; overflow: hidden; padding: 2px 12px; border: 1.5px solid var(--item-color, var(--line)); border-radius: 999px; background: #FFFFFF; font-size: 13px; font-weight: 700; line-height: 1.5; text-overflow: ellipsis; white-space: nowrap; }
.item.text-mode .item-name { padding: 6px 14px; background: var(--item-tint, #FFFFFF); font-size: 14px; }
.item.text-mode.selected .item-name { box-shadow: 0 0 0 3px #FFFFFF, 0 0 0 5px var(--ink); }
.item:focus-visible { outline: 3px solid var(--ink); outline-offset: 2px; }

/* テンプレート */
.templates { position: absolute; z-index: 10; top: 12px; left: 12px; width: 280px; max-height: calc(100% - 24px); overflow: auto; border: 1px solid var(--line); border-radius: 16px; background: #FFFFFF; box-shadow: var(--shadow); }
.panel-heading, .inspector-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.panel-heading { padding: 6px 6px 6px 16px; border-bottom: 1px solid var(--line); }
.panel-heading h2, .inspector-head h2 { font-size: 15px; font-weight: 900; }
.panel-heading .icon-btn, .inspector-head .icon-btn { border-color: transparent; }
.panel-heading .icon-btn:hover, .inspector-head .icon-btn:hover { border-color: var(--line); }
.template-list { display: flex; flex-direction: column; gap: 4px; padding: 8px; }
.template-card { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 68px; padding: 8px 10px; border: 1px solid transparent; border-radius: 12px; background: #FFFFFF; text-align: left; }
.template-card:hover { background: var(--surface); }
.template-card > span:last-child { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.template-card strong { font-size: 14px; font-weight: 700; }
.template-card small { font-size: 12px; color: var(--sub); }
/* 十字の軸と点で描いた小さなマップ */
.template-icon { position: relative; display: block; flex: 0 0 64px; height: 48px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
.template-icon::before, .template-icon::after { content: ""; position: absolute; background: var(--axis); }
.template-icon::before { left: 8px; right: 8px; top: 50%; height: 1.5px; }
.template-icon::after { top: 6px; bottom: 6px; left: 50%; width: 1.5px; }
.template-icon i { position: absolute; z-index: 1; display: block; width: 12px; height: 12px; border: 2px solid var(--ink); border-radius: 50%; background: #FFFFFF; }
.template-icon i:nth-child(1) { top: 6px; left: 12px; border-color: var(--shu); background: var(--blush); }
.template-icon i:nth-child(2) { top: 12px; right: 9px; }
.template-icon i:nth-child(3) { bottom: 6px; left: 26px; }
.template-icon.labels i { width: 18px; height: 9px; border-radius: 999px; }
.template-icon.blank { display: grid; place-items: center; border: 1.5px dashed var(--sub); background: #FFFFFF; font-size: 22px; color: var(--sub); }
.template-icon.blank::before, .template-icon.blank::after { display: none; }

/* アイテムの設定（PCは右上のパネル、スマホは下からのシート） */
.inspector { position: absolute; z-index: 13; top: 12px; right: 12px; width: 280px; max-height: calc(100% - 24px); overflow: auto; padding: 6px 16px 12px; border: 1px solid var(--line); border-radius: 16px; background: #FFFFFF; box-shadow: var(--shadow); }
.inspector-head { margin: 0 -10px 4px 0; }
.field { display: block; margin: 10px 0; padding: 0; border: 0; font-size: 12px; font-weight: 700; color: var(--sub); }
.field legend, .field-label { display: block; padding: 0; }
.inspector input, .inspector select { display: block; width: 100%; min-height: 44px; margin-top: 4px; padding: 0 12px; border: 1px solid var(--line); border-radius: 10px; background: #FFFFFF; font-size: 15px; font-weight: 400; color: var(--ink); }
.inspector input:focus-visible, .inspector select:focus-visible { outline: 3px solid var(--ink); outline-offset: 1px; }
.image-row { display: flex; align-items: center; gap: 10px; margin-top: 4px; }
.avatar.preview { width: 44px; height: 44px; border-width: 2px; }
.image-row .tbtn { min-height: 44px; }
.note { display: block; margin-top: 4px; font-size: 12px; font-weight: 400; line-height: 1.5; color: var(--sub); }
.color-options { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.color-chip { width: 36px; height: 36px; padding: 0; border: 3px solid #FFFFFF; border-radius: 50%; box-shadow: 0 0 0 1px var(--line); }
.color-chip.active { box-shadow: 0 0 0 2px var(--ink); }
.field-pos { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.inspector-actions { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 12px; }
.inspector-actions .tbtn { min-height: 44px; padding: 0 18px; }

/* 下部バー */
.bottom-bar { flex-shrink: 0; display: flex; align-items: center; gap: 8px; padding: 6px 40px calc(6px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: #FFFFFF; }
.title-area { display: flex; align-items: center; gap: 12px; min-width: 0; margin-right: auto; }
.title-area button { display: inline-flex; align-items: center; gap: 6px; min-width: 0; min-height: 44px; padding: 0 12px; border: 0; border-radius: 10px; background: transparent; }
.title-area button:hover { background: var(--surface); }
.title-area strong { overflow: hidden; font-size: 15px; font-weight: 700; text-overflow: ellipsis; white-space: nowrap; }
.title-area svg { width: 16px; height: 16px; color: var(--sub); }
.save-state { font-size: 12px; color: var(--sub); white-space: nowrap; }
.save-state.error { color: var(--shu-text); font-weight: 700; }
.history-actions { display: flex; gap: 4px; }
.history-actions .icon-btn { border-color: transparent; }
.history-actions .icon-btn:hover { border-color: var(--line); }
.history-actions .icon-btn:disabled { opacity: .35; border-color: transparent; }
.view-actions { display: flex; align-items: center; gap: 8px; margin-left: 8px; }
.segmented { display: flex; padding: 2px; border: 1px solid var(--line); border-radius: 999px; }
.segmented button, .grid-btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-width: 40px; height: 40px; padding: 0 12px; border: 0; border-radius: 999px; background: transparent; font-size: 13px; font-weight: 700; white-space: nowrap; }
.segmented button:hover, .grid-btn:hover { background: var(--surface); }
.segmented button[aria-pressed="true"] { background: var(--ink); color: #FFFFFF; }
.grid-btn { border: 1px solid var(--line); height: 44px; }
.grid-btn[aria-pressed="true"] { border-color: var(--shu-deep); background: var(--blush); color: var(--shu-text); }
.segmented svg, .grid-btn svg { width: 18px; height: 18px; }

/* トースト・ダイアログ */
.toast { position: fixed; z-index: 50; left: 50%; bottom: calc(72px + env(safe-area-inset-bottom)); max-width: calc(100% - 32px); padding: 6px 14px; border-radius: 999px; background: var(--ink); color: #FFFFFF; font-size: 13px; font-weight: 700; transform: translateX(-50%); pointer-events: none; }
.app-dialog { width: min(400px, calc(100% - 32px)); padding: 0; border: 1px solid var(--line); border-radius: 16px; background: #FFFFFF; color: var(--ink); box-shadow: 0 20px 48px rgba(31, 29, 27, .16); }
.app-dialog::backdrop { background: rgba(31, 29, 27, .2); }
.app-dialog form { padding: 20px; }
.app-dialog p { margin: 0 0 16px; font-size: 15px; font-weight: 700; line-height: 1.7; white-space: pre-line; }
.app-dialog input { display: block; width: 100%; min-height: 44px; margin: -4px 0 16px; padding: 0 12px; border: 1px solid var(--line); border-radius: 10px; font-size: 16px; }
.app-dialog input:focus-visible { border-color: var(--ink); outline: 3px solid var(--ink); outline-offset: 1px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }
.dialog-actions .tbtn { min-height: 44px; padding: 0 18px; }
.help-dialog { width: min(480px, calc(100% - 32px)); max-height: calc(100% - 32px); }
.help-dialog h2 { margin-bottom: 8px; font-size: 17px; font-weight: 900; }
.help-steps { margin: 0 0 16px; padding-left: 1.4em; font-size: 14px; line-height: 1.7; }
.help-steps li { margin: 10px 0; }
.help-steps strong { display: block; font-weight: 700; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; }
}

@media (max-width: 1020px) {
  .hd, .pm-bar, .bottom-bar { padding-left: 28px; padding-right: 28px; }
  .view-actions .lbl { display: none; }
  .segmented button { width: 40px; padding: 0; }
  .grid-btn { width: 44px; padding: 0; border-radius: 50%; }
}

@media (max-width: 760px) {
  .pm-bar { gap: 8px; min-height: 56px; padding: 6px 12px; }
  .pm-name { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .top-actions { flex: 1; justify-content: space-between; gap: 4px; margin: 0; }
  .top-actions .tbtn { width: 44px; min-height: 44px; padding: 0; }
  .top-actions .tbtn svg { width: 20px; height: 20px; }
  .top-actions .lbl { display: none; }
  .top-actions .icon-btn { width: 44px; height: 44px; }
  .workspace { padding: 8px; }
  .map { border-radius: 12px; }
  .axis-label { width: 108px; min-height: 44px; padding: 4px 6px; font-size: 13px; }
  .axis-label.top { top: 2%; }
  .axis-label.bottom { bottom: 2%; }
  .axis-label.left, .axis-label.right { width: 84px; }
  .axis-label.left { left: 2px; }
  .axis-label.right { right: 2px; }
  .axis.horizontal { left: 25%; right: 25%; }
  .axis.vertical { top: 9%; bottom: 9%; }
  .avatar { width: 48px; height: 48px; }
  .item-name { max-width: 110px; padding: 1px 8px; font-size: 12px; }
  .item.text-mode .item-name { padding: 8px 12px; font-size: 13px; }
  .map-empty { font-size: 12px; white-space: normal; width: 80%; text-align: center; }
  .templates { top: 8px; left: 8px; width: min(280px, calc(100% - 16px)); }
  .inspector { top: auto; right: 8px; bottom: 8px; left: 8px; width: auto; max-height: 72%; display: grid; grid-template-columns: 1fr 1fr; column-gap: 12px; }
  .inspector[hidden] { display: none !important; }
  .inspector-head, .field-image, .field-color, .field-pos, .inspector-actions { grid-column: 1 / -1; }
  .field { margin: 6px 0; }
  .bottom-bar { gap: 2px; padding: 4px 8px calc(4px + env(safe-area-inset-bottom)); }
  .title-area { gap: 0; }
  .title-area button { padding: 0 8px; }
  .title-area strong { font-size: 14px; }
  .save-state { display: none; }
  .history-actions { gap: 0; }
  .view-actions { gap: 2px; margin-left: 2px; }
  .segmented { padding: 0; }
  .segmented button { width: 44px; height: 44px; }
  .toast { bottom: calc(64px + env(safe-area-inset-bottom)); }
}

@media (max-width: 640px) {
  body { font-size: 14px; }
  .hd { padding: 0 16px; gap: 16px; }
  .logo b { font-size: 16px; }
  .logo img { width: 30px; height: 30px; }
  .logo small { display: none; }
  .nav { gap: 16px; font-size: 13px; }
  .nav .hide-sp, .nav .ext { display: none; }
}
