:root {
  --bg: #0f0f1a;
  --surface: #1a1a2e;
  --surface2: #252542;
  --border: #2a2a4a;
  --text: #e0e0e0;
  --text2: #999;
  --accent: #7c5cfc;
  --accent2: #5a3fd4;
  --danger: #e8455c;
  --success: #4caf7d;
  --warn: #f0a030;
  --radius: 8px;
  --shadow: 0 2px 8px rgba(0,0,0,.3);
  --font: system-ui, -apple-system, sans-serif;
  --nav-h: 52px;
}

:root.light {
  --bg: #f0f0f5;
  --surface: #fff;
  --surface2: #e8e8f0;
  --border: #d0d0da;
  --text: #222;
  --text2: #777;
  --accent: #5a3fd4;
  --accent2: #7c5cfc;
  --shadow: 0 2px 8px rgba(0,0,0,.1);
}

* { margin:0; padding:0; box-sizing:border-box; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* NAV */
nav {
  position: fixed; top:0; left:0; right:0; height:var(--nav-h);
  background: var(--surface); border-bottom:1px solid var(--border);
  z-index:100;
}
.nav-inner {
  max-width:1200px; margin:0 auto; height:100%;
  display:flex; align-items:center; padding:0 16px; gap:24px;
}
.logo { font-weight:700; font-size:18px; color:var(--accent); text-decoration:none; white-space:nowrap; }
.nav-links { display:flex; gap:4px; }
.nav-links a {
  padding:6px 14px; border-radius:var(--radius);
  color:var(--text2); text-decoration:none; font-size:14px; font-weight:500;
  transition:background .15s, color .15s;
}
.nav-links a:hover, .nav-links a.active { background:var(--surface2); color:var(--text); }
.nav-right { margin-left:auto; display:flex; align-items:center; gap:12px; }

.status-dot {
  width:10px; height:10px; border-radius:50%;
  display:inline-block;
}
.status-dot.online { background:var(--success); box-shadow:0 0 6px var(--success); }
.status-dot.offline { background:var(--danger); }

#hamburger { display:none; background:none; border:none; font-size:24px; cursor:pointer; color:var(--text); padding:4px; line-height:1; }
#theme-toggle {
  background:none; border:1px solid var(--border); border-radius:var(--radius);
  padding:4px 10px; cursor:pointer; font-size:16px; color:var(--text);
}

/* MAIN */
#app {
  max-width:1200px; margin:0 auto; padding:calc(var(--nav-h) + 20px) 16px 40px;
}

/* PAGE HEADER */
.page-header {
  display:flex; align-items:center; justify-content:space-between;
  margin-bottom:20px; gap:12px; flex-wrap:wrap; min-height:48px;
}
.page-header h1 { font-size:24px; }
.page-header .subtitle { color:var(--text2); font-size:14px; }
.page-header h1 .subtitle { font-size:14px; font-weight:normal; color:var(--text2); margin-left:8px; }

