/* ===== MindMasters ===== */
:root {
  --line-green: #06C755;
  --line-green-dark: #05a648;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --text: #1f2d3d;
  --text-sub: #7b8794;
  --border: #e1e6eb;
  --canvas-bg: #f7f9fb;
  --canvas-dot: #d8dee5;
  --danger: #e5484d;
  --shadow: 0 2px 10px rgba(20, 40, 60, .08);
  --sheet-shadow: 0 -6px 24px rgba(20, 40, 60, .15);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14181c;
    --surface: #1e2429;
    --text: #e8edf2;
    --text-sub: #93a1af;
    --border: #313a42;
    --canvas-bg: #171c21;
    --canvas-dot: #2a323a;
    --shadow: 0 2px 10px rgba(0, 0, 0, .35);
    --sheet-shadow: 0 -6px 24px rgba(0, 0, 0, .5);
  }
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; overscroll-behavior: none; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP", "Yu Gothic UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.hidden { display: none !important; }
button { font-family: inherit; cursor: pointer; }

.screen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
}

/* ===== ホーム ===== */
.home-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 14px) 18px 14px;
  background: var(--line-green);
  color: #fff;
}
.brand { display: flex; align-items: center; gap: 9px; }
.brand-logo {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .18);
}
.brand h1 { font-size: 19px; font-weight: 700; letter-spacing: .02em; }
.profile { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.profile img { width: 30px; height: 30px; border-radius: 50%; border: 2px solid rgba(255,255,255,.6); }
.profile-fallback {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, .6);
  background: rgba(255, 255, 255, .25);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  box-sizing: border-box;
}
.login-btn {
  border: 1.5px solid rgba(255, 255, 255, .8);
  background: transparent;
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  border-radius: 999px;
  padding: 7px 14px;
}
.login-btn:active { background: rgba(255, 255, 255, .2); }

