:root {
  --bg: #1a1a1a;
  --surface: #252525;
  --surface-2: #2e2e2e;
  --border: #3a3a3a;
  --border-strong: #4a4a4a;
  --text: #e6e6e6;
  --muted: #888;
  --accent: #4a90e2;
  --accent-hover: #5ba0f2;
  --danger: #ff6b6b;
  --warning-bg: #4a3010;
  --warning-border: #b87b30;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 15px;
  line-height: 1.5;
}

.hidden { display: none !important; }
.error { color: var(--danger); margin: 0.5rem 0 0 0; font-size: 0.9rem; }
.muted { color: var(--muted); font-size: 0.9rem; }

/* --- Login --- */
#login {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 1rem;
}
#login form {
  background: var(--surface);
  padding: 2rem;
  border-radius: 8px;
  max-width: 380px;
  width: 100%;
  border: 1px solid var(--border);
}
#login h1 {
  margin: 0 0 1.25rem 0;
  font-size: 1.5rem;
  font-weight: 600;
}
#login input {
  width: 100%;
  padding: 0.75rem;
  margin-bottom: 0.75rem;
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  color: var(--text);
  font-size: 1rem;
}
#login input:focus {
  outline: none;
  border-color: var(--accent);
}
#login button {
  width: 100%;
  padding: 0.75rem;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 6px;
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
}
#login button:hover { background: var(--accent-hover); }

/* --- App layout --- */
#app {
  max-width: 960px;
  margin: 0 auto;
  padding: 1.25rem;
}
#app > header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 1rem;
  flex-wrap: wrap;
  gap: 0.5rem;
}
#app h1 {
  margin: 0;
  font-size: 1.4rem;
  font-weight: 600;
}
#status {
  font-size: 0.85rem;
  color: var(--muted);
  display: flex;
  gap: 1rem;
  align-items: baseline;
}
#save-status:not(:empty)::before { content: '· '; color: var(--muted); }
#save-status:empty { display: none; }

/* --- Text section --- */
.text-section { margin-bottom: 2rem; }
#text {
  width: 100%;
  min-height: 240px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 0.85rem;
  font-size: 0.95rem;
  font-family: 'SF Mono', Menlo, Consolas, 'Liberation Mono', monospace;
  line-height: 1.55;
  resize: vertical;
}
#text:focus {
  outline: none;
  border-color: var(--accent);
}

.conflict {
  background: var(--warning-bg);
  border: 1px solid var(--warning-border);
  padding: 0.5rem 0.75rem;
  border-radius: 6px;
  margin-top: 0.5rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
}
.conflict button {
  background: var(--warning-border);
  color: white;
  border: none;
  padding: 0.3rem 0.75rem;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.85rem;
}
.conflict button.ghost {
  background: transparent;
  border: 1px solid var(--warning-border);
  color: var(--warning-border);
}

.text-actions {
  margin-top: 0.5rem;
  display: flex;
  justify-content: flex-end;
}

button.ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border-strong);
  padding: 0.3rem 0.75rem;
  border-radius: 4px;
  font-size: 0.85rem;
  cursor: pointer;
}
button.ghost:hover { background: var(--surface); color: var(--text); }

/* --- Images section --- */
.images-section { margin-top: 1rem; }
.images-section > header { margin-bottom: 0.5rem; }
.images-section h2 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
}
.images-section > header p { margin: 0.25rem 0 0 0; }

#images {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 0.75rem;
  margin-top: 0.75rem;
}
.image-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.image-card a {
  display: block;
  background: var(--bg);
}
.image-card img {
  width: 100%;
  height: 150px;
  object-fit: contain;
  display: block;
}
.image-actions {
  display: flex;
  gap: 0.25rem;
  padding: 0.4rem;
  background: var(--surface-2);
}
.image-actions button {
  flex: 1;
  padding: 0.3rem 0.4rem;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.8rem;
}
.image-actions button:hover { background: var(--border); }
.image-actions button.danger { color: var(--danger); }
.image-actions button.danger:hover { background: #3a1818; }

/* --- Toast --- */
#toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  color: var(--text);
  padding: 0.5rem 1rem;
  border-radius: 6px;
  font-size: 0.9rem;
  box-shadow: 0 4px 12px rgba(0,0,0,0.4);
  z-index: 100;
}
#toast.error { color: var(--danger); }
