
/* =========================================
   Visual Editor Theme
   ========================================= */

:root {
  --bg-page: #1e1e1e;
  --bg-panel: #2a2a2a;
  --bg-panel-alt: #252525;
  --bg-input: #1e1e1e;
  --bg-button: #333333;
  --bg-button-hover: #444444;
  --bg-selected: #3a3a3a;

  --text-main: #e0e0e0;
  --text-heading: #dddddd;
  --text-muted: #bdbdbd;
  --text-subtle: #a0a0a0;

  --border-soft: #3a3a3a;
  --border-medium: #444444;
  --border-strong: #555555;

  --accent: #8b5cf6;
  --accent-text: #bfa9ff;
  --accent-soft: rgba(139, 92, 246, 0.08);
  --accent-soft-strong: rgba(139, 92, 246, 0.16);
  --border-accent: rgba(139, 92, 246, 0.55);

  --danger: #e07a7a;
  --group: #cfacff;

  --chip-bg: #34343a;
  --chip-border: #5a5a65;

  --scroll-thumb: #555555;
  --scroll-thumb-hover: #777777;
  --scroll-track: #252525;

  --shadow-panel: 0 2px 8px rgba(0, 0, 0, 0.35);

  --grid: rgba(189, 189, 189, 0.12);
}

/* Light mode */

body[data-theme="light"] {
  --bg-page: #f4f4f5;
  --bg-panel: #ffffff;
  --bg-panel-alt: #f8f8fa;
  --bg-input: #ffffff;
  --bg-button: #f4f4f5;
  --bg-button-hover: #e9e9ec;
  --bg-selected: #ececf0;

  --text-main: #242428;
  --text-heading: #18181b;
  --text-muted: #4b4b55;
  --text-subtle: #686874;

  --border-soft: #d6d6dc;
  --border-medium: #c4c4cc;
  --border-strong: #a8a8b3;

  --accent: #4f3fb8;
  --accent-text: #31226f;
  --accent-soft: #e6e0ff;
  --accent-soft-strong: #d4c9ff;
  --border-accent: #6d5bd6;

  --danger: #a33a3a;
  --group: #8f56cc;

  --chip-bg: #f3f0ff;
  --chip-border: #cbc4f2;

  --scroll-thumb: #b8b8c2;
  --scroll-thumb-hover: #9999a6;
  --scroll-track: #f1f1f3;

  --shadow-panel: 0 2px 8px rgba(0, 0, 0, 0.08);

  --grid: rgba(90, 72, 200, 0.12);
}

/* =========================================
   General Layout
   ========================================= */

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: system-ui, sans-serif;
  background: var(--bg-page);
  color: var(--text-main);
  padding: 1rem;
}

.app {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

/* =========================================
   Header and Controls
   ========================================= */

.header {
  background: var(--bg-panel);
  border: 1px solid var(--border-soft);
  border-radius: 8px;
  padding: 1rem;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.75rem;
}

button {
  padding: 0.55rem 0.75rem;
  font-family: inherit;
  font-size: 0.9rem;

  background: var(--bg-button);
  color: var(--text-main);

  border: 1px solid var(--border-medium);
  border-radius: 6px;

  cursor: pointer;
  transition:
    background 0.2s ease,
    border-color 0.2s ease;
}

button:hover:not(:disabled) {
  background: var(--bg-button-hover);
  border-color: var(--border-accent);
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

input {
  padding: 0.55rem 0.65rem;
  font-family: inherit;
  font-size: 0.9rem;

  background: var(--bg-input);
  color: var(--text-main);

  border: 1px solid var(--border-medium);
  border-radius: 6px;
}

input:focus,
button:focus-visible {
  outline: none;
  border-color: var(--border-accent);
  box-shadow: 0 0 0 2px var(--accent-soft);
}

.hint {
  margin: 0;
  color: var(--text-subtle);
  font-size: 0.85rem;
  line-height: 1.5;
}

#status {
  min-height: 1.2rem;
  margin-top: 0.5rem;
  color: var(--text-muted);
  font-size: 0.85rem;
}

#status.error {
    color: var(--danger);
    font-weight: 500;
}

