:root {
  --bg: #15171c;
  --bg-header: #0d0e12;
  --surface: #1e2128;
  --surface-alt: #262a33;
  --border: #3a3f4a;
  --text: #e9e7e2;
  --text-muted: #9aa0ab;
  --accent: #ff4d4d;
  --accent-hover: #e63c3c;
  --error: #ff6b6b;
  --panel-white: #ffffff;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: 'Segoe UI', Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  background: var(--bg-header);
  border-bottom: 4px solid var(--accent);
}

.logo {
  color: var(--text);
  font-size: 1.5rem;
  font-weight: 800;
  text-decoration: none;
  letter-spacing: 1px;
}

.btn-primary,
.btn-secondary {
  display: inline-block;
  padding: 10px 18px;
  border-radius: 6px;
  border: 2px solid var(--border);
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  font-size: 0.95rem;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-primary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn-secondary {
  background: var(--surface);
  color: var(--text);
}

.board-page,
.editor-page {
  max-width: 1000px;
  margin: 0 auto;
  padding: 24px;
}

.thread-page {
  max-width: 1500px;
  margin: 0 auto;
  padding: 24px;
}

.tagline {
  color: var(--text-muted);
  margin-bottom: 24px;
}

.thread-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 20px;
}

.thread-card {
  position: relative;
  display: block;
  background: var(--surface);
  border: 3px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  text-decoration: none;
  color: inherit;
  transition: transform 0.1s ease;
}

.thread-card:hover {
  transform: translate(-2px, -2px);
}

.thread-thumb {
  width: 100%;
  aspect-ratio: 4 / 3;
  background: var(--surface-alt);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 0.85rem;
  overflow: hidden;
}

.thread-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.thread-meta {
  display: flex;
  justify-content: space-between;
  padding: 10px 12px;
  font-size: 0.8rem;
  border-top: 3px solid var(--border);
  background: var(--surface-alt);
}

.thread-page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  gap: 16px;
  flex-wrap: wrap;
}

.panel-strip {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}

@media (max-width: 700px) {
  .panel-strip {
    grid-template-columns: repeat(2, 1fr);
  }
}

.panel-frame {
  position: relative;
  background: var(--panel-white);
  border: 1px solid var(--border);
  overflow: hidden;
  aspect-ratio: 4 / 3;
  cursor: pointer;
}

.panel-frame img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.panel-number {
  position: absolute;
  top: 6px;
  left: 6px;
  background: #1a1a1a;
  color: #fff;
  font-weight: 700;
  font-size: 0.7rem;
  padding: 1px 6px;
  border-radius: 3px;
}

.back-link {
  display: inline-block;
  margin-top: 24px;
  color: var(--text);
  text-decoration: none;
  font-weight: 600;
}

.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 24px;
  z-index: 1000;
}

.lightbox[hidden] {
  display: none;
}

.lightbox-img {
  max-width: 90vw;
  max-height: 78vh;
  object-fit: contain;
  border: 3px solid var(--border);
  background: var(--panel-white);
}

.lightbox-close {
  position: absolute;
  top: 16px;
  right: 24px;
  background: none;
  border: none;
  color: #fff;
  font-size: 2rem;
  line-height: 1;
  cursor: pointer;
}

.editor-layout {
  display: flex;
  gap: 20px;
  align-items: flex-start;
  flex-wrap: wrap;
}

.prev-panel {
  border: 3px solid var(--border);
  border-radius: 6px;
  padding: 8px;
  background: var(--surface);
  max-width: 200px;
}

.prev-label {
  margin: 0 0 6px;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-muted);
}

.prev-panel img {
  width: 100%;
  display: block;
  border-radius: 4px;
}

.canvas-wrap {
  border: 4px solid var(--border);
  border-radius: 6px;
  display: inline-block;
  box-shadow: 6px 6px 0 var(--accent);
}

#paintCanvas {
  display: block;
  background: var(--panel-white);
  cursor: crosshair;
  touch-action: none;
  max-width: 100%;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 14px;
  margin: 20px 0;
  flex-wrap: wrap;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: 8px;
  padding: 12px 16px;
}

.tool-btn {
  padding: 8px 14px;
  border: 2px solid var(--border);
  border-radius: 6px;
  background: var(--surface-alt);
  color: var(--text);
  cursor: pointer;
  font-weight: 600;
}

.tool-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.tool-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
}

.actions {
  display: flex;
  gap: 12px;
  align-items: center;
}

.status-msg {
  margin-top: 10px;
  font-size: 0.9rem;
  color: var(--error);
}

.admin-link {
  position: fixed;
  bottom: 8px;
  right: 10px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.7rem;
  opacity: 0.45;
  cursor: pointer;
  padding: 4px 6px;
  z-index: 500;
}

.admin-link:hover {
  opacity: 1;
}

.delete-btn {
  display: none;
}

body.admin-mode .delete-btn {
  display: inline-block;
}

.thread-delete-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 3px;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 3px 8px;
  cursor: pointer;
  z-index: 5;
}

.panel-delete-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 3px;
  font-size: 0.65rem;
  font-weight: 700;
  padding: 2px 6px;
  cursor: pointer;
}

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