.sync-status {
  font-size: 12px;
  text-align: center;
  padding: 6px 12px;
  color: var(--text-sub);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.sync-status.ok { color: var(--line-green-dark); }
.sync-status.warn { color: #b45309; }

.home-main { flex: 1; overflow-y: auto; padding: 16px; }
.map-list { display: flex; flex-direction: column; gap: 10px; max-width: 640px; margin: 0 auto; }
.map-card {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px 16px;
  box-shadow: var(--shadow);
  text-align: left;
  color: var(--text);
  transition: transform .08s;
}
.map-card:active { transform: scale(.98); }
.map-card .map-ic {
  width: 42px; height: 42px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px;
  background: color-mix(in srgb, var(--line-green) 14%, transparent);
  flex-shrink: 0;
}
.map-card .map-info { flex: 1; min-width: 0; }
.map-card .map-name {
  font-size: 15px; font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.map-card .map-meta { font-size: 12px; color: var(--text-sub); margin-top: 3px; }
.map-list { position: relative; }
.m-handle {
  flex-shrink: 0;
  color: var(--text-sub);
  opacity: .45;
  font-size: 17px;
  padding: 8px 4px 8px 10px;
  cursor: grab;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
.map-card.dragging { opacity: .35; }
.map-ghost {
  position: fixed;
  z-index: 40;
  background: var(--surface);
  color: var(--text);
  border: 1.5px solid var(--line-green);
  border-radius: 12px;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 600;
  box-shadow: var(--shadow);
  pointer-events: none;
  opacity: .92;
  max-width: 70vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.m-dropline {
  position: absolute;
  left: 4px;
  right: 4px;
  height: 3px;
  background: var(--line-green);
  border-radius: 2px;
  pointer-events: none;
  z-index: 5;
}
.map-card.archived { opacity: .55; }
.archive-divider {
  font-size: 12px;
  color: var(--text-sub);
  text-align: center;
  padding: 14px 0 4px;
}

.icon-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
  padding: 4px 12px 12px;
}
.icon-cell {
  font-size: 26px;
  padding: 10px 0;
  border: none;
  border-radius: 12px;
  background: var(--bg);
  line-height: 1.2;
}
.icon-cell:active { background: var(--border); }

.empty-hint {
  text-align: center;
  color: var(--text-sub);
  margin-top: 18vh;
  line-height: 1.9;
  font-size: 14px;
}
.fab {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(env(safe-area-inset-bottom) + 56px);
  background: var(--line-green);
  color: #fff;
  border: none;
  border-radius: 999px;
  padding: 15px 30px;
  font-size: 16px;
  font-weight: 700;
  box-shadow: 0 6px 18px rgba(6, 199, 85, .4);
}
.fab:active { background: var(--line-green-dark); }
.home-links {
  position: fixed;
  left: 0;
  right: 0;
  bottom: calc(env(safe-area-inset-bottom) + 16px);
  display: flex;
  justify-content: center;
  gap: 28px;
}
.import-link {
  background: none;
  border: none;
  color: var(--text-sub);
  font-size: 13px;
  text-decoration: underline;
}

/* ===== エディタ ===== */
.editor-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: calc(env(safe-area-inset-top) + 8px) 10px 8px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  z-index: 5;
}
.icon-btn {
  width: 40px; height: 40px;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 20px;
  border-radius: 10px;
  flex-shrink: 0;
}
.icon-btn:active { background: var(--border); }
.map-title {
  flex: 1;
  min-width: 0;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 16px;
  font-weight: 600;
  padding: 8px 6px;
  border-radius: 8px;
  outline: none;
}
.map-title:focus { background: var(--bg); }
.shared-badge {
  font-size: 16px;
  flex-shrink: 0;
  padding: 4px 8px;
  border: none;
  background: var(--bg);
  border-radius: 10px;
  cursor: pointer;
}

.member-list { padding: 0 6px; max-height: 40vh; overflow-y: auto; }
.member-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 11px 10px;
  font-size: 14px;
  color: var(--text);
  border-bottom: 1px solid var(--border);
}
.member-row:last-child { border-bottom: none; }
.member-badge {
  font-size: 11px;
  color: var(--line-green-dark);
  border: 1px solid var(--line-green);
  padding: 1px 8px;
  border-radius: 999px;
  flex-shrink: 0;
}
.member-transfer {
  margin-left: auto;
  border: none;
  background: var(--bg);
  color: var(--text-sub);
  font-size: 12px;
  border-radius: 8px;
  padding: 6px 10px;
  flex-shrink: 0;
}
.member-empty { text-align: center; color: var(--text-sub); font-size: 13px; padding: 14px; }
.member-ts { font-size: 11px; color: var(--text-sub); flex-shrink: 0; }
.member-remove { color: var(--danger); margin-left: 6px; }
.map-icon-btn {
  font-size: 21px;
  background: var(--bg);
  border-radius: 10px;
  width: 38px;
  height: 38px;
}

.canvas-wrap {
  flex: 1;
  position: relative;
  overflow: hidden;
  background: var(--canvas-bg);
  background-image: radial-gradient(var(--canvas-dot) 1px, transparent 1px);
  background-size: 22px 22px;
}
#canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  display: block;
}

.zoom-ctrl {
  position: absolute;
  right: 12px;
  bottom: 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: 4;
}
.zoom-ctrl button {
  width: 42px;
  height: 42px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  font-size: 18px;
  box-shadow: var(--shadow);
}
.zoom-ctrl button:active { background: var(--border); }
.zoom-ctrl #zoom-pct {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-sub);
}

.node-editor {
  position: absolute;
  z-index: 10;
  border: 2px solid var(--line-green);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  line-height: 1.45;
  padding: 8px 12px;
  resize: none;
  outline: none;
  overflow: hidden;
  box-shadow: var(--shadow);
  min-width: 90px;
}