/* =========================================
   Editor Layout
   ========================================= */

.layout {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr);
  gap: 1rem;
  align-items: start;
}

.sidebar-stack {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  min-width: 0;
}

/* =========================================
   Drawing Board
   ========================================= */

.board-wrap {
  background: var(--bg-panel);
  border: 1px solid var(--border-soft);
  border-radius: 8px;
  overflow: hidden;
  min-width: 0;
}

#board {
  position: relative;
  width: 100%;
  height: 1100px;
  min-height: 1100px;

  background:
    linear-gradient(
      to right,
      var(--grid) 1px,
      transparent 1px
    ) 0 0 / 32px 32px,

    linear-gradient(
      to bottom,
      var(--grid) 1px,
      transparent 1px
    ) 0 0 / 32px 32px,

    var(--bg-page);
}

/* =========================================
   Monomer Rectangles
   ========================================= */

.base-rect {
  position: absolute;

  display: flex;
  justify-content: flex-start;
  align-items: flex-start;
  align-content: flex-start;
  flex-wrap: wrap;

  gap: 4px;
  padding: 4px 26px 4px 4px;

  background: var(--bg-panel);
  border: 2px solid var(--border-strong);
  border-radius: 8px;

  cursor: grab;
  user-select: none;

  box-shadow: var(--shadow-panel);

  transition:
    border-color 0.1s ease,
    box-shadow 0.1s ease;
}

.base-rect:not(.editing) {
    display: grid;
    grid-template-columns: repeat(3, max-content);
    grid-auto-rows: max-content;
    align-content: start;
    justify-content: start;
}

.base-rect.selected {
  border-color: var(--accent);
  box-shadow:
    0 0 0 3px var(--accent-soft-strong);
}

.base-rect.dragging {
  cursor: grabbing;
  z-index: 1000;
}

.base-rect.invalid {
  border-color: var(--danger);
  box-shadow: 0 0 0 3px rgba(224, 122, 122, 0.2);
}

/* =========================================
   Grouped Rectangles
   ========================================= */

.group-box {
  position: absolute;

  border: 2px dashed var(--group);
  border-radius: 10px;

  background: var(--accent-soft);

  cursor: pointer;
  pointer-events: auto;
}

.group-box.selected {
  border-style: solid;
  box-shadow:
    0 0 0 3px var(--accent-soft-strong);
}

.group-box.dragging {
  cursor: grabbing;
}

.group-box.invalid {
  border-color: var(--danger);
}

.group-tag {
  position: absolute;
  top: -1.1rem;
  left: 4px;

  padding: 2px 6px;

  border-radius: 999px;
  background: var(--group);
  color: #1f1f24;

  font-size: 0.8rem;
  font-weight: 600;
}

/* =========================================
   Domain Labels
   ========================================= */

.label-chip {
    display: inline-flex;
    align-items: center;
    justify-content: center;

    min-width: 1.2rem;
    min-height: 1.2rem;

    padding: 0 2px;

    background: var(--chip-bg);
    border: 1px solid var(--chip-border);
    border-radius: 5px;

    color: var(--text-main);
    font-size: 0.9rem;
    font-weight: 700;
    line-height: 1.2rem;
    text-align: center;
    white-space: nowrap;
}

.domain-display {
    display: inline-flex;
    align-items: baseline;
    white-space: nowrap;
}

.domain-display sub {
    font-size: 0.7em;
    line-height: 1;
    position: relative;
    bottom: -0.25em;
}

.monomer-name-label sub {
    font-size: 0.75em;
    line-height: 0;
    vertical-align: -0.3em;
}

.label-chip.lowercase-display,
.label-letter-overline,
.score-letter-negative,
.score-main-overline {
  text-decoration-line: overline;
  text-decoration-thickness: 2px;
  text-decoration-skip-ink: none;
}

.label-count {
    margin-left: 4px;
    font-size: 0.8em;
    font-weight: 500;
    white-space: nowrap;
    position: relative;
    top: -0.25em;
}

.label-subscript {
  font-size: 0.72em;
  margin-left: 1px;
  vertical-align: sub;
  line-height: 1;
}

