:root {
  --sidebar-open: 230px;
  --sidebar-closed: 54px;
  --sidebar-width: var(--sidebar-open);
  --bg: #ffffff;
  --fg: #111111;
  --muted: #60666f;
  --line: #d9dee5;
  --panel: rgba(255, 255, 255, 0.85);
  --node-bg: #ffffff;
  --node-border: #b9c0c9;
  --node-selected: #4285F4;
  --link-stroke: rgba(0, 0, 0, 0.38);
  --shadow: 0 2px 10px rgba(0, 0, 0, 0.08);
}

body.dark {
  --bg: #121316;
  --fg: #f2f3f5;
  --muted: #9fa6b0;
  --line: #39424d;
  --panel: rgba(18, 19, 22, 0.9);
  --node-bg: #1b1d22;
  --node-border: #4d5664;
  --node-selected: #f2f3f5;
  --link-stroke: rgba(255, 255, 255, 0.28);
  --shadow: 0 2px 14px rgba(0, 0, 0, 0.35);
}

body.sidebar-collapsed {
  --sidebar-width: var(--sidebar-closed);
}

* { box-sizing: border-box; }

/* 検索・スクリーンリーダー向け（画面上は非表示） */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

html, body {
  margin: 0;
  width: 100%;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: "Roboto", "Noto Sans JP", "Inter", "Segoe UI", system-ui, sans-serif;
  overflow: hidden;
  user-select: none;
}

#app {
  position: fixed;
  inset: 0;
  background: var(--bg);
}

#sidebar {
  position: fixed;
  left: 0;
  top: 0;
  bottom: 0;
  width: var(--sidebar-width);
  z-index: 12;
  border-right: 1px solid var(--line);
  background: var(--panel);
  backdrop-filter: blur(8px);
  box-shadow: var(--shadow);
  padding: 10px;
  overflow-y: auto;
  overflow-x: hidden;
  transition: width 180ms ease;
}

.sb-head {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  margin-bottom: 10px;
  gap: 8px;
  min-width: 0;
}

.sb-head strong {
  font-size: 13px;
  white-space: nowrap;
  writing-mode: horizontal-tb;
  text-orientation: mixed;
  opacity: 1;
  max-width: 160px;
  overflow: hidden;
  transition: opacity 140ms ease 110ms, max-width 140ms ease 110ms;
  flex: 1;
  min-width: 0;
}

.sb-head button {
  border: 1px solid var(--line);
  background: var(--node-bg);
  color: var(--fg);
  border-radius: 8px;
  padding: 5px 8px;
  font-size: 12px;
  cursor: pointer;
}

.icon-btn {
  width: 30px;
  min-width: 30px;
  padding: 0;
  font-size: 14px;
  font-weight: 700;
  line-height: 28px;
  text-align: center;
}

.sidebar-logo {
  width: 24px;
  height: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.sidebar-logo img {
  width: 24px;
  height: 24px;
  object-fit: contain;
  display: block;
}

.sidebar-logo .logo-dark {
  display: none;
}

body.dark .sidebar-logo .logo-light {
  display: none;
}

body.dark .sidebar-logo .logo-dark {
  display: block;
}

.sidebar-logo-bottom {
  position: absolute;
  left: 12px;
  bottom: 12px;
  z-index: 2;
}

.material-symbols-outlined {
  font-variation-settings: "FILL" 0, "wght" 500, "GRAD" 0, "opsz" 24;
  font-size: 20px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  vertical-align: middle;
}

.map-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 10px;
}

#sidebarNewMapBtn {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--node-bg);
  color: var(--fg);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 12px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

#sidebarNewMapBtn .btn-label {
  white-space: nowrap;
  writing-mode: horizontal-tb;
  text-orientation: mixed;
  opacity: 1;
  max-width: 120px;
  overflow: hidden;
  transition: opacity 140ms ease 110ms, max-width 140ms ease 110ms;
}

.map-row {
  position: relative;
  z-index: 0;
}

.map-row.menu-open {
  z-index: 60;
}

.map-item {
  width: 100%;
  text-align: left;
  border: 1px solid var(--line);
  background: var(--node-bg);
  color: var(--fg);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 12px;
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 8px;
  padding-right: 50px;
}

