/* Spectre — dark theme */

:root {
  --bg-primary: #141414;
  --bg-secondary: #1c1c1c;
  --bg-tertiary: #2a2a2a;
  --bg-input: #222222;
  --text-primary: #d4d4d4;
  --text-secondary: #999999;
  --text-muted: #5a5a5a;
  --accent: #4ade80;
  --accent-dim: #22c55e;
  --error: #ef4444;
  --success: #4ade80;
  --border: #333333;
  --mono: 'SF Mono', 'Monaco', 'Inconsolata', 'Fira Code', 'Consolas', monospace;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* Header */

#header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 1rem;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
}

#header h1 {
  font-size: 1.2rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--accent);
}

.status-indicator {
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--text-muted);
  padding: 0.2rem 0.5rem;
  border-radius: 3px;
  background: var(--bg-primary);
}

.status-indicator.connected {
  color: var(--success);
}

.status-indicator.error {
  color: var(--error);
}

/* Layout */

#layout {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* Sidebar */

#sidebar {
  width: 280px;
  min-width: 280px;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem;
  border-bottom: 1px solid var(--border);
}

.sidebar-header h2 {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}

#btn-add-room {
  width: 28px;
  height: 28px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  line-height: 1;
  border-radius: 50%;
  color: var(--text-muted);
  background: transparent;
  border: 1px solid var(--border);
}

#btn-add-room:hover {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--bg-tertiary);
}

/* Room list */

#room-list {
  flex: 1;
  overflow-y: auto;
  list-style: none;
  padding: 0.25rem 0;
}

#room-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0.75rem;
  cursor: pointer;
  font-size: 0.85rem;
  transition: background 0.15s;
}

#room-list li:hover {
  background: var(--bg-tertiary);
}

#room-list li.active {
  background: var(--bg-tertiary);
  border-left: 2px solid var(--accent);
}

.room-item-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.room-item-leave {
  opacity: 0;
  width: 20px;
  height: 20px;
  min-width: 20px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  line-height: 1;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: 3px;
  transition: opacity 0.15s, color 0.15s;
}

#room-list li:hover .room-item-leave {
  opacity: 1;
}

.room-item-leave:hover {
  color: var(--error) !important;
  background: rgba(239, 68, 68, 0.15) !important;
}

/* Forms & Inputs */

input[type="text"],
textarea {
  width: 100%;
  padding: 0.4rem 0.5rem;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 3px;
  color: var(--text-primary);
  font-family: var(--mono);
  font-size: 0.8rem;
  outline: none;
}

input[type="text"]:focus,
textarea:focus {
  border-color: var(--accent);
}

button {
  padding: 0.4rem 0.75rem;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 3px;
  color: var(--text-primary);
  font-size: 0.8rem;
  cursor: pointer;
  transition: background 0.15s;
}

button:hover {
  background: var(--accent-dim);
}

button:active {
  background: var(--accent);
}

.divider {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.7rem;
  margin: 0.4rem 0;
}

.info-row {
  margin-bottom: 0.4rem;
}

.info-row label {
  display: block;
  font-size: 0.7rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.15rem;
}

.info-row code {
  display: block;
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--accent);
  word-break: break-all;
}

.truncated {
  max-height: 2.5em;
  overflow: hidden;
  text-overflow: ellipsis;
}

.error-text {
  display: block;
  color: var(--error);
  font-size: 0.8rem;
  margin-bottom: 0.4rem;
}

.muted-text {
  color: var(--text-muted);
  font-size: 0.85rem;
}

/* Identity setup view (first run) */

#identity-setup {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1;
}

.centered-panel {
  max-width: 360px;
  width: 100%;
  padding: 2rem;
  text-align: center;
}

.centered-panel h2 {
  font-size: 1.4rem;
  font-weight: 600;
  color: var(--accent);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  margin-bottom: 0.5rem;
}

.centered-panel p {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-bottom: 1.5rem;
}

.centered-panel button {
  width: 100%;
  margin-bottom: 0.4rem;
}

.centered-panel input {
  margin-bottom: 0.4rem;
}

/* Create / Join page */

#create-join-page {
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow-y: auto;
}

.page-panel {
  max-width: 480px;
  width: 100%;
  margin: 0 auto;
  padding: 1.5rem;
}

.page-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
}

.page-panel-header h2 {
  font-size: 1rem;
  color: var(--text-primary);
}

.page-section {
  margin-bottom: 1rem;
}

.page-section h3 {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
}

.page-section input {
  margin-bottom: 0.5rem;
}

.page-section button {
  width: 100%;
  margin-bottom: 0.4rem;
}

.page-divider {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.75rem;
  margin: 1.5rem 0;
  position: relative;
}

.page-divider span {
  background: var(--bg-primary);
  padding: 0 0.75rem;
  position: relative;
  z-index: 1;
}

.page-divider::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 0;
  right: 0;
  border-top: 1px solid var(--border);
}

.join-divider {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.7rem;
  margin: 0.75rem 0;
}

/* Share code display */

#share-code-display {
  margin-top: 0.75rem;
  padding: 0.75rem;
  background: var(--bg-secondary);
  border-radius: 4px;
  border: 1px solid var(--border);
}