/* =========================================
   Side Panels
   ========================================= */

.panel {
  min-width: 0;

  padding: 1rem;

  background: var(--bg-panel);
  border: 1px solid var(--border-soft);
  border-radius: 8px;

  box-shadow: var(--shadow-panel);
}

.sidepanel {
  max-height: 530px;
  overflow: auto;
}

.panel h2 {
  margin: 0 0 0.5rem;

  color: var(--text-heading);
  font-size: 1.05rem;
  font-weight: 600;
}

.config-text {
  margin: 0.75rem 0 1.5rem;
  padding: 0.75rem;

  min-height: 90px;

  background: var(--bg-input);
  border: 1px solid var(--border-soft);
  border-radius: 6px;

  color: var(--text-main);
  font-family: monospace;
  font-size: 0.85rem;
  line-height: 1.5;

  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

/* =========================================
   Group Information Tables
   ========================================= */

.group-table-block {
  margin-bottom: 1rem;

  border: 1px solid var(--border-soft);
  border-radius: 8px;
  overflow: hidden;
}

.group-table-title {
  margin: 0;
  padding: 0.6rem;

  background: var(--bg-panel-alt);
  border-bottom: 1px solid var(--border-soft);

  font-size: 0.95rem;
  color: var(--text-heading);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

th,
td {
  padding: 0.5rem;
  border-bottom: 1px solid var(--border-soft);
  text-align: left;
}

th {
  position: sticky;
  top: 0;

  background: var(--bg-panel-alt);
  color: var(--text-heading);
}

.empty-msg {
  margin: 0.5rem 0;
  color: var(--text-subtle);
  font-size: 0.85rem;
}

/* =========================================
   Thin Scrollbars
   ========================================= */

html,
body,
.sidepanel,
.panel,
.config-text {
  scrollbar-width: thin;
  scrollbar-color:
    var(--scroll-thumb) var(--scroll-track);
}

::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: var(--scroll-track);
}

::-webkit-scrollbar-thumb {
  background: var(--scroll-thumb);
  border-radius: 999px;
  border: 2px solid var(--scroll-track);
}

::-webkit-scrollbar-thumb:hover {
  background: var(--scroll-thumb-hover);
}

/* =========================================
   Responsive Layout
   ========================================= */

@media (max-width: 900px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .sidepanel {
    max-height: none;
  }

  #board {
    min-height: 960px;
    height: 960px;
  }
}

@media (max-width: 600px) {
  body {
    padding: 0.5rem;
  }

  .header,
  .panel {
    padding: 0.75rem;
  }

  .controls {
    gap: 0.4rem;
  }

  button {
    font-size: 0.8rem;
  }
}

/* Monomer name edit */

.monomer-edit-menu {
    position: fixed;
    z-index: 10000;

    display: flex;
    flex-direction: column;
    gap: 2px;

    min-width: 130px;
    padding: 4px;

    background: var(--bg-panel);
    border: 1px solid var(--border-medium);
    border-radius: 6px;
    box-shadow: var(--shadow-panel);
}

.monomer-edit-menu button {
    padding: 6px 10px;
    font-size: 0.8rem;
    text-align: left;
    border: none;
    background: transparent;
    color: var(--text-main);
}

.monomer-edit-menu button:hover {
    background: var(--bg-selected);
}

.monomer-name-label {
    position: absolute;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    pointer-events: none;
    white-space: nowrap;
}


/* Monomer edit pencil */

.monomer-edit-btn {
    position: absolute;
    top: 5px;
    right: 5px;

    display: flex;
    align-items: center;
    justify-content: center;

    width: 18px;
    height: 18px;
    padding: 2px;

    background: transparent;
    border: none;
    border-radius: 4px;

    color: var(--text-muted);
    opacity: 0;

    cursor: pointer;
    z-index: 2;
}

.monomer-edit-btn svg {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
    pointer-events: none;
}

.monomer-edit-btn:hover {
    background: var(--bg-button-hover);
    color: var(--accent-text);
    opacity: 1;
}

.base-rect:hover .monomer-edit-btn,
.monomer-edit-btn:focus-visible {
    opacity: 1;
}