.rfs-root {
  --rfs-base: #fff;
  --rfs-base-light: #fafafa;
  --rfs-main: #1e3a5f;
  --rfs-main-dark: #0f1e3a;
  --rfs-main-light: #2d5a8f;
  --rfs-accent: #d4af37;
  --rfs-accent-light: #f4cf5f;
  --rfs-text: #2c3e50;
  --rfs-muted: #7f8c8d;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  min-height: 520px;
  color: var(--rfs-text);
  font-family: system-ui, -apple-system, "Segoe UI", "Hiragino Kaku Gothic ProN", Meiryo, sans-serif;
  line-height: 1.4;
  isolation: isolate;
}

.rfs-root:fullscreen { height: 100vh; height: 100dvh; background: #eaf6ff; }
body.admin-bar .rfs-root { height: calc(100vh - 32px); height: calc(100dvh - 32px); }
.rfs-root, .rfs-root * { box-sizing: border-box; }
.rfs-root [hidden] { display: none !important; }
.rfs-root button, .rfs-root select { font: inherit; }

.rfs-app {
  position: relative;
  height: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: linear-gradient(135deg, #0ea5e9, #6366f1 65%, #8b5cf6);
  border-radius: 18px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .16);
}

.rfs-header {
  height: 64px;
  flex: 0 0 64px;
  padding: 9px 18px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  color: #fff;
  background: var(--rfs-main);
  border-top: 3px solid var(--rfs-accent);
  border-bottom: 3px solid var(--rfs-accent);
  box-shadow: 0 2px 10px rgba(0, 0, 0, .18);
  z-index: 20;
}

.rfs-title { margin: 0; font-size: clamp(17px, 2vw, 22px); font-weight: 900; white-space: nowrap; }
.rfs-header-center {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}
.rfs-mode-switch {
  padding: 3px;
  display: flex;
  gap: 3px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .13);
}
.rfs-mode-button {
  min-height: 34px;
  padding: 5px 13px;
  border: 0;
  border-radius: 999px;
  color: #fff;
  background: transparent;
  font-size: 12px;
  font-weight: 900;
  white-space: nowrap;
  cursor: pointer;
}
.rfs-mode-button[aria-pressed="true"] { color: var(--rfs-main-dark); background: var(--rfs-accent); }
.rfs-view-switch {
  position: absolute;
  top: 12px;
  left: 50%;
  z-index: 11;
  transform: translateX(-50%);
  padding: 3px;
  display: flex;
  gap: 3px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .90);
  box-shadow: 0 3px 12px rgba(15, 30, 58, .16);
}
.rfs-meander-view-switch {
  position: absolute;
  top: 12px;
  left: 50%;
  z-index: 11;
  transform: translateX(-50%);
  padding: 3px;
  display: flex;
  gap: 3px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .92);
  box-shadow: 0 3px 12px rgba(15, 30, 58, .16);
}
.rfs-view-button {
  min-height: 34px;
  padding: 5px 11px;
  border: 0;
  border-radius: 999px;
  color: var(--rfs-main);
  background: transparent;
  font-size: 12px;
  font-weight: 900;
  white-space: nowrap;
  cursor: pointer;
}
.rfs-view-button[aria-pressed="true"] { color: var(--rfs-main-dark); background: var(--rfs-accent); }
.rfs-status {
  min-width: 132px;
  padding: 8px 15px;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  border-radius: 999px;
  color: #fff;
  background: rgba(255, 255, 255, .13);
  font-weight: 900;
}
.rfs-status-dot { width: 10px; height: 10px; border-radius: 50%; background: #72d7f1; box-shadow: 0 0 0 4px rgba(114, 215, 241, .16); }
.rfs-fullscreen {
  justify-self: end;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  color: #fff;
  background: rgba(255, 255, 255, .14);
  font-size: 25px;
  font-weight: 900;
  cursor: pointer;
}

.rfs-workspace { flex: 1; min-height: 0; padding: 14px 14px 18px; }
.rfs-canvas-card {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 0;
  overflow: hidden;
  background: #fff;
  border-top: 4px solid var(--rfs-accent);
  border-radius: 16px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .18);
}
.rfs-canvas { display: block; width: 100%; height: 100%; touch-action: none; }
.rfs-canvas.is-scrollable { cursor: grab; }
.rfs-canvas.is-dragging { cursor: grabbing; }

