:root {
  --bg: #e8eef4;
  --bg-accent: #d4e4f0;
  --ink: #1a2b3c;
  --muted: #5a6f82;
  --line: #b8c9d8;
  --panel: rgba(255, 255, 255, 0.82);
  --accent: #0d6e6e;
  --accent-hover: #0a5757;
  --danger: #b33a3a;
  --shadow: 0 12px 40px rgba(26, 43, 60, 0.1);
  --radius: 14px;
  --font-display: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  --font-body: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font-body);
  color: var(--ink);
  background:
    radial-gradient(1200px 600px at 10% -10%, #c8dde9 0%, transparent 55%),
    radial-gradient(900px 500px at 100% 0%, #d7ebe4 0%, transparent 50%),
    linear-gradient(165deg, var(--bg), var(--bg-accent));
}

button, input, select { font: inherit; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 28px;
  border-bottom: 1px solid rgba(184, 201, 216, 0.7);
  backdrop-filter: blur(8px);
  background: rgba(255,255,255,0.55);
}

.brand {
  font-family: var(--font-display);
  font-size: 1.45rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  margin: 0;
  color: var(--ink);
}

.brand span { color: var(--accent); }

.room-meta {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: 0.95rem;
}

.room-code {
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.12em;
  font-size: 1.05rem;
}

.layout {
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: 20px;
  padding: 20px 28px 40px;
  max-width: 1400px;
  margin: 0 auto;
}

.panel {
  background: var(--panel);
  border: 1px solid rgba(184, 201, 216, 0.65);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
}

.panel h2 {
  margin: 0 0 12px;
  font-size: 1rem;
  font-weight: 650;
}

.qr-box {
  text-align: center;
  padding: 8px 0 4px;
}

.qr-box img {
  width: 220px;
  height: 220px;
  border-radius: 10px;
  background: #fff;
  border: 1px solid var(--line);
}

.hint {
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.5;
  margin: 10px 0 0;
}

.url-list {
  margin-top: 12px;
  display: grid;
  gap: 6px;
}

.public-url-tag {
  font-size: 0.82rem;
  color: var(--accent);
  font-weight: 650;
  word-break: break-all;
  padding: 4px 2px 2px;
}

.url-list button {
  text-align: left;
  border: 1px dashed var(--line);
  background: #f7fafc;
  color: var(--muted);
  border-radius: 8px;
  padding: 8px 10px;
  cursor: pointer;
  word-break: break-all;
  font-size: 0.78rem;
}

.url-list button:hover { border-color: var(--accent); color: var(--ink); }
.url-list button.active-url {
  border-style: solid;
  border-color: var(--accent);
  color: var(--ink);
  background: #e8f4f4;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-bottom: 14px;
}

.toolbar label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 0.92rem;
}

.toolbar select {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 10px;
  background: #fff;
}

.btn {
  border: none;
  border-radius: 9px;
  padding: 9px 16px;
  cursor: pointer;
  font-weight: 600;
  transition: transform .12s ease, background .15s ease;
}

