/* paintmap.css — めっちゃマップ UI スタイル
 * NFR-004/005: WCAG 2.2 AA コントラスト、フォーカス可視
 * NFR-003: 360px モバイル対応
 */

/* ── カスタムプロパティ ──────────────────────────────────────────────── */
:root {
  --paint-brand: #2563eb;
  --paint-brand-dark: #1d4ed8;
  --paint-accent: #f97316;
  --paint-success: #16a34a;
  --paint-danger: #dc2626;
  --paint-warn: #d97706;
  --paint-bg: #f8fafc;
  --paint-surface: #ffffff;
  --paint-border: #e2e8f0;
  --paint-text: #0f172a;
  --paint-text-muted: #475569;
  --paint-radius: 8px;
  --toolbar-h: 52px;
  --side-w: 300px;
  --bottom-bar-h: 56px;
  --sheet-peak: 120px;
  --transition-fast: 150ms ease;
  --transition-normal: 250ms ease;
}

/* ── リセット ──────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { height: 100%; }
body { min-height: 100%; font-family: system-ui, sans-serif; }

body.edit-page,
body.shared-page {
  height: 100%;
  overflow: hidden;
  background: var(--paint-bg);
  color: var(--paint-text);
  display: flex;
  flex-direction: column;
}

/* ── フォーカス ──────────────────────────────────────────────────── */
:focus-visible {
  outline: 3px solid var(--paint-brand);
  outline-offset: 2px;
  border-radius: 3px;
}

/* ── ツールバー ──────────────────────────────────────────────────── */
.toolbar {
  height: var(--toolbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  background: var(--paint-surface);
  border-bottom: 1px solid var(--paint-border);
  box-shadow: 0 1px 4px rgba(0,0,0,.08);
  z-index: 100;
  flex-shrink: 0;
}
.toolbar-shared { background: #f0f9ff; border-bottom-color: #bae6fd; }

.toolbar-brand {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--paint-brand);
  white-space: nowrap;
}
.brand-icon { font-size: 1.3rem; }

.toolbar-tools {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

/* ── ボタン ──────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 6px 14px;
  border: 1px solid transparent;
  border-radius: var(--paint-radius);
  font-size: .875rem;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--transition-fast), box-shadow var(--transition-fast);
  text-decoration: none;
  white-space: nowrap;
  min-height: 36px;
  min-width: 36px;
}
.btn:disabled, .btn.disabled {
  opacity: .45;
  cursor: not-allowed;
  pointer-events: none;
}
.btn-primary {
  background: var(--paint-brand);
  color: #fff;
  border-color: var(--paint-brand-dark);
}
.btn-primary:hover:not(:disabled) { background: var(--paint-brand-dark); }
.btn-secondary {
  background: var(--paint-surface);
  color: var(--paint-text);
  border-color: var(--paint-border);
}
.btn-secondary:hover:not(:disabled) { background: #f1f5f9; }
.btn-danger { background: var(--paint-danger); color: #fff; border-color: #b91c1c; }
.btn-ghost { background: transparent; color: var(--paint-text-muted); border-color: transparent; }
.btn-ghost:hover { background: #f1f5f9; }
.btn-icon { padding: 6px 10px; font-size: 1rem; }
.btn-sm { padding: 4px 10px; font-size: .8rem; min-height: 30px; }
.btn-xs { padding: 2px 8px; font-size: .75rem; min-height: 26px; }
.btn-wide { width: 100%; }
.btn-mode {
  background: var(--paint-surface);
  color: var(--paint-text);
  border-color: var(--paint-border);
}
.btn-mode.active {
  background: #eff6ff;
  color: var(--paint-brand);
  border-color: var(--paint-brand);
  font-weight: 600;
}
.btn-label { font-size: .8rem; }

/* ── レイアウト ──────────────────────────────────────────────────── */
.app-layout {
  display: flex;
  flex: 1;
  overflow: hidden;
  min-height: 0;
}

.side-panel {
  width: var(--side-w);
  flex-shrink: 0;
  background: var(--paint-surface);
  border-right: 1px solid var(--paint-border);
  overflow-y: auto;
  padding-bottom: 16px;
}

.palette-mode-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--paint-border);
}
.palette-mode-label {
  color: var(--paint-text-muted);
  font-size: .78rem;
  font-weight: 600;
  white-space: nowrap;
}
.palette-mode-toolbar .mode-toggle {
  display: flex;
  gap: 4px;
}
.palette-mode-toolbar .btn-mode {
  padding-inline: 10px;
}

.map-container {
  flex: 1;
  position: relative;
  overflow: hidden;
}
#map {
  width: 100%;
  height: 100%;
}

/* ── パネル見出し ──────────────────────────────────────────────── */
.panel-heading {
  font-size: .9rem;
  font-weight: 600;
  color: var(--paint-text);
  padding: 12px 14px 6px;
  border-bottom: 1px solid var(--paint-border);
  margin-bottom: 8px;
}