.rfs-loading, .rfs-message {
  position: absolute;
  inset: 50% auto auto 50%;
  transform: translate(-50%, -50%);
  padding: 16px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-radius: 14px;
  color: var(--rfs-main-dark);
  background: rgba(255, 255, 255, .94);
  box-shadow: 0 6px 24px rgba(15, 30, 58, .18);
  font-weight: 900;
  z-index: 12;
}
.rfs-loading[hidden], .rfs-message[hidden] { display: none; }
.rfs-spinner { width: 24px; height: 24px; border: 4px solid #d9e6ef; border-top-color: var(--rfs-main); border-radius: 50%; animation: rfs-spin .8s linear infinite; }
.rfs-message { max-width: min(88%, 620px); flex-direction: column; text-align: center; }
.rfs-message--fatal { border: 3px solid #c45555; color: #7f2424; }

.rfs-direction {
  position: absolute;
  top: 58px;
  left: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 12px;
  border-radius: 999px;
  color: #12395b;
  background: rgba(255, 255, 255, .82);
  font-size: 13px;
  font-weight: 900;
  pointer-events: none;
}
.rfs-direction-arrow { color: #167ba9; letter-spacing: 2px; }

.rfs-scroll-control {
  position: absolute;
  left: 50%;
  bottom: 12px;
  transform: translateX(-50%);
  width: min(48%, 520px);
  min-width: 230px;
  padding: 7px 12px;
  display: flex;
  align-items: center;
  gap: 9px;
  border-radius: 999px;
  color: #12395b;
  background: rgba(255, 255, 255, .90);
  box-shadow: 0 3px 12px rgba(15, 30, 58, .18);
  font-size: 11px;
  font-weight: 900;
  z-index: 8;
}
.rfs-scroll-control[hidden] { display: none; }
.rfs-scroll-range { width: 100%; accent-color: var(--rfs-accent); cursor: ew-resize; }

.rfs-legend {
  padding: 9px 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 7px 12px;
  border-radius: 10px;
  color: #263b4d;
  background: #edf5fa;
  font-size: 12px;
  font-weight: 800;
}

/* WordPressテーマ側のbutton/text色が設定パネルへ入り込まないよう固定する。 */
.rfs-root .rfs-settings-panel .rfs-legend,
.rfs-root .rfs-settings-panel .rfs-legend-item {
  color: #263b4d !important;
  -webkit-text-fill-color: #263b4d;
}
.rfs-legend-item { display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; }
.rfs-swatch { width: 11px; height: 11px; display: inline-block; border: 1px solid rgba(0, 0, 0, .18); border-radius: 50%; }
.rfs-swatch--gravel { width: 15px; height: 15px; background: #75695e; }
.rfs-swatch--pebble { width: 13px; height: 13px; background: #958477; }
.rfs-swatch--sand { background: #c99d59; }
.rfs-swatch--fine { width: 8px; height: 8px; background: #dfbf82; }

.rfs-type-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 4px;
  border-radius: 12px;
  background: #edf5fa;
}
.rfs-particle-settings,
.rfs-meander-settings {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.rfs-setting-buttons { display: flex; flex-wrap: wrap; gap: 8px; }
.rfs-setting-buttons--column { flex-direction: column; }
.rfs-root .rfs-settings-panel .rfs-setting-button {
  min-height: 42px;
  padding: 8px 13px;
  border: 2px solid #c9dce8 !important;
  border-radius: 12px;
  color: #1e3a5f !important;
  -webkit-text-fill-color: #1e3a5f;
  background: #fff !important;
  font-weight: 900;
  text-align: left;
  cursor: pointer;
}
.rfs-root .rfs-settings-panel .rfs-setting-button[aria-pressed="true"] {
  border-color: var(--rfs-accent) !important;
  background: #fff5cf !important;
  box-shadow: inset 4px 0 0 var(--rfs-accent) !important;
}
.rfs-setting-toggle::before { content: '○'; margin-right: 8px; color: #708291; }
.rfs-setting-toggle[aria-pressed="true"]::before { content: '✓'; color: #17734c; }
.rfs-settings-note { margin: 2px 0 0; padding: 10px; border-radius: 10px; color: #32485a; background: #edf5fa; font-size: 12px; font-weight: 800; }
.rfs-type-button {
  min-height: 40px;
  padding: 7px 11px;
  border: 0;
  border-radius: 999px;
  color: var(--rfs-main);
  background: transparent;
  font-size: 12px;
  font-weight: 900;
  cursor: pointer;
}
.rfs-root .rfs-settings-panel .rfs-type-button {
  color: #1e3a5f !important;
  -webkit-text-fill-color: #1e3a5f;
  background: #ffffff !important;
  border: 2px solid #c9dce8 !important;
  box-shadow: none !important;
}
.rfs-root .rfs-settings-panel .rfs-type-button[aria-pressed="true"] {
  color: #0f1e3a !important;
  -webkit-text-fill-color: #0f1e3a;
  background: var(--rfs-accent) !important;
  border-color: var(--rfs-accent) !important;
}

.rfs-toolbar {
  position: absolute;
  right: max(16px, env(safe-area-inset-right));
  bottom: max(18px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 11px;
  pointer-events: none;
  z-index: 1000;
}
.rfs-tool {
  position: relative;
  width: 58px;
  min-height: 58px;
  padding: 6px 3px;
  border: 2px solid rgba(255, 255, 255, .72);
  border-radius: 50%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  color: var(--rfs-main);
  background: #fff;
  box-shadow: 0 5px 16px rgba(15, 30, 58, .30), 0 1px 0 rgba(255, 255, 255, .78) inset;
  pointer-events: auto;
  cursor: pointer;
  transition: transform .15s ease, box-shadow .15s ease, background .15s ease;
}
.rfs-tool-icon { font-size: 24px; line-height: .85; font-weight: 900; }
.rfs-tool-icon-image { width: 24px; height: 24px; display: block; }
.rfs-tool-label { max-width: 54px; margin-top: 4px; overflow: hidden; font-size: 9px; line-height: 1.05; font-weight: 900; white-space: nowrap; }
.rfs-tool--add, .rfs-tool--flood { background: var(--rfs-accent); color: var(--rfs-main-dark); }
.rfs-tool--settings.is-active { color: #fff; background: var(--rfs-main-light); }
.rfs-tool--flood.is-active { color: #fff; background: #168bb8; }
.rfs-tool--reset { color: #a23c3c; }
.rfs-tool:hover { transform: translateY(-2px); box-shadow: 0 6px 18px rgba(0, 0, 0, .31); }
.rfs-tool:active { transform: translateY(1px); }
.rfs-tool:disabled { opacity: .5; filter: grayscale(.35); cursor: not-allowed; transform: none; }

.rfs-meander-hint {
  position: absolute;
  left: 14px;
  bottom: 14px;
  z-index: 12;
  max-width: calc(100% - 96px);
  padding: 8px 13px;
  border-radius: 999px;
  color: #173955;
  background: rgba(255,255,255,.92);
  box-shadow: 0 3px 12px rgba(15,30,58,.18);
  font-size: 12px;
  font-weight: 900;
  pointer-events: none;
}

.rfs-dev-panel {
  width: 100%;
  min-width: 0;
  padding: 9px 11px;
  border-radius: 10px;
  color: #eaf7ff;
  background: rgba(8, 25, 42, .78);
}
.rfs-dev-panel[hidden] { display: none; }
.rfs-dev-select-label { display: flex; justify-content: space-between; align-items: center; gap: 10px; font-size: 12px; font-weight: 900; }
.rfs-dev-select { min-height: 32px; padding: 3px 6px; border: 1px solid rgba(255, 255, 255, .35); border-radius: 7px; color: #fff; background: #183b58; }
.rfs-metrics { margin: 8px 0 0; color: #d8f2ff; font: 12px/1.35 ui-monospace, SFMono-Regular, Consolas, monospace; }
.rfs-noscript { padding: 20px; color: #7f2424; background: #fff0f0; }

.rfs-settings-backdrop {
  position: absolute;
  inset: 64px 0 0;
  padding: 16px 88px 16px 16px;
  display: flex;
  justify-content: flex-end;
  align-items: flex-start;
  background: rgba(15, 30, 58, .28);
  backdrop-filter: blur(2px);
  z-index: 40;
}
.rfs-settings-backdrop[hidden] { display: none; }
.rfs-settings-panel {
  width: min(390px, 100%);
  max-height: 100%;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow-y: auto;
  border-top: 4px solid var(--rfs-accent);
  border-radius: 16px;
  color: var(--rfs-text);
  background: rgba(255, 255, 255, .98);
  box-shadow: 0 12px 34px rgba(15, 30, 58, .30);
}
.rfs-settings-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.rfs-settings-title { margin: 0; color: var(--rfs-main); font-size: 19px; font-weight: 900; }
.rfs-settings-close {
  width: 42px;
  height: 42px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  color: var(--rfs-main);
  background: #e7f0f6;
  font-size: 26px;
  line-height: 1;
  font-weight: 800;
  cursor: pointer;
}
.rfs-settings-heading { margin: 3px 0 -3px; color: var(--rfs-main); font-size: 13px; font-weight: 900; }

.rfs-root button:focus-visible, .rfs-root select:focus-visible, .rfs-root input:focus-visible { outline: 4px solid var(--rfs-accent-light); outline-offset: 2px; }

@keyframes rfs-spin { to { transform: rotate(360deg); } }

@media (max-width: 780px) {
  .rfs-root { min-height: 500px; }
  .rfs-header { height: 58px; flex-basis: 58px; padding: 7px 10px; grid-template-columns: minmax(90px, 1fr) auto 44px; }
  .rfs-title { font-size: 15px; }
  .rfs-header-center { gap: 5px; }
  .rfs-mode-button { min-height: 31px; padding: 4px 8px; font-size: 10px; }
  .rfs-view-button { min-height: 31px; padding: 4px 7px; font-size: 10px; }
  .rfs-status { min-width: 104px; padding: 7px 8px; font-size: 11px; }
  .rfs-fullscreen { width: 40px; height: 40px; }
  .rfs-workspace { padding: 9px 9px 11px; }
  .rfs-toolbar { right: 9px; bottom: 11px; gap: 8px; }
  .rfs-tool { width: 52px; min-height: 52px; }
  .rfs-tool-icon { font-size: 21px; }
  .rfs-type-button { flex: 0 0 auto; min-height: 32px; padding: 4px 8px; }
  .rfs-legend { gap: 4px 8px; }
  .rfs-scroll-control { bottom: 70px; width: min(62%, 420px); }
  .rfs-settings-backdrop { inset: 58px 0 0; padding: 10px 70px 10px 10px; }
}

@media (max-width: 520px) and (orientation: portrait) {
  .rfs-root { min-height: 470px; }
  .rfs-status { display: none; }
  .rfs-header { grid-template-columns: auto 1fr 40px; }
  .rfs-header-center { justify-content: end; }
  .rfs-view-button { padding-inline: 6px; }
  .rfs-fullscreen { grid-column: 3; }
  .rfs-direction { top: 52px; }
  .rfs-legend { font-size: 10px; }
  .rfs-settings-backdrop { padding-right: 10px; align-items: center; }
  .rfs-settings-panel { max-height: calc(100% - 12px); }
}

@media (max-width: 782px) {
  body.admin-bar .rfs-root { height: calc(100vh - 46px); height: calc(100dvh - 46px); }
}

@media (prefers-reduced-motion: reduce) {
  .rfs-root *, .rfs-root *::before, .rfs-root *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