/* BUTTONS */
.btn {
  display:inline-flex; align-items:center; gap:6px;
  padding:8px 16px; border-radius:var(--radius); border:1px solid var(--border);
  background:var(--surface); color:var(--text); cursor:pointer;
  font-size:14px; font-weight:500; transition:all .15s;
  text-decoration:none; white-space:nowrap;
}
.btn:hover { background:var(--surface2); }
.btn-primary { background:var(--accent); color:#fff; border-color:var(--accent); }
.btn-primary:hover { background:var(--accent2); }
.btn-danger { background:var(--danger); color:#fff; border-color:var(--danger); }
.btn-sm { padding:4px 10px; font-size:12px; }
.btn-icon { padding:4px 8px; font-size:16px; border:none; background:none; color:var(--text2); cursor:pointer; }
.btn-icon:hover { color:var(--text); }

/* CARDS */
.card {
  background:var(--surface); border:1px solid var(--border);
  border-radius:var(--radius); padding:16px; margin-bottom:12px;
}
.card h3 { font-size:16px; margin-bottom:8px; }
.card-grid {
  display:grid; grid-template-columns:repeat(auto-fill,minmax(280px,1fr));
  gap:12px; margin-bottom:20px;
}

/* FORMS */
.form-group { margin-bottom:14px; }
.form-group label { display:block; font-size:13px; font-weight:600; color:var(--text2); margin-bottom:4px; }
.form-group input, .form-group select, .form-group textarea {
  width:100%; padding:8px 12px; border-radius:var(--radius);
  border:1px solid var(--border); background:var(--bg); color:var(--text);
  font-size:14px; font-family:var(--font);
}
.form-group textarea { resize:vertical; min-height:60px; }
.form-group input:focus, .form-group select:focus { outline:2px solid var(--accent); outline-offset:-1px; }
.form-row { display:flex; gap:8px; align-items:center; flex-wrap:wrap; }
.form-row > * { flex:1; min-width:80px; }
.form-row .btn { flex:0 0 auto; }
.roll-form-group { min-width: 120px; }
.roll-form-btn {
  align-self: flex-end;
  margin-bottom: 14px;
  flex: 0 0 auto;
}
.form-inline {
  display:flex; gap:8px; align-items:center; margin-bottom:6px; flex-wrap:wrap;
}
.form-inline input, .form-inline select { flex:1; }
.aspect-row-field,
.aspect-row-actions {
  display: contents;
}

/* ENTITY LIST */
.entity-list { display:flex; flex-direction:column; gap:8px; }
.entity-item {
  display:flex; align-items:center; gap:12px;
  padding:12px 16px; background:var(--surface); border:1px solid var(--border);
  border-radius:var(--radius); cursor:pointer; transition:all .15s;
}
.entity-item:hover { border-color:var(--accent); }
.type-badge {
  font-size:11px; font-weight:600; padding:2px 8px; border-radius:20px;
  text-transform:uppercase; letter-spacing:.5px;
}
.type-badge.character { background:#7c5cfc22; color:var(--accent); border:1px solid var(--accent); }
.type-badge.location { background:#4caf7d22; color:var(--success); border:1px solid var(--success); }
.type-badge.faction { background:#f0a03022; color:var(--warn); border:1px solid var(--warn); }
.participant-row .type-badge { font-size:10px; padding:1px 6px; }
.entity-item .name { flex:1; font-weight:500; }
.entity-item .meta { color:var(--text2); font-size:13px; }
.entity-item .pc-badge { font-size:11px; color:var(--accent); font-weight:600; }
.entity-item .desc-snippet { font-size:12px; color:var(--text2); max-width:200px; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }

/* TAGS */
.tags { display:flex; gap:4px; flex-wrap:wrap; }
.tag {
  font-size:10px; padding:1px 6px; border-radius:20px;
  border:1px solid var(--border); color:var(--text2); background:var(--surface2);
}
.tag.highlight { border-color:var(--accent); color:var(--accent); }

/* DASHBOARD PC GRID */
.pc-grid { display:grid; grid-template-columns:repeat(auto-fill,minmax(350px,1fr)); gap:16px; }
.pc-card { background:var(--surface); border:1px solid var(--border); border-radius:var(--radius); overflow:hidden; }
.pc-card-header { padding:12px 16px; border-bottom:1px solid var(--border); font-weight:600; font-size:16px; }
.pc-card-body { padding:12px 16px; }
.pc-card-body h4 { font-size:12px; text-transform:uppercase; letter-spacing:.5px; color:var(--text2); margin:12px 0 6px; }
.pc-card-body h4:first-child { margin-top:0; }
.aspect-list { list-style:none; }
.aspect-list li { padding:3px 0; font-size:13px; }
.aspect-list li .label { font-weight:600; color:var(--accent); }
.aspect-list li.aspect-hidden { opacity:0.5; }
.aspect-hidden-label { font-size:11px; color:var(--text2); }
.skill-bar { display:flex; align-items:center; gap:6px; margin:2px 0; font-size:13px; }
.skill-bar .skill-name { width:100px; flex-shrink:0; color:var(--text2); }
.skill-bar .skill-rating { width:24px; text-align:center; font-weight:600; }
.skill-bar .skill-track {
  flex:1; height:6px; background:var(--bg); border-radius:3px; overflow:hidden;
  position:relative;
}
.skill-bar .skill-fill {
  height:100%; border-radius:3px; transition:width .2s;
  background:var(--accent); opacity:.6;
}
.skill-bar .skill-fill.negative { background:var(--danger); }
.stunt-item { font-size:13px; padding:4px 0; }
.stunt-item .stunt-name { font-weight:600; }
.consequence-item { font-size:13px; padding:2px 12px; border-left:2px solid var(--warn); margin:4px 0; }

/* BADGES */
.badge {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 20px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  background: var(--surface2);
  color: var(--text2);
  border: 1px solid var(--border);
}

.note-edit-text {
  width: 100%;
  padding: 8px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  font-family: var(--font);
  resize: vertical;
  min-height: 60px;
}
.note-edit-text:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}

.aspect-tag {
  display: inline-block;
  font-size: 13px;
  padding: 4px 10px;
  margin: 2px 4px 2px 0;
  border-radius: 4px;
  background: var(--surface2);
  border: 1px solid var(--border);
}

/* NOTES */
.note-item {
  border-bottom: 1px solid var(--border);
  padding: 8px 0;
}
.note-item:last-child { border-bottom: none; }
.note-header {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
}
.note-header:hover { color: var(--accent); }
.note-chevron {
  font-size: 10px;
  color: var(--text2);
  width: 12px;
  flex-shrink: 0;
}
.note-title {
  flex: 1;
  font-weight: 600;
  font-size: 14px;
}
.note-actions {
  display: flex;
  gap: 2px;
  margin-left: auto;
}
.note-description {
  margin: 6px 0 0 20px;
  font-size: 14px;
  line-height: 1.5;
  white-space: pre-wrap;
  color: var(--text2);
}
.note-block {
  margin-bottom: 8px;
  padding: 8px;
  background: var(--surface2);
  border-radius: var(--radius);
}
.note-add-form,
.note-edit-form {
  padding: 8px 0 4px;
}
.note-add-form .form-group,
.note-edit-form .form-group {
  margin-bottom: 8px;
}
.note-item.note-hidden { opacity: 0.5; }

/* STRESS TRACKER */
.stress-row { display:flex; gap:4px; margin:6px 0; align-items:center; }
.stress-label { font-size:13px; color:var(--text2); width:70px; flex-shrink:0; }
.stress-boxes { display:flex; gap:3px; }
.stress-box {
  width:24px; height:24px; border:1px solid var(--border); border-radius:4px;
  cursor:pointer; transition:all .15s; background:var(--bg);
  display:flex; align-items:center; justify-content:center;
  font-size:11px; font-weight:700; color:var(--text2); user-select:none;
}
.stress-box.filled { background:var(--danger); border-color:var(--danger); color:#fff; }
.stress-box:hover { opacity:0.8; border-color:var(--accent); }

/* FATE POINTS */
.fp-display { display:flex; align-items:baseline; gap:4px; font-size:24px; font-weight:700; }
.fp-current { color:var(--accent); }
.fp-separator { color:var(--text2); font-weight:400; }
.fp-refresh { color:var(--text2); font-weight:400; font-size:16px; }
.fp-controls { display:flex; gap:4px; margin-top:8px; }

/* ENTITY IMAGE */
.entity-image-area {
  margin-bottom: 4px;
}
.entity-image-preview {
  max-width: 200px;
  max-height: 120px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  display: block;
  margin-bottom: 8px;
  object-fit: cover;
  background: var(--bg);
}

/* MAP */
.map-container {
  position:relative; border:2px dashed var(--border); border-radius:var(--radius);
  min-height:400px; overflow:hidden; cursor:crosshair;
  background:var(--surface); margin-bottom:16px;
}
.map-container.has-image { border-style:solid; cursor:crosshair; }
.map-container img { display:block; max-width:100%; height:auto; }
.map-poi {
  position:absolute; transform:translate(-50%,-100%);
  cursor:grab; text-align:center; transition:opacity .15s;
}
.map-poi::before {
  content:'📍'; font-size:20px; display:block;
}
.map-poi .poi-label {
  font-size:11px; background:var(--surface); padding:2px 8px;
  border-radius:4px; border:1px solid var(--border); white-space:nowrap;
  max-width:120px; overflow:hidden; text-overflow:ellipsis;
}
.map-poi:hover .poi-label { border-color:var(--accent); }

/* GM PANEL */
.gm-section { margin-bottom:24px; }
.gm-section h2 { font-size:18px; margin-bottom:12px; }
.player-list { display:flex; flex-direction:column; gap:6px; }
.player-item { display:flex; align-items:center; gap:10px; padding:8px 12px; background:var(--surface2); border-radius:var(--radius); }
.player-dot { width:8px; height:8px; border-radius:50%; }
.player-dot.online { background:var(--success); }
.player-dot.offline { background:var(--text2); }
.visibility-toggle { display:flex; align-items:center; gap:8px; margin:2px 0; }
.visibility-toggle label { font-size:13px; }

/* PARTICIPANT / INITIATIVE */
.participant-row {
  display:flex; align-items:center; gap:8px;
  padding:8px 12px; margin:4px 0;
  background:var(--surface2); border-radius:var(--radius);
  border:1px solid transparent; transition:all .15s;
}
.participant-row.active {
  border-color:var(--accent); background:var(--surface);
  box-shadow:0 0 8px rgba(124,92,252,.25);
}
.participant-row[draggable="true"] { cursor:grab; }
.participant-row[draggable="true"]:active { cursor:grabbing; }

/* SEARCH/FILTER BAR */
.filter-bar { display:flex; gap:8px; margin-bottom:16px; flex-wrap:wrap; }
.filter-bar input, .filter-bar select { padding:8px 12px; border-radius:var(--radius); border:1px solid var(--border); background:var(--surface); color:var(--text); font-size:14px; }
.filter-bar input { flex:1; min-width:150px; }
.filter-bar select { min-width:120px; }

/* EMPTY STATE */
.empty-state {
  text-align:center; padding:60px 20px; color:var(--text2);
}
.empty-state h3 { font-size:18px; margin-bottom:8px; }
.empty-state p { font-size:14px; }

/* MODAL OVERLAY */
.modal-overlay {
  position:fixed; inset:0; background:rgba(0,0,0,.5);
  display:flex; align-items:center; justify-content:center; z-index:200;
}
.modal {
  background:var(--surface); border:1px solid var(--border);
  border-radius:var(--radius); padding:24px; width:90%; max-width:600px;
  max-height:90vh; overflow-y:auto;
}
.modal h2 { margin-bottom:16px; }
.modal-actions { display:flex; gap:8px; justify-content:flex-end; margin-top:16px; }

/* TIMESTAMP (mobile block) */
.ts-mobile { display:inline; }
@media(max-width:600px) {
  .ts-mobile { display:block; }
}

/* DICE ROLLER */
.roll-result { margin-top:8px; padding-top:8px; border-top:1px solid var(--border); }
.roll-result-main { margin-bottom:6px; }
.roll-label { font-size:14px; font-weight:500; }
.roll-dice { display:flex; align-items:center; gap:6px; margin:8px 0; flex-wrap:wrap; }
.die {
  display:inline-flex; align-items:center; justify-content:center;
  width:36px; height:36px; border-radius:6px;
  font-size:16px; font-weight:700; color:#fff;
  box-shadow:0 2px 4px rgba(0,0,0,.3);
}
.die-1 { background: #4caf7d; }  /* green for + */
.die-0 { background: #555; }     /* gray for 0 */
.die--1 { background: #e8455c; }  /* red for - */
.roll-eq { font-size:18px; font-weight:700; color:var(--text2); margin:0 2px; }
.roll-sum { font-size:16px; font-weight:700; padding:2px 8px; border-radius:4px; }
.roll-sum.pos { color:#4caf7d; }
.roll-sum.neg { color:#e8455c; }
.roll-mod { font-size:15px; color:var(--text2); }
.roll-total { font-size:18px; padding:2px 8px; border-radius:4px; }
.roll-total.pos { color:#4caf7d; background:#4caf7d22; }
.roll-total.neg { color:#e8455c; background:#e8455c22; }
.roll-history-toggle { font-size:12px; color:var(--accent); cursor:pointer; margin-bottom:4px; user-select:none; }
.roll-history-toggle:hover { text-decoration:underline; }
.roll-history { max-height:200px; overflow-y:auto; margin-bottom:6px; background:var(--surface2); border-radius:var(--radius); padding:6px 10px; }
.roll-history-item { font-size:12px; padding:2px 0; color:var(--text2); border-bottom:1px solid var(--border); }
.roll-history-item:last-child { border-bottom:none; }

.npc-section-header {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text2);
  margin: 12px 0 6px;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--border);
}

.npc-detail-field {
  font-size: 14px;
  padding: 4px 0;
  line-height: 1.5;
}

.npc-detail-label {
  font-weight: 600;
  color: var(--accent);
  display: inline;
}

/* RESPONSIVE */
@media(max-width:600px) {
  #hamburger { display: block; }
  .nav-links {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    flex-direction: column;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    border-top: 1px solid var(--border);
    box-shadow: var(--shadow);
    padding: 8px 0;
    z-index: 99;
  }
  .nav-links.open { display: flex; }
  .nav-links a {
    padding: 14px 20px;
    font-size: 16px;
    width: 100%;
    border-radius: 0;
    border-bottom: 1px solid var(--border);
  }
  .nav-links a:last-child { border-bottom: none; }
  .nav-links a:hover, .nav-links a.active {
    background: var(--surface2);
    color: var(--text);
  }
  .pc-grid { grid-template-columns:1fr; }
  .card-grid { grid-template-columns:1fr; }

  .nav-inner { gap:8px; }
  .logo { font-size:14px; }
  .entity-item { flex-wrap:wrap; }
  .entity-item .desc-snippet { display:none; }
  .entity-item .meta { width:100%; margin-left:0; }
  .entity-item .tags { width:100%; }
  .filter-bar { flex-direction:column; }
  .filter-bar input, .filter-bar select { min-width:0; width:100%; }
  .skill-bar .skill-name { width:80px; }
  .btn, .btn-sm, .btn-icon { min-height:44px; }
  .map-container { min-height:250px; }
  .participant-row { flex-wrap:wrap; gap:4px; }
  .participant-row .name { min-width:120px; }
  .aspect-row {
    flex-direction: column;
    gap: 6px;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
    margin-bottom: 0;
  }
  .aspect-row:last-child { border-bottom: none; }
  .aspect-row-field {
    display: flex;
    gap: 6px;
    width: 100%;
  }
  .aspect-row-field select,
  .aspect-row-field input {
    flex: 1;
    min-width: 0;
  }
  .aspect-row-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-start;
  }
  .aspect-row-actions .btn-icon {
    padding: 8px 12px;
    font-size: 18px;
  }
  .image-upload-row {
    flex-direction: column;
    gap: 8px;
  }
  .image-upload-row input[type="text"] {
    width: 100%;
  }
  .roll-form {
    flex-direction: column;
    gap: 12px;
  }
  .roll-form-group,
  .roll-form-btn {
    flex: none;
    width: 100%;
    align-self: stretch;
    margin-bottom: 0;
  }
  .roll-form-btn .btn {
    width: 100%;
    justify-content: center;
  }
}

/* RELATION LABEL */
.relation-label {
  font-size: 12px;
  color: var(--text2);
  font-style: italic;
  margin-right: 4px;
}

/* RELATION GRAPH */
.relation-graph-container {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  position: relative;
}
.entity-graph-node:hover circle {
  filter: brightness(1.3);
}
.entity-graph-node text {
  pointer-events: none;
  user-select: none;
}
.edge-label {
  pointer-events: none;
  user-select: none;
}
.graph-legend {
  padding: 8px 16px;
  font-size: 13px;
  color: var(--text2);
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px;
}
.graph-legend-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  vertical-align: middle;
}

.edge-label-bg {
  pointer-events: none;
}

