/* styles.css — Goal Map Mandal-Art Editor */

/* ── Reset & Base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg-page:      #0f0f1a;
  --bg-panel:     #1a1a2e;
  --bg-toolbar:   #141428;
  --bg-cell:      #1e1e36;
  --bg-center-block: #1a2a3a;
  --bg-cell-theme:   #1a3a5a;
  --bg-cell-center:  #3a1a5a;
  --bg-cell-hover:   #2a2a50;
  --border:       #2a2a4a;
  --border-focus: #5a7aff;
  --text:         #e8e8f0;
  --text-dim:     #888;
  --text-label:   #aab;
  --accent:       #5a7aff;
  --accent-dark:  #3a5adc;
  --danger:       #c0392b;
  --success:      #27ae60;
  --warn:         #e67e22;
  --tag-draft:    #555;
  --tag-reviewed: #27ae60;
  --tag-baseline: #2980b9;
  --tag-superseded: #7f8c8d;
  --font-mono:    'Courier New', monospace;
  --radius:       4px;
  --transition:   160ms ease;
}

html, body {
  height: 100%;
  font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
  background: var(--bg-page);
  color: var(--text);
  font-size: 14px;
  line-height: 1.4;
  overflow-x: hidden;
}

/* ── Layout ── */
#app { display: flex; flex-direction: column; height: 100vh; }

/* ── Toolbar ── */
#toolbar {
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
  padding: 8px 12px;
  background: var(--bg-toolbar);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  min-height: 44px;
}

#toolbar .brand {
  font-weight: 700; font-size: 1rem; color: var(--accent);
  margin-right: 8px; white-space: nowrap;
}

#toolbar .sep { width: 1px; height: 20px; background: var(--border); margin: 0 2px; }

/* ── Map Selector ── */
#map-selector-wrap { display: flex; align-items: center; gap: 6px; }
#map-select {
  background: var(--bg-panel); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 4px 8px; font-size: 13px; max-width: 200px;
  cursor: pointer;
}
#map-select:focus { outline: 2px solid var(--border-focus); }

/* ── Buttons ── */
.btn {
  background: var(--bg-panel); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 4px 10px; font-size: 12px; cursor: pointer;
  white-space: nowrap; transition: background var(--transition), border-color var(--transition);
  line-height: 1.4;
}
.btn:hover  { background: var(--bg-cell-hover); border-color: var(--accent); }
.btn:focus  { outline: 2px solid var(--border-focus); }
.btn-primary { background: var(--accent); border-color: var(--accent-dark); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); }
.btn-danger  { color: var(--danger); border-color: var(--danger); }
.btn-danger:hover { background: rgba(192,57,43,.15); }
.btn-sm { padding: 3px 7px; font-size: 11px; }

/* ── Main Content Area ── */
#main {
  display: flex; flex: 1; overflow: hidden;
}

/* ── Side Panel ── */
#side-panel {
  width: 220px; min-width: 180px;
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  overflow-y: auto; flex-shrink: 0;
}

#side-panel h3 {
  font-size: 11px; text-transform: uppercase; letter-spacing: .08em;
  color: var(--text-dim); padding: 12px 12px 6px;
}

#map-list { list-style: none; flex: 1; overflow-y: auto; }
#map-list li {
  padding: 7px 12px; cursor: pointer; font-size: 12px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 6px;
  transition: background var(--transition);
}
#map-list li:hover    { background: var(--bg-cell-hover); }
#map-list li.active   { background: rgba(90,122,255,.15); border-left: 3px solid var(--accent); }
#map-list li .map-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#map-list li .tag { font-size: 10px; padding: 1px 5px; border-radius: 3px; flex-shrink: 0; }

.tag-Draft       { background: var(--tag-draft); color: #ccc; }
.tag-Human-Reviewed { background: var(--tag-reviewed); color: #fff; }
.tag-Baseline    { background: var(--tag-baseline); color: #fff; }
.tag-Superseded  { background: var(--tag-superseded); color: #fff; }

/* ── Editor Area ── */
#editor-area {
  flex: 1; display: flex; flex-direction: column;
  overflow: auto; padding: 12px;
  background: var(--bg-page);
}

/* ── Map Header ── */
#map-header {
  display: flex; align-items: baseline; gap: 10px; margin-bottom: 10px; flex-wrap: wrap;
}
#map-title-display {
  font-size: 1.1rem; font-weight: 700; cursor: pointer;
  color: var(--text); border-bottom: 1px dashed var(--border);
  padding-bottom: 2px;
}
#map-title-display:hover { border-color: var(--accent); }

.review-badge {
  font-size: 11px; padding: 2px 8px; border-radius: 10px; font-weight: 600;
}

#parent-nav {
  font-size: 12px; color: var(--accent); cursor: pointer;
  text-decoration: underline;
}
#parent-nav:hover { color: #fff; }

/* ── Mandal-Art 9×9 Grid ── */
#grid-container {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  grid-template-rows:    repeat(9, 1fr);
  gap: 2px;
  width: min(calc(100vh - 120px), 100%);
  aspect-ratio: 1 / 1;
  max-width: 720px;
  margin: 0 auto;
}

.cell {
  background: var(--bg-cell);
  border: 1px solid var(--border);
  border-radius: 2px;
  display: flex; align-items: center; justify-content: center;
  text-align: center;
  font-size: clamp(8px, 1.1vw, 12px);
  word-break: break-word;
  overflow: hidden;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition);
  line-height: 1.2;
  padding: 2px;
  position: relative;
}