/* ===== ツールバー ===== */
.toolbar {
  display: flex;
  align-items: stretch;
  gap: 4px;
  padding: 8px 8px calc(env(safe-area-inset-bottom) + 8px);
  background: var(--surface);
  border-top: 1px solid var(--border);
  overflow-x: auto;
  scrollbar-width: none;
  z-index: 5;
}
.toolbar::-webkit-scrollbar { display: none; }
.tool-btn {
  flex: 1 0 auto;
  min-width: 52px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  border: none;
  background: transparent;
  color: var(--text);
  border-radius: 10px;
  padding: 6px 8px;
}
.tool-btn:active { background: var(--border); }
.tool-btn:disabled { opacity: .3; }
.tool-btn .tool-ic { font-size: 18px; line-height: 1.2; }
.tool-btn .tool-label { font-size: 10px; color: var(--text-sub); }
.tool-btn.primary .tool-ic { color: var(--line-green); font-weight: 700; }
.tool-btn.danger .tool-ic { color: var(--danger); }
.tool-sep { width: 1px; background: var(--border); margin: 4px 2px; flex-shrink: 0; }

/* ===== シート・トースト ===== */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .4);
  z-index: 20;
}
.sheet {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  background: var(--surface);
  border-radius: 18px 18px 0 0;
  padding: 10px 12px calc(env(safe-area-inset-bottom) + 12px);
  box-shadow: var(--sheet-shadow);
  z-index: 21;
  max-width: 560px;
  margin: 0 auto;
  animation: sheet-up .18s ease-out;
}
@keyframes sheet-up { from { transform: translateY(40%); opacity: .5; } to { transform: none; opacity: 1; } }
.sheet-item {
  display: block;
  width: 100%;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 15px;
  text-align: left;
  padding: 14px 12px;
  border-radius: 12px;
}
.sheet-item:active { background: var(--bg); }
.sheet-item.danger { color: var(--danger); }
.sheet-item.cancel {
  text-align: center;
  color: var(--text-sub);
  border-top: 1px solid var(--border);
  border-radius: 0;
  margin-top: 6px;
}

/* LINEログインゲート */
.login-gate {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 24px;
  text-align: center;
}
.gate-logo {
  width: 88px;
  height: 88px;
  border-radius: 22px;
  box-shadow: 0 4px 16px rgba(6, 199, 85, .35);
}
.gate-title {
  font-size: 24px;
  font-weight: 700;
  color: var(--text);
}
.gate-desc {
  font-size: 14px;
  color: var(--text-sub);
  line-height: 1.8;
}
.gate-btn {
  margin-top: 8px;
  background: var(--line-green);
  color: #fff;
  border: none;
  border-radius: 999px;
  font-size: 16px;
  font-weight: 700;
  padding: 15px 48px;
  box-shadow: 0 6px 18px rgba(6, 199, 85, .4);
}
.gate-btn:active { background: var(--line-green-dark); }
.gate-note {
  font-size: 12px;
  color: var(--text-sub);
  line-height: 1.8;
  margin-top: 8px;
}

.toast {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(env(safe-area-inset-bottom) + 90px);
  background: rgba(30, 36, 42, .92);
  color: #fff;
  font-size: 13px;
  padding: 10px 18px;
  border-radius: 999px;
  z-index: 30;
  pointer-events: none;
  animation: toast-in .2s ease-out;
  max-width: 86vw;
  text-align: center;
}
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* ===== SVGノード ===== */
.node rect {
  stroke-width: 2;
  transition: filter .1s;
}
.node.selected rect {
  stroke: var(--line-green);
  stroke-width: 3;
  filter: drop-shadow(0 0 6px rgba(6, 199, 85, .45));
}
.node text { pointer-events: none; }
.collapse-badge { cursor: pointer; }
.add-btn { cursor: pointer; }
.add-btn text { pointer-events: none; }
.drag-ghost { opacity: .65; pointer-events: none; }
.drop-hint { pointer-events: none; }
.node { cursor: grab; }

@keyframes moved-flash {
  0% { filter: drop-shadow(0 0 14px rgba(6, 199, 85, .95)); }
  100% { filter: none; }
}
.node.moved rect { animation: moved-flash 1s ease-out; }