#share-code-display label {
  display: block;
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-bottom: 0.3rem;
}

#share-code-display textarea {
  font-size: 0.7rem;
  resize: none;
  margin-bottom: 0.4rem;
}

.share-actions {
  margin-bottom: 0.5rem;
}

.share-actions button {
  width: 100%;
}

#share-qr {
  text-align: center;
  margin-top: 0.5rem;
}

#share-qr canvas,
#share-qr img {
  border-radius: 4px;
}

/* QR Scanner */

#qr-scanner {
  margin-top: 0.75rem;
  text-align: center;
}

#qr-video {
  width: 100%;
  max-width: 300px;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: #000;
}

#qr-scanner-status {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin: 0.5rem 0;
}

#qr-scanner button {
  width: auto;
}

/* Main chat area */

#main-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#no-room-selected {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1;
  color: var(--text-muted);
  font-size: 0.9rem;
}

#chat-area {
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
}

#chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 1rem;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
}

#chat-room-name {
  font-family: var(--mono);
  font-size: 0.85rem;
  color: var(--accent);
}

#messages {
  flex: 1;
  overflow-y: auto;
  padding: 0.75rem 1rem;
}

.message {
  margin-bottom: 0.75rem;
  padding: 0.5rem;
  border-radius: 4px;
  background: var(--bg-secondary);
  border-left: 2px solid var(--border);
}

.message.own {
  border-left-color: var(--accent);
}

.message-header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 0.25rem;
}

.message-sender {
  font-family: var(--mono);
  font-size: 0.7rem;
  color: var(--accent);
}

.message-time {
  font-size: 0.7rem;
  color: var(--text-muted);
}

.message-body {
  font-size: 0.85rem;
  line-height: 1.4;
  color: var(--text-primary);
  word-wrap: break-word;
}

.message-error {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-style: italic;
}

/* Mining bar */

#mining-bar {
  position: relative;
  height: 28px;
  background: var(--bg-primary);
  border-top: 1px solid var(--border);
  overflow: hidden;
}

#mining-bar-fill {
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent-dim), var(--accent));
  opacity: 0.25;
  animation: mining-pulse 1.5s ease-in-out infinite;
}

#mining-bar-text {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--mono);
  font-size: 0.7rem;
  color: var(--accent);
  letter-spacing: 0.05em;
}

@keyframes mining-pulse {
  0% { width: 10%; opacity: 0.15; }
  50% { width: 90%; opacity: 0.3; }
  100% { width: 10%; opacity: 0.15; }
}

#mining-bar.mining-done #mining-bar-fill {
  width: 100%;
  opacity: 0.3;
  animation: none;
  transition: width 0.2s ease;
}

#mining-bar.mining-done #mining-bar-text {
  color: var(--text-primary);
}

/* Message form */

#message-form {
  display: flex;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  border-top: 1px solid var(--border);
  background: var(--bg-secondary);
}

#message-form input {
  flex: 1;
}

#message-form button {
  min-width: 60px;
}

/* Status bar */

#status-bar {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.3rem 1rem;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  font-family: var(--mono);
  font-size: 0.7rem;
  color: var(--text-muted);
}

.status-bar-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-left: auto;
}

.status-bar-right button {
  font-size: 0.7rem;
  padding: 0.2rem 0.5rem;
}

/* Identity strip (bottom-right in status bar) */

#identity-strip {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.identity-dot {
  color: var(--accent);
  font-size: 0.6rem;
}

#identity-fingerprint {
  font-family: var(--mono);
  font-size: 0.7rem;
  color: var(--accent);
  cursor: pointer;
}

#identity-fingerprint:hover {
  text-decoration: underline;
}

#identity-strip button {
  font-size: 0.65rem;
  padding: 0.15rem 0.4rem;
}

/* State panel */

#state-panel {
  position: fixed;
  bottom: 2rem;
  right: 1rem;
  width: 520px;
  max-height: 400px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow-y: auto;
  z-index: 100;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
}

#state-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--border);
}

#state-panel-header h3 {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

#state-diagrams {
  padding: 0.5rem 0.75rem;
}

.state-diagram {
  margin-bottom: 0.5rem;
}

.state-diagram h4 {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-bottom: 0.25rem;
}

.state-diagram svg {
  width: 100%;
  height: auto;
}

/* SVG state diagram styling */

.state-node {
  cursor: default;
}

.state-node circle {
  fill: #2a2a2a;
  stroke: #555;
  stroke-width: 1.5;
}

.state-node.active circle {
  fill: var(--accent);
  stroke: var(--accent);
  filter: drop-shadow(0 0 4px rgba(74, 222, 128, 0.3));
}

.state-node text {
  fill: #888;
  font-family: var(--mono);
  font-size: 9px;
  text-anchor: middle;
  dominant-baseline: central;
}

.state-node.active text {
  fill: #fff;
}

.state-arrow {
  stroke: #444;
  stroke-width: 1;
  fill: none;
  marker-end: url(#arrowhead);
}

/* Utility */

.hidden {
  display: none !important;
}

/* Scrollbar */

::-webkit-scrollbar {
  width: 6px;
}

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

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

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