.cell:hover { background: var(--bg-cell-hover); border-color: var(--border-focus); }
.cell:focus { outline: 2px solid var(--border-focus); z-index: 2; }

/* Center block (block 4) */
.cell[data-block="4"] { background: var(--bg-center-block); }

/* Theme cells (center of each outer block) */
.cell[data-type="theme"] { background: var(--bg-cell-theme); font-weight: 700; color: #c8e0ff; }
.cell[data-type="theme"][data-block="4"] { background: #1a2a4a; }

/* Absolute center */
.cell[data-type="center"] {
  background: var(--bg-cell-center);
  font-weight: 900; font-size: clamp(9px, 1.3vw, 14px);
  color: #e8c8ff;
}

/* Confirmed cells */
.cell.confirmed::after {
  content: '✓';
  position: absolute; top: 1px; right: 2px;
  font-size: 8px; color: var(--success); opacity: .8;
}

/* Child map indicator */
.cell.has-child::before {
  content: '↗';
  position: absolute; bottom: 1px; right: 2px;
  font-size: 8px; color: var(--warn); opacity: .9;
}

/* Inline textarea editor */
.cell-editor {
  width: 100%; height: 100%; background: transparent;
  border: none; resize: none; font: inherit; color: var(--text);
  text-align: center; padding: 2px;
  outline: none; line-height: 1.2;
}

/* ── Metadata Panel (below grid) ── */
#meta-panel {
  margin-top: 16px; padding: 12px;
  background: var(--bg-panel); border: 1px solid var(--border);
  border-radius: var(--radius); max-width: 720px; margin-left: auto; margin-right: auto;
  width: 100%;
}

#meta-panel h3 { font-size: 12px; color: var(--text-dim); margin-bottom: 10px; text-transform: uppercase; letter-spacing: .07em; }

.meta-row {
  display: flex; align-items: flex-start; gap: 8px; margin-bottom: 8px; flex-wrap: wrap;
}
.meta-label { font-size: 11px; color: var(--text-label); min-width: 110px; padding-top: 4px; }
.meta-input {
  flex: 1; min-width: 120px;
  background: var(--bg-cell); border: 1px solid var(--border); border-radius: var(--radius);
  color: var(--text); padding: 4px 8px; font-size: 12px;
  transition: border-color var(--transition);
}
.meta-input:focus { outline: none; border-color: var(--border-focus); }
select.meta-input { cursor: pointer; }

/* ── Modal Overlay ── */
#modal-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,.6); z-index: 100;
  align-items: center; justify-content: center;
}
#modal-overlay.open { display: flex; }

#modal-box {
  background: var(--bg-panel); border: 1px solid var(--border);
  border-radius: 6px; padding: 20px; min-width: 320px; max-width: 480px;
  width: 90%;
}
#modal-box h2 { font-size: 1rem; margin-bottom: 12px; }

#modal-input {
  width: 100%; background: var(--bg-cell);
  border: 1px solid var(--border); border-radius: var(--radius);
  color: var(--text); padding: 8px; font-size: 13px; margin-bottom: 12px;
}
#modal-input:focus { outline: 2px solid var(--border-focus); }

#modal-textarea {
  width: 100%; background: var(--bg-cell);
  border: 1px solid var(--border); border-radius: var(--radius);
  color: var(--text); padding: 8px; font-size: 12px; margin-bottom: 12px;
  font-family: var(--font-mono); min-height: 180px; resize: vertical;
}
#modal-textarea:focus { outline: 2px solid var(--border-focus); }

.modal-actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
#modal-error { color: var(--danger); font-size: 12px; margin-bottom: 8px; display: none; }

/* ── Toast / Flash ── */
#toast {
  position: fixed; bottom: 20px; right: 20px; z-index: 200;
  background: var(--bg-panel); border: 1px solid var(--border);
  padding: 10px 16px; border-radius: 6px; font-size: 13px;
  opacity: 0; transition: opacity .2s;
  pointer-events: none; max-width: 300px;
}
#toast.show { opacity: 1; }
#toast.toast-error { border-color: var(--danger); color: var(--danger); }
#toast.toast-ok    { border-color: var(--success); color: var(--success); }

/* ── Empty state ── */
#empty-state {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 16px;
  color: var(--text-dim); text-align: center; padding: 40px;
}
#empty-state h2 { font-size: 1.2rem; color: var(--text); }
#empty-state p  { font-size: 13px; }

/* ── Responsive ── */
@media (max-width: 700px) {
  #side-panel { width: 140px; min-width: 120px; }
  #map-list li { padding: 6px 8px; }
  #grid-container { gap: 1px; max-width: 100%; }
  .cell { font-size: clamp(7px, 2.5vw, 10px); }
  #toolbar { gap: 4px; padding: 6px 8px; }
  .btn { padding: 3px 7px; font-size: 11px; }
}

@media (max-width: 480px) {
  #main { flex-direction: column; }
  #side-panel { width: 100%; height: auto; max-height: 140px; border-right: none; border-bottom: 1px solid var(--border); }
  #map-list { display: flex; flex-wrap: wrap; padding: 4px; gap: 4px; }
  #map-list li { border: 1px solid var(--border); border-radius: 4px; padding: 4px 8px; font-size: 11px; }
  #editor-area { padding: 8px; }
}