/* ── パレット ────────────────────────────────────────────────────── */
.palette-section { padding: 0 0 8px; }

.palette-swatches {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px 14px;
}
.palette-empty { padding: 8px 14px; color: var(--paint-text-muted); font-size: .85rem; }

.swatch-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  position: relative;
}
.swatch {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 2px solid var(--paint-border);
  cursor: pointer;
  position: relative;
  transition: transform var(--transition-fast), box-shadow var(--transition-fast);
  display: flex;
  align-items: center;
  justify-content: center;
}
.swatch:hover { transform: scale(1.1); box-shadow: 0 2px 8px rgba(0,0,0,.2); }
.swatch.selected {
  border: 3px solid var(--paint-text);
  box-shadow: 0 0 0 2px var(--paint-brand);
}
.swatch-check { color: #fff; font-size: .75rem; text-shadow: 0 1px 2px rgba(0,0,0,.8); }
.swatch-label { font-size: .65rem; color: var(--paint-text-muted); max-width: 40px; overflow: hidden; text-overflow: ellipsis; }
.swatch-remove {
  position: absolute;
  top: -4px;
  right: -6px;
  background: var(--paint-surface);
  border: 1px solid var(--paint-border);
  border-radius: 50%;
  width: 16px;
  height: 16px;
  font-size: .65rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity var(--transition-fast);
}
.swatch-wrapper:hover .swatch-remove { opacity: 1; }

.palette-add-form { padding: 8px 14px; }
.palette-add-row {
  display: flex;
  align-items: center;
  gap: 6px;
}
.palette-add-row input[type="color"] {
  width: 40px;
  height: 34px;
  padding: 2px;
  border: 1px solid var(--paint-border);
  border-radius: var(--paint-radius);
  cursor: pointer;
}
.palette-add-row input[type="text"] {
  flex: 1;
  padding: 6px 10px;
  border: 1px solid var(--paint-border);
  border-radius: var(--paint-radius);
  font-size: .85rem;
  font-family: monospace;
  min-width: 0;
}
.palette-add-row input[type="text"]:focus { border-color: var(--paint-brand); }

.preset-colors {
  padding: 4px 14px 8px;
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
}
.preset-label { font-size: .75rem; color: var(--paint-text-muted); }
.preset-swatch {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 1px solid rgba(0,0,0,.15);
  cursor: pointer;
  transition: transform var(--transition-fast);
}
.preset-swatch:hover { transform: scale(1.2); }

/* ── 画像カラーピッカー ───────────────────────────────────────────── */
.image-color-picker { padding-bottom: 10px; }
.image-drop-zone {
  margin: 8px 14px;
  min-height: 132px;
  border: 2px dashed var(--paint-border);
  border-radius: var(--paint-radius);
  background: #f8fafc;
  overflow: hidden;
  transition: border-color var(--transition-fast), background var(--transition-fast);
}
.map-debug-panel {
  position: absolute; top: 12px; right: 12px; z-index: 900;
  width: min(430px, calc(100% - 24px)); max-height: calc(100% - 24px);
  overflow: auto; padding: 10px; border: 2px solid #7c3aed; border-radius: 10px;
  background: rgba(255,255,255,.97); box-shadow: 0 6px 24px rgba(15,23,42,.24);
  color: #172033; font: 12px/1.4 ui-monospace, Consolas, monospace;
}
.map-debug-head, .map-debug-actions { display: flex; gap: 6px; align-items: center; justify-content: space-between; }
.map-debug-grid { display: grid; grid-template-columns: 1fr 1fr .7fr; gap: 6px; margin: 8px 0; }
.map-debug-grid label { display: grid; gap: 2px; }
.map-debug-grid input { width: 100%; min-width: 0; padding: 4px; }
.map-debug-actions { justify-content: flex-start; flex-wrap: wrap; }
.map-debug-point { margin: 8px 0; overflow-wrap: anywhere; }
.map-debug-results { display: grid; gap: 7px; }
.map-debug-selection, .map-debug-feature { padding: 7px; border: 1px solid #cbd5e1; border-radius: 6px; background: #fff; }
.map-debug-feature h3 { margin: 0 0 4px; font-size: 12px; }
.map-debug-key, .map-debug-json { overflow-wrap: anywhere; white-space: pre-wrap; }
.map-debug-json { max-height: 220px; overflow: auto; margin: 4px 0 0; padding: 5px; background: #f1f5f9; }
.map-debug-inspecting { cursor: crosshair !important; }

/* Paint brush cursor and ink feedback */
#map.paint-mode-active .maplibregl-canvas,
#map.paint-mode-active .maplibregl-canvas-container {
  cursor: none !important;
}

.paint-effects {
  position: absolute;
  inset: 0;
  z-index: 4;
  overflow: hidden;
  pointer-events: none;
  contain: strict;
}

.paint-brush-cursor {
  --brush-color: #2563eb;
  position: absolute;
  top: 0;
  left: 0;
  width: 44px;
  height: 44px;
  opacity: 0;
  transform: translate3d(-100px, -100px, 0);
  transform-origin: 7px 37px;
  will-change: transform, opacity;
}

.paint-brush-cursor.is-visible { opacity: 1; }
.paint-brush-cursor.is-unpaintable { opacity: .42; }
.paint-brush-cursor.is-pressing svg { animation: paint-brush-press 360ms ease-out; }
.paint-brush-cursor.is-missing svg { animation: paint-brush-miss 220ms ease-out; }
.paint-brush-cursor svg { width: 100%; height: 100%; overflow: visible; }
.paint-brush-handle { fill: #9a6238; stroke: #5f3823; stroke-width: 1.5; }
.paint-brush-ferrule { fill: #d7dee7; stroke: #718096; stroke-width: 1.2; }
.paint-brush-bristles { fill: var(--brush-color); stroke: #334155; stroke-width: 1.2; }
.paint-brush-shine { fill: none; stroke: rgba(255,255,255,.55); stroke-width: 2; stroke-linecap: round; }

.paint-ink-drop {
  position: absolute;
  width: var(--drop-size);
  height: var(--drop-size);
  margin: calc(var(--drop-size) / -2);
  border-radius: 48% 52% 44% 56%;
  background: var(--ink-color);
  opacity: .9;
  transform: translate3d(0, 0, 0) scale(.45);
  animation: paint-ink-fly var(--drop-duration) cubic-bezier(.15,.7,.25,1) forwards;
}

.paint-ink-splash {
  position: absolute;
  width: 18px;
  height: 13px;
  margin: -7px -9px;
  border-radius: 46% 54% 40% 60%;
  background: var(--ink-color);
  opacity: .78;
  animation: paint-ink-splash 420ms ease-out forwards;
}

@keyframes paint-brush-press {
  0% { transform: translate(0, 0) rotate(0) scale(1); }
  28% { transform: translate(-2px, 4px) rotate(-8deg) scale(.95); }
  48% { transform: translate(-2px, 4px) rotate(-8deg) scale(.98,.90); }
  75% { transform: translate(1px, -4px) rotate(3deg) scale(1.02); }
  100% { transform: none; }
}
@keyframes paint-brush-miss {
  0%, 100% { transform: translateX(0); }
  30% { transform: translateX(-4px) rotate(-5deg); }
  65% { transform: translateX(4px) rotate(5deg); }
}
@keyframes paint-ink-fly {
  65% { opacity: .82; }
  100% { opacity: 0; transform: translate3d(var(--drop-x), var(--drop-y), 0) scale(1); }
}
@keyframes paint-ink-splash {
  0% { transform: scale(.35) rotate(-8deg); }
  55% { opacity: .72; transform: scale(1.25) rotate(5deg); }
  100% { opacity: 0; transform: scale(1.65) rotate(9deg); }
}

@media (pointer: coarse) {
  .paint-brush-cursor { width: 48px; height: 48px; }
}

@media (forced-colors: active) {
  #map.paint-mode-active .maplibregl-canvas,
  #map.paint-mode-active .maplibregl-canvas-container { cursor: crosshair !important; }
  .paint-brush-cursor, .paint-ink-drop, .paint-ink-splash { display: none !important; }
}
.image-drop-zone.drag-over {
  border-color: var(--paint-brand);
  background: #eff6ff;
}
.image-upload-prompt {
  min-height: 132px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  color: var(--paint-text-muted);
  font-size: .82rem;
  cursor: pointer;
  text-align: center;
  padding: 14px;
}
.image-upload-icon {
  font-size: 1.4rem;
  line-height: 1;
  color: var(--paint-brand);
}
.image-upload-or { font-size: .72rem; }
.image-color-viewport {
  width: 100%;
  max-height: 360px;
  overflow: auto;
  background: repeating-conic-gradient(#e2e8f0 0 25%, #fff 0 50%) 0 / 16px 16px;
  overscroll-behavior: contain;
}
.image-color-canvas {
  display: block;
  width: 100%;
  max-width: none;
  height: auto;
  cursor: crosshair;
}
.image-color-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 0 14px;
}
.image-zoom-controls {
  display: flex;
  align-items: center;
  gap: 5px;
  width: 100%;
}
.image-zoom-controls input[type="range"] {
  flex: 1;
  min-width: 70px;
  accent-color: var(--paint-brand);
}
.image-zoom-button {
  width: 34px;
  padding-left: 0;
  padding-right: 0;
  font-size: 1rem;
}
#image-zoom-value {
  min-width: 3.2rem;
  color: var(--paint-text-muted);
  font-family: monospace;
  font-size: .75rem;
  text-align: right;
}
.image-color-help {
  flex: 1;
  color: var(--paint-text-muted);
  font-size: .75rem;
}
.image-color-result {
  min-height: 1.2em;
  padding: 6px 14px 0;
  color: var(--paint-text-muted);
  font-family: monospace;
  font-size: .75rem;
}
.image-color-result.error { color: var(--paint-danger); }
.image-theme-colors {
  margin: 10px 14px 0;
  padding: 10px;
  border: 1px solid var(--paint-border);
  border-radius: var(--paint-radius);
  background: #f8fafc;
}
.image-theme-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}
.image-theme-heading h3 { margin: 0; font-size: .85rem; }
.image-theme-swatches { display: grid; grid-template-columns: repeat(4, 1fr); gap: 7px; }
.image-theme-swatch {
  min-width: 0;
  padding: 4px;
  border: 1px solid var(--paint-border);
  border-radius: 6px;
  background: #fff;
  color: var(--paint-text-muted);
  cursor: pointer;
  font: .68rem/1.2 monospace;
}
.image-theme-swatch:hover { border-color: var(--paint-brand); }
.image-theme-swatch:focus-visible { outline: 2px solid var(--paint-brand); outline-offset: 2px; }
.image-theme-sample {
  display: block;
  height: 32px;
  margin-bottom: 4px;
  border: 1px solid rgba(0,0,0,.12);
  border-radius: 4px;
}
.image-theme-help { margin: 7px 0 0; color: var(--paint-text-muted); font-size: .72rem; }
.visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

/* ── カテゴリ一覧 ────────────────────────────────────────────────── */
.category-section { padding: 0 0 8px; }
.painted-badge {
  font-size: .75rem;
  font-weight: 400;
  background: #eff6ff;
  color: var(--paint-brand);
  padding: 2px 6px;
  border-radius: 12px;
  margin-left: 6px;
}

.generate-cta { padding: 8px 14px; }
.generate-cta.prominent .btn { background: #f97316; border-color: #ea580c; }
.algorithm-label { display: block; margin-bottom: 4px; font-weight: 600; }
.algorithm-select { width: 100%; margin-bottom: 4px; padding: 7px 8px; }
.algorithm-badge {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 999px;
  background: #e0e7ff;
  color: #3730a3;
  font-size: 0.78rem;
}
.hint { font-size: .75rem; color: var(--paint-text-muted); margin-top: 4px; }

.category-list { list-style: none; padding: 0 8px; }
.category-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 6px;
  border-radius: var(--paint-radius);
  transition: background var(--transition-fast);
}
.category-item:hover { background: #f8fafc; }
.category-item.assigned { background: #f0fdf4; }

.cat-info {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1;
  min-width: 0;
}
.cat-swatch {
  width: 16px;
  height: 16px;
  border-radius: 3px;
  flex-shrink: 0;
  border: 1px solid rgba(0,0,0,.1);
}
.cat-unassigned { background: repeating-linear-gradient(45deg, #e2e8f0, #e2e8f0 3px, #f8fafc 3px, #f8fafc 6px); }
.cat-label { font-size: .82rem; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cat-source { font-size: .65rem; padding: 1px 4px; border-radius: 8px; flex-shrink: 0; }
.badge-direct { background: #dbeafe; color: #1d4ed8; }
.badge-auto { background: #f0fdf4; color: #15803d; }
.cat-color-val { font-size: .7rem; color: var(--paint-text-muted); font-family: monospace; }
.cat-unassigned-badge { font-size: .7rem; color: var(--paint-text-muted); }
.btn-paint-cat { flex-shrink: 0; }

/* ── プレビューパネル ─────────────────────────────────────────────── */
.preview-section {
  position: fixed;
  top: calc(var(--toolbar-h) + 16px);
  right: 16px;
  z-index: 600;
  width: min(520px, calc(100vw - var(--side-w) - 48px));
  max-height: calc(100vh - var(--toolbar-h) - 32px);
  overflow-y: auto;
  padding: 0 0 12px;
  background: var(--paint-surface);
  border: 1px solid var(--paint-border);
  border-radius: 12px;
  box-shadow: 0 16px 40px rgba(15, 23, 42, .24);
  animation: preview-window-enter var(--transition-normal);
}
.preview-window-header {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--paint-surface);
  border-bottom: 1px solid var(--paint-border);
  box-shadow: 0 2px 6px rgba(15, 23, 42, .08);
}
.preview-section .panel-heading {
  padding: 14px 16px 10px;
  background: var(--paint-surface);
  border-bottom: 0;
  margin-bottom: 0;
}
@keyframes preview-window-enter {
  from { opacity: 0; transform: translateX(20px); }
  to { opacity: 1; transform: translateX(0); }
}
.preview-table { width: 100%; border-collapse: collapse; font-size: .82rem; }
.preview-table th, .preview-table td {
  padding: 5px 10px;
  text-align: left;
  border-bottom: 1px solid var(--paint-border);
}
.preview-table th { background: #f8fafc; font-weight: 600; font-size: .78rem; }
.direct-row { background: #eff6ff; }
.mini-swatch {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 3px;
  border: 1px solid rgba(0,0,0,.1);
  vertical-align: middle;
  margin-right: 4px;
}
.source-badge { font-size: .7rem; padding: 1px 5px; border-radius: 8px; }
.source-direct { background: #dbeafe; color: #1d4ed8; }
.source-auto { background: #f0fdf4; color: #15803d; }

.preview-actions { display: flex; gap: 8px; padding: 0 14px 12px; }
.preview-actions .btn { flex: 1; }
.preview-empty { padding: 8px 14px; color: var(--paint-text-muted); font-size: .85rem; }

/* ── コントラスト警告 ─────────────────────────────────────────────── */
.contrast-warnings {
  background: #fffbeb;
  border: 1px solid #fcd34d;
  border-radius: var(--paint-radius);
  padding: 10px 14px;
  margin: 8px 14px;
}
.warning-heading { font-size: .85rem; font-weight: 600; color: #92400e; margin-bottom: 4px; }
.warning-desc { font-size: .78rem; color: #78350f; margin-bottom: 6px; }
.contrast-warnings ul { padding-left: 16px; font-size: .8rem; }
.contrast-warnings li { margin-bottom: 4px; }
.correction-hint { font-size: .75rem; color: var(--paint-text-muted); }
.inline-swatch {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 2px;
  border: 1px solid rgba(0,0,0,.2);
  vertical-align: middle;
}

/* ── ステータス ──────────────────────────────────────────────────── */
.status-banner {
  position: fixed;
  top: calc(var(--toolbar-h) + 4px);
  left: 50%;
  transform: translateX(-50%);
  padding: 8px 18px;
  border-radius: 20px;
  font-size: .85rem;
  font-weight: 500;
  z-index: 2000;
  pointer-events: none;
  transition: opacity var(--transition-normal);
}
.status-banner:empty { display: none; }
.status-banner.success { background: #16a34a; color: #fff; }
.status-banner.error { background: var(--paint-danger); color: #fff; }
.status-banner.info { background: var(--paint-brand); color: #fff; }

.status-inline { padding: 8px 14px; font-size: .85rem; border-radius: var(--paint-radius); margin: 6px 14px; }
.status-inline.success { background: #f0fdf4; color: #166534; border: 1px solid #bbf7d0; }
.status-inline.error { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }

.error-list { padding: 8px 14px; }
.error-msg { font-size: .82rem; color: var(--paint-danger); background: #fef2f2; padding: 5px 10px; border-radius: 5px; margin-bottom: 4px; }

/* ── ヒットポップオーバー ────────────────────────────────────────── */
.hit-popup {
  position: absolute;
  top: 60px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--paint-surface);
  border: 1px solid var(--paint-border);
  border-radius: var(--paint-radius);
  padding: 12px 16px;
  box-shadow: 0 8px 24px rgba(0,0,0,.15);
  z-index: 500;
  max-width: 280px;
  width: 90%;
}
.hit-popup.hidden { display: none; }
.hit-label { font-size: .9rem; font-weight: 600; margin-bottom: 6px; }
.hit-result, .hit-ambiguous, .hit-outside { display: flex; flex-direction: column; gap: 8px; }
.candidate-btn { text-align: left; }

.paint-toast {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,.75);
  color: #fff;
  padding: 8px 16px;
  border-radius: 20px;
  font-size: .82rem;
  z-index: 400;
  white-space: nowrap;
}
.paint-toast.hidden { display: none; }

/* ── WebGL エラー ─────────────────────────────────────────────────── */
.no-webgl-msg {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--paint-bg);
  text-align: center;
  padding: 24px;
}
.no-webgl-msg.hidden { display: none; }

/* ── 共有パネル ──────────────────────────────────────────────────── */
.share-panel { padding: 12px 14px; }
.share-desc { font-size: .85rem; color: var(--paint-text-muted); margin-bottom: 8px; }
.share-url-row { display: flex; gap: 6px; margin-bottom: 8px; }
.share-url-input {
  flex: 1;
  padding: 6px 10px;
  border: 1px solid var(--paint-border);
  border-radius: var(--paint-radius);
  font-size: .8rem;
  font-family: monospace;
  min-width: 0;
  background: #f8fafc;
}
.share-link { font-size: .82rem; color: var(--paint-brand); text-decoration: underline; }
.field-label { display: block; margin: 14px 0 6px; font-weight: 600; font-size: .88rem; }
.text-input {
  width: 100%; padding: 9px 10px; border: 1px solid var(--paint-border);
  border-radius: var(--paint-radius); font: inherit; resize: vertical;
}
.design-info {
  position: absolute; top: 76px; left: 16px; z-index: 450;
  width: min(360px, calc(100% - 32px)); padding: 16px;
  border-radius: var(--paint-radius); background: rgba(255,255,255,.95);
  box-shadow: 0 4px 18px rgba(0,0,0,.16);
}
.design-info h1 { margin: 0 0 6px; font-size: 1.25rem; }
.design-info p {
  margin: 0 0 12px; color: var(--paint-text-muted); white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.btn-like { color: #be123c; border: 1px solid #fecdd3; background: #fff1f2; }
.btn-like.liked { color: #fff; background: #e11d48; border-color: #e11d48; }

/* ── ダイアログ ──────────────────────────────────────────────────── */
dialog {
  border: 1px solid var(--paint-border);
  border-radius: var(--paint-radius);
  padding: 24px;
  max-width: 400px;
  width: 90vw;
  box-shadow: 0 8px 32px rgba(0,0,0,.2);
}
dialog::backdrop { background: rgba(0,0,0,.5); }
dialog h2 { font-size: 1.1rem; margin-bottom: 10px; }
dialog p { font-size: .9rem; color: var(--paint-text-muted); margin-bottom: 16px; }
.dialog-actions { display: flex; gap: 8px; justify-content: flex-end; }

.confirm-dialog { padding: 12px 14px; }
.confirm-actions { display: flex; gap: 8px; margin-top: 10px; }

/* ── モバイル ─────────────────────────────────────────────────────── */
.bottom-bar {
  display: none;
  height: var(--bottom-bar-h);
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  background: var(--paint-surface);
  border-top: 1px solid var(--paint-border);
  box-shadow: 0 -1px 4px rgba(0,0,0,.08);
  z-index: 100;
  flex-shrink: 0;
}

.bottom-sheet {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(60vh + var(--sheet-peak));
  transform: translateY(calc(100% - var(--sheet-peak)));
  background: var(--paint-surface);
  border-radius: 16px 16px 0 0;
  box-shadow: 0 -4px 20px rgba(0,0,0,.15);
  transition: transform var(--transition-normal);
  z-index: 200;
  overflow: hidden;
}
.bottom-sheet.open { transform: translateY(0); }
.sheet-handle {
  display: flex;
  justify-content: center;
  padding: 10px;
  cursor: pointer;
  user-select: none;
}
.handle-bar {
  width: 36px;
  height: 4px;
  background: var(--paint-border);
  border-radius: 2px;
}
.sheet-content { overflow-y: auto; height: calc(100% - 40px); }

/* ── エラーページ ─────────────────────────────────────────────────── */
.error-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
}
.error-content { text-align: center; max-width: 480px; }
.error-title { font-size: 1.5rem; font-weight: 700; margin-bottom: 12px; }
.error-desc { color: var(--paint-text-muted); margin-bottom: 24px; }

/* ── NOTICE ─────────────────────────────────────────────────────── */
.global-notice-link {
  position: fixed; bottom: 7px; left: 9px; z-index: 500;
  padding: 3px 7px; border-radius: 5px; background: rgba(255,255,255,.9);
  box-shadow: 0 1px 4px rgba(15,23,42,.12); font-size: .7rem;
}
.global-notice-link a { color: #334155; }
body.notice-page { min-height: 100vh; overflow: auto; background: #f6f7fb; }
.notice-main { width: min(880px, calc(100% - 32px)); margin: 0 auto; padding: 48px 0; }
.notice-card {
  padding: clamp(22px, 5vw, 44px); border: 1px solid var(--paint-border);
  border-radius: 16px; background: #fff; box-shadow: 0 8px 28px rgba(15,23,42,.07);
}
.notice-heading { display: flex; align-items: start; justify-content: space-between; gap: 20px; }
.notice-heading h1 { margin: 2px 0 0; font-size: clamp(1.5rem, 4vw, 2rem); }
.notice-eyebrow { margin: 0; color: var(--paint-brand); font-size: .72rem; font-weight: 800; letter-spacing: .12em; }
.notice-help { margin: 18px 0; color: var(--paint-text-muted); }
.notice-content {
  overflow-x: auto; margin: 0; padding: 20px; border: 1px solid var(--paint-border);
  border-radius: 10px; background: #f8fafc; color: var(--paint-text);
  font: .9rem/1.75 ui-monospace, SFMono-Regular, Consolas, monospace;
  white-space: pre-wrap; overflow-wrap: anywhere;
}

/* ── 共有ページ ──────────────────────────────────────────────────── */
.shared-layout { flex: 1; overflow: hidden; }

/* ── 公開デザイン一覧 ─────────────────────────────────────────────── */
body.gallery-page { min-height: 100vh; background: #f6f7fb; }
.gallery-brand { color: inherit; text-decoration: none; }
.gallery-main { width: min(1180px, calc(100% - 32px)); margin: 0 auto; padding: 32px 0 56px; }
.gallery-heading h1 { margin: 0; font-size: clamp(1.65rem, 4vw, 2.35rem); }
.gallery-heading p { margin: 6px 0 22px; color: var(--paint-text-muted); }
.gallery-controls { padding: 18px; border: 1px solid var(--paint-border); border-radius: 14px; background: #fff; box-shadow: 0 6px 22px rgba(15,23,42,.05); }
.gallery-search-row { display: flex; gap: 10px; }
.gallery-search-row .text-input { flex: 1; }
.theme-filter { margin: 16px 0; padding: 0; border: 0; }
.theme-filter legend { margin-bottom: 8px; font-size: .82rem; font-weight: 700; }
.filter-chip { display: inline-block; margin: 0 5px 7px 0; cursor: pointer; }
.filter-chip input { position: absolute; opacity: 0; }
.filter-chip span { display: block; padding: 6px 11px; border: 1px solid var(--paint-border); border-radius: 999px; background: #fff; font-size: .8rem; }
.filter-chip input:checked + span { border-color: var(--paint-brand); background: #eef6ff; color: var(--paint-brand); font-weight: 700; }
.filter-chip input:focus-visible + span { outline: 2px solid var(--paint-brand); outline-offset: 2px; }
.gallery-selects { display: flex; align-items: end; flex-wrap: wrap; gap: 10px; }
.gallery-selects label { color: var(--paint-text-muted); font-size: .76rem; font-weight: 600; }
.gallery-selects select { min-width: 130px; margin-top: 4px; }
.design-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 20px; margin-top: 24px; }
.design-card { overflow: hidden; border: 1px solid var(--paint-border); border-radius: 13px; background: #fff; box-shadow: 0 6px 20px rgba(15,23,42,.06); transition: transform .16s ease, box-shadow .16s ease; }
.design-card:hover { transform: translateY(-3px); box-shadow: 0 12px 26px rgba(15,23,42,.11); }
.design-card-link { color: inherit; text-decoration: none; }
.design-card img { display: block; width: 100%; height: auto; aspect-ratio: 16/9; object-fit: cover; background: #e2e8f0; }
.design-card-body { padding: 14px; }
.design-theme { display: inline-block; color: var(--paint-brand); font-size: .76rem; font-weight: 700; }
.design-card h2 { overflow: hidden; margin: 5px 0 11px; font-size: 1rem; text-overflow: ellipsis; white-space: nowrap; }
.palette-dots { display: flex; gap: 5px; min-height: 18px; }
.palette-dots span { width: 18px; height: 18px; border: 1px solid rgba(0,0,0,.12); border-radius: 50%; }
.design-card-meta { display: flex; justify-content: space-between; margin: 12px 0 0; color: var(--paint-text-muted); font-size: .78rem; }
.gallery-empty { margin-top: 24px; padding: 64px 20px; border: 1px dashed var(--paint-border); border-radius: 12px; text-align: center; color: var(--paint-text-muted); }
.pagination { display: flex; align-items: center; justify-content: center; gap: 14px; margin-top: 28px; }

/* ── hidden ──────────────────────────────────────────────────────── */
.hidden { display: none !important; }

/* ── レスポンシブ (<= 768px) ─────────────────────────────────────── */
@media (max-width: 768px) {
  .design-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
  .gallery-main { width: min(100% - 20px, 1180px); padding-top: 20px; }
  .gallery-selects label, .gallery-selects select { flex: 1; min-width: 120px; }
  .side-panel { display: none; }
  .bottom-bar { display: flex; }
  .bottom-sheet { display: block; }
  body.edit-page .global-notice-link {
    bottom: calc(var(--bottom-bar-h) + 7px);
  }

  .app-layout {
    flex-direction: column;
    padding-bottom: var(--bottom-bar-h);
  }

  .map-container {
    flex: 1;
  }

  .toolbar-brand .brand-name { font-size: .9rem; }
  body.edit-page .toolbar-tools .btn-secondary { display: none; }

  .preview-section {
    top: calc(var(--toolbar-h) + 8px);
    right: 8px;
    width: calc(100vw - 16px);
    max-height: calc(100vh - var(--toolbar-h) - var(--bottom-bar-h) - 24px);
  }
}

@media (max-width: 480px) {
  .design-grid { grid-template-columns: 1fr; }
  .gallery-search-row { align-items: stretch; }
  .notice-main { width: min(100% - 20px, 880px); padding: 20px 0; }
  .notice-heading { align-items: stretch; flex-direction: column; }
}

/* prefers-reduced-motion */
@media (prefers-reduced-motion: reduce) {
  .paint-brush-cursor.is-pressing svg,
  .paint-brush-cursor.is-missing svg { animation: none; }
  .paint-ink-drop { display: none; }
  .paint-ink-splash { animation-duration: 120ms; }
  *, *::before, *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}

/* ── 放射状属性編集 ─────────────────────────────────────────────── */
.property-radial,
.property-editor {
  position: absolute;
  /* Keep an active editor usable even when the optional debug panel is open. */
  z-index: 950;
  color: var(--ink, #172033);
  background: #fff;
  border: 1px solid #bcc7d8;
  box-shadow: 0 10px 32px rgb(15 23 42 / 24%);
}

.property-radial {
  width: 236px;
  height: 236px;
  border-radius: 50%;
  background: rgb(255 255 255 / 94%);
}

.property-radial.hidden,
.property-editor.hidden { display: none; }

.property-radial-center {
  position: absolute;
  inset: 82px 52px;
  display: grid;
  place-items: center;
  text-align: center;
  font-size: .78rem;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.property-radial-item {
  position: absolute;
  min-width: 72px;
  min-height: 44px;
  padding: .45rem .7rem;
  border: 1px solid #aab6c7;
  border-radius: 999px;
  background: #fff;
  color: #172033;
  font-weight: 700;
}

.property-radial-item.active,
.property-radial-item:focus-visible {
  background: #245eeb;
  color: #fff;
  border-color: #245eeb;
  transform: scale(1.08);
}

.property-radial-item-0 { left: 82px; top: 8px; }
.property-radial-item-1 { right: 8px; top: 96px; }
.property-radial-item-2 { left: 82px; bottom: 8px; }
.property-radial-item-3 { left: 8px; top: 96px; }
.property-radial-item-4 { right: 23px; top: 28px; }
.property-radial-item-5 { right: 23px; bottom: 28px; }

.property-target-chooser {
  width: min(320px, calc(100% - 24px));
  height: auto;
  max-height: 320px;
  padding: 1rem;
  border-radius: 14px;
  overflow-y: auto;
}

.property-target-list { display: grid; gap: .5rem; margin-top: .75rem; }
.property-target-button { min-height: 44px; text-align: left; }

.property-editor {
  width: min(360px, calc(100% - 24px));
  padding: 1rem;
  border-radius: 14px;
}

.property-editor-head,
.property-value-row,
.property-actions {
  display: flex;
  align-items: center;
  gap: .6rem;
}

.property-editor-head { justify-content: space-between; }
.property-target-info { margin-top: .2rem; color: #536176; font-size: .78rem; overflow-wrap: anywhere; }
.property-close { min-width: 44px; min-height: 44px; font-size: 1.3rem; }
.property-scope { padding: .55rem .7rem; border-radius: 8px; background: #eef3fb; font-size: .83rem; }
.property-expression-check { display: flex; gap: .5rem; align-items: center; margin: .75rem 0; }
.property-expression-check input { width: 20px; height: 20px; }
.property-value-row input { min-width: 0; flex: 1; }
.property-value-row button { min-width: 44px; min-height: 44px; }
.property-editor input[type="range"] { width: 100%; min-height: 44px; margin-top: .5rem; }
.property-editor input[type="number"] { min-height: 44px; padding: .45rem; }
.property-actions { justify-content: flex-end; margin-top: 1rem; }
.property-actions button { min-height: 44px; }
.property-error { min-height: 1.25rem; margin-top: .5rem; color: #a11212; }
.property-choice-list { display: grid; gap: .5rem; }
.property-choice { display: flex; align-items: center; gap: .75rem; min-height: 48px; text-align: left; }
.property-choice.selected { outline: 3px solid #245eeb; }
.property-line-sample { width: 72px; height: 4px; background: #263244; }
.property-line-sample[data-pattern="1"] { background: repeating-linear-gradient(90deg, #263244 0 18px, transparent 18px 30px); }
.property-line-sample[data-pattern="2"] { background: repeating-linear-gradient(90deg, #263244 0 4px, transparent 4px 12px); }
.property-line-sample[data-pattern="3"] { background: repeating-linear-gradient(90deg, #263244 0 20px, transparent 20px 28px, #263244 28px 32px, transparent 32px 40px); }

@media (max-width: 768px), (pointer: coarse) {
  .property-editor.property-editor-sheet {
    position: absolute;
    left: 0 !important;
    right: 0;
    top: auto !important;
    bottom: 0;
    width: 100%;
    max-height: 52%;
    overflow-y: auto;
    border-radius: 18px 18px 0 0;
    padding-bottom: max(1rem, env(safe-area-inset-bottom));
  }
}

@media (prefers-color-scheme: dark) {
  .property-radial, .property-editor, .property-radial-item {
    color: #eef4ff;
    background: #202938;
    border-color: #536176;
  }
  .property-target-info { color: #b9c4d5; }
  .property-scope { background: #303b4c; }
  .property-line-sample { filter: invert(1); }
}