.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-ghost { background: #eef4f8; color: var(--ink); }
.btn-ghost:hover { background: #e2ebf2; }
.btn-danger { background: #f6e8e8; color: var(--danger); }
.btn-danger:hover { background: #efd6d6; }

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  display: inline-block;
  background: #c4a24a;
}
.status-dot.on { background: #2f9e6b; }

.thumbs {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
  min-height: 120px;
}

.thumb {
  position: relative;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  cursor: grab;
  user-select: none;
  transition: box-shadow .15s ease, transform .15s ease;
}

.thumb:active { cursor: grabbing; }
.thumb.dragging { opacity: 0.55; transform: scale(0.98); }
.thumb.drag-over { outline: 2px solid var(--accent); }

.thumb img {
  width: 100%;
  height: 120px;
  object-fit: cover;
  display: block;
  pointer-events: none;
}

.thumb .del {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 50%;
  background: rgba(26, 43, 60, 0.72);
  color: #fff;
  cursor: pointer;
  font-size: 1.05rem;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  z-index: 2;
  transition: background .15s ease, transform .12s ease;
}

.thumb .del:hover {
  background: var(--danger);
  transform: scale(1.06);
}

.thumb .meta {
  padding: 7px 10px;
  font-size: 0.75rem;
  color: var(--muted);
}

.thumb .meta span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.empty {
  grid-column: 1 / -1;
  text-align: center;
  color: var(--muted);
  padding: 48px 12px;
  border: 1px dashed var(--line);
  border-radius: 12px;
  background: rgba(255,255,255,0.45);
}

.print-preview {
  margin-top: 18px;
}

.print-preview h2 { margin-bottom: 10px; }

.pages {
  display: grid;
  gap: 16px;
}

.a4-page {
  width: min(100%, 794px);
  aspect-ratio: 210 / 297;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 4px;
  box-shadow: var(--shadow);
  margin: 0 auto;
  padding: 18px;
  display: grid;
  gap: 8px;
  overflow: hidden;
}

.a4-page.layout-1 { grid-template-columns: 1fr; grid-template-rows: 1fr; }
.a4-page.layout-2 { grid-template-columns: 1fr; grid-template-rows: 1fr 1fr; }
.a4-page.layout-3 { grid-template-columns: 1fr; grid-template-rows: 1fr 1fr 1fr; }
.a4-page.layout-4 { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; }
.a4-page.layout-5 {
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1.2fr 1fr 1fr;
}
.a4-page.layout-5 .cell:first-child { grid-column: 1 / -1; }
.a4-page.layout-6 { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr 1fr; }

.a4-page .cell {
  border: 1px dashed #d5dee6;
  border-radius: 4px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #fafcfd;
}

.a4-page .cell img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  display: block;
}

@media print {
  @page { size: A4; margin: 8mm; }

  body * { visibility: hidden !important; }
  #print-root, #print-root * { visibility: visible !important; }

  .topbar, .sidebar, .toolbar, .thumbs-wrap, .no-print { display: none !important; }

  body {
    background: #fff !important;
  }

  #print-root {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    margin: 0;
    padding: 0;
  }

  .pages { gap: 0; }

  .a4-page {
    width: 100%;
    height: 100vh;
    aspect-ratio: auto;
    box-shadow: none;
    border: none;
    border-radius: 0;
    page-break-after: always;
    break-after: page;
    margin: 0;
    padding: 0;
  }

  .a4-page:last-child {
    page-break-after: auto;
    break-after: auto;
  }

  .a4-page .cell { border: none; background: transparent; }
}

@media (max-width: 960px) {
  .layout { grid-template-columns: 1fr; padding: 14px; }
  .topbar { padding: 14px; }
}

.site-footer {
  text-align: center;
  padding: 20px 16px 28px;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.7;
}

.site-footer p { margin: 0; }

.site-footer .footer-rule {
  margin-top: 4px;
  font-size: 0.78rem;
  opacity: 0.92;
}

.site-footer a {
  color: var(--muted);
  text-decoration: none;
}

.site-footer a:hover {
  color: var(--accent);
  text-decoration: underline;
}

.history-wrap h2 {
  margin: 0;
  font-size: 1rem;
  font-weight: 650;
}

.history-toolbar {
  justify-content: flex-start;
  margin-bottom: 12px;
}

.history-toolbar h2 {
  margin-right: auto;
}

.history-list {
  display: grid;
  gap: 10px;
}

.history-item {
  display: grid;
  grid-template-columns: 72px 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
}

.history-thumbs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2px;
  width: 72px;
  height: 72px;
  border-radius: 8px;
  overflow: hidden;
  background: #eef4f8;
}

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

.history-thumbs.single {
  grid-template-columns: 1fr;
}

.history-meta {
  min-width: 0;
}

.history-meta strong {
  display: block;
  font-size: 0.92rem;
  margin-bottom: 4px;
}

.history-meta p {
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.45;
}

.history-empty {
  text-align: center;
  color: var(--muted);
  padding: 28px 12px;
  border: 1px dashed var(--line);
  border-radius: 12px;
  background: rgba(255,255,255,0.45);
}
