:root {
  --bg: #12141a;
  --bg2: #1a1d27;
  --line: #2c3142;
  --text: #e8e6df;
  --muted: #9a9588;
  --accent: #c4a574;
  --danger: #c97a6a;
  --sel: #2a3344;
  --harmonic: #2e854c;
  --harmonic-edge: #96e8a9;
  --harmonic-sel-fill: #2e854c;
  --harmonic-sel-edge: #ffffff;
  --mine: #724899;
  --mine-edge: #d6b3ef;
  --mine-sel-fill: #724899;
  --mine-sel-edge: #ffffff;
  --theirs: #b17448;
  --theirs-edge: #e6b699;
  --theirs-sel-fill: #b17448;
  --theirs-sel-edge: #ffffff;
  --sel-edge: #ffffff;
  --sel-ring: #ffffff;
  --sel-ring-width: 1px;
  --node-ink: #ffffff;
  --idle-stroke-width: 1.2px;
  --sel-stroke-width: 2px;
  --dirty: #2a2e24;
  --right-w: 28rem;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; height: 100dvh; overflow: hidden; background: var(--bg); color: var(--text); font: 15px/1.45 "Iowan Old Style", Palatino, "Palatino Linotype", serif; overscroll-behavior: none; -webkit-text-size-adjust: 100%; touch-action: manipulation; }
body { display: flex; flex-direction: column; }
h1 { font-size: 1.1rem; margin: 0; font-weight: 600; letter-spacing: 0.04em; }
h2 { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin: 0 0 0.6rem; font-family: ui-sans-serif, system-ui, sans-serif; }
button, .file-btn { font: 12px/1 ui-sans-serif, system-ui, sans-serif; background: var(--bg); color: var(--text); border: 1px solid var(--line); padding: 0.35rem 0.6rem; border-radius: 4px; cursor: pointer; }
button:hover, .file-btn:hover { border-color: var(--accent); }
button:disabled { opacity: 0.45; cursor: default; }
button.danger { color: var(--danger); }
.file-btn input { display: none; }
.who { font: 12px/1 ui-sans-serif, system-ui, sans-serif; color: var(--muted); display: inline-flex; align-items: center; gap: 0.4rem; }
.who select { width: auto; margin-top: 0; background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 4px; padding: 0.3rem 0.4rem; font: 12px/1.2 ui-sans-serif, system-ui, sans-serif; }
.select-proxy { display: none; }
main { display: flex; flex: 1 1 auto; min-height: 0; overflow: hidden; }
.pane { padding: 0.8rem; overflow: auto; min-height: 0; }
#graph-pane { flex: 1 1 auto; min-width: 16rem; display: flex; flex-direction: column; container-type: inline-size; }
#detail-pane { flex: 0 0 var(--right-w); width: var(--right-w); min-width: 16rem; display: flex; flex-direction: column; }
.split { flex: 0 0 10px; width: 10px; cursor: col-resize; background: var(--bg2); position: relative; }
.split::after { content: ""; position: absolute; top: 0; bottom: 0; left: 3px; width: 4px; background: var(--line); border-radius: 2px; }
.split:hover::after, body.dragging .split::after { background: var(--accent); }
body.dragging { cursor: col-resize; user-select: none; }
.pane-head { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 0.6rem; margin-bottom: 0.5rem; flex: 0 0 auto; }
.pane-head h1 { margin: 0; }
.map-brand, .map-session { display: flex; align-items: center; gap: 0.65rem; min-width: 0; }
.rule { width: 1px; align-self: stretch; margin-block: 0.2rem; background: var(--line); flex: 0 0 auto; }
.who-name { font: 12px/1 ui-sans-serif, system-ui, sans-serif; color: var(--text); white-space: nowrap; }
@container (max-width: 36rem) {
  .pane-head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.4rem 0.6rem;
  }
  .map-session { margin-inline-start: auto; }
  .map-key { flex: 1 1 100%; order: 3; justify-content: center; margin-inline-start: 0; }
}