.map-icon {
  width: 18px;
  height: 18px;
  border-radius: 999px;
  border: 1px solid var(--line);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  line-height: 1;
  text-align: center;
  flex-shrink: 0;
  display: none;
}

.map-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  writing-mode: horizontal-tb;
  text-orientation: mixed;
  opacity: 1;
  max-width: 140px;
  transition: opacity 140ms ease 110ms, max-width 140ms ease 110ms;
}

.map-actions {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  align-items: center;
}

.map-more {
  border: none;
  background: transparent;
  color: var(--fg);
  border-radius: 7px;
  width: 26px;
  height: 24px;
  cursor: pointer;
  line-height: 1;
  box-shadow: none;
}

.map-menu {
  position: absolute;
  right: 0;
  top: 30px;
  min-width: 78px;
  border: 1px solid var(--line);
  background: var(--node-bg);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 4px;
  z-index: 30;
}

.map-menu.hidden {
  display: none;
}

.map-menu button {
  width: 100%;
  border: 1px solid transparent;
  background: transparent;
  color: var(--fg);
  border-radius: 6px;
  padding: 6px 8px;
  font-size: 12px;
  cursor: pointer;
  text-align: left;
}

.map-menu button:hover {
  border-color: var(--line);
}

.map-item.active {
  border-color: var(--node-selected);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--node-selected) 40%, transparent);
}

#hud {
  position: fixed;
  top: 10px;
  left: calc(var(--sidebar-width) + ((100vw - var(--sidebar-width)) / 2));
  transform: translateX(-50%);
  z-index: 10;
  display: flex;
  gap: 6px;
  align-items: center;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  backdrop-filter: blur(8px);
  box-shadow: var(--shadow);
  transition: left 180ms ease, transform 180ms ease;
  white-space: nowrap;
}

#hud button, #hud label {
  border: 1px solid #dadce0;
  background: #ffffff;
  color: var(--fg);
  border-radius: 999px;
  height: 34px;
  min-height: 34px;
  padding: 0 14px;
  font-size: 12px;
  line-height: 1.2;
  font-weight: 500;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
  writing-mode: horizontal-tb;
  text-orientation: mixed;
  box-shadow: 0 1px 2px rgba(60, 64, 67, 0.18);
  transition: background-color 120ms ease, border-color 120ms ease, box-shadow 120ms ease;
}

#hud button:hover, #hud label:hover {
  border-color: #c5c9ce;
  background: #f8f9fa;
  box-shadow: 0 1px 3px rgba(60, 64, 67, 0.24);
}

#hud button.active {
  border-color: var(--node-selected);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--node-selected) 40%, transparent);
}

body.dark #hud button,
body.dark #hud label {
  background: #23262b;
  border-color: #4a4f58;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
}

body.dark #hud button:hover,
body.dark #hud label:hover {
  background: #2b2f36;
  border-color: #616773;
}

#darkBtn {
  width: 34px;
  min-width: 34px;
  padding: 0;
}

#clearBtn {
  color: #d93025;
  border-color: #f1b7b3;
  background: #fce8e6;
}

#clearBtn:hover {
  color: #b3261e;
  border-color: #e49d97;
  background: #fad2cf;
}

body.dark #clearBtn {
  color: #ffb4ab;
  border-color: #7d3a35;
  background: #3b1d1b;
}

body.dark #clearBtn:hover {
  color: #ffcbc5;
  border-color: #97524c;
  background: #4a2522;
}

#hud .hint {
  font-size: 11px;
  color: var(--muted);
  padding: 0 6px;
  white-space: nowrap;
}

.palette {
  display: grid;
  grid-template-columns: repeat(6, 18px);
  gap: 6px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--node-bg);
}

.palette.hidden {
  display: none;
}

.swatch {
  width: 18px;
  height: 18px;
  min-height: 18px;
  padding: 0;
  border-radius: 999px;
  border: 1px solid #aab3be;
  cursor: pointer;
  box-shadow: none;
  display: block;
}

#hud .swatch {
  width: 18px;
  height: 18px;
  min-height: 18px;
  padding: 0;
  border-radius: 999px;
  box-shadow: none;
  justify-self: center;
  align-self: center;
}

body.dark .swatch {
  border-color: #6b7480;
}