/* ===== アウトラインビュー ===== */
.outline {
  flex: 1;
  overflow-y: auto;
  background: var(--surface);
  padding: 6px 8px calc(env(safe-area-inset-bottom) + 60px);
}
.o-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-top: 11px;
  padding-bottom: 11px;
  padding-right: 10px;
  border-radius: 10px;
  cursor: pointer;
}
.o-row.selected {
  background: color-mix(in srgb, var(--line-green) 13%, transparent);
}
.o-row.o-root .o-text { font-weight: 700; font-size: 16px; }
.o-toggle {
  width: 24px;
  height: 24px;
  flex-shrink: 0;
  border: none;
  background: transparent;
  color: var(--text-sub);
  font-size: 13px;
  border-radius: 6px;
  padding: 0;
}
.o-bullet {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.o-text {
  flex: 1;
  min-width: 0;
  font-size: 15px;
  line-height: 1.5;
  word-break: break-word;
}
.o-input {
  flex: 1;
  min-width: 0;
  font-family: inherit;
  font-size: 15px;
  border: none;
  border-bottom: 2px solid var(--line-green);
  background: transparent;
  color: var(--text);
  outline: none;
  padding: 0 0 2px;
}

/* アウトライン: 選択行のアクションボタン */
.o-act {
  width: 30px;
  height: 30px;
  flex-shrink: 0;
  border: none;
  border-radius: 50%;
  font-size: 16px;
  font-weight: 700;
  color: #fff;
  line-height: 1;
  padding: 0;
}
.o-act-add { background: var(--line-green); }
.o-act-sib { background: #8b97a5; margin-left: 4px; }
.o-act-del { background: var(--danger); margin-left: 4px; }
.o-act:active { opacity: .75; }

/* アウトラインのドラッグ＆ドロップ */
.outline { position: relative; }
.o-handle {
  margin-left: auto;
  flex-shrink: 0;
  color: var(--text-sub);
  opacity: .5;
  font-size: 17px;
  padding: 6px 8px;
  cursor: grab;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
.o-row.o-dragging { opacity: .35; }
.o-row.o-drop-into {
  background: color-mix(in srgb, var(--line-green) 20%, transparent);
  outline: 2px dashed var(--line-green);
  outline-offset: -2px;
}
.o-ghost {
  position: fixed;
  z-index: 40;
  background: var(--surface);
  color: var(--text);
  border: 1.5px solid var(--line-green);
  border-radius: 10px;
  padding: 8px 14px;
  font-size: 14px;
  box-shadow: var(--shadow);
  pointer-events: none;
  opacity: .92;
  max-width: 70vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.o-dropline {
  position: absolute;
  height: 3px;
  background: var(--line-green);
  border-radius: 2px;
  pointer-events: none;
  z-index: 5;
}
@keyframes row-flash {
  0% { background: color-mix(in srgb, var(--line-green) 35%, transparent); }
  100% { background: transparent; }
}
.o-row.moved { animation: row-flash 1s ease-out; }

/* プレゼンモード */
.present-bar {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(env(safe-area-inset-bottom) + 14px);
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 8px 10px;
  box-shadow: var(--sheet-shadow);
  z-index: 15;
}
.present-btn {
  border: none;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
  border-radius: 999px;
  padding: 10px 16px;
}
.present-btn.primary {
  background: var(--line-green);
  color: #fff;
  padding: 10px 26px;
}
.present-btn:active { opacity: .8; }
.present-count {
  font-size: 12px;
  color: var(--text-sub);
  min-width: 52px;
  text-align: center;
}
body.presenting .toolbar { display: none; }
body.presenting .editor-header { opacity: .9; }

/* アプリ内確認ダイアログ */
.confirm-box {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(86vw, 380px);
  background: var(--surface);
  border-radius: 16px;
  padding: 20px 18px 14px;
  box-shadow: var(--sheet-shadow);
  z-index: 50;
}
.confirm-msg {
  font-size: 14px;
  line-height: 1.7;
  color: var(--text);
  margin-bottom: 16px;
  white-space: pre-wrap;
}
.confirm-row {
  display: flex;
  gap: 10px;
}
.confirm-btn {
  flex: 1;
  border: none;
  border-radius: 12px;
  padding: 12px;
  font-size: 14px;
  font-weight: 600;
  background: var(--bg);
  color: var(--text-sub);
}
.confirm-btn.primary {
  background: var(--line-green);
  color: #fff;
}
.confirm-btn:active { opacity: .8; }

/* 復元ダイアログ */
.sheet-title {
  font-size: 16px;
  font-weight: 700;
  padding: 8px 12px 2px;
}
.sheet-desc {
  font-size: 13px;
  color: var(--text-sub);
  padding: 4px 12px 10px;
  line-height: 1.6;
}
.restore-text {
  display: block;
  width: calc(100% - 24px);
  margin: 0 12px 10px;
  font-family: inherit;
  font-size: 13px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  padding: 10px;
  resize: none;
  outline: none;
}
.restore-text:focus { border-color: var(--line-green); }
.key-input {
  display: block;
  width: calc(100% - 24px);
  margin: 0 12px 8px;
  font-family: ui-monospace, monospace;
  font-size: 12px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  padding: 10px;
  outline: none;
}
.key-input:focus { border-color: var(--line-green); }
.key-divider {
  font-size: 12px;
  color: var(--text-sub);
  text-align: center;
  padding: 12px 0 8px;
  border-top: 1px solid var(--border);
  margin-top: 8px;
}

.pair-code {
  font-family: ui-monospace, monospace;
  font-size: 42px;
  font-weight: 700;
  letter-spacing: 8px;
  text-align: center;
  color: var(--line-green-dark);
  background: var(--bg);
  border-radius: 12px;
  margin: 4px 12px 8px;
  padding: 14px 0;
}

.restore-run {
  text-align: center;
  background: var(--line-green);
  color: #fff;
  font-weight: 700;
  border-radius: 12px;
}
.restore-run:active { background: var(--line-green-dark); }

/* スマホ横画面（高さが狭い）向けのコンパクト表示 */
@media (max-height: 480px) {
  .editor-header {
    padding-top: calc(env(safe-area-inset-top) + 2px);
    padding-bottom: 2px;
  }
  .icon-btn { width: 34px; height: 34px; font-size: 17px; }
  .map-title { font-size: 14px; padding: 4px 6px; }
  .toolbar {
    padding-top: 2px;
    padding-bottom: calc(env(safe-area-inset-bottom) + 2px);
  }
  .tool-btn { padding: 2px 8px; min-width: 46px; }
  .tool-btn .tool-ic { font-size: 16px; }
  .tool-btn .tool-label { font-size: 9px; }
  .zoom-ctrl { flex-direction: row; right: 10px; bottom: 10px; }
  .zoom-ctrl button { width: 38px; height: 38px; }
  .home-header { padding-top: calc(env(safe-area-inset-top) + 8px); padding-bottom: 8px; }
  .fab { bottom: calc(env(safe-area-inset-bottom) + 12px); padding: 10px 24px; }
  .o-row { padding-top: 7px; padding-bottom: 7px; }
  .present-bar { bottom: calc(env(safe-area-inset-bottom) + 8px); padding: 5px 8px; }
  .present-btn { padding: 7px 14px; }
}

/* 横画面のノッチ（セーフエリア左右）対応 */
.editor-header,
.toolbar,
.home-header,
.home-main {
  padding-left: max(10px, env(safe-area-inset-left));
  padding-right: max(10px, env(safe-area-inset-right));
}
.zoom-ctrl { right: max(12px, env(safe-area-inset-right)); }
.outline {
  padding-left: max(8px, env(safe-area-inset-left));
  padding-right: max(8px, env(safe-area-inset-right));
}

/* PC向け調整 */
@media (min-width: 768px) {
  .toolbar { justify-content: center; }
  .tool-btn { flex: 0 0 auto; min-width: 64px; }
  .map-card:hover { border-color: var(--line-green); }
  .tool-btn:hover, .icon-btn:hover { background: var(--border); }
  .sheet { bottom: 24px; border-radius: 18px; }
}
