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

:root {
  --bg: #fafafa;
  --surface: #ffffff;
  --surface2: #f5f5f5;
  --border: #e5e5e5;
  --border2: #d4d4d4;
  --accent: #2563eb;
  --accent-light: rgba(37, 99, 235, 0.08);
  --accent-hover: #1d4ed8;
  --danger: #dc2626;
  --danger-light: #fef2f2;
  --success: #16a34a;
  --success-light: #f0fdf4;
  --text: #111111;
  --text2: #555555;
  --muted: #888888;
  --muted2: #aaaaaa;
  --radius: 8px;
  --radius-sm: 5px;
  --shadow: 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.06);
}

html, body { height: 100%; }
body {
  font-family: 'Inter', -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  font-size: 14px;
  overflow: hidden;
}

/* Header - OpenHub branded */
.app-header {
  background: rgba(250, 250, 250, 0.85);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid #f0f0f0;
  padding: 0 24px;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  z-index: 100;
}
.header-brand { display: flex; align-items: center; gap: 10px; }
.header-brand a { text-decoration: none; color: inherit; display: flex; align-items: center; gap: 6px; }
.logo-icon {
  display: inline-grid;
  grid-template-columns: repeat(2, 10px);
  gap: 3px;
  transform: rotate(45deg);
  margin-right: 4px;
}
.logo-icon span { width: 10px; height: 10px; border-radius: 2px; background: var(--accent); }
.header-title { font-size: 1.25rem; font-weight: 700; letter-spacing: -0.02em; }
.header-title .tool-name { font-weight: 200; margin-left: 0.35em; }
.header-nav { display: flex; align-items: center; gap: 20px; }
.header-nav a { font-size: 0.9rem; font-weight: 450; color: var(--text2); text-decoration: none; transition: color 0.2s; }
.header-nav a:hover { color: var(--text); }
.badge {
  font-size: 0.7rem; font-weight: 500;
  background: var(--accent-light);
  color: var(--accent); padding: 4px 12px; border-radius: 100px;
}

/* Layout */
.app-main {
  flex: 1;
  display: grid;
  grid-template-columns: 220px 1fr;
  min-height: 0;
}
.panel { background: var(--surface); display: flex; flex-direction: column; overflow: hidden; min-height: 0; }
.panel-left { border-right: 1px solid var(--border); }

/* Sidebar */
.side-head {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.side-label { font-weight: 600; font-size: 0.85rem; }
.count-chip {
  font-size: 0.68rem; background: var(--accent); color: white;
  padding: 1px 7px; border-radius: 100px; font-weight: 600;
}
.add-wrap { margin-left: auto; position: relative; }
.side-add {
  display: inline-flex; align-items: center; gap: 4px;
  font-family: inherit; font-size: 0.72rem; font-weight: 500;
  background: var(--surface2); border: 1px solid var(--border);
  color: var(--text2); padding: 4px 9px; border-radius: var(--radius-sm);
  cursor: pointer; transition: all 0.14s;
}
.side-add:hover, .side-add.open { border-color: var(--accent); color: var(--accent); background: var(--accent-light); }

.add-menu {
  position: absolute; top: calc(100% + 6px); right: 0; z-index: 60;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-md);
  padding: 4px; min-width: 190px; display: none;
}
.add-menu.show { display: block; }
.add-menu button {
  display: flex; align-items: center; gap: 9px; width: 100%;
  padding: 7px 9px; border: none; background: none; cursor: pointer;
  font-family: inherit; font-size: 0.78rem; color: var(--text2);
  border-radius: var(--radius-sm); text-align: left; transition: all 0.13s;
}
.add-menu button:hover { background: var(--surface2); color: var(--text); }
.add-menu button svg { flex-shrink: 0; color: var(--muted); }
.add-menu button:hover svg { color: var(--accent); }
.add-menu-sep { height: 1px; background: var(--border); margin: 4px 2px; }