.swatch.active {
  outline: 2px solid var(--node-selected);
  outline-offset: 1px;
}

#importInput { display: none; }

#viewport {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: var(--sidebar-width);
  cursor: default;
  overflow: hidden;
  transition: left 180ms ease;
}

.empty-state {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px;
  color: var(--muted);
}

.empty-state.hidden {
  display: none;
}

.empty-state h2 {
  margin: 14px 0 8px;
  color: var(--fg);
  font-size: 22px;
}

.empty-state p {
  margin: 0;
  font-size: 14px;
}

.empty-illustration {
  position: relative;
  width: 120px;
  height: 84px;
  border: 1px dashed var(--line);
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: color-mix(in srgb, var(--node-bg) 80%, transparent);
}

.empty-illustration .material-symbols-outlined {
  font-size: 36px;
  color: #4285F4;
}

.empty-illustration .dot {
  position: absolute;
  width: 10px;
  height: 10px;
  border-radius: 999px;
}

.dot-blue { left: 20px; top: 18px; background: #4285F4; }
.dot-red { right: 20px; top: 18px; background: #EA4335; }
.dot-yellow { left: 20px; bottom: 18px; background: #FBBC05; }
.dot-green { right: 20px; bottom: 18px; background: #34A853; }

body.sidebar-collapsed #sidebarTitle,
body.sidebar-collapsed #sidebarNewMapBtn,
body.sidebar-collapsed .map-label {
  opacity: 0;
  pointer-events: none;
  overflow: hidden;
}


body.sidebar-collapsed #sidebarTitle,
body.sidebar-collapsed .map-label,
body.sidebar-collapsed #sidebarNewMapBtn .btn-label {
  max-width: 0;
  transition-delay: 0ms, 0ms;
}

body.sidebar-collapsed .map-item {
  padding: 8px;
  justify-content: center;
  padding-right: 8px;
  align-items: center;
}

body.sidebar-collapsed .map-icon {
  display: inline-flex;
  margin: 0;
  transform: translateX(0.6px);
}

body.sidebar-collapsed .map-actions {
  display: none;
}

#world {
  position: absolute;
  left: 0;
  top: 0;
  transform-origin: 0 0;
}

#links {
  position: absolute;
  left: 0;
  top: 0;
  overflow: visible;
  pointer-events: none;
}

#nodes {
  position: absolute;
  left: 0;
  top: 0;
}

.node {
  position: absolute;
  min-width: 92px;
  max-width: 280px;
  padding: 8px 12px;
  border: 1px solid var(--node-border);
  border-radius: 999px;
  background: var(--node-bg);
  box-shadow: var(--shadow);
  color: var(--fg);
  font-size: 14px;
  line-height: 1.2;
  text-align: center;
  cursor: grab;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.node.selected {
  border-color: var(--node-selected);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--node-selected) 14%, transparent), var(--shadow);
}

.node.editing {
  cursor: text;
  user-select: text;
  min-width: var(--edit-min-width, 130px);
  min-height: var(--edit-min-height, 36px);
  width: max-content;
  max-width: 340px;
  white-space: pre-wrap;
  word-break: break-word;
  overflow: hidden;
  text-overflow: clip;
  line-height: 1.35;
  border-width: 1px;
  border-radius: 999px;
  padding: 8px 10px;
}

.node.root {
  font-weight: 700;
  font-size: 16px;
  padding: 10px 16px;
  border-width: 2px;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--node-selected) 12%, transparent), var(--shadow);
}

#newMapBtn {
  position: fixed;
  right: 18px;
  bottom: 18px;
  width: 56px;
  height: 56px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--node-bg);
  color: #4285F4;
  box-shadow: var(--shadow);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 80;
}

body.dark #newMapBtn {
  background: #1b1d22;
}

.site-footer {
  position: fixed;
  left: 0;
  right: 88px;
  bottom: 0;
  z-index: 70;
  padding: 6px 12px 8px calc(var(--sidebar-width) + 8px);
  pointer-events: none;
  font-size: 11px;
  line-height: 1.35;
}

.site-footer-nav {
  pointer-events: auto;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 2px 4px;
  color: var(--muted);
}