#graph-wrap { flex: 1 1 auto; min-height: 0; overflow: hidden; background: #0e1016; border: 1px solid var(--line); border-radius: 6px; cursor: grab; touch-action: none; user-select: none; -webkit-user-select: none; }
#graph-wrap.panning { cursor: grabbing; }
#graph { width: 100%; height: 100%; display: block; background: transparent; border: 0; user-select: none; -webkit-user-select: none; }
#graph text { user-select: none; -webkit-user-select: none; pointer-events: none; fill: var(--node-ink); text-shadow: 0 0 1px rgba(0, 0, 0, 1.00), 1px 1px 1px rgba(0, 0, 0, 1.00); }
#graph .node-sel-ring { fill: none; stroke: var(--sel-ring); stroke-width: var(--sel-ring-width); pointer-events: none; }
#graph .wire-sel-under { fill: none; stroke: #0e1016; stroke-width: 4px; opacity: 0.9; pointer-events: none; }
#graph .wire-sel { fill: none; stroke: var(--sel-ring); stroke-width: var(--sel-stroke-width); pointer-events: none; }
#graph .add-child { cursor: pointer; }
#graph .add-child-box { fill: #0e1016; stroke: var(--sel-ring); stroke-width: var(--sel-stroke-width); pointer-events: all; }
#graph .add-child:hover .add-child-box { fill: #1a1d27; }
#graph .add-child-plus { fill: var(--sel-ring); text-shadow: none; }
.map-key { display: flex; justify-content: center; flex-wrap: wrap; gap: 0.35rem; align-items: center; }
.map-key .key-node { font: 11px/1.2 ui-sans-serif, system-ui, sans-serif; color: var(--node-ink); padding: 0.22rem 0.55rem; border-radius: 5px; border: var(--idle-stroke-width) solid; text-shadow: 0 0 1px rgba(0, 0, 0, 1.00), 1px 1px 1px rgba(0, 0, 0, 1.00); }
.map-key .key-node.harmonic { background: var(--harmonic); border-color: var(--harmonic-edge); }
.map-key .key-node.mine { background: var(--mine); border-color: var(--mine-edge); }
.map-key .key-node.theirs { background: var(--theirs); border-color: var(--theirs-edge); }
#detail { flex: 0 0 auto; }
#detail label { display: block; margin: 0 0 0.7rem; font-family: ui-sans-serif, system-ui, sans-serif; font-size: 12px; color: var(--muted); }
input[type=text], input[type=password], textarea, select { width: 100%; margin-top: 0.25rem; background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 4px; padding: 0.4rem; font: 14px/1.4 ui-sans-serif, system-ui, sans-serif; }
input.dirty, textarea.dirty, select.dirty { background: var(--dirty); }
#f-title.locked,
#f-title[readonly] {
  cursor: default;
  background: var(--bg2);
  color: var(--text);
  opacity: 1;
}
#detail-empty { color: var(--muted); }
.action-row { display: flex; gap: 0.4rem; margin: 0.2rem 0 1rem; flex-wrap: wrap; align-items: center; }
.action-row #btn-delete { margin-left: auto; }
#chat-box { display: flex; flex-direction: column; flex: 1 1 auto; min-height: 0; }
.disc-head { display: flex; align-items: center; gap: 0.4rem; flex: 0 0 auto; }
.unread-dot { width: 0.55rem; height: 0.55rem; border-radius: 50%; background: #7ee0a8; box-shadow: 0 0 0 1px #0e1016; flex: 0 0 auto; }
#chat-log { flex: 1 1 auto; min-height: 5rem; overflow: auto; border: 1px solid var(--line); border-radius: 6px; padding: 0.55rem 0.65rem; margin: 0 0 0.5rem; font-family: ui-sans-serif, system-ui, sans-serif; font-size: 13px; background: #0e1016; }
#chat-form { flex: 0 0 auto; }
.msg { margin: 0 0 0.5rem; line-height: 1.4; }
.msg .un { font-weight: 700; }
.msg .un.me { color: #d6b3ef; }
.msg .un.them { color: #e6b699; }
.meta { font-size: 12px; color: var(--muted); }
.meta.chunk { margin: 0.75rem 0 0.4rem; }
.meta.chunk:first-child { margin-top: 0.1rem; }
#chat-form { display: flex; gap: 0.35rem; }
#chat-form input { margin: 0; }
#sel-view.viewing-self, #proxy-view.viewing-self { font-weight: 700; }
#sel-view option.self { font-weight: 700; }
.detail-close { display: none; }
.auth { position: fixed; inset: 0; background: var(--bg); display: flex; align-items: center; justify-content: center; z-index: 40; padding: 1rem; }
.auth[hidden] { display: none; }
.auth-card { width: min(24rem, 100%); background: var(--bg2); border: 1px solid var(--line); border-radius: 8px; padding: 1.1rem 1.2rem; box-shadow: 0 16px 48px rgba(0,0,0,.45); }
.auth-card h3 { margin: 0 0 0.4rem; font-size: 1.1rem; letter-spacing: 0.04em; }
.auth-lead { margin: 0 0 0.9rem; font: 13px/1.4 ui-sans-serif, system-ui, sans-serif; color: var(--muted); }
.auth-card label { display: block; margin: 0 0 0.7rem; font-family: ui-sans-serif, system-ui, sans-serif; font-size: 12px; color: var(--muted); }
.auth-err { margin: 0 0 0.6rem; font: 13px/1.3 ui-sans-serif, system-ui, sans-serif; color: var(--danger); }
.auth-actions { display: flex; justify-content: flex-end; gap: 0.4rem; margin-top: 0.5rem; }
#auth-login { border-color: var(--accent); color: var(--accent); }

.modal { position: fixed; inset: 0; background: rgba(8,9,12,.62); display: flex; align-items: center; justify-content: center; z-index: 20; }
.modal[hidden] { display: none; }
.modal-card { width: min(32rem, calc(100% - 2rem)); background: var(--bg2); border: 1px solid var(--line); border-radius: 8px; padding: 1rem 1.1rem; box-shadow: 0 16px 48px rgba(0,0,0,.45); }
.modal-card h3 { margin: 0 0 0.7rem; font-size: 1rem; }
#modal-body { font-family: ui-sans-serif, system-ui, sans-serif; font-size: 13px; color: var(--text); }
#modal-body p { margin: 0 0 0.65rem; }
#modal-body ul { margin: 0 0 0.65rem; padding-left: 1.2rem; color: var(--muted); }
#modal-body label { display: block; margin: 0 0 0.7rem; font-family: ui-sans-serif, system-ui, sans-serif; font-size: 12px; color: var(--muted); }
.modal-actions { display: flex; justify-content: flex-end; gap: 0.4rem; margin-top: 0.8rem; }
#modal-ok { border-color: var(--accent); color: var(--accent); }

.picker { position: fixed; inset: 0; background: rgba(8,9,12,.62); display: flex; align-items: center; justify-content: center; z-index: 25; padding: 1rem; }
.picker[hidden] { display: none; }
.picker-card { width: min(24rem, 100%); max-height: min(36rem, calc(100% - 2rem)); overflow: auto; background: var(--bg2); border: 1px solid var(--line); border-radius: 8px; padding: 1rem 1.1rem; box-shadow: 0 16px 48px rgba(0,0,0,.45); }
.picker-card h3 { margin: 0 0 0.7rem; font-size: 1rem; }
.picker-options { display: flex; flex-direction: column; gap: 0.25rem; }
.picker-opt { display: block; width: 100%; text-align: left; padding: 0.85rem 0.9rem; font: 16px/1.3 ui-sans-serif, system-ui, sans-serif; background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 6px; }
.picker-opt.selected { border-color: var(--accent); color: var(--accent); font-weight: 700; }
.picker-opt.self { font-weight: 700; }

@media (max-width: 768px) {
  #split { display: none; }
  #graph-pane { flex: 1 1 auto; width: 100%; min-width: 0; }
  #detail-pane {
    position: fixed;
    inset: 0;
    z-index: 15;
    width: 100% !important;
    min-width: 0;
    flex: none;
    display: none;
    background: var(--bg);
    padding-top: max(0.8rem, env(safe-area-inset-top));
    padding-bottom: max(0.8rem, env(safe-area-inset-bottom));
    padding-left: max(0.8rem, env(safe-area-inset-left));
    padding-right: max(0.8rem, env(safe-area-inset-right));
  }
  #detail-pane.open { display: flex; flex-direction: column; touch-action: pan-y; }
  .detail-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    position: absolute;
    top: max(0.8rem, env(safe-area-inset-top));
    right: max(0.8rem, env(safe-area-inset-right));
    z-index: 3;
    width: 2.25rem;
    height: 2.25rem;
    padding: 0;
    font: 1.15rem/1 ui-sans-serif, system-ui, sans-serif;
    color: var(--text);
    background: var(--bg);
    border: 1px solid var(--line);
    border-radius: 4px;
  }
  .detail-close:hover { border-color: var(--accent); }
  #detail .title-field {
    display: grid;
    grid-template-columns: 1fr 2.25rem;
    column-gap: 0.5rem;
    align-items: center;
  }
  #detail .title-field span {
    grid-column: 1;
    grid-row: 1;
    min-height: 2.25rem;
    display: flex;
    align-items: center;
  }
  #detail .title-field input { grid-column: 1 / -1; }
  #detail-empty {
    min-height: 2.25rem;
    padding-right: 2.75rem;
  }
  #detail-empty:not([hidden]) {
    display: flex;
    align-items: center;
  }
  .who-name { font-size: 14px; }
  #btn-logout { min-height: 2.25rem; padding: 0.4rem 0.75rem; font-size: 13px; }
  .who select { display: none; }
  .select-proxy {
    display: inline-flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.45rem;
    width: auto;
    min-width: 5.25rem;
    min-height: 2.25rem;
    margin-top: 0;
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--line);
    border-radius: 4px;
    padding: 0.4rem 0.55rem;
    font: 14px/1.2 ui-sans-serif, system-ui, sans-serif;
  }
  .select-proxy::after {
    content: "";
    border: 0.28rem solid transparent;
    border-top-color: var(--muted);
    transform: translateY(0.15rem);
  }
  #chat-log { -webkit-overflow-scrolling: touch; }
  #chat-box[hidden] { display: none; }
  input[type=text], input[type=password], textarea, select { font-size: 16px; }
  .action-row button { padding: 0.5rem 0.75rem; font-size: 13px; min-height: 2.25rem; }
  #graph-wrap { -webkit-touch-callout: none; }
}