.thumb-scroll { flex: 1; overflow-y: auto; padding: 12px 10px; }
.thumb-list { display: flex; flex-direction: column; gap: 12px; }
.thumb-card { position: relative; cursor: pointer; user-select: none; }
.thumb-frame {
  border: 2px solid var(--border); border-radius: var(--radius-sm);
  background: white; overflow: hidden;
  display: flex; align-items: center; justify-content: center;
  transition: border-color 0.14s, box-shadow 0.14s;
  box-shadow: var(--shadow);
}
.thumb-card:hover .thumb-frame { border-color: var(--border2); }
.thumb-card.current .thumb-frame { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(37,99,235,0.12); }
.thumb-card.drag-over .thumb-frame { border-color: var(--accent); background: var(--accent-light); }
.thumb-card.dragging-item { opacity: 0.35; }
.thumb-frame canvas { display: block; width: 100%; height: auto; }
.thumb-foot { display: flex; align-items: center; gap: 3px; margin-top: 5px; }
.thumb-num { font-size: 0.68rem; color: var(--muted); font-weight: 500; flex: 1; padding-left: 2px; }
.bxs {
  width: 22px; height: 22px; border-radius: 4px;
  border: 1px solid var(--border); background: var(--surface2);
  color: var(--muted); font-size: 0.72rem; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.13s; line-height: 1; padding: 0; font-family: inherit;
}
.bxs:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-light); }
.bxs.del:hover { border-color: var(--danger); color: var(--danger); background: var(--danger-light); }

/* Privacy note */
.privacy-note {
  display: flex; align-items: flex-start; gap: 8px;
  padding: 11px 14px;
  background: var(--success-light); border-top: 1px solid var(--border);
  font-size: 0.71rem; color: var(--success); line-height: 1.5; flex-shrink: 0;
}
.privacy-note svg { flex-shrink: 0; margin-top: 1px; }

/* Toolbar */
.editor-area { display: flex; flex-direction: column; min-height: 0; background: var(--surface2); }
.toolbar {
  display: flex; align-items: center; gap: 4px;
  padding: 8px 12px;
  background: var(--surface); border-bottom: 1px solid var(--border);
  flex-shrink: 0; flex-wrap: wrap;
}
.tb-btn {
  width: 32px; height: 32px; border-radius: var(--radius-sm);
  border: 1px solid transparent; background: none;
  color: var(--text2); cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  transition: all 0.13s; font-family: inherit; flex-shrink: 0;
}
.tb-btn:hover { background: var(--surface2); color: var(--text); }
.tb-btn.active { background: var(--accent-light); color: var(--accent); border-color: rgba(37,99,235,0.25); }
.tb-btn:disabled { opacity: 0.35; cursor: not-allowed; }
.tb-btn:disabled:hover { background: none; color: var(--text2); }
.tb-sep { width: 1px; height: 22px; background: var(--border); margin: 0 6px; flex-shrink: 0; }
.tb-spacer { flex: 1; }

.tb-opt { display: none; align-items: center; gap: 6px; }
.tb-opt.show { display: inline-flex; }
.tb-opt label { font-size: 0.7rem; color: var(--muted); font-weight: 500; }
.tb-opt input[type="color"] {
  width: 28px; height: 28px; padding: 2px; cursor: pointer;
  border: 1px solid var(--border2); border-radius: var(--radius-sm); background: var(--surface);
}
.tb-opt input[type="number"], .tb-opt select {
  font-family: inherit; font-size: 0.78rem;
  background: var(--surface); border: 1px solid var(--border2);
  color: var(--text); padding: 4px 7px; border-radius: var(--radius-sm); outline: none;
}
.tb-opt input[type="number"] { width: 52px; }
.tb-opt select { max-width: 150px; cursor: pointer; }
.tb-opt input[type="number"]:focus, .tb-opt select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(37,99,235,0.1); }
.tb-opt input[type="range"] { width: 80px; accent-color: var(--accent); cursor: pointer; }

.zoom-val { font-size: 0.74rem; color: var(--text2); min-width: 44px; text-align: center; font-weight: 500; }