.site-footer-nav a {
  color: var(--muted);
  text-decoration: none;
  user-select: none;
}

.site-footer-nav a:hover {
  color: var(--fg);
  text-decoration: underline;
}

.site-footer-sep {
  color: var(--line);
  user-select: none;
}

body.sidebar-collapsed .site-footer {
  padding-left: calc(var(--sidebar-closed) + 8px);
}

.app-dialog-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(17, 18, 20, 0.38);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 120;
}

.app-dialog-backdrop.hidden {
  display: none;
}

.app-dialog {
  width: min(420px, calc(100vw - 32px));
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--node-bg);
  color: var(--fg);
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.22);
  padding: 16px;
}

.app-dialog-title {
  margin: 0 0 10px;
  font-size: 15px;
  font-weight: 700;
}

.app-dialog-message {
  margin: 0 0 14px;
  color: var(--fg);
  font-size: 13px;
  line-height: 1.45;
}

.app-dialog-input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  color: var(--fg);
  padding: 8px 10px;
  font-size: 13px;
  margin-bottom: 14px;
}

.app-dialog-input.hidden {
  display: none;
}

.app-dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.app-dialog-btn {
  border: 1px solid #dadce0;
  background: #ffffff;
  color: var(--fg);
  border-radius: 999px;
  height: 34px;
  padding: 0 14px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
}

.app-dialog-btn.primary {
  border-color: #4285F4;
  background: #4285F4;
  color: #ffffff;
}

body.dark .app-dialog-btn {
  background: #23262b;
  border-color: #4a4f58;
}

body.dark .app-dialog-btn.primary {
  border-color: #6ea4f7;
  background: #6ea4f7;
  color: #0f1115;
}

@media (max-width: 768px) {
  :root {
    --sidebar-open: min(82vw, 300px);
    --sidebar-closed: 44px;
  }

  #sidebar {
    padding: 8px;
    width: var(--sidebar-open);
    max-width: none;
    z-index: 20;
    transform: none;
    transition: width 180ms ease;
  }

  body.sidebar-collapsed #sidebar {
    width: var(--sidebar-closed);
  }

  .sb-head {
    margin-bottom: 8px;
    gap: 6px;
  }

  .sb-head strong {
    font-size: 12px;
    max-width: 140px;
  }

  .map-item {
    font-size: 11px;
    padding: 7px 9px;
    padding-right: 44px;
  }

  #sidebarNewMapBtn {
    font-size: 11px;
    padding: 7px 9px;
  }

  .sidebar-logo-bottom {
    left: 10px;
    bottom: 10px;
    width: 20px;
    height: 20px;
  }

  .sidebar-logo-bottom img {
    width: 20px;
    height: 20px;
  }

  #hud {
    top: auto;
    bottom: 12px;
    left: calc(var(--sidebar-closed) + 6px);
    right: 6px;
    width: auto;
    max-width: none;
    transform: none;
    padding: 6px;
    overflow: hidden;
    flex-wrap: wrap;
    justify-content: center;
    row-gap: 6px;
    gap: 5px;
    max-height: 86px;
  }


  #hud > * {
    flex: 0 0 auto;
  }

  #hud .hint {
    display: none;
  }

  #hud button,
  #hud label {
    height: 32px;
    min-height: 32px;
    padding: 0 12px;
    font-size: 11px;
    flex-shrink: 0;
  }

  #darkBtn {
    width: 32px;
    min-width: 32px;
  }

  .palette {
    grid-template-columns: repeat(6, 16px);
    gap: 5px;
    padding: 5px;
    flex-shrink: 0;
    order: 20;
  }

  #hud .swatch,
  .swatch {
    width: 16px;
    height: 16px;
    min-height: 16px;
  }

  #newMapBtn {
    right: 12px;
    bottom: 12px;
    width: 52px;
    height: 52px;
  }

  #newMapBtn,
  #exportBtn,
  #hud label[for="importInput"] {
    display: none;
  }

  .node {
    max-width: 220px;
    font-size: 13px;
  }

  #viewport {
    left: 0;
  }

  .site-footer {
    right: 8px;
    left: calc(var(--sidebar-closed) + 6px);
    bottom: calc(12px + 86px + 8px);
    padding: 4px 0;
    font-size: 10px;
  }
}
