:root {
  --bg: #f6f8fa; --panel: #ffffff; --border: #d0d7de; --strong-border: #8c959f;
  --accent: #0b57d0; --accent-soft: #d3e3fd; --text: #1f2328; --muted: #57606a;
  --success: #137333; --success-soft: #eef8ee; --warning: #b06000; --warning-soft: #fff8e8;
  --danger: #b3261e; --danger-soft: #fff5f5;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; font-family: Inter, "Hiragino Sans", "Yu Gothic", Meiryo, sans-serif; color: var(--text); background: var(--bg); }

#toolbar {
  position: fixed; top: 0; left: 0; right: 0; height: 48px; z-index: 20;
  display: flex; align-items: center; gap: 8px; padding: 0 10px;
  background: var(--panel); border-bottom: 1px solid var(--border);
  overflow-x: auto; scrollbar-width: none;
}
#toolbar h1 { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.toolbar-search { position: relative; flex: none; display: flex; align-items: center; }
.toolbar-search .icon { position: absolute; left: 9px; width: 15px; height: 15px; color: var(--muted); pointer-events: none; }
#search {
  width: 132px; min-height: 34px; padding: 7px 8px 7px 30px;
  border: 1px solid var(--border); border-radius: 6px; font-size: 14px; background: #fff;
}
#search:focus, #sharepanel input:focus, #sharepanel select:focus, #reqpanel input:focus {
  outline: 2px solid var(--accent-soft); border-color: var(--accent);
}
.status-badge {
  display: none; align-items: center; gap: 5px; padding: 4px 8px; border-radius: 999px;
  font-size: 12px; font-weight: 700;
  border: 1px solid var(--border); background: #f1f1f5; color: var(--muted); white-space: nowrap;
}
.status-badge.ready { display: inline-flex; border-color: #8bc48b; background: var(--success-soft); color: var(--success); }
.status-badge.pending { display: inline-flex; border-color: #e2bd72; background: var(--warning-soft); color: var(--warning); }
.icon {
  width: 16px; height: 16px; flex: none; display: inline-block;
  stroke: currentColor; fill: none; stroke-width: 2;
  stroke-linecap: round; stroke-linejoin: round;
}
.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;
}
.tbtn {
  min-height: 34px; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 7px 10px; border: 1px solid var(--border); border-radius: 6px;
  background: var(--panel); color: #30363d; font-size: 13px; font-weight: 600;
  cursor: pointer; white-space: nowrap;
}
.tbtn:hover { background: #f6f8fa; border-color: var(--strong-border); }
.tbtn:active { background: #eaeef2; }
.tbtn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.tbtn.primary:hover { background: #0949b2; border-color: #0949b2; }
.tbtn .btn-label { line-height: 1; }
#spacer { flex: 1; }

#tabbar {
  position: fixed; top: 48px; left: 0; right: 0; height: 38px; z-index: 19;
  display: flex; align-items: flex-end; gap: 4px; padding: 4px 10px 0;
  background: var(--panel); border-bottom: 1px solid var(--border);
  overflow-x: auto; scrollbar-width: thin;
}
.tab {
  min-height: 34px; display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 16px; font-size: 13px; cursor: pointer; white-space: nowrap;
  border: 1px solid var(--border); border-bottom: none;
  border-radius: 8px 8px 0 0; background: #ececf1; color: #555;
}
.tab.active { background: var(--accent); color: #fff; border-color: var(--accent); font-weight: 600; }
.tab.plus { justify-content: center; min-width: 38px; padding: 7px 12px; font-weight: 700; color: var(--accent); background: var(--panel); }
.tab.plus .icon { width: 17px; height: 17px; }
.tab.group {
  align-self: center; cursor: default; border: none; background: transparent;
  padding: 0 4px; color: #777; font-size: 12px; font-weight: 600;
}


#viewport { position: absolute; inset: 86px 0 0 0; overflow: hidden; touch-action: none; cursor: grab; }
#emptyhint {
  position: fixed; left: 50%; top: 52%; transform: translate(-50%, -50%); z-index: 18;
  width: min(520px, 90vw); display: none; text-align: center; color: #555;
  pointer-events: none; line-height: 1.7;
}
#emptyhint h2 { font-size: 20px; color: #222; margin-bottom: 8px; }
#emptyhint .plusmark { display: inline-flex; align-items: center; justify-content: center; padding: 0 7px; border: 1px solid var(--border); border-radius: 6px; color: var(--accent); font-weight: 700; }

#viewport.dragging { cursor: grabbing; }
#world { position: absolute; left: 0; top: 0; transform-origin: 0 0; }
#world img { display: block; user-select: none; -webkit-user-drag: none; pointer-events: none; }
#mapimg, #genreimg { position: absolute; top: 0; left: 0; }
#world #genreimg { display: none; }
#world.has-genre #genreimg { display: block; box-shadow: -1px 0 0 var(--border); }
#overlay { position: absolute; left: 0; top: 0; }
#overlay rect.desk { fill: rgba(0,0,0,0); stroke: rgba(74,111,212,.55); stroke-width: 1.4; cursor: pointer; }
@media (hover: hover) {
  #overlay rect.desk:hover { stroke: #e02020; stroke-width: 3; }
}
#overlay rect.desk.colored { stroke: rgba(0,0,0,.35); stroke-width: 1.4; }
#overlay rect.desk.selected { stroke: #e02020; stroke-width: 3; fill: rgba(224,32,32,.15); }
#overlay rect.flash { animation: flash 1.2s ease-out 3; }
@keyframes flash { 0% { stroke: #e02020; stroke-width: 6; } 100% { stroke: rgba(0,0,0,0); stroke-width: 0; } }
#overlay g.bubble { pointer-events: none; }
body.no-bubbles #overlay g.bubble { display: none; }
#overlay circle.memo-dot { display: none; fill: #e02020; pointer-events: none; }
body.no-bubbles #overlay circle.memo-dot { display: inline; }
.tbtn.toggled { background: var(--accent); color: #fff; border-color: var(--accent); }
#overlay g.bubble rect { fill: #fffbe6; stroke: rgba(160,130,30,.7); stroke-width: 1; }
#overlay g.bubble path { fill: #fffbe6; stroke: rgba(160,130,30,.7); stroke-width: 1; }
#overlay g.bubble text { font-size: 15px; fill: #443c20; font-family: inherit; }
#overlay g.bubble .sync-alert-dot { fill: #d92828; stroke: #fff; stroke-width: 1.5; }
#overlay g.bubble .sync-alert-text {
  fill: #fff; font-size: 12px; font-weight: 700;
  text-anchor: middle; dominant-baseline: central;
}

#popup {
  position: fixed; z-index: 30; width: 260px; display: none;
  background: var(--panel); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: 0 6px 24px rgba(0,0,0,.18); padding: 12px;
}
#popup .pop-head { display: flex; align-items: center; margin-bottom: 8px; }
#popup .pop-id { font-size: 18px; font-weight: 700; }
#popup .pop-close { margin-left: auto; border: none; background: none; font-size: 18px; cursor: pointer; color: #888; }
#popup textarea {
  width: 100%; height: 64px; resize: vertical; padding: 6px; font-size: 14px;
  border: 1px solid var(--border); border-radius: 6px; font-family: inherit;
}
#pop-history {
  display: none; margin-top: 10px; padding-top: 8px; border-top: 1px solid #eee;
  font-size: 12px; color: #555;
}
#pop-history .hist-head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
#pop-history .hist-title { font-weight: 700; color: #444; }
#pop-history .hist-clear { margin-left: auto; padding: 3px 7px; font-size: 11.5px; }
#pop-history .hist-item { padding: 5px 0; border-top: 1px solid #f0f0f0; line-height: 1.45; }
#pop-history .hist-item:first-child { border-top: none; }
#pop-history .hist-time { color: #888; }
#pop-history .hist-empty { color: #999; }
#palette { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.swatch {
  width: 28px; height: 28px; border-radius: 50%; cursor: pointer;
  border: 2px solid rgba(0,0,0,.15);
}
.swatch.none { background: repeating-linear-gradient(45deg, #fff 0 4px, #ddd 4px 8px); }
.swatch.active { border-color: #222; transform: scale(1.15); }
#popup .pop-del { margin-top: 10px; width: 100%; padding: 7px 10px; font-size: 13px;
  border: 1px solid #e0a0a0; color: var(--danger); background: var(--danger-soft); border-radius: 6px; cursor: pointer; }

#listpanel {
  position: fixed; top: 48px; right: 0; bottom: 0; width: 280px; z-index: 25;
  background: var(--panel); border-left: 1px solid var(--border);
  transform: translateX(100%); transition: transform .2s; overflow-y: auto; padding: 10px;
}
#listpanel.open { transform: translateX(0); }
#listpanel h2 { display: flex; align-items: center; gap: 6px; font-size: 14px; margin-bottom: 8px; }
.list-item { display: flex; align-items: center; gap: 8px; padding: 8px 6px; border-bottom: 1px solid #eee; cursor: pointer; }
.list-item .dot { width: 16px; height: 16px; border-radius: 4px; flex: none; border: 1px solid rgba(0,0,0,.15); }
.list-item .lid { font-weight: 700; flex: none; }
.list-item .lmemo { font-size: 12px; color: #555; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#listpanel .empty { color: #999; font-size: 13px; padding: 16px 4px; }

#zoomctl { position: fixed; right: 12px; bottom: 16px; z-index: 20; display: flex; flex-direction: column; gap: 6px; }
#zoomctl button {
  width: 44px; height: 44px; display: inline-flex; align-items: center; justify-content: center;
  font-size: 20px; border-radius: 50%;
  border: 1px solid var(--border); background: var(--panel); cursor: pointer;
  box-shadow: 0 2px 6px rgba(0,0,0,.12);
}
#zoomctl button:hover { background: #f6f8fa; border-color: var(--strong-border); }
#zoomctl .zoom-fit { width: 54px; border-radius: 999px; gap: 4px; font-size: 12px; font-weight: 700; }
#zoomctl .zoom-fit .icon { width: 14px; height: 14px; }
#toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 40;
  background: rgba(40,40,40,.9); color: #fff; padding: 8px 16px; border-radius: 20px;
  font-size: 13px; display: none;
}
@media (max-width: 600px) {
  #toolbar h1 { display: none; }
  #toolbar { gap: 6px; padding: 0 8px; }
  #search { width: 118px; }
  #toolbar .tbtn {
    width: 40px; min-width: 40px; padding: 0;
  }
  #toolbar #btn-search { width: 44px; min-width: 44px; }
  #toolbar .tbtn .btn-label {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
  }
  #listpanel { width: 100%; }
}
#world { background: #fff; box-shadow: 0 0 0 1px var(--border); }

#sharepanel, #reqpanel {
  position: fixed; left: 50%; top: 50%; transform: translate(-50%,-50%); z-index: 32;
  width: min(380px, 92vw); display: none;
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: 0 8px 30px rgba(0,0,0,.2); padding: 18px;
}
#reqpanel { width: min(560px, 94vw); max-height: min(760px, 92vh); overflow-y: auto; }
#sharepanel h3, #reqpanel h3 { display: flex; align-items: center; gap: 7px; font-size: 15px; margin-bottom: 10px; }
#sharepanel h3 .icon, #reqpanel h3 .icon, #listpanel h2 .icon { color: var(--accent); }
#sharepanel label, #reqpanel label { display: block; font-size: 12px; color: #555; margin: 8px 0 3px; }
#sharepanel input, #sharepanel select, #reqpanel input { width: 100%; padding: 7px 8px; border: 1px solid var(--border); border-radius: 6px; font-size: 14px; }
#sharepanel label.checkrow { display: flex; align-items: center; gap: 7px; margin-top: 10px; }
#sharepanel label.checkrow input { width: auto; }
#sharepanel .row, #reqpanel .row { display: flex; gap: 8px; margin-top: 14px; justify-content: flex-end; }
#sharepanel .hint, #reqpanel .hint { font-size: 11.5px; color: #888; margin-top: 10px; line-height: 1.5; }
#sharepanel .share-note { margin-top: 6px; font-size: 12px; color: #555; line-height: 1.45; }
#share-state { margin-top: 8px; font-size: 12px; color: #666; min-height: 1.4em; }
.sync-on { color: #247024; }
.sync-warn { color: #8a5b00; }
.share-code-row, .share-join-row, .restore-row { display: grid; grid-template-columns: 1fr auto auto; gap: 8px; align-items: end; }
.share-join-row { grid-template-columns: 1fr auto; margin-top: 3px; }
.restore-row { grid-template-columns: 1fr auto; margin-top: 3px; }
.share-restore { margin-top: 12px; padding-top: 10px; border-top: 1px solid #eee; }
.share-restore .empty { font-size: 12px; color: #888; margin-top: 4px; }
.req-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.mapmgr-head { display: flex; align-items: center; gap: 6px; margin-top: 16px; padding-top: 14px; border-top: 1px solid #eee; font-size: 13px; font-weight: 700; }
.mapmgr-list { margin-top: 8px; display: grid; gap: 8px; }
.map-row { border: 1px solid var(--border); border-radius: 8px; padding: 10px; background: #fafafa; }
.map-main { display: flex; gap: 8px; align-items: flex-start; justify-content: space-between; }
.map-name { font-size: 13px; font-weight: 700; overflow-wrap: anywhere; }
.map-meta { margin-top: 3px; font-size: 11.5px; color: #777; overflow-wrap: anywhere; }
.map-status { display: inline-flex; align-items: center; gap: 4px; margin-top: 5px; font-size: 11.5px; font-weight: 700; }
.map-status .icon { width: 13px; height: 13px; }
.map-status.ready { color: var(--success); }
.map-status.pending { color: var(--warning); }
.map-row.archived { opacity: .72; background: #f4f4f6; }
.map-row .map-controls { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; align-items: end; margin-top: 8px; }
.map-row .map-controls .map-genre-input, .map-actions { grid-column: 1 / -1; }
.map-actions { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }
.map-empty { color: #777; font-size: 13px; padding: 10px 2px; }
.danger { border-color: #e0a0a0; color: var(--danger); background: var(--danger-soft); }
#modalbg { position: fixed; inset: 0; background: rgba(0,0,0,.25); z-index: 27; display: none; }
@media (max-width: 600px) {
  .req-grid, .map-row .map-controls, .share-code-row, .share-join-row, .restore-row { grid-template-columns: 1fr; }
}