.tb-name {
  font-family: inherit; font-size: 0.78rem;
  background: var(--surface); border: 1px solid var(--border2);
  color: var(--text); padding: 5px 9px; border-radius: var(--radius-sm);
  outline: none; width: 120px; transition: border-color 0.14s, box-shadow 0.14s;
}
.tb-name:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(37,99,235,0.1); }

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 13px; border-radius: var(--radius-sm);
  font-family: inherit; font-size: 0.8rem; font-weight: 500;
  cursor: pointer; transition: all 0.14s; border: 1px solid transparent;
}
.btn-primary { background: var(--accent); color: white; border-color: var(--accent); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-primary:disabled { opacity: 0.4; cursor: not-allowed; }

/* Canvas area */
.canvas-wrap { flex: 1; overflow: auto; position: relative; min-height: 0; }
.stage-outer { min-width: 100%; min-height: 100%; display: flex; padding: 28px; }
.page-stage {
  position: relative; margin: auto; flex-shrink: 0;
  box-shadow: 0 2px 12px rgba(0,0,0,0.12), 0 0 0 1px rgba(0,0,0,0.05);
  background: white; border-radius: 2px;
}
.page-stage canvas { display: block; position: absolute; top: 0; left: 0; }
#base-canvas { position: static; }
#overlay-canvas { z-index: 2; }

/* Text edit box */
.text-edit {
  position: absolute; z-index: 5;
  border: 1.5px dashed var(--accent);
  background: rgba(255,255,255,0.85);
  outline: none; resize: none; overflow: hidden;
  font-family: Helvetica, Arial, sans-serif;
  line-height: 1.25; padding: 0; border-radius: 2px;
  min-width: 30px; white-space: pre;
}

/* Empty state / drop zone */
.editor-empty {
  flex: 1; display: flex; align-items: center; justify-content: center; padding: 30px;
}
.upload-zone {
  border: 2px dashed var(--border2); border-radius: var(--radius);
  padding: 52px 60px; text-align: center; cursor: pointer;
  transition: all 0.18s; background: var(--surface); position: relative; overflow: hidden;
  max-width: 420px;
}
.upload-zone:hover, .upload-zone.dragging { border-color: var(--accent); background: var(--accent-light); }
.upload-zone input[type="file"] { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; height: 100%; }
.upload-icon {
  width: 46px; height: 46px;
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 11px; display: flex; align-items: center; justify-content: center;
  margin: 0 auto 12px; font-size: 20px; box-shadow: var(--shadow);
}
.upload-primary { font-size: 0.95rem; font-weight: 600; margin-bottom: 4px; }
.upload-secondary { font-size: 0.78rem; color: var(--muted); margin-bottom: 10px; }
.upload-formats {
  font-size: 0.68rem; color: var(--muted2);
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 100px; padding: 2px 10px; display: inline-block;
}

/* Busy overlay */
.busy {
  position: fixed; inset: 0; z-index: 500;
  background: rgba(250,250,250,0.7); backdrop-filter: blur(2px);
  display: none; align-items: center; justify-content: center;
}
.busy.show { display: flex; }
.busy-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-md);
  padding: 18px 26px; font-size: 0.85rem; font-weight: 500;
  display: flex; align-items: center; gap: 12px;
}
.spin {
  width: 18px; height: 18px; border-radius: 50%;
  border: 2.5px solid var(--border); border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Toast */
.toast-container { position: fixed; bottom: 18px; right: 18px; z-index: 9999; display: flex; flex-direction: column; gap: 6px; }
.toast {
  display: flex; align-items: flex-start; gap: 9px;
  padding: 9px 13px; border-radius: var(--radius-sm); border: 1px solid;
  font-size: 0.77rem; max-width: 290px;
  animation: tin 0.22s ease, tout 0.28s ease 3.2s forwards;
  box-shadow: var(--shadow-md); background: var(--surface);
}
.toast.success { border-color: #86efac; }
.toast.success .ti { color: var(--success); }
.toast.error { border-color: #fca5a5; }
.toast.error .ti { color: var(--danger); }
.toast.info { border-color: #93c5fd; }
.toast.info .ti { color: var(--accent); }
.ti { font-size: 0.82rem; flex-shrink: 0; margin-top: 1px; }
@keyframes tin { from { transform: translateX(18px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes tout { to { opacity: 0; transform: translateY(5px); pointer-events: none; } }

@media (max-width: 680px) {
  .app-main { grid-template-columns: 1fr; }
  .panel-left { display: none; }
  body { overflow: auto; }
}